add message

This commit is contained in:
baoliang 2020-10-22 12:05:23 +08:00
parent e964957abc
commit 3466b6c88b
3 changed files with 50 additions and 26 deletions

View File

@ -210,34 +210,39 @@ class NewMedia(models.Model):
@classmethod @classmethod
def category_one_count(cls): def category_one_count(cls):
t1 = Weixin.objects.exclude( t1 = Weixin.objects.exclude(
status=0,
organization__province='' organization__province=''
).filter( ).filter(
organization__cities='', organization__cities='',
organization__district='' organization__district='',
).count() ).count()
t2 = Weibo.objects.exclude( t2 = Weibo.objects.exclude(
status=0,
organization__province='' organization__province=''
).filter( ).filter(
organization__cities='', organization__cities='',
organization__district='' organization__district='',
).count() ).count()
t3 = Toutiao.objects.exclude( t3 = Toutiao.objects.exclude(
status=0,
organization__province='' organization__province=''
).filter( ).filter(
organization__cities='', organization__cities='',
organization__district='' organization__district='',
).count() ).count()
t4 = Douyin.objects.exclude( t4 = Douyin.objects.exclude(
status=0,
organization__province='' organization__province=''
).filter( ).filter(
organization__cities='', organization__cities='',
organization__district='' organization__district='',
).count() ).count()
t5 = Qita.objects.exclude( t5 = Qita.objects.exclude(
status=0,
organization__province='' organization__province=''
).filter( ).filter(
organization__cities='', organization__cities='',
organization__district='' organization__district='',
).count() ).count()
return t1 + t2 + t3 + t4 + t5 return t1 + t2 + t3 + t4 + t5
@ -245,59 +250,69 @@ class NewMedia(models.Model):
def category_two_count(cls): def category_two_count(cls):
t1 = Weixin.objects.exclude( t1 = Weixin.objects.exclude(
organization__province='', organization__province='',
organization__cities='' organization__cities='',
status=0
).filter( ).filter(
organization__district='' organization__district='',
).count() ).count()
t2 = Weibo.objects.exclude( t2 = Weibo.objects.exclude(
organization__province='', organization__province='',
organization__cities='' organization__cities='',
status=0
).filter( ).filter(
organization__district='' organization__district='',
).count() ).count()
t3 = Toutiao.objects.exclude( t3 = Toutiao.objects.exclude(
organization__province='', organization__province='',
organization__cities='' organization__cities='',
status=0
).filter( ).filter(
organization__district='' organization__district='',
).count() ).count()
t4 = Douyin.objects.exclude( t4 = Douyin.objects.exclude(
organization__province='', organization__province='',
organization__cities='' organization__cities='',
status=0
).filter( ).filter(
organization__district='' organization__district='',
).count() ).count()
t5 = Qita.objects.exclude( t5 = Qita.objects.exclude(
organization__province='', organization__province='',
organization__cities='' organization__cities='',
status=0
).filter( ).filter(
organization__district='' organization__district='',
).count() ).count()
return t1 + t2 + t3 + t4 + t5 return t1 + t2 + t3 + t4 + t5
@classmethod @classmethod
def category_three_count(cls): def category_three_count(cls):
t1 = Weixin.objects.exclude( t1 = Weixin.objects.exclude(
status=0,
organization__province='', organization__province='',
organization__cities='', organization__cities='',
organization__district='' organization__district=''
).count() ).count()
t2 = Weibo.objects.exclude( t2 = Weibo.objects.exclude(
status=0,
organization__province='', organization__province='',
organization__cities='', organization__cities='',
organization__district='' organization__district=''
).count() ).count()
t3 = Toutiao.objects.exclude( t3 = Toutiao.objects.exclude(
status=0,
organization__province='', organization__province='',
organization__cities='', organization__cities='',
organization__district='' organization__district=''
).count() ).count()
t4 = Douyin.objects.exclude( t4 = Douyin.objects.exclude(
status=0,
organization__province='', organization__province='',
organization__cities='', organization__cities='',
organization__district='' organization__district=''
).count() ).count()
t5 = Qita.objects.exclude( t5 = Qita.objects.exclude(
status=0,
organization__province='', organization__province='',
organization__cities='', organization__cities='',
organization__district='' organization__district=''

View File

@ -26,11 +26,11 @@ COMPARTMENTS = {
@csrf_exempt @csrf_exempt
def monitor_statistics(request): def monitor_statistics(request):
wbc = Weibo.objects.count() wbc = Weibo.objects.exclude(status=0).count()
wxc = Weixin.objects.count() wxc = Weixin.objects.exclude(status=0).count()
ttc = Toutiao.objects.count() ttc = Toutiao.objects.exclude(status=0).count()
qtc = Qita.objects.count() qtc = Qita.objects.exclude(status=0).count()
dyc = Douyin.objects.count() dyc = Douyin.objects.exclude(status=0).count()
total = wbc+wxc+ttc+qtc+dyc total = wbc+wxc+ttc+qtc+dyc
chart1_data = [] chart1_data = []
@ -41,10 +41,12 @@ def monitor_statistics(request):
chart1_data.append({'name': '其它', 'value': qtc}) chart1_data.append({'name': '其它', 'value': qtc})
results = dict() results = dict()
q = Weixin.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Weixin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
if not code:
continue
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if code in results: if code in results:
nums = results[compartment] nums = results[compartment]
@ -52,10 +54,12 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Weibo.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Weibo.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
if not code:
continue
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if compartment in results: if compartment in results:
nums = results[compartment] nums = results[compartment]
@ -63,10 +67,12 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Toutiao.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Toutiao.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
if not code:
continue
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if compartment in results: if compartment in results:
nums = results[compartment] nums = results[compartment]
@ -74,10 +80,12 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Douyin.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Douyin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
if not code:
continue
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if compartment in results: if compartment in results:
nums = results[compartment] nums = results[compartment]
@ -85,10 +93,12 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Qita.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Qita.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
if not code:
continue
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if compartment in results: if compartment in results:
nums = results[compartment] nums = results[compartment]
@ -96,7 +106,6 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
chart2_data = [] chart2_data = []
for k in results: for k in results:
chart2_data.append({'name': k, 'value': sum(results[k])}) chart2_data.append({'name': k, 'value': sum(results[k])})