分析按时间段查询

This commit is contained in:
caoqianming 2021-02-21 23:23:39 +08:00
parent 925cf5fbd7
commit 596293d45a
3 changed files with 121 additions and 69 deletions

View File

@ -15,31 +15,35 @@ export function searchCandidates(data) {
})
}
export function getAdmindata1() {
export function getAdmindata1(query) {
//各管理员录入学员数
return request({
url: '/analyse/admindata1/',
method: 'get',
params: query
})
}
export function getCompanydis() {
export function getCompanydis(query) {
return request({
url: '/analyse/companydis/',
method: 'get',
params: query
})
}
export function getConsumerdis() {
export function getConsumerdis(query) {
return request({
url: '/analyse/consumerdis/',
method: 'get',
params: query
})
}
export function getMonitest() {
export function getMonitest(query) {
return request({
url: '/analyse/monitest/',
method: 'get',
params: query
})
}

View File

@ -1,68 +1,106 @@
<template>
<div class="app-container">
<el-card>
<bar-chart :chartData="admindata1" />
</el-card>
<el-row :gutter="6" style="margin-top:6px">
<el-col :xs="24" :md="12">
<el-card>
<china-map :chartData="companydis" />
</el-card>
</el-col>
<el-col :xs="24" :md="12">
<el-card>
<china-map :chartData="consumerdis" />
</el-card>
</el-col>
</el-row>
<el-card style="margin-top:6px">
<line-chart :chartData="monidata" />
</el-card>
<div class="app-container">
<div style="margin-bottom: 2px">
<el-date-picker
v-model="daterange"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
>
</el-date-picker>
<el-button type="primary" icon="el-icon-query" @click="handleFilter"
>确定</el-button
>
</div>
<el-card>
<bar-chart :chartData="admindata1" />
</el-card>
<el-row :gutter="6" style="margin-top: 6px">
<el-col :xs="24" :md="12">
<el-card>
<china-map :chartData="companydis" />
</el-card>
</el-col>
<el-col :xs="24" :md="12">
<el-card>
<china-map :chartData="consumerdis" />
</el-card>
</el-col>
</el-row>
<el-card style="margin-top: 6px">
<line-chart :chartData="monidata" />
</el-card>
</div>
</template>
<script>
import BarChart from '../components/BarChart'
import ChinaMap from '../components/ChinaMap'
import LineChart from '../components/LineChart'
import { getAdmindata1, getCompanydis, getConsumerdis, getMonitest } from '@/api/analyse'
import BarChart from "../components/BarChart";
import ChinaMap from "../components/ChinaMap";
import LineChart from "../components/LineChart";
import {
getAdmindata1,
getCompanydis,
getConsumerdis,
getMonitest,
} from "@/api/analyse";
import { option } from 'runjs';
export default {
components:{BarChart, ChinaMap, LineChart},
data(){
return {
admindata1:{},
companydis:{},
consumerdis:{},
monidata:{}
}
components: { BarChart, ChinaMap, LineChart },
data() {
return {
admindata1: {},
companydis: {},
consumerdis: {},
monidata: {},
daterange: [],
query: { datestart: null, dateend: null },
pickerOptions: null,
};
},
created() {
this.initquery();
},
methods: {
initquery() {
let date = new Date();
this.query.datestart = date.getFullYear() + "-01-01";
this.query.dateend = date.getFullYear() + 1 + "-01-01";
this.daterange = [this.query.datestart, this.query.dateend];
this.getadmindata1(this.query);
this.getcompanydis(this.query);
this.getconsumerdis(this.query);
this.getmonitest(this.query);
},
created(){
this.getadmindata1()
this.getcompanydis()
this.getconsumerdis()
this.getmonitest()
handleFilter() {
this.query.datestart = this.daterange[0];
this.query.dateend = this.daterange[1];
this.getadmindata1(this.query);
this.getcompanydis(this.query);
this.getconsumerdis(this.query);
this.getmonitest(this.query);
},
methods:{
getadmindata1(){
getAdmindata1().then(res=>{
this.admindata1 = res.data
})
},
getcompanydis(){
getCompanydis().then(res=>{
this.companydis = res.data
})
},
getconsumerdis(){
getConsumerdis().then(res=>{
this.consumerdis = res.data
})
},
getmonitest(){
getMonitest().then(res=>{
this.monidata = res.data
})
}
}
}
getadmindata1(query) {
getAdmindata1(query).then((res) => {
this.admindata1 = res.data;
});
},
getcompanydis(query) {
getCompanydis(query).then((res) => {
this.companydis = res.data;
});
},
getconsumerdis(query) {
getConsumerdis(query).then((res) => {
this.consumerdis = res.data;
});
},
getmonitest(query) {
getMonitest(query).then((res) => {
this.monidata = res.data;
});
},
},
};
</script>

View File

@ -32,8 +32,9 @@ class Admindata1(APIView):
各管理员录入学员数-柱状图
"""
def get(self, request, format=None):
queryset = UserProfile.objects.filter(is_delete=False)
ret = {'x':{'name':'管理员', 'data':[]}, 's':[{'name':'学员数', 'data':[]}], 't':'各管理员录入学员数'}
tmp = UserProfile.objects.filter(is_delete=False).annotate(total=Count('consumer_create_admin')).order_by('-total').values('username', 'total')
tmp = queryset.annotate(total=Count('consumer_create_admin')).order_by('-total').values('username', 'total')
for i in tmp:
ret['x']['data'].append(i['username'])
ret['s'][0]['data'].append(i['total'])
@ -47,8 +48,10 @@ class Monitest(APIView):
def get(self, request):
ret = {'x':{'name':'月份', 'data':[]}, 's':[{'name':'模考数', 'data':[]}], 't':'趋势图', 'l':['模考数']}
# ret = {'x':{'name':'月份', 'data':[]}, 's':[{'name':'自助模考', 'data':[]}, {'name':'押卷模考', 'data':[]}], 't':'模考次数趋势图', 'l':['自助模考', '押卷模考']}
tmp = ExamTest.objects.exclude(consumer__create_admin__isnull=True)\
.annotate(create_month=ExtractMonth('create_time'), create_year=ExtractYear('create_time'))\
queryset = ExamTest.objects.exclude(consumer__create_admin__isnull=True)
queryset = queryset.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else queryset
queryset = queryset.filter(create_time__lte = request.query_params.get('dateend')) if request.query_params.get('dateend', None) else queryset
tmp = queryset.annotate(create_month=ExtractMonth('create_time'), create_year=ExtractYear('create_time'))\
.values('create_month', 'create_year').order_by('create_year', 'create_month').annotate(total=Count('create_month'))
for i in tmp:
# if str(i['create_year'])+'年'+str(i['create_month'])+'月' not in ret['x']['data']:
@ -101,7 +104,10 @@ class Companydis(APIView):
"""
def get(self, request, format=None):
ret = {'s':[], 't':'单位分布', 'max':800, 'min':0}
tmp = Company.objects.exclude(geo__pname__isnull=True).values('geo__pname').annotate(total=Count('geo__pname'))
queryset = Company.objects.exclude(geo__pname__isnull=True)
queryset = queryset.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else queryset
queryset = queryset.filter(create_time__lte = request.query_params.get('dateend')) if request.query_params.get('dateend', None) else queryset
tmp = queryset.values('geo__pname').annotate(total=Count('geo__pname'))
for i in tmp:
if i['geo__pname'] in nameMap:
ret['s'].append({'name':nameMap[i['geo__pname']], 'value':i['total']})
@ -113,11 +119,15 @@ class Consumerdis(APIView):
"""
def get(self, request, format=None):
ret = {'s':[], 't':'学员分布', 'max':3000, 'min':0}
tmp = Consumer.objects.exclude(company__geo__pname__isnull=True).values('company__geo__pname').annotate(total=Count('company__geo__pname'))
queryset = Consumer.objects.exclude(company__geo__pname__isnull=True)
queryset = queryset.filter(create_time__gte = request.query_params.get('datestart')) if request.query_params.get('datestart', None) else queryset
queryset = queryset.filter(create_time__lte = request.query_params.get('dateend')) if request.query_params.get('dateend', None) else queryset
tmp = queryset.values('company__geo__pname').annotate(total=Count('company__geo__pname'))
for i in tmp:
if i['company__geo__pname'] in nameMap:
ret['s'].append({'name':nameMap[i['company__geo__pname']], 'value':i['total']})
return Response(ret)
class Quota(APIView):
'''
获取考试名额