Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
gm_telemetry_server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christopher Reis
gm_telemetry_server
Commits
a7486a3b
Commit
a7486a3b
authored
May 16, 2017
by
Christopher Reis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added history query
parent
ceaab152
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
dataset.hpp
dataset.hpp
+27
-2
No files found.
dataset.hpp
View file @
a7486a3b
...
@@ -34,6 +34,7 @@ struct measurement {
...
@@ -34,6 +34,7 @@ struct measurement {
};
};
struct
subsystem
{
struct
subsystem
{
std
::
string
server
;
std
::
string
name
;
std
::
string
name
;
std
::
vector
<
measurement
>
v
;
std
::
vector
<
measurement
>
v
;
MYSQL
*
con
=
mysql_init
(
NULL
);
MYSQL
*
con
=
mysql_init
(
NULL
);
...
@@ -45,7 +46,7 @@ struct subsystem {
...
@@ -45,7 +46,7 @@ struct subsystem {
if
(
it
->
name
==
m
){
if
(
it
->
name
==
m
){
it
->
v
=
value
;
it
->
v
=
value
;
it
->
timestamp
=
t
;
it
->
timestamp
=
t
;
std
::
string
insert
=
"INSERT INTO "
+
m
+
" VALUES("
+
value
+
","
+
std
::
to_string
(
t
)
+
");"
;
std
::
string
insert
=
"INSERT INTO "
+
m
+
" VALUES("
+
std
::
to_string
(
t
)
+
","
+
value
+
");"
;
mysql_query
(
con
,
insert
.
c_str
());
mysql_query
(
con
,
insert
.
c_str
());
return
;
return
;
}
}
...
@@ -60,13 +61,37 @@ struct subsystem {
...
@@ -60,13 +61,37 @@ struct subsystem {
std
::
cout
<<
str
<<
'\n'
;
std
::
cout
<<
str
<<
'\n'
;
mysql_query
(
con
,
str
.
c_str
());
mysql_query
(
con
,
str
.
c_str
());
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
str
=
"INSERT INTO "
+
m
+
" VALUES("
+
value
+
","
+
std
::
to_string
(
t
)
+
");"
;
str
=
"INSERT INTO "
+
m
+
" VALUES("
+
std
::
to_string
(
t
)
+
","
+
value
+
");"
;
mysql_query
(
con
,
str
.
c_str
());
mysql_query
(
con
,
str
.
c_str
());
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
std
::
cout
<<
mysql_error
(
con
)
<<
'\n'
;
return
;
return
;
}
}
nlohmann
::
json
getHistory
(
std
::
string
his
){
nlohmann
::
json
json_re
;
nlohmann
::
json
json_val
;
for
(
std
::
vector
<
measurement
>::
iterator
it
=
v
.
begin
();
it
!=
v
.
end
();
++
it
){
if
(
it
->
name
==
his
){
MYSQL
*
c
=
mysql_init
(
NULL
);
mysql_real_connect
(
c
,
server
.
c_str
(),
"root"
,
"root"
,
"gmsec"
,
0
,
NULL
,
0
);
std
::
string
q
=
"SELECT * FROM "
+
his
;
mysql_query
(
c
,
q
.
c_str
());
MYSQL_RES
*
r
=
mysql_store_result
(
c
);
int
num_fields
=
mysql_num_fields
(
r
);
MYSQL_ROW
*
row
;
while
(
row
=
mysql_fetch_row
(
result
)){
json_val
[
"timestamp"
]
=
row
[
0
];
json_val
[
"value"
]
=
row
[
1
];
json_re
[
"value"
]
+=
json_val
;
}
std
::
cout
<<
json_re
.
dump
()
<<
'\n'
;
}
}
return
json_re
;
}
void
connectToDB
(
std
::
string
s
,
std
::
string
prefix
){
void
connectToDB
(
std
::
string
s
,
std
::
string
prefix
){
server
=
s
;
std
::
cout
<<
"Connecting to server "
<<
s
<<
" version: "
<<
mysql_get_client_info
()
<<
'\n'
;
std
::
cout
<<
"Connecting to server "
<<
s
<<
" version: "
<<
mysql_get_client_info
()
<<
'\n'
;
mysql_real_connect
(
con
,
s
.
c_str
(),
"root"
,
"root"
,
"gmsec"
,
0
,
NULL
,
0
);
mysql_real_connect
(
con
,
s
.
c_str
(),
"root"
,
"root"
,
"gmsec"
,
0
,
NULL
,
0
);
std
::
string
test
=
"CREATE TABLE "
+
prefix
+
"(Timestamp TEXT, Value TEXT);"
;
std
::
string
test
=
"CREATE TABLE "
+
prefix
+
"(Timestamp TEXT, Value TEXT);"
;
...
...
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