Files
PORTAL_COD2/src/front/src/views/AboutPortalPage2.vue
T
2024-02-29 14:32:10 +03:00

603 lines
16 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<v-row v-if="Object.keys(feedback).length==0">
<v-col class="text-h6 text-grey text-center align-self-center text--lighten-1 font-weight-light">
<v-progress-circular
:size="150"
:width="7"
color="cyan-darken-3"
indeterminate
></v-progress-circular>
</v-col>
</v-row>
<v-row no-gutters class="flex-column gap ma-1" v-else>
<toolbar-filter/>
<v-col lg=3 class="w100">
<v-row no-gutters class="h-100 gap">
<v-col >
<!-- <portal-traffic :traffic=dataAttendance /> -->
</v-col>
<v-col lg=9>
<!-- <line-chart :dataLineChart="dataLineChart" :dataChart="dataChart"/> -->
</v-col>
<v-col >
<v-btn block class="text-caption" @click="filter='year'">Год</v-btn>
<v-btn block class="text-caption" @click="filter='month'">Месяц</v-btn>
<v-btn block class="text-caption" @click="filter='day'">День</v-btn>
<!-- ------------------------------------------------------------------------- -->
<my-helper :pretext="dataActivusers"/>
{{filter}}
</v-col>
</v-row>
</v-col>
<v-col class="w100 ">
<v-row no-gutters class="h-100 gap">
<v-col class="flex-column d-flex">
<v-row no-gutters class="flex-column gap" >
<my-helper :pretext="dataIndicators"/>
<v-col v-for="x in dataIndicators" :key=x>
<!-- -->
<card-total :indicator=x />
</v-col>
</v-row>
</v-col>
<v-col lg=4 class="d-flex flex-column">
<rating-page :pages_count=pages_count />
</v-col>
<v-col lg=4 class="d-flex flex-column ">
<top-user
:activusers = dataActivusers
/>
</v-col>
<v-col lg=2 class="d-flex flex-column">
<feedmodul
:feedback="feedback"
/>
</v-col>
</v-row>
</v-col>
</v-row>
</template>
<script>
import { ref, watch } from 'vue'
import {pagecounter, splitname, formatComa, formatDash} from '@/utils/universal_functions'
import { axiosApiInstance } from '@/utils/axios-api'
import { usePortalFilterStore } from '@/store/AboutPortalFilter'
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'
import LineChart from '@/components/UI/aboutportal/line-chart.vue'
import PortalTraffic from '@/components/UI/aboutportal/portal-traffic.vue'
import ToolbarFilter from '@/components/UI/aboutportal/toolbar-filter.vue'
import RatingPage from '@/components/UI/aboutportal/rating-page.vue'
import CardTotal from '@/components/UI/aboutportal/card-total.vue'
// import Feedmodul from '@/components/UI/aboutportal/feedmodul.vue'
export default {
components: {
Feedmodul,
DateSelect,
TopUser,
LineChart,
PortalTraffic,
ToolbarFilter,
RatingPage,
CardTotal,
// Feedmodul
},
setup(){
const filterStore = usePortalFilterStore()
const filter = ref('day')
const visiting = ref([])
const feedback = ref([])
const for_formulas = ref({})
const dataLineChart = ref({})
const dataActivusers = ref([])
const dataAttendance = ref({})
const dataIndicators = ref({})
const dataChart = ref({})
const unicuser = ref([])
const selected_days = ref({today: 'сегодня', year: {start: new Date(), end: new Date()}})
const pages_count = ref({data: {}, title: {}})
pagecounter()
const visition = () => {
axiosApiInstance.get(`api/watcher/counter/?start=${formatDash(filterStore.date_period.startdate)}&end=${formatDash(filterStore.date_period.enddate)}`).then(result => {
for_formulas.value = result.data.for_formulas
visiting.value = result.data.result
feedback.value = result.data.feedback
dataIndicators.value = result.data.indicators
dataChart.value = result.data.chart,
console.log(result.data, 'result.data');
visitionreduce()
funActiveUser()
})}
visition()
const checking_for_entry = (where, what) => {
if (!where.includes(what))
{
where.push(what)
}
}
const funLineChart = (data, item) => {
if (item.visitdate <= formatDash(filterStore.date_period.enddate)) {
if (!data[item.visitdate]) {
data[item.visitdate] = {count: 0, unic: []}
}
checking_for_entry(data[item.visitdate]['unic'], splitname(item.author))
data[item.visitdate].count += item.count
}
}
const funActiveUser = () => {
dataActivusers.value = []
unicuser.value.map(iduser => {
let activuser ={
user: {
id: "",
login: "",
post: "",
fio: ""
},
info: {
count: 0,
session: 0,
pages: 0
},
tooltip: [],
}
let yearpages = {}
let pages = []
let user = visiting.value.filter(e => e.author.id == iduser)
const groupUser = user.reduce((acc, item) => {
if (item.visitdate <= formatDash(filterStore.date_period.enddate)) {
funyearpages(yearpages, item)
checking_for_entry(pages, item.pages)
acc['id'] = item.author.id
acc['login'] = item.author.login
acc['post'] = item.author.post
acc['fio'] = splitname(item.author)
acc['count'] += item.count
acc['session'] = Object.keys(yearpages).length
}
return acc
}, {count: 0})
let arrbigs = []
pages.map(namepages => {
let onetooltip = {
namepages: "",
count: 0,
unic: 0
}
let unicpages = user.filter(e => (e.pages == namepages))
const pagesData = unicpages.reduce((accpag, pag) => {
accpag['pages'] = pag.pages
accpag['count'] += pag.count
accpag['unic'] += 1
return accpag
}, {count: 0, unic: 0})
onetooltip.namepages = pagesData.pages
onetooltip.count = pagesData.count
onetooltip.unic = pagesData.unic
arrbigs.push(onetooltip)
}
)
activuser.user.id = groupUser.id
activuser.user.login = groupUser.login
activuser.user.post = groupUser.post
activuser.user.fio = groupUser.fio
activuser.info.count = groupUser.count
activuser.info.session = groupUser.session
activuser.info.pages = user.length
activuser.tooltip = arrbigs
dataActivusers.value.push(activuser)
})
}
const funyearpages = (data, item) => {
if (item.visitdate <= formatDash(filterStore.date_period.enddate)) {
if (!data[item.visitdate]) {
data[item.visitdate] = {}
}
if (!data[item.visitdate][item.pages]) {
data[item.visitdate][item.pages] = 0
}
data[item.visitdate][item.pages] += item.count
}
}
const data_collection = (data, obj) => {
let attendance = {
today: {
title: 'сегодня',
user: [],
proc: 0
},
period: {
title: 'за период',
user: [],
proc: 0,
previos: 0
},
}
const groupedData = data.reduce((acc, item) => {
if (!acc[item.pages]) {
acc[item.pages] = {
now:
{unique: [], countall: 0},
year:
{unique: [], countall: 0}
}
}
if (obj) {
funLineChart(obj, item)
}
if (item.visitdate >= formatDash(filterStore.date_period.startdate) && item.visitdate <= formatDash(filterStore.date_period.enddate)){
checking_for_entry(unicuser.value, item.author.id)
checking_for_entry(acc[item.pages].year.unique, splitname(item.author))
acc[item.pages].year.countall += item.count
checking_for_entry(attendance.period.user, splitname(item.author))
}
if (item.visitdate == formatDash(new Date())) {
// console.log(item, 'item');
checking_for_entry(acc[item.pages].now.unique, splitname(item.author))
acc[item.pages].now.countall += item.count
checking_for_entry(attendance.today.user, splitname(item.author))
}
return acc
}, {})
let proctoday = (attendance.today.user.length*100)/for_formulas.value.staff
let procperiod = (attendance.period.user.length*100)/for_formulas.value.staff
attendance.today.proc = `${Number.isInteger(proctoday)?proctoday:(proctoday).toFixed(2)}%`
attendance.period.proc = `${Number.isInteger(procperiod)?procperiod:(procperiod).toFixed(2)}%`
let previos = (for_formulas.value.previos*100)/attendance.period.user.length
attendance.period.previos = 100- (Number.isInteger(previos)?previos:(previos).toFixed(2))
dataAttendance.value = attendance
// console.log(attendance, 'attendance[splitname(item.author)]')
return groupedData
}
const visitionreduce = () => {
let lineCharts = {}
unicuser.value = []
pages_count.value.data= data_collection(visiting.value, lineCharts)
// const gruppitovka= () => {
// console.log(visiting.value, 'dataLineChart');
// }
// gruppitovka()
Object.entries(lineCharts).map(e=> {
lineCharts[e[0]].crr = dataChart.value[e[0]].crr
lineCharts[e[0]].br = dataChart.value[e[0]].br
lineCharts[e[0]].ppv = dataChart.value[e[0]].ppv
})
dataLineChart.value = lineCharts
}
watch(()=>filterStore.date_period,(newValue,oldValue)=>{
if(newValue){
visition()
visitionreduce()
title_period()
}
}, {deep:true})
const title_period = () => {
selected_days.value.year.start = formatComa(filterStore.date_period.startdate)
selected_days.value.year.end = formatComa(filterStore.date_period.enddate)
pages_count.value.title = selected_days.value
}
title_period()
return {
visiting,
pages_count,
visitionreduce,
dataLineChart,
dataActivusers,
formatComa,
selected_days,
for_formulas,
dataAttendance,
dataIndicators,
dataChart,
feedback,
filter
// countgrupp,
// activuser,
// feedback,
// traffic,
// crit,
// visition,
// icons,
// periodname,
// weekstart,
// selected_days,
// modelrating,
// pages_count
}
// const pages_count = ref({})
// const traffic = ref({
// now: {
// title: '',
// unique: new Set(),
// percentage_staff: 0,
// comparison_period: new Set(),
// percentage_period: 0
// },
// year: {
// title: '',
// unique: new Set(),
// percentage_staff: 0,
// comparison_period: new Set(),
// percentage_period: 0
// }
// })
// const crit = ref([])
// const last_days = ref(new Date())
// const previous_period = ref(new Date())
// const icons = ['mdi-numeric-1-box-outline', 'mdi-numeric-2-box-outline', 'mdi-numeric-3-box-outline']
// const modelrating = ref(false)
// const weekstart = () => {
// let days_between = Math.floor((new Date(enddate.value) - new Date(startdate.value)) / (1000*60*60*24))
// if (startdate.value == enddate.value) {
// days_between = 1
// }
// previous_period.value = new Date(new Date(startdate.value).setDate(new Date(startdate.value).getDate() - days_between))
// }
// const lastperiod = () => {
// let last_day = []
// visiting.value.map((e)=>{
// if (e.visitdate < formatDash(enddate.value)) {
// last_day.push(e.visitdate)
// }
// })
// last_days.value = last_day[last_day.length-1]
// }
// const countgrupp = () => {
// let us = {}
// let portal_traffic = {
// now: {
// title: '',
// info: '',
// unique: new Set(),
// percentage_staff: 0,
// comparison_period: new Set(),
// percentage_period: 0
// },
// year: {
// title: 'За период',
// info: '',
// unique: new Set(),
// percentage_staff: 0,
// comparison_period: new Set(),
// percentage_period: 0
// }
// }
// const groupedData =
// visiting.value.reduce((acc, item) => {
// if (!acc[item.pages]) {
// acc[item.pages] = {
// now:
// {unique: new Set(), countall: 0},
// year:
// {unique: new Set(), countall: 0}
// }
// }
// acc[item.pages].year.unique.add(item.author.id)
// acc[item.pages].year.countall += item.count
// portal_traffic.year.unique.add(item.author.id)
// if (item.visitdate == formatDash(enddate.value)) {
// acc[item.pages].now.unique.add(item.author.id)
// acc[item.pages].now.countall += item.count
// portal_traffic.now.unique.add(item.author.id)
// }
// Посещаемость портала для периода 1 день
// if (item.visitdate ==formatDash(last_days.value)){
// portal_traffic.now.comparison_period.add(item.author.id)
// portal_traffic.now.info = `за ${formatComa(last_days.value)}`
// }
// portal_traffic.year.info = `с ${formatComa(previous_period.value)} по ${formatComa(startdate.value)} `
// console.log( `${formatComa(previous_period.value)} >=${formatComa(item.visitdate)} <= ${formatComa(startdate.value)}`,'до')
// Посещаемость портала для периода - выбранный период фильтра
// if (item.visitdate >= formatDash(previous_period.value) && item.visitdate < formatDash(startdate.value)) {
// console.log( `${formatComa(previous_period.value)} >=${formatComa(item.visitdate)} < ${formatComa(startdate.value)}`,'после')
// console.log(previous_period.value, formatDash(startdate.value), '-------------------------------')
// portal_traffic.year.comparison_period.add(item.author.id)
// }
// 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)
// return acc
// }, {});
// portal_traffic.now.percentage_staff = percentageStaff(portal_traffic.now.unique, staff.value)
// portal_traffic.now.percentage_period = percentageStaff(portal_traffic.now.comparison_period, portal_traffic.now.unique.size)
// portal_traffic.year.percentage_staff = percentageStaff(portal_traffic.year.unique, staff.value)
// portal_traffic.year.percentage_period = percentageStaff(portal_traffic.year.comparison_period, portal_traffic.year.unique.size)
// portal_traffic.now.title = `На ${selected_days.value.today}`
// pages_count.value = groupedData
// traffic.value = portal_traffic
// }
// const percentageStaff = (customers, delitel) => {
// return Math.round((customers.size*100)/delitel)+'%'
// }
// const activuser = () => {
// const groupedData =
// visiting.value.reduce((acc, item) => {
// if (!acc[splitname(item.author)]) {
// acc[splitname(item.author)] = {count: 0, login: '', fio: '', post: '', info: new Set()}
// }
// acc[splitname(item.author)]['fio'] = splitname(item.author)
// acc[splitname(item.author)]['info'].add(item.pages)
// acc[splitname(item.author)]['login'] = item.author.login
// acc[splitname(item.author)]['post'] = item.author.post
// acc[splitname(item.author)]['count'] += item.count
// return acc
// }, {})
// const sorted = Object.entries(groupedData)
// .sort(([,a],[,b]) => (b.count - a.count))
// .reduce((r, [k, v]) =>
// ({ ...r, [k]: v } ), {}
// )
// return sorted
// }
// visition()
}
}
</script>
<style>
</style>