Eg: To get a single point at a given time: http://localhost/api/sensors?id=0&start_time=5&points=1
The binary search means it will either get the closest point before or after the specified time.
Should probably make it so that FindTime will always get the same index given the same input.
Otherwise problems might arise.
Need some more argument checking?
double start_time = -1;
double end_time = -1;
double start_time = -1;
double end_time = -1;
+ double current_time = (now.tv_sec - g_options.start_time.tv_sec) + 1e-6*(now.tv_usec - g_options.start_time.tv_usec);
+ bool points_specified = false;
int query_size = SENSOR_QUERYBUFSIZ;
int start_index = -1;
int end_index = -1;
int query_size = SENSOR_QUERYBUFSIZ;
int start_index = -1;
int end_index = -1;
}
else if (strcmp(key, "points") == 0)
{
}
else if (strcmp(key, "points") == 0)
{
+ points_specified = true;
if (strcmp(value, "all") == 0)
{
query_size = sensor->points_written;
if (strcmp(value, "all") == 0)
{
query_size = sensor->points_written;
status = STATUS_ERROR;
break;
}
status = STATUS_ERROR;
break;
}
+
+ // Treat negative values as being relative to the current time
+ if (start_time < 0)
+ {
+ start_time = current_time + start_time;
+ }
+ start_time = floor(start_time);
}
else if (strcmp(key, "end_time") == 0)
{
}
else if (strcmp(key, "end_time") == 0)
{
Log(LOGERR, "Require a double: %s = %s", key, value);
status = STATUS_ERROR;
break;
Log(LOGERR, "Require a double: %s = %s", key, value);
status = STATUS_ERROR;
break;
+ }
+
+ // Treat negative values as being relative to the current time
+ if (end_time < 0)
+ {
+ end_time = current_time + end_time;
+ }
+ end_time = ceil(end_time);
}
// For backward compatability:
else if (strcmp(key, "dump") == 0)
}
// For backward compatability:
else if (strcmp(key, "dump") == 0)
+ if (end_time < 0 && !points_specified)
end_index = sensor->points_written;
else
{
int count = 0; DataPoint d;
end_index = FindTime(sensor, end_time, &count, &d);
end_index = sensor->points_written;
else
{
int count = 0; DataPoint d;
end_index = FindTime(sensor, end_time, &count, &d);
- //Log(LOGDEBUG, "FindTime - Looked for %f; found [%f,%f] after %d iterations; sensor %d, position %d", end_time, d.time_stamp, d.value, count, sensor->id, end_index);
+ Log(LOGDEBUG, "FindTime - Looked for %f; found [%f,%f] after %d iterations; sensor %d, position %d", end_time, d.time_stamp, d.value, count, sensor->id, end_index);
}
if (start_time < 0)
start_time = 0;
}
if (start_time < 0)
start_time = 0;
{
int count = 0; DataPoint d;
start_index = FindTime(sensor, start_time, &count, &d);
{
int count = 0; DataPoint d;
start_index = FindTime(sensor, start_time, &count, &d);
- //Log(LOGDEBUG, "FindTime - Looked for %f; found [%f,%f] after %d iterations; sensor %d, position %d", start_time, d.time_stamp, d.value, count, sensor->id, start_index);
+ Log(LOGDEBUG, "FindTime - Looked for %f; found [%f,%f] after %d iterations; sensor %d, position %d", start_time, d.time_stamp, d.value, count, sensor->id, start_index);
+
+ if (points_specified)
+ end_index = start_index + query_size;