Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
4ea9e9b7
Commit
4ea9e9b7
authored
Apr 14, 2016
by
Michael Ott
Browse files
Use DCDB::TimeStamp for parsing timestamps to facilitate different types of timestamps
Add more debug output
parent
9e65fb84
Changes
1
Hide whitespace changes
Inline
Side-by-side
DCDBCSVImport/dcdbcsvimport.cpp
View file @
4ea9e9b7
/*
* dcdb
benchmark
.cpp
* dcdb
csvimport
.cpp
*
* Created on:
Nov 05
, 201
5
* Author: Axel Auweter
* Created on:
Apr 13
, 201
6
* Author: Axel Auweter
& Michael Ott
*/
#define SENSORS 20
#define INSERTS_PER_SENSOR 100000
#define INSERTS_INTERVAL 1000000000
#define THREADS 4
#define USE_SIN_DATA
#include <iostream>
#include <cstdio>
#include <cstdint>
...
...
@@ -56,17 +50,21 @@ int main(int argc, char** argv)
DCDB
::
SensorConfig
sensorConfig
(
connection
);
DCDB
::
SensorDataStore
sensorDataStore
(
connection
);
/* Insert test data */
std
::
ifstream
fs
;
std
::
string
s
;
std
::
vector
<
std
::
string
>
vec
;
std
::
vector
<
sensor_t
>
sensors
;
std
::
string
csvFilename
=
argv
[
1
];
std
::
string
prefix
=
argv
[
2
];
uint64_t
lineno
=
0
;
fs
.
open
(
argv
[
1
],
std
::
fstream
::
in
);
/* Read header line from CSV to obtain sensor names and topics */
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"Parsing CSV file: "
<<
csvFilename
<<
std
::
endl
;
std
::
cout
<<
"Using sensor name prefix: "
<<
prefix
<<
std
::
endl
;
fs
.
open
(
csvFilename
,
std
::
fstream
::
in
);
std
::
getline
(
fs
,
s
);
lineno
++
;
boost
::
tokenizer
<
boost
::
escaped_list_separator
<
char
>
>
tk
(
s
,
boost
::
escaped_list_separator
<
char
>
(
'\\'
,
','
,
'\"'
));
int
topics
=
0
;
for
(
boost
::
tokenizer
<
boost
::
escaped_list_separator
<
char
>
>::
iterator
i
=
tk
.
begin
();
i
!=
tk
.
end
();
++
i
)
...
...
@@ -93,27 +91,31 @@ int main(int argc, char** argv)
topics
++
;
}
/* Read actual sensor readings */
while
(
std
::
getline
(
fs
,
s
))
{
int
col
=
0
;
uint64_t
ts
=
0
;
lineno
++
;
DCDB
::
TimeStamp
ts
;
boost
::
tokenizer
<
boost
::
escaped_list_separator
<
char
>
>
tk
(
s
,
boost
::
escaped_list_separator
<
char
>
(
'\\'
,
','
,
'\"'
));
for
(
boost
::
tokenizer
<
boost
::
escaped_list_separator
<
char
>
>::
iterator
i
=
tk
.
begin
();
i
!=
tk
.
end
();
++
i
)
{
if
(
0
==
col
)
{
ts
=
std
::
stoull
(
*
i
)
*
1000000
;
ts
=
DCDB
::
TimeStamp
(
*
i
)
;
}
else
{
std
::
cout
<<
ts
<<
" "
<<
sensors
[
col
-
1
].
topic
<<
":"
<<
*
i
<<
std
::
endl
;
//
std::cout << ts
.getRaw()
<< " " << sensors[col-1].topic << ":" << *i << std::endl;
try
{
DCDB
::
SensorId
sid
(
sensors
[
col
-
1
].
topic
);
sensorDataStore
.
insert
(
&
sid
,
ts
,
std
::
stoll
(
*
i
));
sensorDataStore
.
insert
(
&
sid
,
ts
.
getRaw
()
,
std
::
stoll
(
*
i
));
}
catch
(
std
::
exception
&
e
)
{
std
::
c
out
<<
e
.
what
()
<<
":"
<<
*
i
<<
std
::
endl
;
std
::
c
err
<<
"Error parsing CSV line "
<<
lineno
<<
" column "
<<
col
+
1
<<
":
\"
"
<<
*
i
<<
"
\"
"
<<
std
::
endl
;
}
}
col
++
;
}
}
fs
.
close
();
/* Create public sensor names */
std
::
cout
<<
std
::
endl
;
...
...
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