Счетчик
This commit is contained in:
1 parent
339f854494
commit
1b1220b9e7
11 files changed
+112
-80
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="d-flex h-100">
|
||||
<div class="d-flex h-100 ">
|
||||
|
||||
<v-card
|
||||
v-if="t_daily.length > 0"
|
||||
@@ -19,7 +19,11 @@
|
||||
elevation="0"
|
||||
>
|
||||
<v-card class="h-100 text-center text-black_grey bg-black_and_white">
|
||||
<v-card-title class="statstyle py-0 text-overline font-weight-bold bg-black_and_white">
|
||||
<v-card-title
|
||||
class="statstyle py-0
|
||||
text-xl-overline
|
||||
text-lg-subtitle-1
|
||||
text-md-h5 font-weight-bold bg-black_and_white">
|
||||
{{x.position__name}}
|
||||
</v-card-title>
|
||||
<v-card-text
|
||||
@@ -60,7 +64,7 @@
|
||||
</v-switch>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row >
|
||||
<v-row class="ma-3">
|
||||
<!-- <v-col class="fiction flex-column d-flex align-self-center"> -->
|
||||
<v-card-text class="d-flex flex-column align-self-center " v-if="changeData">
|
||||
<!-- <v-row> -->
|
||||
@@ -92,8 +96,13 @@
|
||||
<!-- </v-row> -->
|
||||
</v-card-text>
|
||||
<v-card-text v-else>
|
||||
|
||||
<v-row class="text-h5 text-white text-center h-100" align-content="center">Данные не загружены </v-row>
|
||||
<!-- class="text-h5 text-white text-center h-100 text-sm-overline" -->
|
||||
<v-row
|
||||
class="text-white text-center text-lg-h5 h-100 ma-3"
|
||||
align-content="center"
|
||||
>
|
||||
Данные не загружены
|
||||
</v-row>
|
||||
|
||||
</v-card-text>
|
||||
<!-- </v-col> -->
|
||||
|
||||
@@ -316,7 +316,7 @@ import AuthForm from '@/components/UI/Auth-form.vue'
|
||||
import OnlineUsers from '@/components/onlineUsers.vue'
|
||||
import CardUsers from '@/components/cardUsers.vue'
|
||||
import CardLike from '@/components/cardLike.vue'
|
||||
import { pagecounter } from '@/utils/universal_functions'
|
||||
// import { pagecounter } from '@/utils/universal_functions'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { baseURL } from '@/utils/axios-api'
|
||||
export default {
|
||||
@@ -326,7 +326,7 @@ export default {
|
||||
mixins: [uf],
|
||||
|
||||
setup() {
|
||||
pagecounter()
|
||||
// pagecounter()
|
||||
const router = useRouter()
|
||||
const appStore = useAppStore()
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -5,6 +5,10 @@ const routes = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/default/DefaultPortal.vue'),
|
||||
meta:{
|
||||
title:"Вход"
|
||||
},
|
||||
|
||||
children: [
|
||||
{
|
||||
path: '/',
|
||||
|
||||
@@ -66,17 +66,19 @@ export function pagecounter(){
|
||||
const accountStore = useAccountStore()
|
||||
const appStore = useAppStore()
|
||||
console.log(router.currentRoute.value.meta, '----роутер страницы--');
|
||||
let postdata = {user__id: "user" in accountStore &&"id" in accountStore.user? accountStore.user.id: null,
|
||||
page: router.currentRoute.value.meta.title,
|
||||
fullPath: router.currentRoute.value.fullPath,
|
||||
ico: router.currentRoute.value.meta.ico
|
||||
let postdata = {
|
||||
user__id: "user" in accountStore &&"id" in accountStore.user? accountStore.user.id: null,
|
||||
page: router.currentRoute.value.meta.title,
|
||||
fullPath: router.currentRoute.value.fullPath,
|
||||
ico: router.currentRoute.value.meta.ico
|
||||
}
|
||||
console.log(postdata, 'postdata');
|
||||
|
||||
|
||||
}
|
||||
clearAxios.post(`${baseURL}api/watcher/counter/`, postdata)
|
||||
.then(result => {
|
||||
|
||||
appStore.countvisitor = result.data})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -65,17 +65,17 @@
|
||||
|
||||
<script>
|
||||
import { ref } from 'vue'
|
||||
import {pagecounter} from '@/utils/universal_functions'
|
||||
|
||||
import {getfromserver} from '@/utils/universal_functions'
|
||||
export default {
|
||||
setup(){
|
||||
pagecounter()
|
||||
|
||||
const visiting = ref({})
|
||||
|
||||
|
||||
|
||||
|
||||
getfromserver(`api/watcher/counter/`, visiting)
|
||||
// getfromserver(`api/watcher/counter/`, visiting)
|
||||
|
||||
return {
|
||||
visiting
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {pagecounter} from '@/utils/universal_functions'
|
||||
|
||||
export default {
|
||||
setup(){
|
||||
pagecounter()
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<template>
|
||||
<v-container fluid class="d-flex mx-0 ">
|
||||
<v-row>
|
||||
<v-container fluid class="d-flex mx-0 pa-0">
|
||||
<v-row class="ma-2">
|
||||
<v-col
|
||||
class="d-flex flex-column"
|
||||
lg=7
|
||||
md=12
|
||||
cols=12
|
||||
>
|
||||
<v-row class="flex-grow-0">
|
||||
<v-col class="pr-0 pb-0">
|
||||
<v-row class="flex-grow-0">
|
||||
<v-col class="pa-1">
|
||||
<Carousel-list/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row style="height:250px">
|
||||
<v-col class="d-flex flex-column pr-0 pt-3" >
|
||||
<v-col class="d-flex flex-column pa-1">
|
||||
<event-calendar/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
@@ -26,29 +26,27 @@
|
||||
>
|
||||
<v-row>
|
||||
<v-col class="d-flex flex-column">
|
||||
<v-row style="min-height:550px">
|
||||
<v-row >
|
||||
<v-col
|
||||
lg=4
|
||||
md=2
|
||||
cols=12
|
||||
class="pb-0"
|
||||
|
||||
class="pa-1"
|
||||
style="min-height:250px"
|
||||
>
|
||||
<digital-letna/>
|
||||
</v-col>
|
||||
<v-col
|
||||
class="pb-0 pl-0 d-flex flex-column"
|
||||
class="d-flex flex-column pa-1"
|
||||
lg=8
|
||||
md=10
|
||||
cols=12
|
||||
style="min-height:550px"
|
||||
>
|
||||
<v-card class="h-100 d-flex flex-column">
|
||||
|
||||
|
||||
<v-row class="d-flex">
|
||||
<v-col class="flex-column d-flex">
|
||||
<news-home/>
|
||||
<!-- <News-list-home /> -->
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card>
|
||||
@@ -57,8 +55,8 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row class="flex-grow-0">
|
||||
<v-col>
|
||||
<v-card class=" flex-colmn">
|
||||
<v-col class="pa-1">
|
||||
<v-card class="flex-colmn">
|
||||
<v-btn-toggle
|
||||
v-model="toggle"
|
||||
divided
|
||||
@@ -84,10 +82,6 @@
|
||||
</v-row>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
|
||||
|
||||
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
@@ -129,19 +123,20 @@
|
||||
const favorit = ref([])
|
||||
const toggle = ref(null)
|
||||
|
||||
pagecounter()
|
||||
const accountStore = useAccountStore()
|
||||
pagecounter()
|
||||
|
||||
onMounted(() => {
|
||||
favoritLinks()
|
||||
})
|
||||
|
||||
const favoritLinks = () => {
|
||||
|
||||
|
||||
axiosApiInstance.get(`api/watcher/selectedlinks/`)
|
||||
.then(data => {
|
||||
favorit.value = data.data
|
||||
})
|
||||
// axiosApiInstance.get(`api/watcher/selectedlinks/`)
|
||||
// .then(data => {
|
||||
// favorit.value = data.data
|
||||
// })
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
+22
-11
@@ -1,27 +1,38 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from accounts.models import User
|
||||
# Create your models here.
|
||||
import pandas as pd
|
||||
|
||||
class CountVisitor(models.Model):
|
||||
page = models.CharField(db_index=True, max_length=255)
|
||||
visitdate = models.DateField()
|
||||
user = models.ForeignKey(User, null=True, blank=True, on_delete=models.PROTECT)
|
||||
count = models.IntegerField(default=0)
|
||||
fullPath = models.CharField(max_length=255)
|
||||
class Pages(models.Model):
|
||||
page = models.CharField(max_length=255)
|
||||
fullPath = models.CharField(max_length=255)
|
||||
ico = models.CharField(verbose_name='Иконка', max_length=150, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.page)
|
||||
return str(self.page)
|
||||
|
||||
|
||||
class CountVisitor(models.Model):
|
||||
# page = models.CharField(db_index=True, max_length=255)
|
||||
pages = models.ForeignKey(Pages, on_delete=models.PROTECT, related_name='get_pages', verbose_name='Страница', null=True)
|
||||
visitdate = models.DateField()
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, verbose_name='Пользователь', null=True, blank=True)
|
||||
count = models.IntegerField(default=0)
|
||||
# fullPath = models.CharField(max_length=255)
|
||||
# ico = models.CharField(verbose_name='Иконка', max_length=150, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.pages)
|
||||
|
||||
|
||||
|
||||
class Meta:
|
||||
# class Meta:
|
||||
|
||||
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['page', 'user', 'visitdate', 'fullPath', 'ico'], name='unique appversion')
|
||||
]
|
||||
# constraints = [
|
||||
# models.UniqueConstraint(fields=['page', 'user', 'visitdate', 'fullPath', 'ico'], name='unique appversion')
|
||||
# ]
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('counter/', Counter.as_view(),name="CountVisitors"),
|
||||
path('selectedlinks/', SelectedLinksAPIView.as_view(),name="SelectedLinks")
|
||||
# path('selectedlinks/', SelectedLinksAPIView.as_view(),name="SelectedLinks")
|
||||
# path('', views.Watchuser.as_view()), selectedlinks
|
||||
|
||||
|
||||
|
||||
+38
-27
@@ -16,49 +16,60 @@ class Counter(ListAPIView):
|
||||
permission_classes = (AllowAny,)
|
||||
serializer_class = CountSerializer
|
||||
|
||||
def get(self, request):
|
||||
res = CountVisitor.objects.values('page').annotate(Sum('count'))
|
||||
users = CountVisitor.objects.values('page', 'user__username').annotate(Sum('count'))
|
||||
outuser = DictEmployee.objects.values('login', 'fio')
|
||||
pUser = pd.DataFrame.from_records(users)
|
||||
pOutUser = pd.DataFrame.from_records(outuser)
|
||||
h = pUser.merge(pOutUser, how="left", left_on="user__username", right_on="login")
|
||||
# def get(self, request):
|
||||
# res = CountVisitor.objects.values('page').annotate(Sum('count'))
|
||||
# users = CountVisitor.objects.values('page', 'user__username').annotate(Sum('count'))
|
||||
# outuser = DictEmployee.objects.values('login', 'fio')
|
||||
# pUser = pd.DataFrame.from_records(users)
|
||||
# pOutUser = pd.DataFrame.from_records(outuser)
|
||||
# h = pUser.merge(pOutUser, how="left", left_on="user__username", right_on="login")
|
||||
|
||||
for x in users:
|
||||
if x['user__username'] is not None:
|
||||
x['user__username'] = h.loc[h['login']==x['user__username']]['fio'].unique()[0]
|
||||
else:
|
||||
x['user__username'] = 'Анонимные'
|
||||
# for x in users:
|
||||
# if x['user__username'] is not None:
|
||||
# x['user__username'] = h.loc[h['login']==x['user__username']]['fio'].unique()[0]
|
||||
# else:
|
||||
# x['user__username'] = 'Анонимные'
|
||||
|
||||
return Response({"pages":res, "users": users})
|
||||
# return Response({"pages":res, "users": users})
|
||||
|
||||
|
||||
def post(self, request):
|
||||
|
||||
print('ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')
|
||||
|
||||
|
||||
|
||||
|
||||
myfullPath = request.data['fullPath']
|
||||
if "?" in myfullPath:
|
||||
myfullPath= myfullPath.split("?")[0]
|
||||
# print(fullPath.split("?")[0], '---request.data-------------------------')
|
||||
print(request.data['page'], 'request.data[page]-------')
|
||||
page, create = Pages.objects.get_or_create(page=request.data['page'], fullPath=myfullPath, ico=request.data['ico'])
|
||||
|
||||
if request.data['user__id'] is not None:
|
||||
watch,create = CountVisitor.objects.get_or_create(user = User(id=request.data['user__id']),page=request.data['page'], visitdate=date.today(), fullPath=myfullPath, ico=request.data['ico'])
|
||||
else:
|
||||
watch,create = CountVisitor.objects.get_or_create(user__id__isnull=True, page=request.data['page'], visitdate=date.today(), fullPath=myfullPath, ico=request.data['ico'])
|
||||
watch,create = CountVisitor.objects.get_or_create(user = User(id=request.data['user__id']),pages=page, visitdate=date.today())
|
||||
print('if ----------------------------')
|
||||
else:
|
||||
watch,create = CountVisitor.objects.get_or_create(user__id__isnull=True, pages=page, visitdate=date.today())
|
||||
watch.count+=1
|
||||
watch.save()
|
||||
|
||||
res = {"totalvisit": CountVisitor.objects.filter(page=request.data['page']).aggregate(Sum('count'))['count__sum'],
|
||||
"visittoday":CountVisitor.objects.filter(visitdate=date.today(), page=request.data['page']).aggregate(Sum('count'))['count__sum'],
|
||||
"uniqtoday" : CountVisitor.objects.filter(visitdate=date.today(), page=request.data['page']).count()
|
||||
|
||||
res = {"totalvisit": CountVisitor.objects.filter(pages=page.id).aggregate(Sum('count'))['count__sum'],
|
||||
"visittoday":CountVisitor.objects.filter(visitdate=date.today(), pages=page.id).aggregate(Sum('count'))['count__sum'],
|
||||
"uniqtoday" : CountVisitor.objects.filter(visitdate=date.today(), pages=page.id).count()
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Response(res)
|
||||
|
||||
class SelectedLinksAPIView(ListAPIView):
|
||||
# class SelectedLinksAPIView(ListAPIView):
|
||||
|
||||
def get(self, request):
|
||||
user = User.objects.get(username=self.request.user)
|
||||
res = CountVisitor.objects.values('page','fullPath','ico').filter(user_id=user).annotate(Sum('count')).exclude(fullPath='/')
|
||||
sort = res.order_by('-count__sum')[:20]
|
||||
# def get(self, request):
|
||||
# user = User.objects.get(username=self.request.user)
|
||||
# res = CountVisitor.objects.values('page','fullPath','ico').filter(user_id=user).annotate(Sum('count')).exclude(fullPath='/')
|
||||
# sort = res.order_by('-count__sum')[:20]
|
||||
|
||||
|
||||
return Response(sort)
|
||||
# return Response(sort)
|
||||
|
||||
Reference in new issue
Block a user