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

Skip to content

Commit 49595f5

Browse files
データがない部分に0を埋め込むように
1 parent a1298f9 commit 49595f5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

txtToCsv.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def data_convert(data_json, keys, user_id):
167167
result_data = []
168168
# 行データ
169169
row_data = []
170+
rows = []
171+
max_len = 0;
170172
for i in range(event_count_all):
171173
event_count_in_row += 1
172174
for col in COLUMNS:
@@ -176,13 +178,20 @@ def data_convert(data_json, keys, user_id):
176178
row_data.append(data_json[col['bind_name']][i])
177179
# イベントがUPの場合
178180
if data_json[EVENT_NAME][i].find(EVENT_VALUE_TO) != -1:
179-
result_data.append(','.join(row_data) + '\n')
180-
# 行データをリセット
181-
row_data = []
181+
rows.append(row_data)
182182
if event_count_in_row > max_event_count_in_row:
183183
max_event_count_in_row = event_count_in_row
184+
max_len = len(row_data)
184185
# カウントをリセット
185186
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')
186195

187196
# 出力ヘッダを作成
188197
result_header = []

0 commit comments

Comments
 (0)