moving development to master for a while since there is no need for branching yet #8
147
src/main.c
147
src/main.c
@@ -1,58 +1,171 @@
|
||||
#include <duckdb.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int main(int argc, char **argv) {
|
||||
printf("Hello from HardCompound!\n");
|
||||
|
||||
if(argc < 2){
|
||||
if (argc < 2) {
|
||||
printf("You need to specify a duckdb file path! Terminating!\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("First argument: %s\n", argv[1]);
|
||||
|
||||
duckdb_database db;
|
||||
if(duckdb_open(argv[1], &db) == DuckDBError){
|
||||
if (duckdb_open(argv[1], &db) == DuckDBError) {
|
||||
printf("Error opening duckdb file, terminating!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
duckdb_connection conn;
|
||||
if(duckdb_connect(db, &conn) == DuckDBError){
|
||||
if (duckdb_connect(db, &conn) == DuckDBError) {
|
||||
printf("Error connecting to the duckdb database! Terminating!\n");
|
||||
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"};
|
||||
|
||||
//Test query
|
||||
const int channel_table_count =
|
||||
sizeof(channel_tables) / sizeof(channel_tables[0]);
|
||||
|
||||
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"};
|
||||
|
||||
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){
|
||||
while (true) {
|
||||
iterations++;
|
||||
|
||||
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result);
|
||||
|
||||
if(!data_chunk){
|
||||
|
||||
if (!data_chunk) {
|
||||
break;
|
||||
}
|
||||
|
||||
idx_t row_count = duckdb_data_chunk_get_size(data_chunk); //number of rows from the data chunk
|
||||
idx_t row_count = duckdb_data_chunk_get_size(
|
||||
data_chunk); // number of rows from the data chunk
|
||||
number_of_data_points += row_count;
|
||||
|
||||
//first column
|
||||
// first column
|
||||
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
||||
float_t *col1_data = (float_t *) duckdb_vector_get_data(col1);
|
||||
float *col1_data = (float *)duckdb_vector_get_data(col1);
|
||||
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||
|
||||
for (idx_t row = 0; row < row_count; row++) {
|
||||
number_of_data_points++;
|
||||
if(duckdb_validity_row_is_valid(col1_validity, row)){
|
||||
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
||||
printf("%f, ", col1_data[row]);
|
||||
}else{
|
||||
} else {
|
||||
printf("NULL");
|
||||
}
|
||||
}
|
||||
@@ -60,7 +173,8 @@ int main(int argc, char** argv){
|
||||
duckdb_destroy_data_chunk(&data_chunk);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
@@ -71,6 +185,5 @@ int main(int argc, char** argv){
|
||||
duckdb_disconnect(&conn);
|
||||
duckdb_close(&db);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user