forked from sts07142/BTmapping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMOTbetween.py
More file actions
40 lines (31 loc) · 1.13 KB
/
MOTbetween.py
File metadata and controls
40 lines (31 loc) · 1.13 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
# 입력 파일 이름과 출력 파일 이름 설정
input_file = r"BTmapping\transMOT.txt"
output_file = r"BTmapping\MOTbetween.txt"
# 입력 파일 열기
with open(input_file, "r") as f:
lines = f.readlines()
# 출력 파일 열기
with open(output_file, "w") as f:
# 헤더 쓰기
f.write("objectId,time,value\n")
# 각 줄을 파싱하고 변환하여 출력 파일에 쓰기
for line in lines[1:]: # 첫 번째 줄은 헤더이므로 건너뜁니다.
parts = line.strip().split(',')
objectId = parts[0]
first_time = parts[1]
last_time = parts[2]
# objectId, 시간 및 value를 출력 파일에 쓰기
f.write(f"{objectId},{first_time},first\n")
f.write(f"{objectId},{last_time},last\n")
# 입력 파일 열기
with open(output_file, "r") as f:
lines = f.readlines()
# 헤더를 제외한 데이터 정렬
sorted_lines = sorted(lines[1:], key=lambda line: line.split(',')[1])
# 출력 파일 열기
with open(output_file, "w") as f:
# 헤더 쓰기
f.write(lines[0])
# 정렬된 데이터 쓰기
for line in sorted_lines:
f.write(line)