Add basic stats list
This commit is contained in:
34
shynet/analytics/migrations/0004_auto_20200411_1541.py
Normal file
34
shynet/analytics/migrations/0004_auto_20200411_1541.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-11 19:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('analytics', '0003_auto_20200410_1325'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='hit',
|
||||
old_name='start',
|
||||
new_name='start_time',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='session',
|
||||
old_name='first_seen',
|
||||
new_name='start_time',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='hit',
|
||||
name='duration',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='hit',
|
||||
name='last_seen',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -18,7 +18,7 @@ class Session(models.Model):
|
||||
identifier = models.TextField(blank=True)
|
||||
|
||||
# Time
|
||||
first_seen = models.DateTimeField(auto_now_add=True)
|
||||
start_time = models.DateTimeField(auto_now_add=True)
|
||||
last_seen = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
# Core request information
|
||||
@@ -40,8 +40,8 @@ class Hit(models.Model):
|
||||
session = models.ForeignKey(Session, on_delete=models.CASCADE)
|
||||
|
||||
# Base request information
|
||||
start = models.DateTimeField(auto_now_add=True)
|
||||
duration = models.FloatField(default=0.0) # Seconds spent on page
|
||||
start_time = models.DateTimeField(auto_now_add=True)
|
||||
last_seen = models.DateTimeField(auto_now_add=True)
|
||||
heartbeats = models.IntegerField(default=0)
|
||||
tracker = models.TextField() # Tracking pixel or JS
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ def ingress_request(
|
||||
try:
|
||||
ip_data = _geoip2_lookup(ip)
|
||||
|
||||
service = Service.objects.get(uuid=service_uuid)
|
||||
service = Service.objects.get(uuid=service_uuid, status=Service.ACTIVE)
|
||||
log.debug(f"Linked to service {service}")
|
||||
|
||||
# Create or update session
|
||||
@@ -95,7 +95,7 @@ def ingress_request(
|
||||
# this is a heartbeat.
|
||||
log.debug("Hit is a heartbeat; updating old hit with new data...")
|
||||
hit.heartbeats += 1
|
||||
hit.duration = (timezone.now() - hit.start).total_seconds()
|
||||
hit.last_seen = timezone.now()
|
||||
hit.save()
|
||||
if hit is None:
|
||||
log.debug("Hit is a page load; creating new hit...")
|
||||
|
||||
Reference in New Issue
Block a user