Commit cca2bbf7 authored by lvshibao's avatar lvshibao

数据更新

parent 26eb7051
import os
from inspect_report.cron import team_seat
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.config.settings")
import django
django.setup()
from datetime import datetime
from dateutil.rrule import rrule, DAILY
from src.inspect_report.models import RulesStat, SeatStat, ScoreStat
def data_update_by_date(clazz, date, seat_code_team_name):
create_date = date
agent_names = clazz.objects.filter(create_date=create_date).values_list('agentName', flat=True).distinct()
total_count = 0
for agent_name in agent_names:
count = clazz.objects.filter(create_date=create_date, agentName=agent_name).update(
task=seat_code_team_name.get(agent_name, '未找到团队'))
total_count = total_count + count
print(str(date) + ', 更新' + clazz.Meta.db_table + str(total_count) + '个')
def rule_seat_score_data_update(start_date, end_date):
"""
数据细分后更新数据
:param start_date: %Y-%m-%d格式
:param end_date: %Y-%m-%d格式
:return:
"""
seat_code_team_name = team_seat()
s_date = datetime.strptime(start_date, '%Y-%m-%d')
e_date = datetime.strptime(end_date, '%Y-%m-%d')
seed_dt = list(rrule(DAILY, byweekday=[0, 1, 2, 3, 4, 5, 6], dtstart=s_date, until=e_date))
for date in seed_dt:
for clazz in (RulesStat, SeatStat, ScoreStat):
data_update_by_date(clazz, date, seat_code_team_name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment