-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathV2_read_csv_analyze_difference.py
178 lines (132 loc) · 7.58 KB
/
V2_read_csv_analyze_difference.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 7 15:45:23 2022
@author: chen_hung
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
from sklearn.preprocessing import MinMaxScaler
def get_video_seconds(path):
df = pd.read_excel(path, header = None)
seconds_data = df[0].tolist()
score_data = df[2].tolist()
seconds_correspond_score={seconds_data[i]:score_data[i] for i in range(len(score_data))}
reg ,record_1,record_2 = 0, None, None
for i,data in enumerate(score_data):
if(i>0):
if (not(np.isnan(data)) and reg==0):
record_1 = int(seconds_data[i])
reg = 1
if(np.isnan(data) and reg==1):
record_2 = int(seconds_data[i-1])
reg = 0
print("秒數:{}-{}".format(record_1,record_2))
return seconds_correspond_score,[record_1,record_2]
#%%
if __name__ == "__main__":
#path = r'H:\.shortcut-targets-by-id\1vItTjppV9Gfw1svIRJVJtjZ9JFG4OgDB\IRB拍攝影片\模板\110 11-12月\(7)20211209 江妮芝 吳曉語St\正面\20211209_bad2_正(7).xlsx'
template_path = r'H:\.shortcut-targets-by-id\1vItTjppV9Gfw1svIRJVJtjZ9JFG4OgDB\IRB拍攝影片\模板'
sun = [] #孫
chang = [] #張
file_names = []
index = 0
for month in os.listdir(template_path):#取 9-10月,10-11月
if('月' in month):
#print(month)
template_month_path= os.path.join(template_path,month)
for people in os.listdir(template_month_path):#取 人
if(people != 'desktop.ini'):
people_path= os.path.join(template_month_path,people)
for angle in os.listdir(people_path):#取 正面
if('正' in angle):
#print(angle)
angle_path= os.path.join(people_path,angle)
for file in os.listdir(angle_path):
if('.xlsx' in file ):
#print(file)
file_name = file#.replace('.xlsx','')
file_names.append(file.replace('.xlsx',''))
#print(file_name)
input_path = os.path.join(angle_path,file_name)
print(input_path)
df = pd.read_excel(input_path, header = None,sheet_name=None)
for sheet in list(df.keys()):
#print(df.keys())
seconds_data = df[sheet][0].tolist()
score_data = df[sheet][2].tolist()
seconds_correspond_score={seconds_data[i]:score_data[i] for i in range(len(score_data))}
reg ,record_1,record_2 = 0, None, None
for i,data in enumerate(score_data):
if(i>0):
if (not(np.isnan(data)) and reg==0):
record_1 = int(seconds_data[i])
reg = 1
if(np.isnan(data) and reg==1):
record_2 = int(seconds_data[i-1])
reg = 0
score = [seconds_correspond_score[str(i).zfill(2)] for i in range(record_1,record_2+1)]
max_n,min_n = max(score),min(score)
difference = max_n-min_n
Norm_score = score#[(i-min_n)/difference for i in score]
if(sheet.replace(" ","")=='孫'):
#sun = np.append(sun,score,axis=0)
sun.append(Norm_score)
elif(sheet.replace(" ","")=='張'):
#chang = np.append(chang,score,axis=0)
chang.append(Norm_score)
else:
print(sheet)
'''
#index = 0
X = range(len(sun[index]))
plt.title('{}'.format(index))
plt.plot(X, sun[index], 'r',label='sun')
plt.plot(X, chang[index], 'b',label='chang')
plt.plot(X, (np.array(sun[index])+np.array(chang[index]))/2, 'g',label='mean')
#plt.plot(X, score, 'b')
plt.legend()
plt.show()
index += 1
'''
#%%
max_sun = max(max(sun))
min_sun = min(min(sun))
max_chang = max(max(chang))
min_chang = min(min(chang))
new_sun,new_chang = [],[]
for data in sun:
score = [(i-min_sun)/(max_sun-min_sun) for i in data]
new_sun.append(score)
for data in chang:
score = [(i-min_chang)/(max_chang-min_chang) for i in data]
new_chang.append(score)
#%%
for index in range(len(new_sun)):
file_name_in = file_names[index]
print(file_name_in)
data_path = r'C:\Users\chen_hung\Desktop\長庚科大_數據集\Data\{}.csv'.format(file_name_in)
df_data = pd.read_csv(data_path)
df_data['Scores2'] = np.NaN#pd.Series()
df_data['Scores_combine'] = np.NaN#pd.Series()
set_data_seconds = list(set(df_data['Seconds']))
new_mean = (np.array(new_sun[index])+np.array(new_chang[index]))/2
for i in range(len(df_data)):
search_index = set_data_seconds.index(df_data.loc[i,'Seconds'])
if(search_index<len(sun[index])):
df_data.loc[i,'Scores'] = new_chang[index][search_index]
df_data.loc[i,'Scores2'] = new_sun[index][search_index]
df_data.loc[i,'Scores_combine'] = new_mean[search_index]
df_data.to_csv(r'C:\Users\chen_hung\Desktop\長庚科大_數據集\Data_v2\{}.csv'.format(file_name_in),na_rep="nan", index=False)
'''
for index in range(len(new_sun)):
X = range(len(sun[index]))
plt.title('{}'.format(index))
plt.plot(X, new_sun[index], 'r',label='sun')
plt.plot(X, new_chang[index], 'b',label='chang')
plt.plot(X, (np.array(new_sun[index])+np.array(new_chang[index]))/2, 'g',label='mean')
#plt.plot(X, score, 'b')
plt.legend()
plt.show()
'''