Commit 4ea9e9b7 authored by Michael Ott's avatar Michael Ott
Browse files

Use DCDB::TimeStamp for parsing timestamps to facilitate different types of timestamps

Add more debug output
parent 9e65fb84
/*
* dcdbbenchmark.cpp
* dcdbcsvimport.cpp
*
* Created on: Nov 05, 2015
* Author: Axel Auweter
* Created on: Apr 13, 2016
* 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,28 +91,32 @@ 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::cout << e.what() << ":" << *i << std::endl;
std::cerr << "Error parsing CSV line " << lineno << " column " << col+1 << ": \"" << *i << "\"" << std::endl;
}
}
col++;
}
}
fs.close();
/* Create public sensor names */
std::cout << std::endl;
std::cout << "Publishing sensors..." << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment