Skip to content

Commit

Permalink
Merge branch 'develop' into 'staging'
Browse files Browse the repository at this point in the history
Develop -> Staging

See merge request bullet-train/bullet-train-api!236
  • Loading branch information
matthewelwell committed Dec 5, 2020
2 parents 6db68f6 + c9189ae commit 426e777
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
19 changes: 16 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ The application relies on the following environment variables to run:
* `ALLOWED_ADMIN_IP_ADDRESSES`: restrict access to the django admin console to a comma separated list of IP addresses (e.g. `127.0.0.1,127.0.0.2`)
* `USER_CREATE_PERMISSIONS`: set the permissions for creating new users, using a comma separated list of djoser or rest_framework permissions. Use this to turn off public user creation for self hosting. e.g. `'djoser.permissions.CurrentUserOrAdmin'` Defaults to `'rest_framework.permissions.AllowAny'`.
* `ENABLE_EMAIL_ACTIVATION`: new user registration will go via email activation flow, default False
* `SENTRY_SDK_DSN`: If using Sentry, set the project DSN here.
* `SENTRY_TRACE_SAMPLE_RATE`: Float. If using Sentry, sets the trace sample rate. Defaults to 1.0.

## Pre commit

The application uses pre-commit configuration ( `.pre-commit-config.yaml` ) to run black formatting before commits.

To install pre-commit:

```bash
pip install pre-commit
pre-commit install
```

### Creating a secret key

Expand Down Expand Up @@ -191,9 +204,9 @@ given project. The number of seconds this is cached for is configurable using th

## Stack

- Python 2.7.14
- Django 1.11.13
- DjangoRestFramework 3.8.2
- Python 3.8
- Django 2.2.17
- DjangoRestFramework 3.12.1

## Static Files

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ django-ses==1.0.3
django-axes==5.8.0
django-admin-sso==3.0.0
drf-yasg2==1.19.3
django-debug-toolbar==3.1.1
django-debug-toolbar==3.1.1
sentry-sdk==0.19.4
11 changes: 6 additions & 5 deletions src/analytics/influxdb_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import defaultdict

from django.conf import settings
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
Expand Down Expand Up @@ -88,14 +90,13 @@ def get_event_list_for_organisation(organisation_id: int):
drop_columns='"organisation", "organisation_id", "type", "project", "project_id"',
extra="|> aggregateWindow(every: 24h, fn: sum)",
)
dataset = []
dataset = defaultdict(list)
labels = []
for result in results:
for record in result.records:
dataset.append(
{"t": record.values["_time"].isoformat(), "y": record.values["_value"]}
)
labels.append(record.values["_time"].strftime("%Y-%m-%d"))
dataset[record["resource"]].append(record["_value"])
if len(labels) != 31:
labels.append(record.values["_time"].strftime("%Y-%m-%d"))
return dataset, labels


Expand Down
15 changes: 15 additions & 0 deletions src/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import dj_database_url
import environ
import requests
import sentry_sdk
from corsheaders.defaults import default_headers
from django.core.management.utils import get_random_secret_key
from sentry_sdk.integrations.django import DjangoIntegration

env = environ.Env()

Expand Down Expand Up @@ -403,3 +405,16 @@
"/admin/login/?next=/admin",
"/admin/",
]

# Sentry tracking
SENTRY_SDK_DSN = env("SENTRY_SDK_DSN", default=None)
if SENTRY_SDK_DSN:
sentry_sdk.init(
dsn=env.str("SENTRY_SDK_DSN"),
integrations=[DjangoIntegration()],
traces_sample_rate=env.float("SENTRY_TRACE_SAMPLE_RATE", default=1.0),
environment=env("ENVIRONMENT", default="unknown"),
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True,
)
51 changes: 26 additions & 25 deletions src/sales_dashboard/templates/sales_dashboard/organisation.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,33 @@ <h2>Users</h2>
<script>
var ctx = document.getElementById("examChart").getContext("2d");
var myChart = new Chart(ctx, {
type: 'line',
type: 'bar',
data: {
labels: {{labels}},
datasets: [{
label: 'Api Requests',
data: {{ event_list }},
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {}
});
datasets: [
{
label: 'Flags',
data: {{flags}},
backgroundColor: '#D6E9C6',
},
{
label: 'Identities',
data: {{identities}},
backgroundColor: '#FAEBCC',
},
{
label: 'Traits',
data: {{traits}},
backgroundColor: '#EBCCD1',
}
]
},
options: {
scales: {
xAxes: [{ stacked: true }],
yAxes: [{ stacked: true }]
}
}
});
</script>
{% endblock %}
5 changes: 4 additions & 1 deletion src/sales_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def organisation_info(request, organisation_id):
template = loader.get_template("sales_dashboard/organisation.html")
context = {
"organisation": organisation,
"event_list": mark_safe(json.dumps(event_list)),
"event_list": event_list,
"traits": mark_safe(json.dumps(event_list["traits"])),
"identities": mark_safe(json.dumps(event_list["identities"])),
"flags": mark_safe(json.dumps(event_list["flags"])),
"labels": mark_safe(json.dumps(labels)),
}

Expand Down

0 comments on commit 426e777

Please sign in to comment.