Skip to content
Snippets Groups Projects
Commit 8cf6cd74 authored by Erlend Sørhus's avatar Erlend Sørhus
Browse files

added code and example files for converting from hr.min.sec to only sec

parent 5d1a6f39
Branches csv-timeformat-changer
No related tags found
No related merge requests found
# Programm that takes a csv with timestamps from videofiles in formats hr.min.sec
# or min.sec or sec entrys and converts them to only seconds.
# It needs a groundTruth.csv file as an input. This file should have a header
# with the videofilename
# Example of csv file that will work:
# Myggbukta-101
# 40, 58
# 1.49, 3.56
# 1.10.30, 1.13.45
# The header makes it so in this example you get an outputfile named groundTruthMyggbukta-101.csv
import csv
delimiter = "."
file = open('groundTruth.csv')
csvreader = csv.reader(file)
header = []
header = next(csvreader)
secs = []
for row in csvreader:
newRow = []
for item in row:
newRow.append(sum(int(x) * 60 ** i for i, x in enumerate(reversed(item.split(delimiter))))) #Stack overflow https://stackoverflow.com/questions/6402812/how-to-convert-an-hmmss-time-string-to-seconds-in-python
secs.append(newRow)
file.close
for name in header:
filename = "groundTruth" + name + ".csv"
with open(filename, 'w', newline="") as newFile:
csvwriter = csv.writer(newFile)
#csvwriter.writerow(header)
for row in secs:
csvwriter.writerow(row)
\ No newline at end of file
Myggbukta-[2021-05-21_10-47-06]-716
29, 34
34, 1.26
1.49, 1.57
2.06, 2.12
2.13, 2.31
2.32, 7.28
7.28, 9.02
9.34, 9.45
9.56, 10.00
10.12, 10.21
10.41, 11.13
11.38, 12.07
12.53, 13.14
15.03, 15.08
15.47, 17.27
19.02, 19.20
20.29, 20.51
21.35, 22.17
23.22, 23.36
23.40, 24.11
24.13, 24.29
24.29, 24.58
25.13, 25.43
27.09, 27.46
28.43, 29.00
\ No newline at end of file
29,34
34,86
109,117
126,132
133,151
152,448
448,542
574,585
596,600
612,621
641,673
698,727
773,794
903,908
947,1047
1142,1160
1229,1251
1295,1337
1402,1416
1420,1451
1453,1469
1469,1498
1513,1543
1629,1666
1723,1740
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment