513 lines
14 KiB
Vue
513 lines
14 KiB
Vue
<template>
|
||
<!-- <v-row no-gutters class="ma-1">
|
||
<v-col class="d-flex flex-column gap">
|
||
|
||
<v-row no-gutters class="flex-grow-0">
|
||
<v-col>
|
||
<v-toolbar
|
||
density="compact"
|
||
class="text-h6 font-weight-regular"
|
||
>
|
||
<v-icon
|
||
icon="mdi-poll"
|
||
color="cyan-darken-3"
|
||
class="mx-2"
|
||
/>
|
||
|
||
Статистика портала за период с
|
||
<div class="px-2 pb-1">
|
||
<date-select
|
||
@returndate="returnstart"
|
||
:datedefault = "startdate"
|
||
/>
|
||
</div>
|
||
по
|
||
<div class="px-2 pb-1">
|
||
<date-select
|
||
@returndate="returnend"
|
||
:datedefault = "endate"
|
||
/>
|
||
</div>
|
||
</v-toolbar>
|
||
</v-col>
|
||
</v-row>
|
||
|
||
<v-row no-gutters class="gap">
|
||
<v-col lg=3>
|
||
|
||
|
||
|
||
|
||
{{weekstart(new Date()).WeekStart}}
|
||
{{weekstart(new Date()).WeekEnd}}
|
||
<v-card
|
||
class="text-center"
|
||
title="Количество посещений"
|
||
height="200px"
|
||
>
|
||
<v-list class="text-start text-subtitle-1">
|
||
|
||
<v-list-item>
|
||
Посетителей сегодня: {{ countvising['now'] }}
|
||
</v-list-item>
|
||
<v-list-item>
|
||
Посетителей на прошлой неделе: {{ countvising['week'] }}
|
||
</v-list-item>
|
||
<v-list-item>
|
||
Посетителей с начала года: {{ countvising['year'] }}
|
||
</v-list-item>
|
||
</v-list>
|
||
</v-card>
|
||
</v-col>
|
||
<v-col>
|
||
<v-card class="d-flex flex-column text-center"
|
||
height="200px"
|
||
>
|
||
<line-graph :data="data" :options="options"/>
|
||
</v-card>
|
||
</v-col>
|
||
</v-row> -->
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- <v-row >
|
||
<v-col class="pa-1 d-flex flex-column">
|
||
<v-row>
|
||
<v-col
|
||
lg=3
|
||
>
|
||
<feedmodul
|
||
:feedback="feedback"/>
|
||
</v-col>
|
||
<v-col class=" d-flex flex-column">
|
||
<v-row>
|
||
<v-col class="d-flex flex-column">
|
||
<v-card class="text-center h-100" title="Рейтинг посещаемости страниц портала">
|
||
<v-table class="">
|
||
<thead>
|
||
<tr>
|
||
<th>Имя страницы</th>
|
||
<th class="text-center">Сегодня</th>
|
||
<th class="text-center">На прошлой неделе</th>
|
||
<th class="text-center">С начала года</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="(val, key) in countgrupp()" :key = key>
|
||
<td class="text-left">{{key}}</td>
|
||
<td class="text-center">{{ val.now }} </td>
|
||
<td class="text-center">{{ val.week }}</td>
|
||
<td class="text-center">{{ val.year }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</v-table>
|
||
</v-card>
|
||
</v-col>
|
||
</v-row>
|
||
<v-row class="flex-grow-0">
|
||
<v-col class="" v-for="(val, key) in activuser()" :key = key>
|
||
<top-user
|
||
:users="val"
|
||
:ico="icons[Object.keys(activuser()).indexOf(key)]"
|
||
name="Активность"
|
||
/>
|
||
</v-col>
|
||
</v-row>
|
||
</v-col>
|
||
</v-row>
|
||
</v-col>
|
||
</v-row> -->
|
||
<!-- </v-col>
|
||
</v-row> -->
|
||
<v-row class="ma-3">
|
||
|
||
<v-col
|
||
class="d-flex flex-column"
|
||
lg=4
|
||
>
|
||
<v-row class="flex-grow-0">
|
||
<v-col>
|
||
|
||
<v-card
|
||
class="d-flex flex-column text-center"
|
||
title="Количество посещений">
|
||
|
||
<v-list class="d-flex flex-column align-start text-subtitle-1">
|
||
<!-- {{periodname()}} -->
|
||
<v-list-item>
|
||
Посетителей сегодня: {{ countvising['now'] }}
|
||
</v-list-item>
|
||
<v-list-item>
|
||
Посетителей на прошлой неделе: {{ countvising['week'] }}
|
||
</v-list-item>
|
||
<v-list-item>
|
||
Посетителей с начала года: {{ countvising['year'] }}
|
||
</v-list-item>
|
||
</v-list>
|
||
</v-card>
|
||
</v-col>
|
||
</v-row>
|
||
<feedmodul :feedback="feedback"/>
|
||
|
||
</v-col>
|
||
<v-col class="d-flex flex-column ">
|
||
<v-row class="flex-grow-0">
|
||
<v-col >
|
||
<line-graph :data="data" :options="options"/>
|
||
</v-col>
|
||
</v-row>
|
||
<v-row>
|
||
<v-col class="d-flex flex-column ">
|
||
<v-row>
|
||
<v-col
|
||
lg=7
|
||
>
|
||
|
||
|
||
<v-card class="pt-3 text-center" title="Рейтинг посещаемости страниц портала">
|
||
<v-table class="pt-3 ma-0">
|
||
<thead>
|
||
<tr>
|
||
<th>Имя страницы</th>
|
||
<th class="text-center">Сегодня</th>
|
||
<th class="text-center">На прошлой неделе</th>
|
||
<th class="text-center">С начала года</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="(val, key) in countgrupp()" :key = key>
|
||
<td class="text-left">{{key}}</td>
|
||
<td class="text-center">{{ val.now }} </td>
|
||
<td class="text-center">{{ val.week }}</td>
|
||
<td class="text-center">{{ val.year }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</v-table>
|
||
</v-card>
|
||
|
||
|
||
</v-col>
|
||
<v-col lg=5>
|
||
|
||
|
||
|
||
<div v-for="(val, key) in activuser()" :key = key>
|
||
|
||
<top-user
|
||
:users="val"
|
||
:ico="icons[Object.keys(activuser()).indexOf(key)]"
|
||
/>
|
||
|
||
</div>
|
||
|
||
</v-col>
|
||
|
||
</v-row>
|
||
<v-row>
|
||
<v-col>
|
||
<date-select
|
||
@returndate="returnstart"
|
||
:datedefault = "startdate"
|
||
/>
|
||
<date-select
|
||
@returndate="returnend"
|
||
:datedefault = "endate"
|
||
/>
|
||
|
||
|
||
</v-col>
|
||
</v-row>
|
||
</v-col>
|
||
</v-row>
|
||
</v-col>
|
||
</v-row>
|
||
</template>
|
||
|
||
<script>
|
||
import { ref, computed } from 'vue'
|
||
|
||
import {pagecounter, splitname} from '@/utils/universal_functions'
|
||
import moment from 'moment'
|
||
import lineGraph from '@/components/graph/line-graph.vue'
|
||
import { axiosApiInstance } from '@/utils/axios-api'
|
||
import Feedmodul from '@/components/UI/aboutportal/feedmodul.vue'
|
||
import DateSelect from '@/components/UI/date-select.vue'
|
||
import TopUser from '@/components/UI/aboutportal/top-user.vue'
|
||
|
||
|
||
export default {
|
||
components: {
|
||
lineGraph,
|
||
Feedmodul,
|
||
DateSelect,
|
||
TopUser
|
||
},
|
||
|
||
|
||
setup(){
|
||
const visiting = ref([])
|
||
const feedback = ref([])
|
||
const countvising = ref({now: 0, week: 0, year: 0})
|
||
const crit = ref([])
|
||
const startdate =ref(moment(new Date(new Date().getFullYear(), 0, 1)).format('YYYY-MM-DD'))
|
||
const endate =ref(moment(new Date()).format('YYYY-MM-DD'))
|
||
const icons = ['mdi-numeric-1-box-outline', 'mdi-numeric-2-box-outline', 'mdi-numeric-3-box-outline']
|
||
|
||
// const previousWeekEnd = moment().subtract(1, 'weeks').endOf('week'); // конец предыдущей недели
|
||
|
||
const arrlines = {}
|
||
const data = computed({
|
||
get() {
|
||
arrlines.value = {
|
||
labels: [],
|
||
datasets: [
|
||
{
|
||
label: 'Посещений всего',
|
||
backgroundColor: '#f87979',
|
||
data: []
|
||
},
|
||
{
|
||
label: 'Уникальные посещения',
|
||
backgroundColor: '#f87975',
|
||
data: []
|
||
}
|
||
]
|
||
}
|
||
arrforline()
|
||
return arrlines.value
|
||
}
|
||
|
||
})
|
||
const options = {
|
||
responsive: true,
|
||
maintainAspectRatio: false
|
||
}
|
||
|
||
|
||
const arrforline=() => {
|
||
|
||
|
||
let datas =
|
||
visiting.value.reduce((acc, item) => {
|
||
|
||
|
||
if (!acc[item.visitdate]) {
|
||
acc[item.visitdate] = {unic: [], count: 0}
|
||
}
|
||
acc[item.visitdate]['count'] += item.count
|
||
if (!acc[item.visitdate]['unic'].includes(item.author.id))
|
||
{
|
||
acc[item.visitdate]['unic'].push(item.author.id)
|
||
}
|
||
|
||
|
||
|
||
|
||
return acc
|
||
}, {})
|
||
for (let key in datas) {
|
||
|
||
|
||
arrlines.value.datasets[0].data.push(datas[key].count)
|
||
arrlines.value.datasets[1].data.push(datas[key]['unic'].length)
|
||
}
|
||
|
||
|
||
|
||
|
||
arrlines.value.labels = Object.keys(datas)
|
||
|
||
}
|
||
|
||
|
||
|
||
const weekstart = (date) => {
|
||
let WeekStart = moment(date).subtract(1, 'weeks').startOf('isoWeek')._d // начало предыдущей недели
|
||
let WeekEnd =new Date(new Date(WeekStart).setDate(new Date(WeekStart).getDate() + 4)) // конец предыдущей недели
|
||
return {WeekStart, WeekEnd}
|
||
}
|
||
|
||
|
||
|
||
|
||
const returnstart = (dates) => {
|
||
startdate.value = dates
|
||
visition()
|
||
}
|
||
|
||
const returnend = (dates) => {
|
||
endate.value = dates
|
||
visition()
|
||
}
|
||
|
||
const visition = () => {
|
||
axiosApiInstance.get(`api/watcher/counter/?start=${startdate.value}&end=${endate.value}`).then(result => {
|
||
visiting.value = result.data.result
|
||
feedback.value = result.data.feedback
|
||
})}
|
||
|
||
pagecounter()
|
||
|
||
// const periodname = () => {
|
||
// let today = 'Посетителей сегодня:'
|
||
// let weekday = 'Посетителей на прошлой неделе'
|
||
|
||
// if (new Date(endate.value) < new Date() ) {
|
||
// today = `Посетителей на ${moment(endate.value).format('DD.MM.YYYY')} число`
|
||
// // weekday = `Посетителей с ${moment(previousWeekStart._d).format('DD.MM.YYYY')} по ${moment(previousWeekEnd._d,).format('DD.MM.YYYY')}`
|
||
// }
|
||
|
||
// return [
|
||
// {now: [today, countvising.value['now']],
|
||
// week: [weekday, countvising.value['week']]
|
||
// },
|
||
// ]
|
||
// }
|
||
|
||
|
||
const countgrupp = () => {
|
||
let us = {}
|
||
let countall = {now: 0, week: 0, year: 0}
|
||
|
||
|
||
const groupedData =
|
||
visiting.value.reduce((acc, item) => {
|
||
|
||
|
||
if (!acc[item.pages]) {
|
||
acc[item.pages] = {now: 0, week: 0, year: 0}
|
||
}
|
||
|
||
acc[item.pages]['year'] += item.count
|
||
countall.year += item.count
|
||
|
||
|
||
|
||
|
||
|
||
if (item.visitdate == moment(endate.value).format('YYYY-MM-DD')) {
|
||
acc[item.pages]['now'] += item.count
|
||
countall.now += item.count
|
||
|
||
}
|
||
|
||
let week = weekstart(endate.value)
|
||
if (item.visitdate >= moment(week.WeekStart).format('YYYY-MM-DD') && item.visitdate <= moment(week.WeekEnd).format('YYYY-MM-DD')) {
|
||
acc[item.pages]['week'] += item.count
|
||
countall.week += item.count
|
||
}
|
||
|
||
if (!us[splitname(item.author)])
|
||
{
|
||
us[splitname(item.author)] = {page: new Set(), login: 0}
|
||
}
|
||
|
||
us[splitname(item.author)]['page'].add(item.pages)
|
||
us[splitname(item.author)]['login'] = item.author.login
|
||
|
||
|
||
let arrcount = []
|
||
for (let [key,val] of Object.entries(us)) {
|
||
|
||
arrcount.push({fio:key,max:val.page.size, login: val.login})
|
||
}
|
||
arrcount.sort((a, b) => {
|
||
|
||
return b['max']- a['max']
|
||
})
|
||
|
||
crit.value = arrcount.slice(0, 3)
|
||
countvising.value=countall
|
||
|
||
return acc
|
||
}, {});
|
||
|
||
|
||
|
||
return groupedData
|
||
}
|
||
|
||
// const countgruppsumm = () => {
|
||
// countgrupp()
|
||
// }
|
||
|
||
|
||
const activuser = () => {
|
||
|
||
const groupedData =
|
||
visiting.value.reduce((acc, item) => {
|
||
|
||
if (Object.keys(acc).length <3) {
|
||
|
||
|
||
|
||
if (!acc[splitname(item.author)]) {
|
||
acc[splitname(item.author)] = {count: 0, login: ''}
|
||
}
|
||
|
||
acc[splitname(item.author)]['fio'] = splitname(item.author)
|
||
acc[splitname(item.author)]['count'] += item.count
|
||
acc[splitname(item.author)]['login'] = item.author.login
|
||
acc[splitname(item.author)]['post'] = item.author.post
|
||
|
||
|
||
}
|
||
|
||
|
||
return acc
|
||
}, {});
|
||
|
||
|
||
|
||
|
||
const sorted = Object.entries(groupedData)
|
||
.sort(([,a],[,b]) => b.count-a.count)
|
||
.reduce((r, [k, v]) =>
|
||
|
||
({ ...r, [k]: v } ), {}
|
||
|
||
)
|
||
|
||
|
||
|
||
|
||
return sorted
|
||
}
|
||
|
||
visition()
|
||
|
||
|
||
|
||
|
||
return {
|
||
visiting,
|
||
countgrupp,
|
||
activuser,
|
||
data,
|
||
options,
|
||
feedback,
|
||
countvising,
|
||
crit,
|
||
visition,
|
||
returnstart,
|
||
returnend,
|
||
endate,
|
||
startdate,
|
||
icons,
|
||
// periodname,
|
||
|
||
weekstart
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
</script>
|
||
|
||
<style>
|
||
|
||
</style> |