Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
milesmcc committed Mar 29, 2021
1 parent b63863e commit fe8e766
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 72 deletions.
6 changes: 1 addition & 5 deletions shynet/a17t/templatetags/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ def pagination(
after_current_pages=4,
):
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)
Expand Down
8 changes: 6 additions & 2 deletions shynet/analytics/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class Migration(migrations.Migration):
),
),
],
options={"ordering": ["-start_time"],},
options={
"ordering": ["-start_time"],
},
),
migrations.CreateModel(
name="Hit",
Expand Down Expand Up @@ -90,7 +92,9 @@ class Migration(migrations.Migration):
),
),
],
options={"ordering": ["-start_time"],},
options={
"ordering": ["-start_time"],
},
),
migrations.AddIndex(
model_name="session",
Expand Down
36 changes: 22 additions & 14 deletions shynet/analytics/migrations/0004_auto_20210328_1514.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,40 @@
class Migration(migrations.Migration):

dependencies = [
('analytics', '0003_auto_20200502_1227'),
("analytics", "0003_auto_20200502_1227"),
]

operations = [
migrations.AlterField(
model_name='hit',
name='last_seen',
model_name="hit",
name="last_seen",
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='hit',
name='start_time',
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now),
model_name="hit",
name="start_time",
field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
),
migrations.AlterField(
model_name='session',
name='last_seen',
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now),
model_name="session",
name="last_seen",
field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
),
migrations.AlterField(
model_name='session',
name='start_time',
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now),
model_name="session",
name="start_time",
field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
),
migrations.AddIndex(
model_name='session',
index=models.Index(fields=['service', '-last_seen'], name='analytics_s_service_10bb96_idx'),
model_name="session",
index=models.Index(
fields=["service", "-last_seen"], name="analytics_s_service_10bb96_idx"
),
),
]
14 changes: 8 additions & 6 deletions shynet/analytics/migrations/0005_auto_20210328_1518.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
class Migration(migrations.Migration):

dependencies = [
('analytics', '0004_auto_20210328_1514'),
("analytics", "0004_auto_20210328_1514"),
]

operations = [
migrations.AlterField(
model_name='hit',
name='last_seen',
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now),
model_name="hit",
name="last_seen",
field=models.DateTimeField(
db_index=True, default=django.utils.timezone.now
),
),
migrations.AlterField(
model_name='hit',
name='load_time',
model_name="hit",
name="load_time",
field=models.FloatField(db_index=True, null=True),
),
]
34 changes: 18 additions & 16 deletions shynet/analytics/migrations/0006_hit_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@
import django.db.models.deletion
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]
service = Session.objects.filter(pk=OuterRef("session")).values_list("service")[:1]

Hit.objects.update(service=Subquery(service))

Hit.objects.update(
service=Subquery(service)
)

class Migration(migrations.Migration):

dependencies = [
('core', '0008_auto_20200628_1403'),
('analytics', '0005_auto_20210328_1518'),
("core", "0008_auto_20200628_1403"),
("analytics", "0005_auto_20210328_1518"),
]

operations = [
migrations.AddField(
model_name='hit',
name='service',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.service'),
model_name="hit",
name="service",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="core.service",
),
),
migrations.RunPython(add_service_to_hits, lambda: ()),
migrations.AlterField(
model_name='hit',
name='service',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.service'),
model_name="hit",
name="service",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="core.service"
),
),
]
8 changes: 5 additions & 3 deletions shynet/analytics/migrations/0007_auto_20210328_1634.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
class Migration(migrations.Migration):

dependencies = [
('analytics', '0006_hit_service'),
("analytics", "0006_hit_service"),
]

operations = [
migrations.AddIndex(
model_name='hit',
index=models.Index(fields=['service', '-start_time'], name='analytics_h_service_f4f41e_idx'),
model_name="hit",
index=models.Index(
fields=["service", "-start_time"], name="analytics_h_service_f4f41e_idx"
),
),
]
12 changes: 8 additions & 4 deletions shynet/analytics/migrations/0008_session_is_bounce.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
from django.db import migrations, models
from django.db.models import Subquery, OuterRef


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):

dependencies = [
('analytics', '0007_auto_20210328_1634'),
("analytics", "0007_auto_20210328_1634"),
]

operations = [
migrations.AddField(
model_name='session',
name='is_bounce',
model_name="session",
name="is_bounce",
field=models.BooleanField(db_index=True, default=True),
),
migrations.RunPython(update_bounce_stats, lambda: ()),
Expand Down
2 changes: 1 addition & 1 deletion shynet/analytics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def ingress_request(
load_time=payload.get("loadTime"),
start_time=time,
last_seen=time,
service=service
service=service,
)

# Recalculate whether the session is a bounce
Expand Down
4 changes: 3 additions & 1 deletion shynet/analytics/views/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def get(self, *args, **kwargs):
endpoint = (
reverse(
"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
else reverse(
Expand Down
9 changes: 6 additions & 3 deletions shynet/core/management/commands/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"name", type=str,
"name",
type=str,
)
parser.add_argument("owner_email", type=str)
parser.add_argument(
"avg", type=int,
"avg",
type=int,
)
parser.add_argument("deviation", type=float, default=0.4)
parser.add_argument(
"days", type=int,
"days",
type=int,
)
parser.add_argument("load_time", type=float, default=1000)

Expand Down
3 changes: 2 additions & 1 deletion shynet/core/management/commands/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"hostname", type=str,
"hostname",
type=str,
)

def handle(self, *args, **options):
Expand Down
3 changes: 2 additions & 1 deletion shynet/core/management/commands/registeradmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"email", type=str,
"email",
type=str,
)

def handle(self, *args, **options):
Expand Down
3 changes: 2 additions & 1 deletion shynet/core/management/commands/whitelabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"name", type=str,
"name",
type=str,
)

def handle(self, *args, **options):
Expand Down
4 changes: 3 additions & 1 deletion shynet/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class Migration(migrations.Migration):
"verbose_name_plural": "users",
"abstract": False,
},
managers=[("objects", django.contrib.auth.models.UserManager()),],
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name="Service",
Expand Down
3 changes: 2 additions & 1 deletion shynet/core/migrations/0002_auto_20200415_1742.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Migration(migrations.Migration):

operations = [
migrations.AlterModelOptions(
name="service", options={"ordering": ["name", "uuid"]},
name="service",
options={"ordering": ["name", "uuid"]},
),
]
5 changes: 4 additions & 1 deletion shynet/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@ def get_relative_stats(self, start_time, end_time):
}

def get_absolute_url(self):
return reverse("dashboard:service", kwargs={"pk": self.pk},)
return reverse(
"dashboard:service",
kwargs={"pk": self.pk},
)
7 changes: 6 additions & 1 deletion shynet/dashboard/templatetags/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def country_name(isocode):

@register.simple_tag
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"
bad_classes = bad_classes or "~critical"
Expand Down
8 changes: 4 additions & 4 deletions shynet/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from .mixins import DateRangeMixin


class DashboardView(
LoginRequiredMixin, DateRangeMixin, ListView
):
class DashboardView(LoginRequiredMixin, DateRangeMixin, ListView):
model = Service
template_name = "dashboard/pages/dashboard.html"
paginate_by = 5
Expand All @@ -38,7 +36,9 @@ def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)

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

Expand Down
16 changes: 11 additions & 5 deletions shynet/shynet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
"debug_toolbar"
"debug_toolbar",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -147,9 +147,15 @@
{
"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.NumericPasswordValidator",},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]

# Logging
Expand Down Expand Up @@ -250,7 +256,7 @@
SITE_ID = 1

INTERNAL_IPS = [
'127.0.0.1',
"127.0.0.1",
]

# Celery
Expand Down
2 changes: 1 addition & 1 deletion shynet/shynet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import debug_toolbar

urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
path("__debug__/", include(debug_toolbar.urls)),
path("admin/", admin.site.urls),
path("accounts/", include("allauth.urls")),
path("ingress/", include(("analytics.ingress_urls", "ingress")), name="ingress"),
Expand Down

0 comments on commit fe8e766

Please sign in to comment.