import os, sys
import pandas as pd
import numpy as np
sys.path.append('..')
import modules.coordsi as csi
import math
import time

# initialize root path
root = './List_Data_Call/'

summary_1 = csi.summaryOriginCoord(root, camid=1)

#make a loop for each index
for index, row in summary_1.iterrows():
    timestamp = []
    start_time = time.time()
    df = csi.readCam(os.path.join(index,'cam1.csv'))
    df = csi.convertToSI(df, 3.5, 1.5, 3.4)
    df = csi.getVelocity(df)
    df = csi.getAcceleration(df)
    df = csi.getFullTrace(df,row['approx_total_frame'] )
    df = csi.addValidDetection(df, 25.0)
    try:
        df.to_csv(os.path.join('./handletrace/', index[17:]+'.csv'), index=False)
    #save spend time and index of summary_1 in timestamp list    
        timestamp.append([index, time.time() - start_time])
        print([index, time.time() - start_time])
    except Exception as e:
        print(e)
        continue
#save timestamp list to csv file
pd.DataFrame(timestamp, columns=['index', 'time']).to_csv('./handletrace/timestamp.csv', index=False)