Monitor Daily Temperature Swings

May 4, 2021 9:43:24 AM / By Gravwell

This query uses data from the Weather Kit to see how much the temperature changed each day -- the difference between the daily low and the daily high. Due to the format we get from openweathermap, we have to do some tricks to get nice values for individual *days*.  First, we use a sub-query to extract city name and temperature from each record. Then we render the timestamp so it only shows the day, e.g. "Apr 01 2021" and use that plus the city name to figure out the max and min temperatures for the day, then send that to the text renderer.

In the main query, we use the dump module to extract the results of the sub-query and set the timestamps to the days calculated before: this is a trick to get nice, evenly-spaced timestamps. Finally, we use the stats module to "condense" the diff values by the city names and send them to chart; we must do a condensing operation so the chart can figure out how to re-draw if you zoom in.

@Q{tag=weather json name main.temp | time -f "Jan 02 2006" TIMESTAMP day | stats max(temp) min(temp) by name day | diff max min | table}; dump -r @Q -t day -f "Jan 02 2006" | stats mean(diff) by name | chart mean by name

Example chart that could result from the query:



Written by Gravwell