Selaa lähdekoodia

upload kpi.py

master
Jeong Geol Kim 4 vuotta sitten
vanhempi
commit
72bc76204d
1 muutettua tiedostoa jossa 201 lisäystä ja 0 poistoa
  1. 201
    0
      kpi.py

+ 201
- 0
kpi.py Näytä tiedosto

@@ -0,0 +1,201 @@
1
+import os
2
+import time
3
+import math
4
+import sys
5
+import numpy as np
6
+import pandas as pd
7
+from pandas import DataFrame as df
8
+from sklearn.cluster import DBSCAN
9
+import matplotlib.pyplot as plt
10
+
11
+
12
+ssd_dir = str(sys.argv[1])
13
+file_path = '/hdd/' + ssd_dir[5:]
14
+count = 1
15
+
16
+def get_quad(df):
17
+    if df['x'] >= 0 and df['y'] >= 0:
18
+        return 1
19
+    elif df['x'] >= 0 and df['y'] < 0:
20
+        return 2
21
+    elif df['x'] < 0 and df['y'] < 0:
22
+        return 3
23
+    elif df['x'] < 0 and df['y'] >= 0:
24
+        return 4
25
+def get_inc_num(df):
26
+    global count
27
+    prev_count = 0
28
+    if abs(df['diff_diff']) > 0.0008:                
29
+        prev_count = df['inc_num']
30
+        df['inc_num'] = count
31
+        #print(prev_count)
32
+        return count        
33
+    else:
34
+        if prev_count != 0:            
35
+            count += 1
36
+            df['inc_num'] = 0
37
+            prev_count = df['inc_num']
38
+            return 0
39
+        else:
40
+            df['inc_num'] = 0
41
+            prev_count = df['inc_num']
42
+            return 0
43
+
44
+
45
+def count_inc(df):
46
+    e= 0
47
+    count  = 1
48
+    prev_count = 0
49
+    for x in df['diff_diff']:
50
+        if abs(x) > 8:
51
+            df['inc_num'][e] = count
52
+            prev_count = count
53
+            e +=1
54
+        else:
55
+            if prev_count != 0:
56
+                count += 1
57
+                df['inc_num'][e] = 0
58
+                prev_count = 0
59
+                e +=1
60
+            else:
61
+                df['inc_num'][e] = 0
62
+                prev_count = 0
63
+                e +=1
64
+
65
+def stroke_count(df):
66
+    e = 0
67
+    count = 1    
68
+    for x in df['diff_diff']:
69
+        if x > 1.2:
70
+            df['stroke_count'][e] = count
71
+            e +=1
72
+        else:
73
+            df['stroke_count'][e] = 0
74
+            e+=1
75
+            
76
+def get_sqrt(df):
77
+    e =0
78
+    count = 1
79
+    prev_x = 0.0
80
+    prev_y = 0.0
81
+    prev_z = 0.0
82
+    for x in range(len(df)):
83
+        df['sqrt'][e] = np.sqrt((df['x'][e] - prev_x) **2 + (df['y'][e] - prev_y) ** 2 +(df['z'][e] - prev_z) ** 2)
84
+        prev_x = df['x'][e]
85
+        prev_y = df['y'][e]
86
+        prev_z = df['z'][e]
87
+        e += 1
88
+
89
+        
90
+
91
+
92
+def dist():
93
+    file = os.path.join(file_path, 'coordinate.csv')
94
+    norm = pd.read_csv(file)
95
+    norm = norm.drop(norm.columns[0], axis=1)
96
+    norm = norm.fillna(0)
97
+    data = norm[['x', 'y', 'z']]
98
+    norm['sqrt'] = 0.0
99
+
100
+    get_sqrt(norm)
101
+
102
+    #norm = norm.apply(lambda x:np.sqrt(x) if x.name in ['sqrt'] else x, axis =1)
103
+    norm['diff'] = norm.diff()['sqrt']
104
+    norm['diff_diff'] = norm.diff()['diff']
105
+
106
+
107
+    norm['quad'] = norm.apply(get_quad, axis =1)
108
+    
109
+    
110
+    norm = norm.fillna(0)
111
+
112
+    norm['inc_num'] = 0
113
+    #norm['inc_num'] = norm.apply(get_inc_num, axis = 1)
114
+    count_inc(norm)
115
+    norm['stroke_count'] = 0
116
+    stroke_count(norm)
117
+    
118
+    print('num of inc')
119
+    print(norm['inc_num'].unique())
120
+
121
+    print('total stroke')
122
+    #print(norm['stroke_count'].unique())
123
+    print(norm)
124
+
125
+    
126
+
127
+    plt.plot(norm['frame'],norm['diff_diff'])
128
+    plt.savefig('/sources/diff_diff.png')
129
+
130
+
131
+
132
+    kpi = pd.DataFrame(index=range(0,1))
133
+
134
+    quad_count = norm[norm['stroke_count'] != 0]
135
+    
136
+    quad1_c = quad_count[quad_count['quad'] == 1]
137
+    quad2_c = quad_count[quad_count['quad'] == 2]
138
+    quad3_c = quad_count[quad_count['quad'] == 3]
139
+    quad4_c = quad_count[quad_count['quad'] == 4]
140
+    print(len(quad1_c))
141
+    print(len(quad2_c))
142
+    print(len(quad3_c))
143
+    print(len(quad4_c))
144
+    print(quad1_c)
145
+    kpi['PK'] = ssd_dir[5:] 
146
+    kpi['qaud1_c'] = len(quad1_c)
147
+    kpi['qaud2_c'] = len(quad2_c)
148
+    kpi['qaud3_c'] = len(quad3_c)
149
+    kpi['qaud4_c'] = len(quad4_c)
150
+    kpi['qaud1_s'] = quad1_c['sqrt'].mean() / 30
151
+    kpi['qaud2_s'] = quad2_c['sqrt'].mean() / 30
152
+    kpi['qaud3_s'] = quad3_c['sqrt'].mean() / 30
153
+    kpi['qaud4_s'] = quad4_c['sqrt'].mean() / 30
154
+    kpi['qaud1_d'] = quad1_c['sqrt'].mean() / 45
155
+    kpi['qaud2_d'] = quad2_c['sqrt'].mean() / 45
156
+    kpi['qaud3_d'] = quad3_c['sqrt'].mean() / 45
157
+    kpi['qaud4_d'] = quad4_c['sqrt'].mean() / 45
158
+
159
+
160
+    kpi_1 = {
161
+        "stroke": [len(quad1_c),len(quad2_c),len(quad3_c),len(quad4_c)],
162
+        "velocity": [quad1_c['sqrt'].mean() / 30, quad2_c['sqrt'].mean() / 30, quad3_c['sqrt'].mean() / 30, quad4_c['sqrt'].mean() / 30],
163
+        "depth": [quad1_c['sqrt'].mean() / 45, quad2_c['sqrt'].mean() / 45, quad3_c['sqrt'].mean() / 45, quad4_c['sqrt'].mean() / 45]
164
+    }
165
+
166
+
167
+    print(kpi)
168
+    val_list = []
169
+
170
+    #PK =
171
+    val_list.append(str(ssd_dir[5:-1]))
172
+
173
+    #t_stroke = 
174
+    val_list.append(sum(kpi_1['stroke']))
175
+    #t_vel
176
+    val_list.append("{:.4f}".format(sum(kpi_1['velocity'])/4)) 
177
+    #t_dep
178
+    val_list.append("{:.4f}".format(sum(kpi_1['depth'])/4)) 
179
+    #ud_s_rate =
180
+    val_list.append("{:.4f}".format((kpi_1['stroke'][0] + kpi_1['stroke'][3] - kpi_1['stroke'][1] - kpi_1['stroke'][2]) / sum(kpi_1['stroke'])*100))
181
+    #ud_v_rate =
182
+    val_list.append("{:.4f}".format((kpi_1['velocity'][0] + kpi_1['velocity'][3] - kpi_1['velocity'][1] - kpi_1['velocity'][2])/2))
183
+    #ud_d_rate =
184
+    val_list.append("{:.4f}".format((kpi_1['depth'][0] + kpi_1['depth'][3] - kpi_1['depth'][1] - kpi_1['depth'][2])/2))
185
+
186
+    #lr_s_rate =
187
+    val_list.append("{:.4f}".format((kpi_1['stroke'][2] + kpi_1['stroke'][3] - kpi_1['stroke'][0] - kpi_1['stroke'][1]) / sum(kpi_1['stroke'])*100))
188
+    #lr_v_rate =
189
+    val_list.append("{:.4f}".format((kpi_1['velocity'][2] + kpi_1['velocity'][3] - kpi_1['velocity'][0] - kpi_1['velocity'][1])/2))
190
+    #lr_d_rate =
191
+    val_list.append("{:.4f}".format((kpi_1['depth'][2] + kpi_1['depth'][3] - kpi_1['depth'][0] - kpi_1['depth'][1])/2))
192
+
193
+
194
+    print(val_list)
195
+
196
+
197
+
198
+
199
+
200
+
201
+dist()

Loading…
Peruuta
Tallenna