d1c086a8 by 周伟奇

modify bs statistics

1 parent c8a6639d
...@@ -8,6 +8,7 @@ from django.core.management import BaseCommand ...@@ -8,6 +8,7 @@ from django.core.management import BaseCommand
8 from settings import conf 8 from settings import conf
9 from common.mixins import LoggerMixin 9 from common.mixins import LoggerMixin
10 from apps.doc import consts 10 from apps.doc import consts
11 from apps.doc.models import HILDoc, AFCDoc
11 12
12 13
13 class Command(BaseCommand, LoggerMixin): 14 class Command(BaseCommand, LoggerMixin):
...@@ -40,17 +41,30 @@ class Command(BaseCommand, LoggerMixin): ...@@ -40,17 +41,30 @@ class Command(BaseCommand, LoggerMixin):
40 print('log_path not exists') 41 print('log_path not exists')
41 return 42 return
42 43
43 wb = Workbook() 44 summary_dict = {}
44 ws = wb.get_sheet_by_name('Sheet')
45 ws.title = date_str
46 ws.append(('版式', '数目'))
47
48 with open(log_path, 'r', encoding='utf-8') as fp: 45 with open(log_path, 'r', encoding='utf-8') as fp:
49 for line in fp: 46 for line in fp:
50 search_obj = re.search(r'(\d{1,2}):(\d+)', line) 47 search_obj = re.search(r'task=(.*) merged_bs_summary=(.*)', line)
51 classify = search_obj.group(1) 48 task_str = search_obj.group(1)
52 count = search_obj.group(2) 49 business_type, doc_id_str = task_str.split(consts.SPLIT_STR)
53 label = consts.CLASSIFY_LIST[int(classify)][0] 50 doc_id = int(doc_id_str)
54 ws.append((label, int(count))) 51 doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc
52 application_id = doc_class.objects.filter(id=doc_id).values_list('application_id', flat=True)
55 53
54 bs_summary_str = search_obj.group(2)
55 new_bs_summary_str = re.sub(r'datetime.date\(\d+, \d+, \d+\)', 'None', bs_summary_str)
56 bs_summary = ast.literal_eval(new_bs_summary_str)
57 for value_dict in bs_summary.values():
58 classify = value_dict.get('classify')
59 if classify is None:
60 continue
61 summary_dict.setdefault(classify, []).append(application_id[0])
62
63 wb = Workbook()
64 wb.remove(wb.get_sheet_by_name('Sheet'))
65 for classify, application_id_list in summary_dict.items():
66 sheet_name = consts.CLASSIFY_LIST[classify][0]
67 ws = wb.create_sheet(sheet_name)
68 for application_id in application_id_list:
69 ws.append((application_id, None))
56 wb.save(excel_path) 70 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!