diff --git a/api/app/settings.py b/api/app/settings.py
index a29bd9e..d359593 100644
--- a/api/app/settings.py
+++ b/api/app/settings.py
@@ -45,7 +45,7 @@
"django.contrib.staticfiles",
"corsheaders",
"allauth",
- 'django.contrib.sites',
+ "django.contrib.sites",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
@@ -76,7 +76,7 @@
"allauth.account.auth_backends.AuthenticationBackend",
)
-AUTHENTICATION_REQUIRED=os.environ.get("IS_AUTHENTICATION_REQUIRED", False)
+AUTHENTICATION_REQUIRED = os.environ.get("IS_AUTHENTICATION_REQUIRED", False)
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
@@ -162,6 +162,7 @@
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = "/static/"
+STATIC_ROOT = os.path.join(BASE_DIR, "static_root")
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
diff --git a/api/ops/tasks/detectionTypes/lifetime.py b/api/ops/tasks/detectionTypes/lifetime.py
index 5a44dc2..bc1b7d0 100644
--- a/api/ops/tasks/detectionTypes/lifetime.py
+++ b/api/ops/tasks/detectionTypes/lifetime.py
@@ -12,9 +12,17 @@ def checkLatestAnomaly(df):
lastAnomalyRow = anomalies.iloc[-1]
anomalyTime = lastAnomalyRow["ds"]
+ maxRow = anomalies[anomalies["y"] == anomalies.y.max()].iloc[-1]
+ minRow = anomalies[anomalies["y"] == anomalies.y.min()].iloc[-1]
+
return {
- "highOrLow": "high" if lastAnomalyRow["y"] == df.y.max() else "low",
+ "highOrLow": "high" if lastAnomalyRow["y"] == anomalies.y.max() else "low",
"value": float(lastAnomalyRow["y"]),
+ "highVal": float(maxRow["y"]),
+ "highDate": dp.parse(maxRow["ds"]).isoformat(),
+ "lowVal": float(minRow["y"]),
+ "lowDate": dp.parse(minRow["ds"]).isoformat(),
+ "firstDate": dp.parse(df.iloc[0]["ds"]).isoformat(),
"anomalyTimeISO": dp.parse(anomalyTime).isoformat(),
"anomalyTime": dp.parse(anomalyTime).timestamp() * 1000,
}
diff --git a/api/ops/tasks/detectionTypes/tests/test_lifetime.py b/api/ops/tasks/detectionTypes/tests/test_lifetime.py
index b0c3f27..cf0c93e 100644
--- a/api/ops/tasks/detectionTypes/tests/test_lifetime.py
+++ b/api/ops/tasks/detectionTypes/tests/test_lifetime.py
@@ -67,9 +67,15 @@ def testPercentChange():
{'ds': '2020-08-10T00:00:00', 'y': 725, 'anomaly': 1}]},
'anomalyLatest': {'highOrLow': 'high',
'value': 1324.0,
+ 'highVal': 1324.0,
+ 'highDate': '2020-07-30T00:00:00',
+ 'lowVal': 340.0,
+ 'lowDate': '2020-07-26T00:00:00',
+ 'firstDate': '2020-07-12T00:00:00',
'anomalyTimeISO': '2020-07-30T00:00:00',
'anomalyTime': 1596067200000.0}}
-
- assert lifetimeDetect(df, "day") == output
+
+
+ assert lifetimeDetect(df, "day") == output
diff --git a/api/seeddata/anomalyCardTemplate.json b/api/seeddata/anomalyCardTemplate.json
index e1b8de0..90b7ff4 100644
--- a/api/seeddata/anomalyCardTemplate.json
+++ b/api/seeddata/anomalyCardTemplate.json
@@ -45,7 +45,7 @@
"fields": {
"templateName": "Anomaly Daily Template Lifetime",
"title": "{{metric}}{% if dimensionVal %} for filter {{dimension}} = {{dimensionVal}}{% endif %} was at a lifetime {{highOrLow}} value on {{anomalyTimeISO|slice:\"0:10\"}}",
- "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was at lifetime {{highOrLow}} value of {{value}} on {{anomalyTimeISO|slice:\"0:10\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
+ "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was at lifetime high value of {{highVal}} on {{highDate|slice:\"0:10\"}} and lifetime low value of {{lowVal}} on {{lowDate|slice:\"0:10\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %} The lifetime period started on {{firstDate|slice:\"0:10\"}}.",
"supportedVariables": "granularity, datasetName, metric, dimension, dimensionVal, percent, contribution, anomalyTimeISO, highOrLow"
}
},
@@ -55,7 +55,7 @@
"fields": {
"templateName": "Anomaly Hourly Template Lifetime",
"title": "{{metric}}{% if dimensionVal %} for filter {{dimension}} = {{dimensionVal}}{% endif %} was at a lifetime {{highOrLow}} value on {{anomalyTimeISO|slice:\"0:10\"}} {{anomalyTimeISO|slice:\"11:16\"}}",
- "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was at lifetime {{highOrLow}} value of {{value}} on {{anomalyTimeISO|slice:\"0:10\"}} {{anomalyTimeISO|slice:\"11:16\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
+ "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was at lifetime high value of {{highVal}} on {{highDate|slice:\"0:10\"}} {{highDate|slice:\"11:16\"}} and lifetime low value of {{lowVal}} on {{lowDate|slice:\"0:10\"}} {{lowDate|slice:\"11:16\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %} The lifetime period started on {{firstDate|slice:\"0:10\"}} {{firstDate|slice:\"11:16\"}}.",
"supportedVariables": "granularity, datasetName, metric, dimension, dimensionVal, percent, contribution, anomalyTimeISO, highOrLow"
}
},
@@ -65,7 +65,7 @@
"fields": {
"templateName": "Anomaly Daily Template Value Threshold",
"title": "{{metric}}{% if dimensionVal %} for filter {{dimension}} = {{dimensionVal}}{% endif %} was {{operationCheck}}",
- "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was {{{operationCheck}} on {{anomalyTimeISO|slice:\"0:10\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
+ "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was {{operationCheck}} on {{anomalyTimeISO|slice:\"0:10\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
"supportedVariables": "granularity, datasetName, metric, dimension, dimensionVal, percent, contribution, anomalyTimeISO, operationCheck"
}
},
@@ -75,7 +75,7 @@
"fields": {
"templateName": "Anomaly Hourly Template Value Threshold",
"title": "{{metric}}{% if dimensionVal %} for filter {{dimension}} = {{dimensionVal}}{% endif %} was {{operationCheck}}",
- "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was {{{operationCheck}} on {{anomalyTimeISO|slice:\"0:10\"}} {{anomalyTimeISO|slice:\"11:16\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
+ "bodyText": "{% if dimensionVal %}For {{dimension}} = {{dimensionVal}} filter, {% endif %}{{datasetName}}.{{metric}} was {{operationCheck}} on {{anomalyTimeISO|slice:\"0:10\"}} {{anomalyTimeISO|slice:\"11:16\"}}.{% if dimensionVal and contribution %} This filter's contribution to {{metric}} was {{contribution|floatformat:\"1\"}}%.{% endif %}",
"supportedVariables": "granularity, datasetName, metric, dimension, dimensionVal, contribution, anomalyTimeISO, operationCheck"
}
}
diff --git a/api/start_server.sh b/api/start_server.sh
index 26bd08e..24a86ea 100644
--- a/api/start_server.sh
+++ b/api/start_server.sh
@@ -9,6 +9,7 @@ if [ -n "$DJANGO_SUPERUSER_USERNAME" ] && [ -n "$DJANGO_SUPERUSER_EMAIL" ] && [
fi
chmod -R 777 db
chown -R www-data:www-data db
+python ./manage.py collectstatic
(gunicorn app.wsgi --user www-data --bind 0.0.0.0:8000 --workers 3 --timeout 300) &
(celery -A app worker --concurrency=6 -l INFO --purge) &
(celery -A app beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler) &
diff --git a/nginx.conf b/nginx.conf
index 7cb8e49..14ef156 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -30,6 +30,12 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
+ location /static {
+ proxy_pass http://127.0.0.1:8000;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ }
+
location / {
root /usr/share/nginx/html;
index index.html index.htm;