【django项目后台开发】数据统计——用户总数统计、日增用户数统计、日活跃用户统计(3)
一、用户总数统计
1、后端接⼝设计
请求⽅式: GET /statistics/total_count/
请求参数: 通过请求头传递jwt token数据。
返回数据: JSON
{ "count": "总⽤户量"}
2、后端代码实现
路由
from django.urls import re_path
from rest_framework_jwt.views import obtain_jwt_token
from .views import users
from .views import statisticsurlpatterns=[re_path('^mg_admin/login/$',obtain_jwt_token),re_path('^statistics/total_count/$',statistics.UserTotalAPIView.as_view()),
视图
from datetime import date
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
from userapp.models import Usersclass UserTotalCountView(APIView):'''获取用户总数'''#指定管理员权限permission_classes=IsAdminUserdef get(self,request):count=Users.objects.all().count()return Response({'count':count})
二、日增用户数统计
1、后端接⼝设计
请求⽅式: GET /statistics/day_increment/
请求参数: 通过请求头传递jwt token数据。
返回数据: JSON
{ "count": "新增⽤户量", }
2、后端代码实现
date_joined 记录创建账户时间
路由
from django.urls import re_path
from rest_framework_jwt.views import obtain_jwt_token
from .views import users
from .views import statisticsurlpatterns=[re_path('^mg_admin/login/$',obtain_jwt_token),re_path('^statistics/day_increment/$',statistics.UserDayCountView.as_view()),
视图
class UserDayCountView(APIView):'''获取日增用户数'''#指定管理员权限permission_classes=IsAdminUserdef get(self,request):#获取当前日期now_today=date.today()year=now_today.yearmonth=now_today.monthday=now_today.daycount=Users.objects.filter(date_joined__year=year,date_joined__month=month,date_joined__day=day)return Response({'count':count})
三、日活跃用户统计
1、后端接⼝设计
请求⽅式:GET /statistics/day_active/
请求参数: 通过请求头传递jwt token数据。
返回数据: JSON
{ "count": "活跃⽤户量"}
2、后端代码实现
路由
from django.urls import re_path
from rest_framework_jwt.views import obtain_jwt_token
from .views import users
from .views import statisticsurlpatterns=[re_path('^mg_admin/login/$',obtain_jwt_token),re_path('^statistics/day_active/$',statistics.UserActiveCountView.as_view()),
]
视图
class UserActiveCountView(APIView):'''获取⽇活跃⽤户数'''#指定管理员权限permission_classes=IsAdminUserdef get(self,request):#获取当前日期now_today=date.today()year=now_today.yearmonth=now_today.monthday=now_today.day# 获取当⽇登录⽤户数量 last_login记录最后登录时间count=User.objects.filter(last_login__year=year,last_login__month=month,last_login__day=day).count()return Response({'count':count})
注意:需要将配置文件中的USE_TZ改为False,才能展示当前时间
上述前端代码实现
data() {return {host:'http://192.168.17.129:8880',token:localStorage.token,username:localStorage.username,userid:localStorage.user_id,stat: [[],]}},computed:{chartLine1() {return this.$echarts.init(Util.getDom('line1'));}},methods: {getOrderCount(){this.$axios.get(this.host +'/statistics/time_order_count/',{headers:{'Authorization': 'JWT ' + this.token}}).then(response=>{this.drawLine1(response.data);}).catch(error=>{console.log(error.response);})},drawLine1(data){let title = "今日和昨日下单量";let option = {title: Object.assign({}, Util.defaultEchartsOpt.title, {text: title}),grid: {top: 60,left: 60,right: 80,bottom: 20,containLabel: true},tooltip: {trigger: 'axis',axisPointer: {lineStyle: {color: '#ddd'}},backgroundColor: 'rgba(255,255,255,1)',padding: [5, 10],textStyle: {color: '#999',},extraCssText: 'box-shadow: 0 0 5px rgba(0,0,0,0.3)'},legend: {top: 15,right: 20,orient: 'vertical',textStyle: {color: "#666"}},xAxis: {type: 'category',data: ['00:00','2:00','4:00','6:00','8:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00'],boundaryGap: false,splitLine: {show: false,interval: 'auto',lineStyle: {color: ['#D4DFF5']}},axisTick: {show: false},axisLine: {lineStyle: {color: '#999'}},axisLabel: {margin: 10,textStyle: {fontSize: 14}}},yAxis: {type: 'value',splitLine: {lineStyle: {color: ['#D4DFF5']}},axisTick: {show: false},axisLine: {lineStyle: {color: '#999'}},axisLabel: {margin: 10,textStyle: {fontSize: 14}}},series: [{name: '今日',type: 'line',smooth: true,showSymbol: false,symbol: 'circle',symbolSize: 4,data: data['t_count_list'],areaStyle: {normal: {color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: 'rgba(199, 237, 250,0.5)'}, {offset: 1,color: 'rgba(199, 237, 250,0.2)'}], false)}},itemStyle: {normal: {color: 'rgba(154, 116, 179, 0.7)'}},lineStyle: {normal: {width: 2}}}, {name: '昨日',type: 'line',smooth: true,showSymbol: false,symbol: 'circle',symbolSize: 4,data: data['y_count_list'],areaStyle: {normal: {color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: 'rgba(216, 244, 247,1)'}, {offset: 1,color: 'rgba(216, 244, 247,1)'}], false)}},itemStyle: {normal: {color: 'rgba(126, 237, 238, 0.7)'}},lineStyle: {normal: {width: 2}}}]};this.chartLine1.setOption(option);return this;},day_active_count(){// 获取日活跃用户总数this.$axios.get(this.host+'/statistics/day_active/',{headers:{'Authorization': 'JWT ' + this.token}}).then(response=>{this.stat[0].splice(2,0,{title: '日活跃用户总数',total: response.data.count,bgColor: '#67c4ed'});}).catch(error=>{console.log(error.response);});},day_increment_count(){// 获取日增用户总数this.$axios.get(this.host+'/statistics/day_increment/',{headers:{'Authorization': 'JWT ' + this.token}}).then(response=>{this.stat[0].splice(1,0,{title: '日增用户总数',total: response.data.count,bgColor: '#3acaa9'});}).catch(error=>{console.log(error.response);});},total_user_count(){// 获取用户总数this.$axios.get(this.host+'/statistics/total_count/',{headers:{'Authorization': 'JWT ' + this.token}}).then(response=>{this.stat[0].splice(0,0,{title: '用户总数',total: response.data.count,bgColor: '#ebcc6f'});}).catch(error=>{console.log(error.response);});},},mounted() { this.total_user_count();this.day_increment_count();this.day_active_count();this.getOrderCount();}}
【django项目后台开发】数据统计——用户总数统计、日增用户数统计、日活跃用户统计(3)相关推荐
- 数据统计之日活跃用户统计
日活跃用户统计 接口分析 请求方式:GET /meiduo_admin/statistical/day_active/ # 日活跃用户统计url(r'^statistical/day_active/$ ...
- 分布式商城项目-后台开发-SSM工程整合网站模板
分布式商城项目-后台开发-SSM工程整合网站模板 我们在JavaWeb开发学习过程中,需要使用到前端的页面,可能很多时候,我们并不擅长于设计UI,比如html,jsp.但又希望自己做出来的程序能够好看 ...
- Redis高级类型(统计全站访问量,日活跃用户)
HyperLogLog(超级日志)(统计访客) 采用一种基数算法,用于完成独立总数的统计 占据空间小,无论统计多少个数据,只占12K的内存空间 不精确的统计算法,标准误差为0.81% Bitmap(位 ...
- 2017微信数据报告:日活跃用户达9亿、日发消息380亿条
1.引言 2017年11月9日,微信团队在成都腾讯全球合作伙伴大会上为全球伙伴解读了最新的<2017微信数据报告>.微信每天有多少条消息被发送?目前有多少个行业已经在使用小程序了?答案尽在 ...
- 互联网日报 | 4月26日 星期一 | 快手二次元日活跃用户突破1亿;小米全球范围内专利达1.9万件;艺龙酒店首家旗舰店在沪开业
今日看点 ✦ 华为云发布沃土计划2021,将投入2.2亿美元支持开发者 ✦ 小米:全球范围内专利达1.9万件,近一半在境外获得 ✦ 快手:二次元日活跃用户突破1亿,将重点发力二次元电商 ✦ OP ...
- 产品思考:如何计算资讯类产品的日活跃用户天花板?
作者:lei 全文共 1834 字 2 图,阅读需要 4 分钟 ---- / BEGIN / ---- 结合市场现状及合理假设,请推算出资讯类 App 日活跃用户数 DAU 的天花板? 前 2 天,一 ...
- Slack:日活跃用户50万人、6周增幅35%造就奇迹
[机器人读报]Slack:日活跃用户50万人.6周增幅35%造就奇迹 机器学习企业应用SaaS大数据云计算机器人读报 width="22" height="16&q ...
- 【产品经理】日活跃用户「MAU」 和月活跃用户「DAU」
日活跃用户「MAU」 和月活跃用户「DAU」 1.日活的概念 一天之内打开某产品的用户数(去重),也就是说一个人打开 100 次,即计算为 1 个日活. 但是 100 个人,每人只开 1 次,也计算为 ...
- centos8部署Django项目---后台运行
参考:https://www.cnblogs.com/yoyoketang/p/10220941.html 一.安装 pip install django 创建项目 django-admin star ...
最新文章
- 1024程序员节 继续薅羊毛
- 27、oracle(三)
- input type 属性
- sklearn的train_test_split,果然很好用啊!
- CMake 常用命令和变量
- 【英语学习】【WOTD】abstruse 释义/词源/示例
- mysql多线程访问总结
- mysql数据库操作语句整合
- php转义还原,PHP中addslashes()和stripslashes()实现字符串转义和还原用法实例_PHP
- Matlab中struct的用法
- ue4联网和多人游戏总结(第二部分)
- 计算机中丨kb表示的字节数是,5mb是多少kb?计算机中5mb是多少字节?2MB表示多少字节?4mb是多少字节...
- AD7705和压力传感器的计算
- 阅兵方阵(蓝桥杯2018真题)
- 经常戴耳机对耳朵有危害?耳机这样用对耳朵伤害最小!
- docker-tags 命令行获取docker远程仓库上指定镜像的tag列表
- 如何在微信中取消已授权的第三方应用APP
- PyQt(Python+Qt)入门:Designer组件属性编辑界面中QWidget类相关属性详解
- 鼠标滚动导航放大缩小
- 【工业相机】【深度3】相机选择-精度和曝光需求计算 - 输入:1 被测试物体的最小体积 2 被测物体的移动相对速度