Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
4313988b
Commit
4313988b
authored
May 31, 2016
by
Claes Sjofors
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sev_server, read values adapted to deadband linear regr
parent
8aa690d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
40 deletions
+140
-40
sev/lib/sev/src/sev_dbms.cpp
sev/lib/sev/src/sev_dbms.cpp
+139
-40
sev/lib/sev/src/sev_dbms.h
sev/lib/sev/src/sev_dbms.h
+1
-0
No files found.
sev/lib/sev/src/sev_dbms.cpp
View file @
4313988b
...
@@ -1514,56 +1514,82 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
...
@@ -1514,56 +1514,82 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
}
}
if
(
item
.
options
&
pwr_mSevOptionsMask_Event
)
{
if
(
item
.
options
&
pwr_mSevOptionsMask_Event
)
{
total_rows
=
atoi
(
row
[
4
]);
total_rows
=
atoi
(
row
[
4
]);
}
else
if
(
starttime
&&
endtime
)
{
pwr_tTime
update_time
;
if
(
row
[
12
])
timestr_to_time
(
row
[
12
],
&
update_time
);
if
(
time_Acomp
(
creatime
,
&
stime
)
==
1
)
stime
=
*
creatime
;
if
(
row
[
12
]
&&
time_Acomp
(
&
etime
,
&
update_time
)
==
1
)
etime
=
update_time
;
time_Adiff
(
&
dt
,
&
etime
,
&
stime
);
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
div
=
total_rows
/
maxsize
+
1
;
div
=
total_rows
/
maxsize
+
1
;
}
}
else
if
(
starttime
)
{
else
if
(
item
.
options
&
pwr_mSevOptionsMask_UseDeadBand
&&
pwr_tTime
update_time
;
item
.
options
&
pwr_mSevOptionsMask_DeadBandLinearRegr
)
{
if
(
row
[
12
])
int
startid
;
timestr_to_time
(
row
[
12
],
&
update_time
);
int
endid
;
else
time_GetTime
(
&
update_time
);
if
(
time_Acomp
(
&
update_time
,
starttime
)
!=
1
)
{
if
(
starttime
)
{
mysql_free_result
(
result
);
// Get id for starttime
*
sts
=
SEV__NODATATIME
;
*
sts
=
get_closest_time
(
item
.
tablename
,
item
.
options
,
starttime
,
1
,
&
startid
);
return
0
;
}
}
time_Adiff
(
&
dt
,
&
update_time
,
starttime
);
else
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
startid
=
0
;
}
if
(
endtime
)
{
else
if
(
endtime
)
{
// Get id for starttime
pwr_tTime
create_time
;
*
sts
=
get_closest_time
(
item
.
tablename
,
item
.
options
,
endtime
,
0
,
&
endid
);
timestr_to_time
(
row
[
11
],
&
create_time
);
if
(
endid
==
0
)
endid
=
atoi
(
row
[
4
]);
if
(
time_Acomp
(
endtime
,
&
create_time
)
!=
1
)
{
mysql_free_result
(
result
);
*
sts
=
SEV__NODATATIME
;
return
0
;
}
}
time_Adiff
(
&
dt
,
endtime
,
&
create_time
);
else
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
endid
=
atoi
(
row
[
4
]);
printf
(
"startid %d, endid %d
\n
"
,
startid
,
endid
);
div
=
(
endid
-
startid
+
1
)
/
maxsize
+
1
;
}
}
else
{
else
{
total_rows
=
atoi
(
row
[
4
]);
if
(
starttime
&&
endtime
)
{
pwr_tTime
update_time
;
if
(
row
[
12
])
timestr_to_time
(
row
[
12
],
&
update_time
);
if
(
time_Acomp
(
creatime
,
&
stime
)
==
1
)
stime
=
*
creatime
;
if
(
row
[
12
]
&&
time_Acomp
(
&
etime
,
&
update_time
)
==
1
)
etime
=
update_time
;
time_Adiff
(
&
dt
,
&
etime
,
&
stime
);
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
div
=
total_rows
/
maxsize
+
1
;
}
else
if
(
starttime
)
{
pwr_tTime
update_time
;
if
(
row
[
12
])
timestr_to_time
(
row
[
12
],
&
update_time
);
else
time_GetTime
(
&
update_time
);
if
(
time_Acomp
(
&
update_time
,
starttime
)
!=
1
)
{
mysql_free_result
(
result
);
*
sts
=
SEV__NODATATIME
;
return
0
;
}
time_Adiff
(
&
dt
,
&
update_time
,
starttime
);
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
}
else
if
(
endtime
)
{
pwr_tTime
create_time
;
timestr_to_time
(
row
[
11
],
&
create_time
);
if
(
time_Acomp
(
endtime
,
&
create_time
)
!=
1
)
{
mysql_free_result
(
result
);
*
sts
=
SEV__NODATATIME
;
return
0
;
}
time_Adiff
(
&
dt
,
endtime
,
&
create_time
);
total_rows
=
int
(
time_DToFloat
(
0
,
&
dt
)
/
scantime
);
}
else
{
total_rows
=
atoi
(
row
[
4
]);
}
div
=
total_rows
/
maxsize
+
1
;
}
}
mysql_free_result
(
result
);
mysql_free_result
(
result
);
div
=
total_rows
/
maxsize
+
1
;
if
(
starttime
)
{
if
(
starttime
)
{
*
sts
=
time_AtoAscii
(
&
stime
,
time_eFormat_NumDateAndTime
,
starttimstr
,
*
sts
=
time_AtoAscii
(
&
stime
,
time_eFormat_NumDateAndTime
,
starttimstr
,
...
@@ -3169,6 +3195,58 @@ int sev_dbms::check_deadband(pwr_eType type, unsigned int size, pwr_tFloat32 dea
...
@@ -3169,6 +3195,58 @@ int sev_dbms::check_deadband(pwr_eType type, unsigned int size, pwr_tFloat32 dea
return
deadband_active
;
return
deadband_active
;
}
}
int
sev_dbms
::
get_closest_time
(
char
*
tablename
,
unsigned
int
options
,
pwr_tTime
*
time
,
int
before
,
int
*
id
)
{
char
query
[
200
];
pwr_tStatus
sts
;
char
timstr
[
20
];
sts
=
time_AtoAscii
(
time
,
time_eFormat_NumDateAndTime
,
timstr
,
sizeof
(
timstr
));
if
(
EVEN
(
sts
))
return
sts
;
timstr
[
19
]
=
0
;
if
(
options
&
pwr_mSevOptionsMask_PosixTime
)
{
if
(
before
)
sprintf
(
query
,
"select id from %s where time <= %ld order by time desc limit 1"
,
tablename
,
(
long
int
)
time
->
tv_sec
);
else
sprintf
(
query
,
"select id from %s where time >= %ld order by time asc limit 1"
,
tablename
,
(
long
int
)
time
->
tv_sec
);
}
else
{
if
(
before
)
sprintf
(
query
,
"select id from %s where time <= '%s' order by time desc limit 1"
,
tablename
,
timstr
);
else
sprintf
(
query
,
"select id from %s where time >= '%s' order by time asc limit 1"
,
tablename
,
timstr
);
}
int
rc
=
mysql_query
(
m_env
->
con
(),
query
);
if
(
rc
)
{
printf
(
"In %s row %d:
\n
"
,
__FILE__
,
__LINE__
);
printf
(
"%s Query Error
\n
"
,
__FUNCTION__
);
return
SEV__DBERROR
;
}
MYSQL_ROW
row
;
MYSQL_RES
*
result
=
mysql_store_result
(
m_env
->
con
());
if
(
!
result
)
{
printf
(
"In %s row %d:
\n
"
,
__FILE__
,
__LINE__
);
printf
(
"%s Status Result Error
\n
"
,
__FUNCTION__
);
return
SEV__DBERROR
;
}
row
=
mysql_fetch_row
(
result
);
if
(
!
row
)
{
*
id
=
0
;
}
else
*
id
=
atoi
(
row
[
0
]);
mysql_free_result
(
result
);
return
1
;
}
int
sev_dbms
::
get_objectvalues
(
pwr_tStatus
*
sts
,
sev_item
*
item
,
int
sev_dbms
::
get_objectvalues
(
pwr_tStatus
*
sts
,
sev_item
*
item
,
unsigned
int
size
,
pwr_tTime
*
starttime
,
pwr_tTime
*
endtime
,
unsigned
int
size
,
pwr_tTime
*
starttime
,
pwr_tTime
*
endtime
,
int
maxsize
,
pwr_tTime
**
tbuf
,
void
**
vbuf
,
unsigned
int
*
bsize
)
int
maxsize
,
pwr_tTime
**
tbuf
,
void
**
vbuf
,
unsigned
int
*
bsize
)
...
@@ -3227,6 +3305,27 @@ int sev_dbms::get_objectvalues( pwr_tStatus *sts, sev_item *item,
...
@@ -3227,6 +3305,27 @@ int sev_dbms::get_objectvalues( pwr_tStatus *sts, sev_item *item,
if
(
item
->
options
&
pwr_mSevOptionsMask_Event
)
{
if
(
item
->
options
&
pwr_mSevOptionsMask_Event
)
{
total_rows
=
atoi
(
row
[
4
]);
total_rows
=
atoi
(
row
[
4
]);
}
}
else
if
(
item
->
options
&
pwr_mSevOptionsMask_UseDeadBand
&&
item
->
options
&
pwr_mSevOptionsMask_DeadBandLinearRegr
)
{
int
startid
;
int
endid
;
if
(
starttime
)
{
// Get id for starttime
*
sts
=
get_closest_time
(
item
->
tablename
,
item
->
options
,
starttime
,
1
,
&
startid
);
}
else
startid
=
0
;
if
(
endtime
)
{
// Get id for starttime
*
sts
=
get_closest_time
(
item
->
tablename
,
item
->
options
,
endtime
,
0
,
&
endid
);
}
else
endid
=
atoi
(
row
[
4
]);
printf
(
"startid %d, endid %d
\n
"
,
startid
,
endid
);
div
=
(
endid
-
startid
+
1
)
/
maxsize
+
1
;
}
else
if
(
starttime
&&
endtime
)
{
else
if
(
starttime
&&
endtime
)
{
pwr_tTime
update_time
;
pwr_tTime
update_time
;
if
(
row
[
12
])
if
(
row
[
12
])
...
...
sev/lib/sev/src/sev_dbms.h
View file @
4313988b
...
@@ -206,6 +206,7 @@ class sev_dbms : public sev_db {
...
@@ -206,6 +206,7 @@ class sev_dbms : public sev_db {
void
add_cache
(
int
item_idx
);
void
add_cache
(
int
item_idx
);
int
begin_transaction
();
int
begin_transaction
();
int
commit_transaction
();
int
commit_transaction
();
int
get_closest_time
(
char
*
tablename
,
unsigned
int
options
,
pwr_tTime
*
time
,
int
before
,
int
*
id
);
inline
char
*
create_colName
(
unsigned
int
index
,
char
*
attributename
)
{
inline
char
*
create_colName
(
unsigned
int
index
,
char
*
attributename
)
{
static
char
colName
[
constMaxColNameLength
];
static
char
colName
[
constMaxColNameLength
];
strncpy
(
colName
,
attributename
,
constMaxColNameLength
);
strncpy
(
colName
,
attributename
,
constMaxColNameLength
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment