query lap timestamps
This commit is contained in:
74
src/main.c
74
src/main.c
@@ -2,6 +2,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "lapinfo.h"
|
#include "lapinfo.h"
|
||||||
|
|
||||||
@@ -90,49 +91,60 @@ int main(int argc, char **argv) {
|
|||||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||||
int32_t *col1_data = (int32_t *)duckdb_vector_get_data(col1);
|
int32_t *col1_data = (int32_t *)duckdb_vector_get_data(col1);
|
||||||
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||||
|
idx_t row_count = duckdb_data_chunk_get_size(data_chunk); // number of rows from the data chunk
|
||||||
|
|
||||||
if (duckdb_validity_row_is_valid(col1_validity, 0)) {
|
for (idx_t row = 0; row < row_count; row++) {
|
||||||
lap_count = col1_data[0];
|
if (duckdb_validity_row_is_valid(col1_validity, 0)) {
|
||||||
|
lap_count = col1_data[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duckdb_destroy_data_chunk(&data_chunk);
|
duckdb_destroy_data_chunk(&data_chunk);
|
||||||
duckdb_destroy_result(&lap_count_res);
|
duckdb_destroy_result(&lap_count_res);
|
||||||
|
|
||||||
printf("Lap count: %d\n", lap_count);
|
printf("Lap count: %d\n", lap_count);
|
||||||
|
LapInfo *session_data = malloc(sizeof(LapInfo) * lap_count);
|
||||||
|
|
||||||
LapInfo *session_data;
|
double lap_timestamps[lap_count];
|
||||||
|
memset(lap_timestamps, 0, sizeof(lap_timestamps));
|
||||||
|
|
||||||
LapInfo info = {.lap_number = 0,
|
duckdb_result lap_timestamps_res;
|
||||||
.start_time = 0,
|
if (duckdb_query(conn, "Select ts as DOUBLE from Lap\n", &lap_timestamps_res) == DuckDBError) {
|
||||||
.throttle_pos = {.data_last_index = 0,
|
exit(5);
|
||||||
.data_size = 75000,
|
}
|
||||||
.frequency = 50,
|
|
||||||
.type = FLOAT,
|
|
||||||
.validity = NULL,
|
|
||||||
.data = malloc(sizeof(float) * 75000)},
|
|
||||||
.brake_pos = {.data_last_index = 0,
|
|
||||||
.data_size = 75000,
|
|
||||||
.frequency = 50,
|
|
||||||
.type = FLOAT,
|
|
||||||
.validity = NULL,
|
|
||||||
.data = malloc(sizeof(float) * 75000)},
|
|
||||||
.steering_pos = {.data_last_index = 0,
|
|
||||||
.data_size = 75000,
|
|
||||||
.frequency = 50,
|
|
||||||
.type = FLOAT,
|
|
||||||
.validity = NULL,
|
|
||||||
.data = malloc(sizeof(float) * 75000)},
|
|
||||||
.speed = {.data_last_index = 0,
|
|
||||||
.data_size = 75000,
|
|
||||||
.frequency = 50,
|
|
||||||
.type = FLOAT,
|
|
||||||
.validity = NULL,
|
|
||||||
.data = malloc(sizeof(float) * 75000)}};
|
|
||||||
|
|
||||||
get_data_from_db("Select * from \"Throttle Pos\"\n", &conn, &info.throttle_pos);
|
int current_index = 0;
|
||||||
|
while (true) {
|
||||||
|
duckdb_data_chunk data_chunk_2 = duckdb_fetch_chunk(lap_timestamps_res);
|
||||||
|
if (!data_chunk_2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
destroyLapinfo(&info);
|
idx_t current_chunk_size = duckdb_data_chunk_get_size(data_chunk_2);
|
||||||
|
|
||||||
|
duckdb_vector col2 = duckdb_data_chunk_get_vector(data_chunk_2, 0);
|
||||||
|
double *ts_data = (double *)duckdb_vector_get_data(col2);
|
||||||
|
uint64_t *col2_validity = duckdb_vector_get_validity(col2);
|
||||||
|
|
||||||
|
for (idx_t row = 0; row < current_chunk_size; row++) {
|
||||||
|
if (!col2_validity || duckdb_validity_row_is_valid(col2_validity, row)) {
|
||||||
|
if (current_index < lap_count) {
|
||||||
|
lap_timestamps[current_index++] = ts_data[row];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
duckdb_destroy_data_chunk(&data_chunk_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
duckdb_destroy_result(&lap_timestamps_res);
|
||||||
|
|
||||||
|
for (int i = 0; i < lap_count; i++) {
|
||||||
|
printf("%f, ", lap_timestamps[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
free(session_data);
|
||||||
printf("Shutting down HardCompound!\n");
|
printf("Shutting down HardCompound!\n");
|
||||||
|
|
||||||
printf("Closing database and any connection.\n");
|
printf("Closing database and any connection.\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user