Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save el-hoshino/00f8dd0c46c7b71f4caa29680c531b7f to your computer and use it in GitHub Desktop.
Save el-hoshino/00f8dd0c46c7b71f4caa29680c531b7f to your computer and use it in GitHub Desktop.
A converting python script that converts a CSV file produced from RaceChrono Pro format to general Telemetry Overlay format. Created with ChatGPT: https://chat.openai.com/share/7c8e8f2c-60ee-4024-86cd-bc82a3b3c06c
import pandas as pd
import argparse
def process_file(input_file_path, output_file_path):
# Read the file line by line until we find the header row starting with 'timestamp'
with open(input_file_path, 'r') as file:
lines = file.readlines()
# Get the line number where 'timestamp' is found
line_number = next(i for i, line in enumerate(lines) if line.lower().startswith('timestamp'))
# Get the title row as a list of strings
title_row = lines[line_number].strip().split(',')
# Load the CSV file again, skipping the rows up to the title row, and also skip the subsequent 2 rows (for units and source)
df = pd.read_csv(input_file_path, skiprows=range(line_number + 3), header=None)
# Assign the correct column names
df.columns = title_row
# Drop duplicate columns, keeping only the last occurrence
df = df.loc[:, ~df.columns.duplicated(keep='last')]
# Create 'utc (ms)' column by multiplying 'timestamp' by 1000 and converting to integer
df['utc (ms)'] = (df['timestamp'] * 1000).astype(int)
# Rename the specified columns
df.rename(columns={
'altitude': 'alt (m)',
'latitude': 'lat (deg)',
'longitude': 'lon (deg)',
'rpm': 'engine (rpm)'
}, inplace=True)
# Save the updated DataFrame to a new CSV file
df.to_csv(output_file_path, index=False)
print(f"Processed file saved to: {output_file_path}")
def main():
parser = argparse.ArgumentParser(description='Process CSV data file.')
parser.add_argument('-i', '--input', required=True, help='Input CSV file path')
parser.add_argument('-o', '--output', required=True, help='Output CSV file path')
args = parser.parse_args()
process_file(args.input, args.output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment