This commit is contained in:
R. Miles McCain 2021-03-29 14:37:59 +00:00
parent b63863e283
commit fe8e766670
20 changed files with 116 additions and 73 deletions

View File

@ -16,11 +16,7 @@ def pagination(
after_current_pages=4, after_current_pages=4,
): ):
url_parameters = urlencode( url_parameters = urlencode(
[ [(key, value) for key, value in request.GET.items() if key != "page"]
(key, value)
for key, value in request.GET.items()
if key != "page"
]
) )
before = max(page.number - before_current_pages - 1, 0) before = max(page.number - before_current_pages - 1, 0)

View File

@ -60,7 +60,9 @@ class Migration(migrations.Migration):
), ),
), ),
], ],
options={"ordering": ["-start_time"],}, options={
"ordering": ["-start_time"],
},
), ),
migrations.CreateModel( migrations.CreateModel(
name="Hit", name="Hit",
@ -90,7 +92,9 @@ class Migration(migrations.Migration):
), ),
), ),
], ],
options={"ordering": ["-start_time"],}, options={
"ordering": ["-start_time"],
},
), ),
migrations.AddIndex( migrations.AddIndex(
model_name="session", model_name="session",

View File

@ -7,32 +7,40 @@ import django.utils.timezone
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('analytics', '0003_auto_20200502_1227'), ("analytics", "0003_auto_20200502_1227"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='hit', model_name="hit",
name='last_seen', name="last_seen",
field=models.DateTimeField(default=django.utils.timezone.now), field=models.DateTimeField(default=django.utils.timezone.now),
), ),
migrations.AlterField( migrations.AlterField(
model_name='hit', model_name="hit",
name='start_time', name="start_time",
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='session', model_name="session",
name='last_seen', name="last_seen",
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='session', model_name="session",
name='start_time', name="start_time",
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
), ),
migrations.AddIndex( migrations.AddIndex(
model_name='session', model_name="session",
index=models.Index(fields=['service', '-last_seen'], name='analytics_s_service_10bb96_idx'), index=models.Index(
fields=["service", "-last_seen"], name="analytics_s_service_10bb96_idx"
),
), ),
] ]

View File

@ -7,18 +7,20 @@ import django.utils.timezone
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('analytics', '0004_auto_20210328_1514'), ("analytics", "0004_auto_20210328_1514"),
] ]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='hit', model_name="hit",
name='last_seen', name="last_seen",
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
), ),
migrations.AlterField( migrations.AlterField(
model_name='hit', model_name="hit",
name='load_time', name="load_time",
field=models.FloatField(db_index=True, null=True), field=models.FloatField(db_index=True, null=True),
), ),
] ]

View File

@ -5,34 +5,36 @@ from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db.models import Subquery, OuterRef from django.db.models import Subquery, OuterRef
def add_service_to_hits(_a, _b):
service = Session.objects.filter(
pk=OuterRef('session')
).values_list(
'service'
)[:1]
Hit.objects.update( def add_service_to_hits(_a, _b):
service=Subquery(service) service = Session.objects.filter(pk=OuterRef("session")).values_list("service")[:1]
)
Hit.objects.update(service=Subquery(service))
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('core', '0008_auto_20200628_1403'), ("core", "0008_auto_20200628_1403"),
('analytics', '0005_auto_20210328_1518'), ("analytics", "0005_auto_20210328_1518"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='hit', model_name="hit",
name='service', name="service",
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.service'), field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="core.service",
),
), ),
migrations.RunPython(add_service_to_hits, lambda: ()), migrations.RunPython(add_service_to_hits, lambda: ()),
migrations.AlterField( migrations.AlterField(
model_name='hit', model_name="hit",
name='service', name="service",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.service'), field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="core.service"
),
), ),
] ]

View File

@ -6,12 +6,14 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('analytics', '0006_hit_service'), ("analytics", "0006_hit_service"),
] ]
operations = [ operations = [
migrations.AddIndex( migrations.AddIndex(
model_name='hit', model_name="hit",
index=models.Index(fields=['service', '-start_time'], name='analytics_h_service_f4f41e_idx'), index=models.Index(
fields=["service", "-start_time"], name="analytics_h_service_f4f41e_idx"
),
), ),
] ]

View File

@ -5,19 +5,23 @@ from ..models import Session, Hit
from django.db import migrations, models from django.db import migrations, models
from django.db.models import Subquery, OuterRef from django.db.models import Subquery, OuterRef
def update_bounce_stats(_a, _b): def update_bounce_stats(_a, _b):
Session.objects.all().annotate(hit_count=models.Count("hit")).filter(hit_count__gt=1).update(is_bounce=False) Session.objects.all().annotate(hit_count=models.Count("hit")).filter(
hit_count__gt=1
).update(is_bounce=False)
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('analytics', '0007_auto_20210328_1634'), ("analytics", "0007_auto_20210328_1634"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='session', model_name="session",
name='is_bounce', name="is_bounce",
field=models.BooleanField(db_index=True, default=True), field=models.BooleanField(db_index=True, default=True),
), ),
migrations.RunPython(update_bounce_stats, lambda: ()), migrations.RunPython(update_bounce_stats, lambda: ()),

View File

@ -184,7 +184,7 @@ def ingress_request(
load_time=payload.get("loadTime"), load_time=payload.get("loadTime"),
start_time=time, start_time=time,
last_seen=time, last_seen=time,
service=service service=service,
) )
# Recalculate whether the session is a bounce # Recalculate whether the session is a bounce

View File

@ -112,7 +112,9 @@ class ScriptView(ValidateServiceOriginsMixin, View):
endpoint = ( endpoint = (
reverse( reverse(
"ingress:endpoint_script", "ingress:endpoint_script",
kwargs={"service_uuid": self.kwargs.get("service_uuid"),}, kwargs={
"service_uuid": self.kwargs.get("service_uuid"),
},
) )
if self.kwargs.get("identifier") == None if self.kwargs.get("identifier") == None
else reverse( else reverse(

View File

@ -54,15 +54,18 @@ class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument( parser.add_argument(
"name", type=str, "name",
type=str,
) )
parser.add_argument("owner_email", type=str) parser.add_argument("owner_email", type=str)
parser.add_argument( parser.add_argument(
"avg", type=int, "avg",
type=int,
) )
parser.add_argument("deviation", type=float, default=0.4) parser.add_argument("deviation", type=float, default=0.4)
parser.add_argument( parser.add_argument(
"days", type=int, "days",
type=int,
) )
parser.add_argument("load_time", type=float, default=1000) parser.add_argument("load_time", type=float, default=1000)

View File

@ -14,7 +14,8 @@ class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument( parser.add_argument(
"hostname", type=str, "hostname",
type=str,
) )
def handle(self, *args, **options): def handle(self, *args, **options):

View File

@ -14,7 +14,8 @@ class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument( parser.add_argument(
"email", type=str, "email",
type=str,
) )
def handle(self, *args, **options): def handle(self, *args, **options):

View File

@ -14,7 +14,8 @@ class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument( parser.add_argument(
"name", type=str, "name",
type=str,
) )
def handle(self, *args, **options): def handle(self, *args, **options):

View File

@ -112,7 +112,9 @@ class Migration(migrations.Migration):
"verbose_name_plural": "users", "verbose_name_plural": "users",
"abstract": False, "abstract": False,
}, },
managers=[("objects", django.contrib.auth.models.UserManager()),], managers=[
("objects", django.contrib.auth.models.UserManager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="Service", name="Service",

View File

@ -11,6 +11,7 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.AlterModelOptions( migrations.AlterModelOptions(
name="service", options={"ordering": ["name", "uuid"]}, name="service",
options={"ordering": ["name", "uuid"]},
), ),
] ]

View File

@ -244,4 +244,7 @@ class Service(models.Model):
} }
def get_absolute_url(self): def get_absolute_url(self):
return reverse("dashboard:service", kwargs={"pk": self.pk},) return reverse(
"dashboard:service",
kwargs={"pk": self.pk},
)

View File

@ -44,7 +44,12 @@ def country_name(isocode):
@register.simple_tag @register.simple_tag
def relative_stat_tone( def relative_stat_tone(
start, end, good="UP", good_classes=None, bad_classes=None, neutral_classes=None, start,
end,
good="UP",
good_classes=None,
bad_classes=None,
neutral_classes=None,
): ):
good_classes = good_classes or "~positive" good_classes = good_classes or "~positive"
bad_classes = bad_classes or "~critical" bad_classes = bad_classes or "~critical"

View File

@ -22,9 +22,7 @@ from .forms import ServiceForm
from .mixins import DateRangeMixin from .mixins import DateRangeMixin
class DashboardView( class DashboardView(LoginRequiredMixin, DateRangeMixin, ListView):
LoginRequiredMixin, DateRangeMixin, ListView
):
model = Service model = Service
template_name = "dashboard/pages/dashboard.html" template_name = "dashboard/pages/dashboard.html"
paginate_by = 5 paginate_by = 5
@ -38,7 +36,9 @@ class DashboardView(
data = super().get_context_data(**kwargs) data = super().get_context_data(**kwargs)
for service in data["object_list"]: for service in data["object_list"]:
service.stats = service.get_core_stats(self.get_start_date(), self.get_end_date()) service.stats = service.get_core_stats(
self.get_start_date(), self.get_end_date()
)
return data return data

View File

@ -58,7 +58,7 @@ INSTALLED_APPS = [
"allauth", "allauth",
"allauth.account", "allauth.account",
"allauth.socialaccount", "allauth.socialaccount",
"debug_toolbar" "debug_toolbar",
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -147,9 +147,15 @@ AUTH_PASSWORD_VALIDATORS = [
{ {
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
}, },
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, {
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, },
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
] ]
# Logging # Logging
@ -250,7 +256,7 @@ LOGIN_REDIRECT_URL = "/"
SITE_ID = 1 SITE_ID = 1
INTERNAL_IPS = [ INTERNAL_IPS = [
'127.0.0.1', "127.0.0.1",
] ]
# Celery # Celery

View File

@ -18,7 +18,7 @@ from django.urls import include, path
import debug_toolbar import debug_toolbar
urlpatterns = [ urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)), path("__debug__/", include(debug_toolbar.urls)),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("accounts/", include("allauth.urls")), path("accounts/", include("allauth.urls")),
path("ingress/", include(("analytics.ingress_urls", "ingress")), name="ingress"), path("ingress/", include(("analytics.ingress_urls", "ingress")), name="ingress"),