5
5
import getopt
6
6
7
7
# キーワード
8
- KEYWORD_LIST = ['huawei' , 'pixcel4a ' ]
8
+ KEYWORD_LIST = ['huawei' , 'pixel4a ' ]
9
9
# 処理ファイルに項目名のindex
10
10
KEY_FROM = 50
11
11
KEY_TO = 68
@@ -97,17 +97,18 @@ def create_data_from_file(file_name, keyword, device_code):
97
97
data_json = {'TIME' : []}
98
98
keys = []
99
99
i = 0
100
+ index = KEYWORD_LIST .index (keyword );
100
101
101
- if keyword == '' :
102
+ if index == - 1 :
102
103
print ('can not found keyword from file name...' )
103
104
sys .exit ()
104
105
105
106
with open (file_name , 'r' , encoding = 'utf-8' ) as f :
106
107
for row in f .readlines ():
107
108
if row .find (device_code ) > - 1 and row .find ('add device' ) == - 1 :
108
109
key = str .strip (row [KEY_FROM :KEY_TO ])
109
- # pixcel4aの特別のデータを集めないように
110
- if keyword == 'pixcel4a' :
110
+ # pixel4aの特別のデータを集めないように
111
+ if index == 1 :
111
112
if (key == 'ABS_MT_PRESSURE' and row [VALUE_FROM :VALUE_TO ] == '00000000' ) or (
112
113
key == 'ABS_MT_TRACKING_ID' and row [VALUE_FROM :VALUE_TO ] == 'ffffffff' ):
113
114
continue
@@ -166,6 +167,8 @@ def data_convert(data_json, keys, user_id):
166
167
result_data = []
167
168
# 行データ
168
169
row_data = []
170
+ rows = []
171
+ max_len = 0 ;
169
172
for i in range (event_count_all ):
170
173
event_count_in_row += 1
171
174
for col in COLUMNS :
@@ -175,13 +178,20 @@ def data_convert(data_json, keys, user_id):
175
178
row_data .append (data_json [col ['bind_name' ]][i ])
176
179
# イベントがUPの場合
177
180
if data_json [EVENT_NAME ][i ].find (EVENT_VALUE_TO ) != - 1 :
178
- result_data .append (',' .join (row_data ) + '\n ' )
179
- # 行データをリセット
180
- row_data = []
181
+ rows .append (row_data )
181
182
if event_count_in_row > max_event_count_in_row :
182
183
max_event_count_in_row = event_count_in_row
184
+ max_len = len (row_data )
183
185
# カウントをリセット
184
186
event_count_in_row = 0
187
+ # 行データをリセット
188
+ row_data = []
189
+
190
+ # result_dataの長さを統一する(0を埋め込む)
191
+ for row in rows :
192
+ if len (row ) < max_len :
193
+ row .extend (['0' ] * (max_len - len (row )))
194
+ result_data .append (',' .join (row ) + '\n ' )
185
195
186
196
# 出力ヘッダを作成
187
197
result_header = []
0 commit comments