Commit fe8ae8d9 by 杨林龙

优化分摊代码

1 parent e71d8887
...@@ -2,6 +2,7 @@ import logging ...@@ -2,6 +2,7 @@ import logging
import time import time
from datetime import datetime from datetime import datetime
from decimal import Decimal from decimal import Decimal
from itertools import groupby
import MySQLdb import MySQLdb
from dateutil.relativedelta import * from dateutil.relativedelta import *
...@@ -414,6 +415,45 @@ def getMonthDataMap(ft_table, device_id): ...@@ -414,6 +415,45 @@ def getMonthDataMap(ft_table, device_id):
return my_map return my_map
def get_job_id(job_info_data):
return job_info_data[1]
def getMonthDataBigMap(ft_table):
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
SELECT id,device_id,apportionment_date,apportionment_price FROM {ft_table};
"""
logger.info(sql)
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
my_month_big_map = {}
my_dic = [(key, list(group)) for key, group in groupby(result, key=get_job_id)]
for job_id, group_list in my_dic:
my_month_big_map[job_id] = {i[2].strftime("%Y-%m-%d"): i for i in group_list}
return my_month_big_map
def getYearDataBigMap(zj_table):
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
SELECT id,device_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num,jianshao_unit_price,jianshao_total_price
FROM {zj_table} tddz;
"""
logger.info(sql)
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
my_year_big_map = {}
my_dic = [(key, list(group)) for key, group in groupby(result, key=get_job_id)]
for job_id, group_list in my_dic:
my_year_big_map[job_id] = {i[2]: i for i in group_list}
return my_year_big_map
def calculate(base_table, ft_table, zj_table, device_type, service_type, file_name): def calculate(base_table, ft_table, zj_table, device_type, service_type, file_name):
""" """
以结算为维度 以结算为维度
......
# 记录仪 # 记录仪
year_list = [2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028] obd_year_list = [2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028]
range_num = 120 obd_range_num = 120
start_month = "2020-01-01" obd_start_month = "2020-01-01"
# GPS # GPS
# year_list = [2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028] gps_year_list = [2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028]
# range_num = 160 gps_range_num = 160
# start_month = "2017-01-01" gps_start_month = "2017-01-01"
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!