график

This commit is contained in:
iriska-gri committed 2024-02-28 16:46:03 +03:00
1 parent 2ad0211d5f
commit 5f47f0682b
5 files changed
+139 -50

No files matched your search

@@ -1,20 +1,47 @@
<template> <template>
<v-card class="h-100 "> <v-card class="h-100 ">
<line-graph v-if="data!==null" :data="data" :options="options"/> <!-- <line-graph v-if="data!==null" :data="data" ref ='linear' :options="options"/> -->
<Line v-if="data!==null" :data="data" ref ='linear' :options="options" />
</v-card> </v-card>
</template> </template>
<script> <script>
import lineGraph from '@/components/graph/line-graph.vue' // import lineGraph from '@/components/graph/line-graph.vue'
import moment from 'moment'
import {computed, onMounted, ref, watch } from 'vue' import {computed, onMounted, ref, watch } from 'vue'
import { usePortalFilterStore } from '@/store/AboutPortalFilter'
import {formatComa, splitname} from '@/utils/universal_functions' import {formatComa, splitname} from '@/utils/universal_functions'
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
TimeScale
} from 'chart.js'
import { Line } from 'vue-chartjs'
import ChartDataLabels from 'chartjs-plugin-datalabels'
import 'chartjs-adapter-moment'
ChartJS.register(
ChartDataLabels,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
TimeScale
)
export default { export default {
components: { components: {
lineGraph, Line,
}, },
props: { props: {
@@ -23,10 +50,16 @@ export default {
default: () => {} default: () => {}
}, },
period: {
type: Object,
default: () => {}
}
}, },
setup(props, {emit}) { setup(props, {emit}) {
const filterStore = usePortalFilterStore()
const between = ref(0)
const arrlines = { const arrlines = {
// labels: [''], // labels: [''],
datasets: [ datasets: [
@@ -57,35 +90,38 @@ export default {
yAxisID: 'y' yAxisID: 'y'
} }
, ,
// { {
// label: 'CRR', label: 'CRR',
// backgroundColor: '#673AB7', backgroundColor: '#673AB7',
// borderColor: '#673AB7', borderColor: '#673AB7',
// borderWidth: 3, borderWidth: 3,
// cubicInterpolationMode: 'monotone', cubicInterpolationMode: 'monotone',
// data: [], data: [],
// func: (val)=>{return val}, func: (val, key)=>{ return crrfunc(key)
// hidden: true, },
// datakey: "crr", hidden: true,
// customlabel: [], datakey: "crr",
// tooltips: true, customlabel: [],
tooltips: true,
yAxisID: 'y1'
// } }
// , ,
// { {
// label: 'BR', label: 'BR',
// backgroundColor: '#283593', backgroundColor: '#283593',
// borderColor: '#283593', borderColor: '#283593',
// borderWidth: 3, borderWidth: 3,
// cubicInterpolationMode: 'monotone', cubicInterpolationMode: 'monotone',
// data: [], data: [],
// func: (val)=>{return val}, func: (val)=>{return parseFloat((val.br/val.unic.length*100).toFixed(2))},
// datakey: "br", datakey: "br",
// hidden: true, hidden: true,
// customlabel: [], customlabel: [],
// tooltips: true tooltips: true,
// } yAxisID: 'y1'
// , }
,
{ {
label: 'PPV', label: 'PPV',
backgroundColor: '#EF9A9A', backgroundColor: '#EF9A9A',
@@ -102,37 +138,82 @@ export default {
} }
] ]
} }
const datachanged=()=> { const dataf=computed({get() {
fullpercreate()
let data1 = moment(filterStore.date_period.enddate)
let data2 = moment(filterStore.date_period.startdate)
between.value = data1.diff(data2, 'days') + 1
let res = null let res = null
console.log("sdssdss");
if (Object.keys(props.dataLineChart).length>0){ if (Object.keys(props.dataLineChart).length>0){
res = arrlines res = arrlines
res.labels=[] res.labels=[]
console.log(props.dataLineChart, 'uuuuuuuuuuuuuuuuuuuuuu'); // console.log(props.dataLineChart, 'uuuuuuuuuuuuuuuuuuuuuu');
for(let [key,val] of Object.entries(props.dataLineChart)) for(let [key,val] of Object.entries(props.dataLineChart))
{ {
res.datasets.forEach((e) => { res.datasets.forEach((e) => {
e.data.push(e.func(val)) e.data.push(e.func(val,key))
// e.data = [10,20,30] // e.data = [10,20,30]
}); });
res.labels.push(formatComa(key)) res.labels.push(formatComa(key))
} }
console.log(res, "kdjshskjhd");
// console.log(fullper.value,"reeeeeeee"); // console.log(res, "kdjshskjhd");
} }
// res.datasets[1].data=[] // res.datasets[1].data=[]
// console.log(res,"reeeeeeee");
return res return res
}})
const fullper = ref([])
const fullpercreate = () => {
console.log(props.period, 'ddddddddddddd');
let arr = []
props.period.period.forEach((e) => {
let ind = arr.findIndex(el => el.visitdate == e.visitdate)
if (ind ==-1) {
arr.push({visitdate: e.visitdate, user: Array.from(new Set([e.user.id]))})
} }
watch(()=>props.dataLineChart,()=>{ else {
console.log('changed'); arr[ind].user = Array.from(new Set(arr[ind].user).add(e.user.id))
data.value = datachanged() }
},{deep:true}) })
fullper.value= [...props.period.before, ...arr]
const data = ref(datachanged()) }
// const data = ref(datachanged.value)
const crrfunc = (date)=>{
// let h = new Date('2024-01-20') >=moment(new Date(date)).subtract(between.value*2, 'd')
let baseunic = unicperson(fullper.value.filter(e => new Date(e.visitdate) >=moment(new Date(date)).subtract(between.value*2, 'd') && new Date(e.visitdate) < moment(new Date(date)).subtract(between.value, 'd')))
let crrunic = unicperson(fullper.value.filter(e => new Date(e.visitdate) >=moment(new Date(date)).subtract(between.value, 'd') && new Date(e.visitdate) < new Date(date)))
let bothuser = new Set([...baseunic].filter(element => crrunic.has(element)))
// console.log(h);
console.log(baseunic, crrunic, bothuser, "date");
return parseFloat((bothuser.size*100/baseunic.size).toFixed(2))
}
const unicperson = (arr) => {
let arrnew =[]
arr.forEach(e => arrnew.push(...e.user) )
return new Set(arrnew)
}
const data=computed({get() {return JSON.parse(JSON.stringify(dataf.value))
}
})
const options = { const options = {
plugins: { plugins: {
datalabels: { datalabels: {
@@ -207,10 +288,18 @@ export default {
// // console.log(props.dataLineChart,'dataYear2 -------------'); // // console.log(props.dataLineChart,'dataYear2 -------------');
// } // }
// const linear=ref(null)
// watch(()=>props.dataLineChart,(newValue, oldValue)=>{
// if (linear.value!==null) {
// renderChart(data.value, options)
// }
// linear.value.chart.datasets =data.value.datasets
// },{deep:true})
return { return {
data, data,
options, options,
// linear
} }
} }
} }
@@ -148,7 +148,7 @@ export default {
} }
const arrforline=() => { const arrforline=() => {
console.log(props.dataLineChart, 'props.dataLineChart');
Object.entries(props.dataLineChart).forEach(e => { Object.entries(props.dataLineChart).forEach(e => {
const [key, value] = e const [key, value] = e
arrlines.value.datasets[0].data.push(value.count) arrlines.value.datasets[0].data.push(value.count)
@@ -127,7 +127,7 @@ export default {
console.log( data1.diff(data2, 'days'), 'props.alldata') console.log(between, 'props.alldata')
return res return res
} }
}) })
+2 -1
View File
@@ -19,7 +19,7 @@
</v-col> </v-col>
<v-col lg=9> <v-col lg=9>
<line-chart :dataLineChart="dataLineChart" /> <line-chart :dataLineChart="dataLineChart" :period="{before:alldata.beforperiod,period:alldata.period}"/>
</v-col> </v-col>
<v-col > <v-col >
<v-btn block class="text-caption" @click="filter='year'">Год</v-btn> <v-btn block class="text-caption" @click="filter='year'">Год</v-btn>
@@ -35,6 +35,7 @@
<v-row no-gutters class="h-100 gap"> <v-row no-gutters class="h-100 gap">
<v-col class="flex-column d-flex"> <v-col class="flex-column d-flex">
<v-row no-gutters class="flex-column gap" > <v-row no-gutters class="flex-column gap" >
<my-helper :pretext="alldata.beforperiod"/>
<my-helper :pretext="alldata.period"/> <my-helper :pretext="alldata.period"/>
<v-col v-for="x in cardtotal" :key=x> <v-col v-for="x in cardtotal" :key=x>
<card-total :indicator=x /> <card-total :indicator=x />
+3 -4
View File
@@ -171,11 +171,10 @@ class TestwatcherAPIView(ListAPIView):
data_start = datetime.strptime(request.GET.get("start"), "%Y-%m-%d").date() data_start = datetime.strptime(request.GET.get("start"), "%Y-%m-%d").date()
data_end = datetime.strptime(request.GET.get("end"), "%Y-%m-%d").date() data_end = datetime.strptime(request.GET.get("end"), "%Y-%m-%d").date()
beetween = data_end - (data_start + timedelta(days=1)) beetween = data_end - (data_start - timedelta(days=1))
new_date_start = data_start - beetween print(beetween, 'beetween')
print(new_date_start, '-----------------' )
# #
res = CountVisitor.objects.filter(visitdate__lt = request.GET.get("start"), visitdate__gte=data_start - beetween).distinct().values('visitdate','user__user_id') res = CountVisitor.objects.filter(visitdate__lt = request.GET.get("start"), visitdate__gte=data_start - beetween*2).distinct().values('visitdate','user__user_id')
# .annotate(total=Count('user', distinct=True)).order_by('visitdate') # .annotate(total=Count('user', distinct=True)).order_by('visitdate')
per = CountVisitor.objects.filter(Q(visitdate__lte = request.GET.get("end"), visitdate__gte =request.GET.get("start")) | Q(visitdate=date.today())) per = CountVisitor.objects.filter(Q(visitdate__lte = request.GET.get("end"), visitdate__gte =request.GET.get("start")) | Q(visitdate=date.today()))
# print( DictEmployee.objects.filter(Q(deleteddate__isnull= True) | Q(deleteddate__gte = request.GET.get("end"))).count()) # print( DictEmployee.objects.filter(Q(deleteddate__isnull= True) | Q(deleteddate__gte = request.GET.get("end"))).count())