Commit ae32094b authored by Michael Ott's avatar Michael Ott
Browse files

Add option to drop constant values in import

parent 3ec6ad95
......@@ -57,6 +57,7 @@ typedef struct {
std::string topic;
std::string publicName;
uint64_t count;
uint64_t prev;
} sensor_t;
void usage(int argc, char* argv[])
......@@ -66,6 +67,7 @@ void usage(int argc, char* argv[])
std::cout << " -t <col> - Column in the CSV that contains the timestamp [default: 0]" << std::endl;
std::cout << " -n <col> - Sensor name column" << std::endl;
std::cout << " -c <col[,col,col]> - Column in the CSV to use [default: all]" << std::endl;
std::cout << " -d - Drop constant values" << std::endl;
std::cout << " -s <offset> - MQTT suffix start value [default: 0]" << std::endl;
std::cout << " -p - Publish sensors" << std::endl;
......@@ -129,9 +131,10 @@ int main(int argc, char** argv)
int suffixStart = 0;
int tsColumn = 0;
std::set<int> columns;
bool dropConstantValues = false;
bool publish = false;
int sensorNameColumn = -1;
while ((ret=getopt(argc, argv, "+h:t:n:c:s:pv:"))!=-1) {
while ((ret=getopt(argc, argv, "+h:t:n:c:ds:pv:"))!=-1) {
switch(ret) {
case 'h':
host = optarg;
......@@ -148,6 +151,9 @@ int main(int argc, char** argv)
for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i=tk.begin(); i!=tk.end();++i)
columns.insert(std::stoi(*i));
} break;
case 'd':
dropConstantValues = true;
break;
case 's':
suffixStart = atoi(optarg);
std::cout << ret << ": " << optarg << std::endl;
......@@ -294,8 +300,13 @@ int main(int argc, char** argv)
}
try {
DCDB::SensorId sid(sensor->topic);
sensorDataStore.insert(&sid, ts.getRaw(), std::stoll(*i));
sensor->count++;
uint64_t val = std::stoll(*i);
if (!dropConstantValues || val != sensor->prev) {
sensorDataStore.insert(&sid, ts.getRaw(), val);
sensor->count++;
sensor->prev = val;
count++;
}
}
catch (std::exception &e) {
if (verbose > 1) {
......@@ -303,7 +314,6 @@ int main(int argc, char** argv)
}
}
total++;
count++;
if (total % 1000 == 0) {
time_t t1 = time(NULL);
if (t1 != t0) {
......
Markdown is supported
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