MeasurementEvaluator/MeasurementConverter.py
hoernschen 52e328122d Init
2020-11-05 16:58:11 +01:00

31 lines
1.1 KiB
Python

import os
import glob
from pathlib import Path
import pandas as pd
import time
from datetime import datetime
csv_dir = "/home/hoernschen/cloud/Studium/Master/Masterthesis/Messungen/"
output_dir = "/home/hoernschen/workspace/python/MeasurementConverter/"
def format_timestamp(ts):
time_string = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(ts)))
#time = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
time_string = time_string + "." + str(int(ts)%1000).zfill(3)
return time_string
measurement_files = Path(csv_dir).rglob('*.csv')
for measurement_file in measurement_files:
if "Messung" or "Network" in measurement_file.name:
continue
print(measurement_file.name)
csv_data = pd.read_csv(measurement_file.absolute())
new_csv_data = []
for data in csv_data.to_numpy():
new_csv_data.append([format_timestamp(data[1]),"startTestrun"])
new_csv_data.append([format_timestamp(data[2]),"stopTestrun"])
new_csv = pd.DataFrame(new_csv_data)
new_csv.to_csv(output_dir + measurement_file.name,header=False, index=False)