diff options
author | Galen Guyer <galen@galenguyer.com> | 2020-11-13 16:00:56 -0500 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2020-11-13 16:00:56 -0500 |
commit | d094f4f7f7c9a9ab98e3fbde86730549d36a5864 (patch) | |
tree | 4543832c5eeacb02cfb740965896be82fb07953b /poller | |
parent | 0082af242cf9453b1cf6ba31083d3148c54e28f2 (diff) |
add difference route
Diffstat (limited to 'poller')
-rw-r--r-- | poller/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/poller/__init__.py b/poller/__init__.py index e711f06..6d6d143 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -240,3 +240,23 @@ def _api_v0_latestdb(): def _api_v0_history(): data = get_all_from_db() return jsonify(data) + +@APP.route('/api/v0/difference') +def _api_v0_difference(): + data = get_all_from_db() + latest = data[-1] + prev = data[-2] + data = { + 'alert_level': f'{prev["alert_level"]} -> {latest["alert_level"]}', + 'total_students': latest["total_students"] - prev["total_students"], + 'total_staff': latest["total_staff"] - prev["total_staff"], + 'new_students': latest["new_students"] - prev["new_students"], + 'new_staff': latest["new_staff"] - prev["new_staff"], + 'quarantine_on_campus': latest["quarantine_on_campus"] - prev["quarantine_on_campus"], + 'quarantine_off_campus': latest["quarantine_off_campus"] - prev["quarantine_off_campus"], + 'isolation_on_campus': latest["isolation_on_campus"] - prev["isolation_on_campus"], + 'isolation_off_campus': latest["isolation_off_campus"] - prev["isolation_off_campus"], + 'beds_available': latest["beds_available"] - prev["beds_available"], + 'tests_administered': latest["tests_administered"] - prev["tests_administered"], + } + return jsonify(data) |