diff --git a/topic/timeseries/README.md b/topic/timeseries/README.md index 54e919d0..3830cfdd 100644 --- a/topic/timeseries/README.md +++ b/topic/timeseries/README.md @@ -41,4 +41,11 @@ repository, e.g. about machine learning, to see predictions and AutoML in action Furthermore, it shows how to preprocess data and plot time series decomposition by breaking it down into its basic components: trend, seasonality, and residual (or irregular) fluctuations. +- `weather-data-grafana-dashboard.json` + + An exported JSON representation of a Grafana dashboard designed to visualize weather data. This dashboard includes a set of pre-defined panels and widgets that display various weather metrics. Additionally, within this dashboard configuration, there are advanced time-series analysis queries. These queries are tailored to fetch, aggregate, interpolate, and process weather data over time. + + To ensure the dashboard functions correctly, it's necessary to configure the data source within Grafana. This dashboard uses the `grafana-postgresql-datasource` or another configured default data source. In the data source settings, fill in the necessary parameters to connect to your CrateDB instance. This includes setting up the database name (`database=doc`), user, password, and host. + + [CrateDB]: https://github.com/crate/crate diff --git a/topic/timeseries/weather-data-grafana-dashboard.json b/topic/timeseries/weather-data-grafana-dashboard.json new file mode 100644 index 00000000..0ff412be --- /dev/null +++ b/topic/timeseries/weather-data-grafana-dashboard.json @@ -0,0 +1,674 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 21, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 8, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "10.3.3", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT\n COUNT(timestamp) AS \"Measurements\",\n COUNT(DISTINCT location) AS \"Cities\"\nFROM doc.weather_data\n", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "type": "stat" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "none", + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 7, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "/.*/", + "values": true + }, + "showPercentChange": false, + "text": { + "titleSize": 16, + "valueSize": 21 + }, + "textMode": "value_and_name", + "wideLayout": true + }, + "pluginVersion": "10.3.3", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT\nMIN(timestamp) \"First Measurement\",\nMAX(timestamp) \"Last Measurement\"\nFROM doc.weather_data;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 8 + }, + "id": 1, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true + }, + "pluginVersion": "10.3.3", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT location,\n max(temperature) AS highest_temp,\n max_by(timestamp, temperature) AS time_of_highest_temp\nFROM doc.weather_data\nGROUP BY location;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Highest temperature by city", + "type": "table" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "hidden", + "placement": "right", + "showLegend": false + }, + "timezone": [ + "browser" + ], + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "WITH OrderedData AS (\n SELECT timestamp,\n location,\n temperature,\n LAG(temperature, 1) IGNORE NULLS OVER w AS prev_temp,\n LEAD(temperature, 1) IGNORE NULLS OVER w AS next_temp\n FROM doc.weather_data\n WINDOW w AS (PARTITION BY location ORDER BY timestamp)\n)\nSELECT timestamp,\n location,\n COALESCE(temperature, (prev_temp + next_temp)/2) AS interpolated_temperature,\n temperature AS temperature\nFROM OrderedData\nWHERE location='Berlin'\nORDER BY timestamp,location;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Temperature vs Interpolated Temperature in Berlin", + "type": "timeseries" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 16 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT \n timestamp, \n location,\n temperature,\n AVG(temperature) OVER w_10 AS temperature_ma_10,\n AVG(temperature) OVER w_20 AS temperature_ma_20,\n humidity,\n AVG(humidity) OVER w_10 AS humidity_ma_10,\n AVG(humidity) OVER w_20 AS humidity_ma_20,\n wind_speed,\n AVG(wind_speed) OVER w_10 AS wind_speed_ma_10,\n AVG(wind_speed) OVER w_20 AS wind_speed_ma_20\nFROM \n doc.weather_data\nWINDOW\n w_10 AS (ORDER BY location, timestamp ROWS BETWEEN 10 PRECEDING AND CURRENT ROW),\n w_20 AS (ORDER BY location, timestamp ROWS BETWEEN 20 PRECEDING AND CURRENT ROW)\n", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Moving Averages", + "type": "timeseries" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 16 + }, + "id": 9, + "options": { + "basemap": { + "config": {}, + "name": "Layer 0", + "type": "default" + }, + "controls": { + "mouseWheelZoom": true, + "showAttribution": true, + "showDebug": false, + "showMeasure": false, + "showScale": false, + "showZoom": true + }, + "layers": [ + { + "config": { + "showLegend": false, + "style": { + "color": { + "fixed": "red" + }, + "opacity": 0.6, + "rotation": { + "fixed": 0, + "max": 360, + "min": -360, + "mode": "mod" + }, + "size": { + "fixed": 5, + "max": 15, + "min": 2 + }, + "symbol": { + "fixed": "img/icons/marker/circle.svg", + "mode": "fixed" + }, + "symbolAlign": { + "horizontal": "center", + "vertical": "center" + }, + "textConfig": { + "fontSize": 12, + "offsetX": 0, + "offsetY": 0, + "textAlign": "center", + "textBaseline": "middle" + } + } + }, + "filterData": { + "id": "byRefId", + "options": "A" + }, + "location": { + "mode": "auto" + }, + "name": "Layer 1", + "tooltip": false, + "type": "markers" + } + ], + "tooltip": { + "mode": "details" + }, + "view": { + "allLayers": true, + "id": "europe", + "lat": 46, + "lon": 14, + "zoom": 4.04 + } + }, + "pluginVersion": "10.3.3", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "RidvjruGk" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT city,\n latitude(geopoint) AS latitude,\n longitude(geopoint) AS longitude\nFROM doc.weather_stations\nWHERE distance('POINT(13.4050 52.5200)'::GEO_POINT, geopoint) < 1000000 \n", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Weather data stations around Berlin", + "transparent": true, + "type": "geomap" + } + ], + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "2023-04-05T06:00:20.000Z", + "to": "2023-04-27T06:45:14.000Z" + }, + "timepicker": {}, + "timezone": "", + "title": "Weather data", + "uid": "be80d5e2-5f87-481b-9eb2-b49db87a3727", + "version": 10, + "weekStart": "" +} \ No newline at end of file diff --git a/topic/timeseries/weather-data-grafana-dashboard.png b/topic/timeseries/weather-data-grafana-dashboard.png new file mode 100644 index 00000000..242bf600 Binary files /dev/null and b/topic/timeseries/weather-data-grafana-dashboard.png differ