Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb541c3

Browse files
Merge pull request #6 from yangpeng-coder/5-0
5 余分に0を埋め込むように
2 parents 64dccea + 49595f5 commit bb541c3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

txtToCsv.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import getopt
66

77
# キーワード
8-
KEYWORD_LIST = ['huawei', 'pixcel4a']
8+
KEYWORD_LIST = ['huawei', 'pixel4a']
99
# 処理ファイルに項目名のindex
1010
KEY_FROM = 50
1111
KEY_TO = 68
@@ -97,17 +97,18 @@ def create_data_from_file(file_name, keyword, device_code):
9797
data_json = {'TIME': []}
9898
keys = []
9999
i = 0
100+
index = KEYWORD_LIST.index(keyword);
100101

101-
if keyword == '':
102+
if index == -1:
102103
print('can not found keyword from file name...')
103104
sys.exit()
104105

105106
with open(file_name, 'r', encoding='utf-8') as f:
106107
for row in f.readlines():
107108
if row.find(device_code) > -1 and row.find('add device') == -1:
108109
key = str.strip(row[KEY_FROM:KEY_TO])
109-
# pixcel4aの特別のデータを集めないように
110-
if keyword == 'pixcel4a':
110+
# pixel4aの特別のデータを集めないように
111+
if index == 1:
111112
if (key == 'ABS_MT_PRESSURE' and row[VALUE_FROM:VALUE_TO] == '00000000') or (
112113
key == 'ABS_MT_TRACKING_ID' and row[VALUE_FROM:VALUE_TO] == 'ffffffff'):
113114
continue
@@ -166,6 +167,8 @@ def data_convert(data_json, keys, user_id):
166167
result_data = []
167168
# 行データ
168169
row_data = []
170+
rows = []
171+
max_len = 0;
169172
for i in range(event_count_all):
170173
event_count_in_row += 1
171174
for col in COLUMNS:
@@ -175,13 +178,20 @@ def data_convert(data_json, keys, user_id):
175178
row_data.append(data_json[col['bind_name']][i])
176179
# イベントがUPの場合
177180
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)
181182
if event_count_in_row > max_event_count_in_row:
182183
max_event_count_in_row = event_count_in_row
184+
max_len = len(row_data)
183185
# カウントをリセット
184186
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')
185195

186196
# 出力ヘッダを作成
187197
result_header = []

0 commit comments

Comments
 (0)