working on separating data by laps
This commit is contained in:
BIN
data/Circuit.duckdb
Normal file
BIN
data/Circuit.duckdb
Normal file
Binary file not shown.
38
src/lapinfo.c
Normal file
38
src/lapinfo.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
BOOL,
|
||||
INT,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
} TelemetryDataType;
|
||||
|
||||
typedef struct {
|
||||
TelemetryDataType type;
|
||||
int8_t frequency;
|
||||
void *data;
|
||||
} TelemetryInfo;
|
||||
|
||||
typedef struct {
|
||||
int lap_number;
|
||||
double start_time;
|
||||
TelemetryInfo throttle_pos;
|
||||
TelemetryInfo brake_pos;
|
||||
TelemetryInfo steering_pos;
|
||||
TelemetryInfo speed;
|
||||
} LapInfo;
|
||||
|
||||
void free_telemetry_info(TelemetryInfo *t) {
|
||||
free(t->data);
|
||||
// free(t);
|
||||
}
|
||||
|
||||
// Dont use for now
|
||||
void destroyLapinfo(LapInfo *info) {
|
||||
free_telemetry_info(&info->throttle_pos);
|
||||
free_telemetry_info(&info->brake_pos);
|
||||
free_telemetry_info(&info->steering_pos);
|
||||
free_telemetry_info(&info->speed);
|
||||
free(info);
|
||||
}
|
||||
59
src/main.c
59
src/main.c
@@ -1,4 +1,5 @@
|
||||
#include <duckdb.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -89,8 +90,7 @@ int main(int argc, char **argv) {
|
||||
"Wind Speed",
|
||||
"Yaw Rate"};
|
||||
|
||||
const int channel_table_count =
|
||||
sizeof(channel_tables) / sizeof(channel_tables[0]);
|
||||
const int channel_table_count = sizeof(channel_tables) / sizeof(channel_tables[0]);
|
||||
|
||||
const char *event_tables[] = {"ABS",
|
||||
"ABSLevel",
|
||||
@@ -135,46 +135,51 @@ int main(int argc, char **argv) {
|
||||
"WheelsDetached",
|
||||
"Yellow Flag State"};
|
||||
|
||||
const int event_table_count =
|
||||
sizeof(event_tables) / sizeof(event_tables[0]);
|
||||
const int event_table_count = sizeof(event_tables) / sizeof(event_tables[0]);
|
||||
|
||||
// Test query
|
||||
duckdb_result result;
|
||||
duckdb_query(conn, "SELECT * from \"Ambient Temperature\";\n", &result);
|
||||
int32_t iterations = 0;
|
||||
int32_t number_of_data_points = 0;
|
||||
|
||||
while (true) {
|
||||
iterations++;
|
||||
for (int i = 0; i < 1 /*channel_table_count*/; i++) {
|
||||
char queryBuffer[256]; // buffer to hold the formatted query
|
||||
|
||||
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result);
|
||||
// snprintf(queryBuffer, sizeof(queryBuffer), "SELECT * FROM \"%s\"\n", channel_tables[i]);
|
||||
|
||||
if (!data_chunk) {
|
||||
break;
|
||||
}
|
||||
// duckdb_query(conn, queryBuffer, &result);
|
||||
duckdb_query(conn, "SELECT CAST(value AS FLOAT) from \"Lap Time\"\n", &result);
|
||||
|
||||
idx_t row_count = duckdb_data_chunk_get_size(
|
||||
data_chunk); // number of rows from the data chunk
|
||||
number_of_data_points += row_count;
|
||||
while (true) {
|
||||
iterations++;
|
||||
|
||||
// first column
|
||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||
float *col1_data = (float *)duckdb_vector_get_data(col1);
|
||||
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result);
|
||||
|
||||
for (idx_t row = 0; row < row_count; row++) {
|
||||
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
||||
printf("%f, ", col1_data[row]);
|
||||
} else {
|
||||
printf("NULL");
|
||||
if (!data_chunk) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
idx_t row_count = duckdb_data_chunk_get_size(data_chunk); // number of rows from the data chunk
|
||||
number_of_data_points += row_count;
|
||||
|
||||
duckdb_destroy_data_chunk(&data_chunk);
|
||||
// set column
|
||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||
float_t *col1_data = (float_t *)duckdb_vector_get_data(col1);
|
||||
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||
|
||||
for (idx_t row = 0; row < row_count; row++) {
|
||||
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
||||
printf("%f, ", col1_data[row]);
|
||||
} else {
|
||||
printf("NULL");
|
||||
}
|
||||
}
|
||||
|
||||
duckdb_destroy_data_chunk(&data_chunk);
|
||||
}
|
||||
duckdb_destroy_result(&result);
|
||||
}
|
||||
|
||||
printf("\nNumber of iterations: %d, number of data points: %d\n",
|
||||
iterations, number_of_data_points);
|
||||
printf("\nNumber of iterations: %d, number of data points: %d\n", iterations, number_of_data_points);
|
||||
|
||||
printf("Shutting down HardCompound!\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user