From a4ebeca3b78a4618301a63f211512301d2381474 Mon Sep 17 00:00:00 2001 From: Ray Slakinski Date: Thu, 3 Jun 2021 11:47:20 -0400 Subject: [PATCH] fixed formatting and updated the dashboard again --- contrib/grafana/dashboard.json | 4 +- .../ontvacstats-snapshot.json | 839 ++++++++++-------- main.go | 9 +- 3 files changed, 459 insertions(+), 393 deletions(-) diff --git a/contrib/grafana/dashboard.json b/contrib/grafana/dashboard.json index 4666fab..d93db6d 100644 --- a/contrib/grafana/dashboard.json +++ b/contrib/grafana/dashboard.json @@ -259,7 +259,7 @@ "description": "% of Ontario Population partially or Fully Vaccinated.", "fieldConfig": { "defaults": { - "decimals": 0, + "decimals": 1, "mappings": [], "thresholds": { "mode": "absolute", @@ -388,5 +388,5 @@ "timezone": "", "title": "Ontario Vaccination Stats", "uid": "vhnVv3lMk", - "version": 38 + "version": 40 } \ No newline at end of file diff --git a/contrib/update_dashboard/ontvacstats-snapshot.json b/contrib/update_dashboard/ontvacstats-snapshot.json index 8e6f2ea..30ba263 100644 --- a/contrib/update_dashboard/ontvacstats-snapshot.json +++ b/contrib/update_dashboard/ontvacstats-snapshot.json @@ -1,396 +1,463 @@ { - "dashboard": { - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": true, - "gnetId": null, - "graphTooltip": 0, - "id": 25, - "links": [], - "panels": [ + "dashboard": { - "cacheTimeout": null, - "datasource": null, - "description": "~Days left until everyone 12+ Is partially vaccinated.\n\nThis divides the remaining population without any vaccination by the average doses administered over the past 3 days.", - "fieldConfig": { - "defaults": { - "mappings": [ + "annotations": + { + "list": + [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 25, + "links": + [], + "panels": + [ { - "id": 0, - "op": "=", - "text": "N/A", - "type": 1, - "value": "null" + "cacheTimeout": null, + "datasource": null, + "description": "~Days left until everyone 12+ Is partially vaccinated.\n\nThis divides the remaining population without any vaccination by the average doses administered over the past 3 days.", + "fieldConfig": + { + "defaults": + { + "mappings": + [ + { + "id": 0, + "op": "=", + "text": "N/A", + "type": 1, + "value": "null" + } + ], + "thresholds": + { + "mode": "absolute", + "steps": + [ + { + "color": "green", + "value": null + }, + { + "color": "#EAB839", + "value": 80 + }, + { + "color": "red", + "value": 100 + } + ] + }, + "unit": "none" + }, + "overrides": + [] + }, + "gridPos": + { + "h": 6, + "w": 5, + "x": 0, + "y": 0 + }, + "id": 8, + "interval": null, + "links": + [], + "maxDataPoints": 100, + "options": + { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": + { + "calcs": + [ + "lastNotNull" + ], + "fields": "/^{instance=\"127.0.0.1:8080\", job=\"ontvacstat\"}$/", + "values": false + }, + "text": + {}, + "textMode": "auto" + }, + "pluginVersion": "7.5.1", + "targets": + [ + { + "exemplar": true, + "expr": "((ontvacstat_eligible_population - ontvacstat_total_individuals_fully_vaccinated) - (ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals)) / avg_over_time(ontvacstat_previous_day_doses_administered[7d])", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "", + "refId": "A" + } + ], + "title": "~ Days Left", + "type": "stat" + }, + { + "datasource": null, + "fieldConfig": + { + "defaults": + { + "mappings": + [], + "thresholds": + { + "mode": "absolute", + "steps": + [ + { + "color": "red", + "value": null + }, + { + "color": "#EAB839", + "value": 10000 + }, + { + "color": "green", + "value": 110000 + } + ] + } + }, + "overrides": + [] + }, + "gridPos": + { + "h": 6, + "w": 6, + "x": 5, + "y": 0 + }, + "id": 4, + "links": + [], + "options": + { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": + { + "calcs": + [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "text": + {}, + "textMode": "auto" + }, + "pluginVersion": "7.5.1", + "targets": + [ + { + "exemplar": true, + "expr": "ontvacstat_previous_day_doses_administered", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Previous Day Doses Administered", + "refId": "A" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Doses Administered Yesterday", + "type": "stat" + }, + { + "aliasColors": + {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fieldConfig": + { + "defaults": + {}, + "overrides": + [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": + { + "h": 7, + "w": 11, + "x": 0, + "y": 6 + }, + "hiddenSeries": false, + "id": 10, + "legend": + { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "connected", + "options": + { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": + [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": + [ + { + "exemplar": true, + "expr": "avg_over_time(ontvacstat_previous_day_doses_administered[3d:1d])", + "interval": "", + "intervalFactor": 1, + "legendFormat": "3d:1d Avg", + "refId": "A" + } + ], + "thresholds": + [], + "timeFrom": null, + "timeRegions": + [], + "timeShift": null, + "title": "Vacination Rate", + "tooltip": + { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": + { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": + [] + }, + "yaxes": + [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": + { + "align": false, + "alignLevel": null + } + }, + { + "datasource": null, + "description": "% of Ontario Population partially or Fully Vaccinated.", + "fieldConfig": + { + "defaults": + { + "decimals": 1, + "mappings": + [], + "thresholds": + { + "mode": "absolute", + "steps": + [ + { + "color": "dark-red", + "value": null + }, + { + "color": "semi-dark-red", + "value": 40 + }, + { + "color": "light-red", + "value": 50 + }, + { + "color": "semi-dark-yellow", + "value": 60 + }, + { + "color": "light-yellow", + "value": 70 + }, + { + "color": "light-green", + "value": 80 + }, + { + "color": "semi-dark-green", + "value": 90 + } + ] + }, + "unit": "percent" + }, + "overrides": + [] + }, + "gridPos": + { + "h": 8, + "w": 11, + "x": 0, + "y": 13 + }, + "id": 2, + "links": + [], + "options": + { + "displayMode": "lcd", + "orientation": "horizontal", + "reduceOptions": + { + "calcs": + [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showUnfilled": true, + "text": + {} + }, + "pluginVersion": "7.5.1", + "targets": + [ + { + "exemplar": true, + "expr": "(ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals) / (ontvacstat_eligible_population) * 100", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Partially Vaccinated", + "refId": "A" + }, + { + "exemplar": true, + "expr": "ontvacstat_total_individuals_fully_vaccinated / ontvacstat_eligible_population * 100", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Fully Vaccinated", + "refId": "B" + }, + { + "exemplar": true, + "expr": "(ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals + ontvacstat_total_individuals_fully_vaccinated) / (ontvacstat_eligible_population) * 100", + "hide": false, + "interval": "", + "legendFormat": "Combined", + "refId": "C" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Total Vaccinations & Fully Vaccinated (12+)", + "type": "bargauge" } - ], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "#EAB839", - "value": 80 - }, - { - "color": "red", - "value": 100 - } + ], + "refresh": "15m", + "schemaVersion": 27, + "style": "dark", + "tags": + [], + "templating": + { + "list": + [] + }, + "time": + { + "from": "now-3d", + "to": "now" + }, + "timepicker": + { + "refresh_intervals": + [ + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": + [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" ] - }, - "unit": "none" }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 5, - "x": 0, - "y": 0 - }, - "id": 8, - "interval": null, - "links": [], - "maxDataPoints": 100, - "options": { - "colorMode": "value", - "graphMode": "area", - "justifyMode": "auto", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "/^{instance=\"127.0.0.1:8080\", job=\"ontvacstat\"}$/", - "values": false - }, - "text": {}, - "textMode": "auto" - }, - "pluginVersion": "7.5.1", - "targets": [ - { - "exemplar": true, - "expr": "((ontvacstat_eligible_population - ontvacstat_total_individuals_fully_vaccinated) - (ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals)) / avg_over_time(ontvacstat_previous_day_doses_administered[7d])", - "format": "time_series", - "interval": "", - "intervalFactor": 1, - "legendFormat": "", - "refId": "A" - } - ], - "title": "~ Days Left", - "type": "stat" + "timezone": "", + "title": "Ontario Vaccination Stats", + "uid": "vhnVv3lMk", + "version": 40 }, - { - "datasource": null, - "fieldConfig": { - "defaults": { - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "red", - "value": null - }, - { - "color": "#EAB839", - "value": 10000 - }, - { - "color": "green", - "value": 110000 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 6, - "x": 5, - "y": 0 - }, - "id": 4, - "links": [], - "options": { - "colorMode": "value", - "graphMode": "area", - "justifyMode": "auto", - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "text": {}, - "textMode": "auto" - }, - "pluginVersion": "7.5.1", - "targets": [ - { - "exemplar": true, - "expr": "ontvacstat_previous_day_doses_administered", - "format": "time_series", - "interval": "", - "intervalFactor": 1, - "legendFormat": "Previous Day Doses Administered", - "refId": "A" - } - ], - "timeFrom": null, - "timeShift": null, - "title": "Doses Administered Yesterday", - "type": "stat" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": null, - "fieldConfig": { - "defaults": {}, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 11, - "x": 0, - "y": 6 - }, - "hiddenSeries": false, - "id": 10, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "connected", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "7.5.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "exemplar": true, - "expr": "avg_over_time(ontvacstat_previous_day_doses_administered[3d:1d])", - "interval": "", - "intervalFactor": 1, - "legendFormat": "3d:1d Avg", - "refId": "A" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Vacination Rate", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "datasource": null, - "description": "% of Ontario Population partially or Fully Vaccinated.", - "fieldConfig": { - "defaults": { - "decimals": 0, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "dark-red", - "value": null - }, - { - "color": "semi-dark-red", - "value": 40 - }, - { - "color": "light-red", - "value": 50 - }, - { - "color": "semi-dark-yellow", - "value": 60 - }, - { - "color": "light-yellow", - "value": 70 - }, - { - "color": "light-green", - "value": 80 - }, - { - "color": "semi-dark-green", - "value": 90 - } - ] - }, - "unit": "percent" - }, - "overrides": [] - }, - "gridPos": { - "h": 8, - "w": 11, - "x": 0, - "y": 13 - }, - "id": 2, - "links": [], - "options": { - "displayMode": "lcd", - "orientation": "horizontal", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showUnfilled": true, - "text": {} - }, - "pluginVersion": "7.5.1", - "targets": [ - { - "exemplar": true, - "expr": "(ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals) / (ontvacstat_eligible_population) * 100", - "format": "time_series", - "interval": "", - "intervalFactor": 1, - "legendFormat": "Partially Vaccinated", - "refId": "A" - }, - { - "exemplar": true, - "expr": "ontvacstat_total_individuals_fully_vaccinated / ontvacstat_eligible_population * 100", - "format": "time_series", - "interval": "", - "intervalFactor": 1, - "legendFormat": "Fully Vaccinated", - "refId": "B" - }, - { - "exemplar": true, - "expr": "(ontvacstat_total_doses_administered - ontvacstat_total_doses_in_fully_vaccinated_individuals + ontvacstat_total_individuals_fully_vaccinated) / (ontvacstat_eligible_population) * 100", - "hide": false, - "interval": "", - "legendFormat": "Combined", - "refId": "C" - } - ], - "timeFrom": null, - "timeShift": null, - "title": "Total Vaccinations & Fully Vaccinated (12+)", - "type": "bargauge" - } - ], - "refresh": "15m", - "schemaVersion": 27, - "style": "dark", - "tags": [], - "templating": { - "list": [] - }, - "time": { - "from": "now-3d", - "to": "now" - }, - "timepicker": { - "refresh_intervals": [ - "15m", - "30m", - "1h", - "2h", - "1d" - ], - "time_options": [ - "5m", - "15m", - "1h", - "6h", - "12h", - "24h", - "2d", - "7d", - "30d" - ] - }, - "timezone": "", - "title": "Ontario Vaccination Stats", - "uid": "vhnVv3lMk", - "version": 38 -}, "expires": 86400, "key": "ontvacstats" } \ No newline at end of file diff --git a/main.go b/main.go index 374a1a6..a4e2d77 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ type OntCovidData struct { ID int `json:"_id"` ReportDate string `json:"report_date"` PreviousDayDosesAdministered int `json:"previous_day_total_doses_administered"` - PreviousDayAtLeastOne int `json:"previous_day_at_least_one"` + PreviousDayAtLeastOne int `json:"previous_day_at_least_one"` PreviousDayFullyVaccinated int `json:"previous_day_fully_vaccinated"` TotalDosesAdministered int `json:"total_doses_administered"` TotalDosesAtLeastOne int `json:"total_individuals_at_least_one"` @@ -55,10 +55,10 @@ type OntCovidData struct { var records struct { PreviousDayDosesAdministered func() prometheus.Gauge `name:"previous_day_doses_administered" help:"Previous day doses administered"` - PreviousDayAtLeastOne func() prometheus.Gauge `name:"previous_day_at_least_one" help:"Previous day doses administered at least one shot"` + PreviousDayAtLeastOne func() prometheus.Gauge `name:"previous_day_at_least_one" help:"Previous day doses administered at least one shot"` PreviousDayFullyVaccinated func() prometheus.Gauge `name:"previous_day_fully_vaccinated" help:"Previous day doses administered fully vaccinated"` TotalDosesAdministered func() prometheus.Gauge `name:"total_doses_administered" help:"Total doses administered"` - TotalDosesAtLeastOne func() prometheus.Gauge `name:"total_individuals_at_least_one" help:"Total at least one dose in individuals"` + TotalDosesAtLeastOne func() prometheus.Gauge `name:"total_individuals_at_least_one" help:"Total at least one dose in individuals"` TotalDosesInFullyVaccinatedIndividuals func() prometheus.Gauge `name:"total_doses_in_fully_vaccinated_individuals" help:"Total does in fully vaccinated individuals"` TotalIndividualsFullyVaccinated func() prometheus.Gauge `name:"total_individuals_fully_vaccinated" help:"Total individuals fully vaccinated"` EligiblePopulation func() prometheus.Gauge `name:"eligible_population" help:"Total population eligible for the vaccination"` @@ -70,7 +70,7 @@ func init() { func updateMetrics() { data_url := "https://data.ontario.ca/api/3/action/datastore_search?sort=report_date+desc&limit=1&resource_id=8a89caa9-511c-4568-af89-7f2174b4378c" - eligiblePopulation := int64(12932471) // Ontario population 12+ (https://www150.statcan.gc.ca/t1/tbl1/en/cv!recreate.action?pid=1710000501&selectedNodeIds=1D7,3D16,3D17,3D18,3D20,3D21,3D22,3D101&checkedLevels=1D1&refPeriods=20160101,20200101&dimensionLayouts=layout2,layout2,layout3,layout2&vectorDisplay=false) + eligiblePopulation := int64(12932471) // Ontario population 12+ (https://www150.statcan.gc.ca/t1/tbl1/en/cv!recreate.action?pid=1710000501&selectedNodeIds=1D7,3D16,3D17,3D18,3D20,3D21,3D22,3D101&checkedLevels=1D1&refPeriods=20160101,20200101&dimensionLayouts=layout2,layout2,layout3,layout2&vectorDisplay=false) resp, getErr := http.Get(data_url) if getErr != nil { log.Println(getErr) @@ -88,7 +88,6 @@ func updateMetrics() { return } - records.PreviousDayDosesAdministered().Set(float64(data.Result.Records[0].PreviousDayDosesAdministered)) records.PreviousDayAtLeastOne().Set(float64(data.Result.Records[0].PreviousDayAtLeastOne)) records.PreviousDayFullyVaccinated().Set(float64(data.Result.Records[0].PreviousDayFullyVaccinated))