celery 更新
This commit is contained in:
parent
165156aff1
commit
a85fd26d8b
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
@ -24,6 +24,13 @@ def gettime(x=datetime.datetime.now()):
|
||||||
first_day_of_next_month = first_day + datetime.timedelta(days = days_num)
|
first_day_of_next_month = first_day + datetime.timedelta(days = days_num)
|
||||||
return first_day,first_day_of_next_month
|
return first_day,first_day_of_next_month
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def get_wtoken():
|
||||||
|
r=requests.get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx4d75244c1b980b5b&secret=edf7d23a457fb4df5ad47eeb9d4b7a39').text
|
||||||
|
token=json.loads(r)['access_token']
|
||||||
|
with open('D:/safesite/safesite/token.txt','w') as f:
|
||||||
|
f.write(token)
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def send_wechatmsgs(postdict,tolist):
|
def send_wechatmsgs(postdict,tolist):
|
||||||
with open(dirname + 'token.txt','r',encoding= 'utf-8') as f:
|
with open(dirname + 'token.txt','r',encoding= 'utf-8') as f:
|
||||||
|
@ -47,8 +54,7 @@ def send_wechatmsg(postdict):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def yjjs(companyid):
|
def yjjs(companyid, first_day=gettime()[0], first_day_of_next_month=gettime()[1]):
|
||||||
first_day,first_day_of_next_month = gettime()
|
|
||||||
#隐患算分
|
#隐患算分
|
||||||
a = Trouble.objects.filter(fxsj__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
|
a = Trouble.objects.filter(fxsj__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
|
||||||
#隐患按时上报率
|
#隐患按时上报率
|
||||||
|
@ -90,8 +96,7 @@ def yjjs(companyid):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def yjjs_px(companyid):
|
def yjjs_px(companyid, first_day=gettime()[0], first_day_of_next_month=gettime()[1]):
|
||||||
first_day,first_day_of_next_month = gettime()
|
|
||||||
#培训算分
|
#培训算分
|
||||||
a = Train.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效培训
|
a = Train.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效培训
|
||||||
#计算培训效果
|
#计算培训效果
|
||||||
|
@ -121,8 +126,7 @@ def yjjs_px(companyid):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def yjjs_gc(companyid):
|
def yjjs_gc(companyid, first_day=gettime()[0], first_day_of_next_month=gettime()[1]):
|
||||||
first_day,first_day_of_next_month = gettime()
|
|
||||||
#观察算分
|
#观察算分
|
||||||
a = Observe.objects.filter(looktime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
|
a = Observe.objects.filter(looktime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
|
||||||
num = a.count()
|
num = a.count()
|
||||||
|
@ -138,9 +142,8 @@ def yjjs_gc(companyid):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def yjjs_ws(companyid):
|
def yjjs_ws(companyid, first_day=gettime()[0], first_day_of_next_month=gettime()[1]):
|
||||||
#未遂算分
|
#未遂算分
|
||||||
first_day,first_day_of_next_month = gettime()
|
|
||||||
a = Miss.objects.filter(misstime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1) #
|
a = Miss.objects.filter(misstime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1) #
|
||||||
score = (a.count())*0.6
|
score = (a.count())*0.6
|
||||||
year = first_day.year
|
year = first_day.year
|
||||||
|
@ -151,8 +154,7 @@ def yjjs_ws(companyid):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def yjjs_yl(companyid):
|
def yjjs_yl(companyid, first_day=gettime()[0], first_day_of_next_month=gettime()[1]):
|
||||||
first_day,first_day_of_next_month = gettime()
|
|
||||||
a = Drill.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效演练
|
a = Drill.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效演练
|
||||||
#计算演练效果
|
#计算演练效果
|
||||||
participantnum = Drill.objects.filter(drillid__in=a).count()
|
participantnum = Drill.objects.filter(drillid__in=a).count()
|
||||||
|
@ -180,6 +182,23 @@ def yjjs_yl(companyid):
|
||||||
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue,2)
|
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue,2)
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def correct_yjz(year:int, month:int, companyid: int = 0):
|
||||||
|
# 重新更新某个月的预警值
|
||||||
|
days_num = calendar.monthrange(year, month)[1]
|
||||||
|
first_day = datetime.date(year, month, 1)
|
||||||
|
first_day_of_next_month = first_day + datetime.timedelta(days = days_num)
|
||||||
|
if companyid == 0:
|
||||||
|
companys = Partment.objects.filter(iscompany=1)
|
||||||
|
else:
|
||||||
|
companys = Partment.objects.filter(partid=companyid)
|
||||||
|
for i in companys:
|
||||||
|
yjjs(i.id, first_day, first_day_of_next_month)
|
||||||
|
yjjs_px(i.id, first_day, first_day_of_next_month)
|
||||||
|
yjjs_gc(i.id, first_day, first_day_of_next_month)
|
||||||
|
yjjs_ws(i.id, first_day, first_day_of_next_month)
|
||||||
|
yjjs_yl(i.id, first_day, first_day_of_next_month)
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def ycjs():
|
def ycjs():
|
||||||
#print('正在执行预测计算。。。')
|
#print('正在执行预测计算。。。')
|
||||||
|
@ -188,7 +207,7 @@ def ycjs():
|
||||||
nowmonth = datetime.datetime.now().month
|
nowmonth = datetime.datetime.now().month
|
||||||
objs = Yjyc.objects.exclude(yjz=0,year=nowyear,month=nowmonth)
|
objs = Yjyc.objects.exclude(yjz=0,year=nowyear,month=nowmonth)
|
||||||
for x in companys:
|
for x in companys:
|
||||||
obj = objs.filter(usecomp=x).order_by('-yjycid')
|
obj = objs.filter(usecomp=x).order_by('-yjycid')[-6:] # 只取半年内的
|
||||||
objv = obj.values('yjycid','yjz')
|
objv = obj.values('yjycid','yjz')
|
||||||
#print(objv)
|
#print(objv)
|
||||||
if len(obj)>1:
|
if len(obj)>1:
|
||||||
|
@ -215,6 +234,7 @@ def ycjs():
|
||||||
objnew.b = ("%.2f" % b)
|
objnew.b = ("%.2f" % b)
|
||||||
objnew.save()
|
objnew.save()
|
||||||
#print('执行完毕!')
|
#print('执行完毕!')
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def risktask():
|
def risktask():
|
||||||
nowtime = datetime.datetime.now()
|
nowtime = datetime.datetime.now()
|
||||||
|
|
Loading…
Reference in New Issue