-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadTextFile.py
More file actions
87 lines (75 loc) · 3.39 KB
/
Copy pathreadTextFile.py
File metadata and controls
87 lines (75 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'''
Manual processing part 1
This file was designed to read the manual annotation made by Nora. The file will read the file and create a csv out of it.
Moreover, each file is assigned to its *.wav file, this way automated analysis is simplified.
The annotation is time noted for the call.
'''
# Author : Hemal Naik
import math
import csv
def find_time_stamp(fifteentime):
mins = math.floor( fifteentime / 60)
totalSecs = math.floor(fifteentime - (mins * 60))
seconds = math.floor(totalSecs/5)*5
return mins, seconds
def read_File(filename):
print("Read files")
filename_without_extension = filename.split(".txt")[0]
filename_with_extension = filename_without_extension + "_modified" + ".txt"
csvFileName = filename_without_extension + "_modified" + ".csv"
csvFileHandler = open(csvFileName,'w', newline= "")
csvWriter = csv.writer(csvFileHandler, delimiter = ",")
#
dataFile = open(filename_with_extension, "w+")
# For identification of file names
wavFilePrefix = "trial1_Chan14_2019-12-09_"
wavFileSuffix = "_ADC05000mV_00dB.wav"
lineCount = 0
with open(filename) as file:
lines = file.readlines()
# Go through everyline
for line in lines:
line = line.rstrip()
listOfValues = line.split("\t")
# find the lines with values (Not header and not empty lines)
if lineCount == 0:
listOfValues.append("soundFileName")
csvWriter.writerow(listOfValues)
elif len(listOfValues)>1 and lineCount != 0:
# Find time of call within 15 min session (Mins and Seconds)
timeOfCall = float(listOfValues[3])
call_mins, base_seconds = find_time_stamp(timeOfCall)
# Find the correct 15 min segment to add mins and seconds
time_stamp = listOfValues[6].split("_")
base_hour = int(time_stamp[0]) # Extract base hour value
base_mins = int(time_stamp[1]) # Extract base min value
total_mins = base_mins + call_mins
#listOfValues.append(str(hour))
#listOfValues.append(str(basemins + mins))
if base_seconds < 10:
base_seconds = "0" + str(base_seconds)
if total_mins < 10:
total_mins = "0"+str(total_mins)
#listOfValues.append(str(base_seconds) )
# Create name of the audio file
audioFileName = wavFilePrefix + str(base_hour) + "-" + str(total_mins) + "-" + str(base_seconds) + wavFileSuffix
listOfValues.append(audioFileName)
# Replace time and date with actual values
date, time = listOfValues[5].split("_")
updatedDateTime = date + "_" + str(base_hour) + "-" + str(total_mins) + "-" + str(base_seconds)
listOfValues[5] = updatedDateTime
print(listOfValues)
dataFile.write(str(listOfValues))
dataFile.write("\n")
# Write in CSV writer
csvWriter.writerow(listOfValues)
else:
print("Error ")
lineCount = lineCount + 1
#
dataFile.close()
if __name__ == '__main__':
"""
"""
name = "D:\\Barn Stuff\\VerificationFile\\trial1_Chan14_2019-12-09_11-15-00to13-00_OnlyVerrifiedCalls.txt"
read_File(name)