# up org on task
This commit is contained in:
parent
1123f2846c
commit
4e55433573
|
@ -58,6 +58,7 @@ class MosqPostStatistic(models.Model):
|
||||||
|
|
||||||
class DevicePostStatistic(models.Model):
|
class DevicePostStatistic(models.Model):
|
||||||
device_id = models.CharField(max_length=100, verbose_name='设备ID')
|
device_id = models.CharField(max_length=100, verbose_name='设备ID')
|
||||||
|
org = models.ForeignKey('Org', verbose_name='所在组织', on_delete='PROTECT')
|
||||||
total = models.PositiveIntegerField(verbose_name='总数')
|
total = models.PositiveIntegerField(verbose_name='总数')
|
||||||
date = models.DateField(auto_now_add=False, verbose_name='日期', unique=False)
|
date = models.DateField(auto_now_add=False, verbose_name='日期', unique=False)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from datetime import datetime, time, timedelta
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from celery import task
|
from celery import task
|
||||||
from counter.models import DeviceCount
|
from counter.models import DeviceCount
|
||||||
from mosquito.models import MosqPostStatistic, DevicePostStatistic
|
from mosquito.models import MosqPostStatistic, DevicePostStatistic, DeviceInfo
|
||||||
|
|
||||||
|
|
||||||
def max_count(x, y):
|
def max_count(x, y):
|
||||||
|
@ -73,6 +73,8 @@ def update_daily_statistic():
|
||||||
|
|
||||||
if device_container:
|
if device_container:
|
||||||
for device_id in device_container:
|
for device_id in device_container:
|
||||||
|
device = DeviceInfo.objects.get(device_id=device_id)
|
||||||
|
org = device.org
|
||||||
container = dict(device_container[device_id])
|
container = dict(device_container[device_id])
|
||||||
full_daily_ret = fill_date(container, tz=pytz.timezone("UTC"))
|
full_daily_ret = fill_date(container, tz=pytz.timezone("UTC"))
|
||||||
|
|
||||||
|
@ -85,9 +87,10 @@ def update_daily_statistic():
|
||||||
obj = None
|
obj = None
|
||||||
if obj:
|
if obj:
|
||||||
obj.total = full_daily_ret[d]
|
obj.total = full_daily_ret[d]
|
||||||
|
obj.org = org
|
||||||
obj.save()
|
obj.save()
|
||||||
else:
|
else:
|
||||||
DevicePostStatistic.objects.create(device_id=device_id, total=full_daily_ret[d], date=d)
|
DevicePostStatistic.objects.create(device_id=device_id, total=full_daily_ret[d], org=org, date=d)
|
||||||
|
|
||||||
# 写入数据库
|
# 写入数据库
|
||||||
if full_ret:
|
if full_ret:
|
||||||
|
|
Loading…
Reference in New Issue