Compare commits
No commits in common. "44042233502936c8d6e833c9b9c514d73ee37698" and "02aee01d208d0aacc4de7541c49d8f4e49d75613" have entirely different histories.
4404223350
...
02aee01d20
@ -1,20 +0,0 @@
|
|||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
|
|
||||||
from doorcontrol.models import Door
|
|
||||||
from doorcontrol.tasks.scrapehidevents import getMessages
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
parser.add_argument("door_names", nargs="*")
|
|
||||||
|
|
||||||
def handle(self, *args, door_names: list[str], verbosity: int, **options):
|
|
||||||
doors = Door.objects.all()
|
|
||||||
if door_names:
|
|
||||||
doors = doors.filter(name__in=door_names)
|
|
||||||
if len(doors) != len(door_names):
|
|
||||||
raise CommandError("Not all door names matched doors in database")
|
|
||||||
|
|
||||||
for door in doors:
|
|
||||||
print(door)
|
|
||||||
getMessages(door)
|
|
@ -1,5 +1,4 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Self
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -180,10 +179,6 @@ class HIDEvent(models.Model):
|
|||||||
DOOR_UNLOCKED = 12032, "Door Unlocked"
|
DOOR_UNLOCKED = 12032, "Door Unlocked"
|
||||||
DOOR_LOCKED = 12033, "Door Locked"
|
DOOR_LOCKED = 12033, "Door Locked"
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def any_granted_access(cls) -> list[Self]:
|
|
||||||
return [t for t in cls if t.name.startswith("GRANTED_ACCESS")]
|
|
||||||
|
|
||||||
door = models.ForeignKey(Door, on_delete=models.CASCADE)
|
door = models.ForeignKey(Door, on_delete=models.CASCADE)
|
||||||
timestamp = models.DateTimeField()
|
timestamp = models.DateTimeField()
|
||||||
event_type = models.IntegerField(db_column="eventType", choices=EventType.choices)
|
event_type = models.IntegerField(db_column="eventType", choices=EventType.choices)
|
||||||
|
@ -46,7 +46,6 @@ class DetailByDayTable(tables.Table):
|
|||||||
timestamp__date = tables.DateColumn(verbose_name="Date")
|
timestamp__date = tables.DateColumn(verbose_name="Date")
|
||||||
name = tables.Column()
|
name = tables.Column()
|
||||||
access_count = tables.Column()
|
access_count = tables.Column()
|
||||||
granted_access_count = tables.Column()
|
|
||||||
|
|
||||||
|
|
||||||
class BusiestDayOfWeekTable(tables.Table):
|
class BusiestDayOfWeekTable(tables.Table):
|
||||||
|
@ -3,7 +3,7 @@ import datetime
|
|||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.core.exceptions import BadRequest
|
from django.core.exceptions import BadRequest
|
||||||
from django.core.paginator import Page
|
from django.core.paginator import Page
|
||||||
from django.db.models import Count, F, FloatField, Q, Window
|
from django.db.models import Count, F, FloatField, Window
|
||||||
from django.db.models.functions import Lead, Trunc
|
from django.db.models.functions import Lead, Trunc
|
||||||
from django.urls import path, reverse_lazy
|
from django.urls import path, reverse_lazy
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
@ -165,10 +165,13 @@ class AccessPerUnitTime(BaseAccessReport):
|
|||||||
if unit_time not in self.UNIT_TIMES:
|
if unit_time not in self.UNIT_TIMES:
|
||||||
raise BadRequest("unit time must be one of day, week, month, or year")
|
raise BadRequest("unit time must be one of day, week, month, or year")
|
||||||
|
|
||||||
|
granted_event_types = [
|
||||||
|
t for t in HIDEvent.EventType if t.name.startswith("GRANTED_ACCESS")
|
||||||
|
]
|
||||||
return (
|
return (
|
||||||
super()
|
super()
|
||||||
.get_table_data()
|
.get_table_data()
|
||||||
.filter(event_type__in=HIDEvent.EventType.any_granted_access())
|
.filter(event_type__in=granted_event_types)
|
||||||
.with_member_id()
|
.with_member_id()
|
||||||
.values(unit_time=Trunc("timestamp", unit_time))
|
.values(unit_time=Trunc("timestamp", unit_time))
|
||||||
.annotate(
|
.annotate(
|
||||||
@ -252,10 +255,6 @@ class DetailByDay(BaseAccessReport):
|
|||||||
.filter(member_id__isnull=False)
|
.filter(member_id__isnull=False)
|
||||||
.annotate(
|
.annotate(
|
||||||
access_count=Count("member_id"),
|
access_count=Count("member_id"),
|
||||||
granted_access_count=Count(
|
|
||||||
"member_id",
|
|
||||||
filter=Q(event_type__in=HIDEvent.EventType.any_granted_access()),
|
|
||||||
),
|
|
||||||
name=GroupConcat(
|
name=GroupConcat(
|
||||||
ConcatWS("forename", "surname", separator=" "), distinct=True
|
ConcatWS("forename", "surname", separator=" "), distinct=True
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user