Skip to content

5 余分に0を埋め込むように #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions txtToCsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import getopt

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

if keyword == '':
if index == -1:
print('can not found keyword from file name...')
sys.exit()

with open(file_name, 'r', encoding='utf-8') as f:
for row in f.readlines():
if row.find(device_code) > -1 and row.find('add device') == -1:
key = str.strip(row[KEY_FROM:KEY_TO])
# pixcel4aの特別のデータを集めないように
if keyword == 'pixcel4a':
# pixel4aの特別のデータを集めないように
if index == 1:
if (key == 'ABS_MT_PRESSURE' and row[VALUE_FROM:VALUE_TO] == '00000000') or (
key == 'ABS_MT_TRACKING_ID' and row[VALUE_FROM:VALUE_TO] == 'ffffffff'):
continue
Expand Down Expand Up @@ -166,6 +167,8 @@ def data_convert(data_json, keys, user_id):
result_data = []
# 行データ
row_data = []
rows = []
max_len = 0;
for i in range(event_count_all):
event_count_in_row += 1
for col in COLUMNS:
Expand All @@ -175,13 +178,20 @@ def data_convert(data_json, keys, user_id):
row_data.append(data_json[col['bind_name']][i])
# イベントがUPの場合
if data_json[EVENT_NAME][i].find(EVENT_VALUE_TO) != -1:
result_data.append(','.join(row_data) + '\n')
# 行データをリセット
row_data = []
rows.append(row_data)
if event_count_in_row > max_event_count_in_row:
max_event_count_in_row = event_count_in_row
max_len = len(row_data)
# カウントをリセット
event_count_in_row = 0
# 行データをリセット
row_data = []

# result_dataの長さを統一する(0を埋め込む)
for row in rows:
if len(row) < max_len:
row.extend(['0'] * (max_len - len(row)))
result_data.append(','.join(row) + '\n')

# 出力ヘッダを作成
result_header = []
Expand Down