Skip to content

Commit

Permalink
Merge branch 'main' into CUEAPP#2437
Browse files Browse the repository at this point in the history
  • Loading branch information
PraveenCuebook committed Aug 17, 2021
2 parents 1789af5 + c540617 commit b81134d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
5 changes: 3 additions & 2 deletions api/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"django.contrib.staticfiles",
"corsheaders",
"allauth",
'django.contrib.sites',
"django.contrib.sites",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion api/ops/tasks/detectionTypes/lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
10 changes: 8 additions & 2 deletions api/ops/tasks/detectionTypes/tests/test_lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


8 changes: 4 additions & 4 deletions api/seeddata/anomalyCardTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"fields": {
"templateName": "Anomaly Daily Template Lifetime",
"title": "<b>{{metric}}</b>{% if dimensionVal %} for filter <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span>{% endif %} was at a lifetime {{highOrLow}} value on {{anomalyTimeISO|slice:\"0:10\"}}",
"bodyText": "{% if dimensionVal %}For <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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 <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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"
}
},
Expand All @@ -55,7 +55,7 @@
"fields": {
"templateName": "Anomaly Hourly Template Lifetime",
"title": "<b>{{metric}}</b>{% if dimensionVal %} for filter <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span>{% endif %} was at a lifetime {{highOrLow}} value on {{anomalyTimeISO|slice:\"0:10\"}} {{anomalyTimeISO|slice:\"11:16\"}}",
"bodyText": "{% if dimensionVal %}For <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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 <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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"
}
},
Expand All @@ -65,7 +65,7 @@
"fields": {
"templateName": "Anomaly Daily Template Value Threshold",
"title": "<b>{{metric}}</b>{% if dimensionVal %} for filter <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span>{% endif %} was {{operationCheck}}",
"bodyText": "{% if dimensionVal %}For <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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 <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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"
}
},
Expand All @@ -75,7 +75,7 @@
"fields": {
"templateName": "Anomaly Hourly Template Value Threshold",
"title": "<b>{{metric}}</b>{% if dimensionVal %} for filter <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span>{% endif %} was {{operationCheck}}",
"bodyText": "{% if dimensionVal %}For <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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 <span style=\"background:#eeeeee; padding: 0 4px; border-radius: 4px;\">{{dimension}} = {{dimensionVal}}</span> 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"
}
}
Expand Down
1 change: 1 addition & 0 deletions api/start_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) &
Expand Down
6 changes: 6 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b81134d

Please sign in to comment.