getting laptime data to know how many lapinfo needs to be allocated
This commit is contained in:
164
src/main.c
164
src/main.c
@@ -7,34 +7,43 @@
|
||||
|
||||
void get_data_from_db(const char *query, duckdb_connection *conn, TelemetryInfo *info) {
|
||||
duckdb_result result;
|
||||
int32_t iterations = 0;
|
||||
int32_t number_of_data_points = 0;
|
||||
|
||||
duckdb_query(*conn, query, &result);
|
||||
|
||||
while (true) {
|
||||
iterations++;
|
||||
|
||||
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result);
|
||||
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;
|
||||
|
||||
// set column
|
||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||
float *col1_data = (float *)duckdb_vector_get_data(col1);
|
||||
void *col1_data = 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)) {
|
||||
// put a switch here based on the info from the struct
|
||||
((float *)info->data)[info->data_last_index] = col1_data[row];
|
||||
info->data_last_index++;
|
||||
// TODO: set info->data_size as capacity at struct creation
|
||||
printf("%f, ", col1_data[row]);
|
||||
switch (info->type) {
|
||||
case FLOAT:
|
||||
((float *)info->data)[info->data_last_index] = ((float *)col1_data)[row];
|
||||
info->data_last_index++;
|
||||
break;
|
||||
case BOOL:
|
||||
((bool *)info->data)[info->data_last_index] = ((bool *)col1_data)[row];
|
||||
info->data_last_index++;
|
||||
break;
|
||||
case DOUBLE:
|
||||
((double *)info->data)[info->data_last_index] = ((double *)col1_data)[row];
|
||||
info->data_last_index++;
|
||||
break;
|
||||
case INT:
|
||||
((int32_t *)info->data)[info->data_last_index] = ((int32_t *)col1_data)[row];
|
||||
info->data_last_index++;
|
||||
break;
|
||||
}
|
||||
// printf("%f, ", ((float *)col1_data)[row]);
|
||||
} else {
|
||||
printf("NULL");
|
||||
}
|
||||
@@ -43,7 +52,6 @@ void get_data_from_db(const char *query, duckdb_connection *conn, TelemetryInfo
|
||||
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);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -67,117 +75,32 @@ int main(int argc, char **argv) {
|
||||
exit(3);
|
||||
}
|
||||
|
||||
const char *channel_tables[] = {"Ambient Temperature",
|
||||
"Brake Pos",
|
||||
"Brake Pos Unfiltered",
|
||||
"Brake Thickness",
|
||||
"Brakes Air Temp",
|
||||
"Brakes Force",
|
||||
"Brakes Temp",
|
||||
"Clutch Pos",
|
||||
"Clutch Pos Unfiltered",
|
||||
"Clutch RPM",
|
||||
"Drag",
|
||||
"Engine Oil Temp",
|
||||
"Engine RPM",
|
||||
"Engine Water Temp",
|
||||
"FFB Output",
|
||||
"Front3rdDeflection",
|
||||
"FrontDownForce",
|
||||
"FrontRideHeight",
|
||||
"FrontWingHeight",
|
||||
"Fuel Level",
|
||||
"G Force Lat",
|
||||
"G Force Long",
|
||||
"G Force Vert",
|
||||
"GPS Latitude",
|
||||
"GPS Longitude",
|
||||
"GPS Speed",
|
||||
"GPS Time",
|
||||
"Ground Speed",
|
||||
"Lap Dist",
|
||||
"Lateral Acceleration",
|
||||
"Longitudinal Acceleration",
|
||||
"OverheatingState",
|
||||
"Path Lateral",
|
||||
"ReadDownForce",
|
||||
"Rear3rdDeflection",
|
||||
"RearRideHeight",
|
||||
"Regen Rate",
|
||||
"RideHeights",
|
||||
"SoC",
|
||||
"Steered Angle",
|
||||
"Steering Pos",
|
||||
"Steering Pos Unfiltered",
|
||||
"Steering Shaft Torque",
|
||||
"Susp Pos",
|
||||
"Throttle Pos",
|
||||
"Throttle Pos Unfiltered",
|
||||
"Time Behind Next",
|
||||
"Total Dist",
|
||||
"Track Edge",
|
||||
"Track Temperature",
|
||||
"Turbo Boost Pressure",
|
||||
"Tyres Wear",
|
||||
"TyresCarcassTemp",
|
||||
"TyresPressure",
|
||||
"TyresRimTemp",
|
||||
"TyresRubberTemp",
|
||||
"TyresTempCentre",
|
||||
"TyresTempLeft",
|
||||
"TyresTempRight",
|
||||
"Virtual Energy",
|
||||
"Wheel Speed",
|
||||
"Wind Heading",
|
||||
"Wind Speed",
|
||||
"Yaw Rate"};
|
||||
// get how many laps is in the session and allocate that many LapInfo-s
|
||||
duckdb_result lap_count_res;
|
||||
int32_t lap_count = 0;
|
||||
duckdb_query(conn, "Select count(value) from Lap\n", &lap_count_res);
|
||||
|
||||
const int channel_table_count = sizeof(channel_tables) / sizeof(channel_tables[0]);
|
||||
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(lap_count_res);
|
||||
if (!data_chunk) {
|
||||
printf("Error in retrieving laps");
|
||||
exit(4);
|
||||
}
|
||||
|
||||
const char *event_tables[] = {"ABS",
|
||||
"ABSLevel",
|
||||
"AntiStall Activated",
|
||||
"Best LapTime",
|
||||
"Best Sector1",
|
||||
"Best Sector2",
|
||||
"Brake Bias Rear",
|
||||
"Brake Migration",
|
||||
"CloudDarkness",
|
||||
"Current LapTime",
|
||||
"Current Sector",
|
||||
"Current Sector1",
|
||||
"Current Sector2",
|
||||
"Engine Max RPM",
|
||||
"Finish Status",
|
||||
"FrontFlapActivated",
|
||||
"FuelMixtureMap",
|
||||
"Gear",
|
||||
"Headlights State",
|
||||
"In Pits",
|
||||
"Lap",
|
||||
"Lap Time",
|
||||
"Last Sector1",
|
||||
"Last Sector2",
|
||||
"LastImpactMagnitude",
|
||||
"LaunchControlActive",
|
||||
"Minimum Path Wetness",
|
||||
"OffpathWetness",
|
||||
"RearFlapActivated",
|
||||
"RearFlapLegalStatus",
|
||||
"Sector1 Flag",
|
||||
"Sector2 Flag",
|
||||
"Sector3 Flag",
|
||||
"Speed Limiter",
|
||||
"SurfaceTypes",
|
||||
"TC",
|
||||
"TCCut",
|
||||
"TCLevel",
|
||||
"TCSlipAngle",
|
||||
"TyresCompound",
|
||||
"WheelsDetached",
|
||||
"Yellow Flag State"};
|
||||
// set column
|
||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||
int32_t *col1_data = (int32_t *)duckdb_vector_get_data(col1);
|
||||
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||
|
||||
const int event_table_count = sizeof(event_tables) / sizeof(event_tables[0]);
|
||||
if (duckdb_validity_row_is_valid(col1_validity, 0)) {
|
||||
lap_count = col1_data[0];
|
||||
}
|
||||
|
||||
duckdb_destroy_data_chunk(&data_chunk);
|
||||
duckdb_destroy_result(&lap_count_res);
|
||||
|
||||
printf("Lap count: %d\n", lap_count);
|
||||
|
||||
LapInfo *session_data;
|
||||
|
||||
LapInfo info = {.lap_number = 0,
|
||||
.start_time = 0,
|
||||
@@ -207,6 +130,7 @@ int main(int argc, char **argv) {
|
||||
.data = malloc(sizeof(float) * 75000)}};
|
||||
|
||||
get_data_from_db("Select * from \"Throttle Pos\"\n", &conn, &info.throttle_pos);
|
||||
|
||||
destroyLapinfo(&info);
|
||||
|
||||
printf("Shutting down HardCompound!\n");
|
||||
|
||||
Reference in New Issue
Block a user