0
TypeError: 'int' object has no attribute 'getitem', 1 # rows.append([error, str(dct['value']), str(dct['uniques']),類型錯誤: 'INT' 對象沒有屬性 '__getitem__',rows.append([出錯,STR(DCT [ '值']),STR(DCT [ '不重複']),
不知道爲什麼我正在錯誤#類型錯誤:「詮釋」對象有沒有屬性「的GetItem」,1#
def errors_to_csv(errors):
rows = [HEADER]
for error, dct in errors.items():
rows.append([error, str(dct['value']), str(dct['uniques']),
str(dct['percentage_total']),
str(dct['percentage_runs']), str(dct['links'][:10]),
str(dct['additional_info'][:11])])
if error == 'runs':
continue
return rows
def capture_data_in_json(product, recipients, runtype, startdate, enddate):
errors = dd(lambda: {'value': 0, 'uniques': 0, 'percentage_total': None,
'percentage_runs': None, 'links': [],
'additional_info': []})
last_runs = get_last_n_runs(product, RESULTS_LIMIT, runtype, RUN_STATUS, startdate, enddate)
#last_runs += get_last_n_runs(product, RESULTS_LIMIT, 'distributed-test',
#RUN_STATUS, startdate, enddate)
log.info('Collected {0} runs'.format(len(last_runs)))
outputs = [get_file_from_uuid('console.log', run['uuid']) for run in last_runs]
log.info('Outputs collected')
for output, link in outputs:
current = dd(lambda: 0)
lines = output.split('\n')
for index, line in enumerate(lines):
line = ''.join([i for i in line if not i.isdigit()])
if '[ERROR]' in line:
errors[line]['value'] += 1
errors[line]['links'] += [link]
errors[line]['additional_info'] += lines[index - 5: index + 5]
if line not in current.keys():
current[line] += 1
for line in current.keys():
errors[line]['uniques'] += 1
total_errors = sum([errors[error]['value'] for error in errors.keys()])
for error in errors.keys():
errors[error]['percentage_total'] = round(100.0 * errors[error]['value']/total_errors, 2)
errors[error]['percentage_runs'] = round(100.0 * errors[error]['uniques']/len(last_runs), 2)
log.info('Analyzed {0} runs.'.format(len(outputs)))
errors['runs'] = len(outputs)
with open('data_' + product + '.json', 'w+') as out_file:
json.dump(errors, out_file)
return errors