d1c086a8 by 周伟奇

modify bs statistics

1 parent c8a6639d
......@@ -8,6 +8,7 @@ from django.core.management import BaseCommand
from settings import conf
from common.mixins import LoggerMixin
from apps.doc import consts
from apps.doc.models import HILDoc, AFCDoc
class Command(BaseCommand, LoggerMixin):
......@@ -40,17 +41,30 @@ class Command(BaseCommand, LoggerMixin):
print('log_path not exists')
return
wb = Workbook()
ws = wb.get_sheet_by_name('Sheet')
ws.title = date_str
ws.append(('版式', '数目'))
summary_dict = {}
with open(log_path, 'r', encoding='utf-8') as fp:
for line in fp:
search_obj = re.search(r'(\d{1,2}):(\d+)', line)
classify = search_obj.group(1)
count = search_obj.group(2)
label = consts.CLASSIFY_LIST[int(classify)][0]
ws.append((label, int(count)))
search_obj = re.search(r'task=(.*) merged_bs_summary=(.*)', line)
task_str = search_obj.group(1)
business_type, doc_id_str = task_str.split(consts.SPLIT_STR)
doc_id = int(doc_id_str)
doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc
application_id = doc_class.objects.filter(id=doc_id).values_list('application_id', flat=True)
bs_summary_str = search_obj.group(2)
new_bs_summary_str = re.sub(r'datetime.date\(\d+, \d+, \d+\)', 'None', bs_summary_str)
bs_summary = ast.literal_eval(new_bs_summary_str)
for value_dict in bs_summary.values():
classify = value_dict.get('classify')
if classify is None:
continue
summary_dict.setdefault(classify, []).append(application_id[0])
wb = Workbook()
wb.remove(wb.get_sheet_by_name('Sheet'))
for classify, application_id_list in summary_dict.items():
sheet_name = consts.CLASSIFY_LIST[classify][0]
ws = wb.create_sheet(sheet_name)
for application_id in application_id_list:
ws.append((application_id, None))
wb.save(excel_path)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!