Skip to content
Edit this page

Weather overview

The overview is the one-line message under the current conditions, for example "Rain is likely to start around 5:00 PM with 70% chance." It opens behind the info button, and it can also be sent as a desktop notification while the window is minimized, in compact mode or closed.

The rules document is the source of truth

docs/overview-rules.md in the app repository describes every rule in plain English. To change a rule, change that file first, then the code and the numbers. If they disagree, the code is wrong. This page explains how the code is organised; Overview architecture goes deeper, with the modules, data model, decision flow and engine lifecycle.

Part Code
Wordings core/overview/messages.py
Rules and merging core/overview/rules.py, hour_tests.py, context.py (no GTK)
When it opens core/overview/announce.py (no GTK)
Timing state/overview_engine.py
The pill ui/sections/current.py (CurrentCondition)
Notifications ui/notifications.py, sent by app.py
Numbers config.py, under "Overview" and "Overview rules", in metric

One run

flowchart LR
    C[OverviewContext<br>built from the store] --> R[RuleBook.run<br>every rule: Insight or None]
    R --> D[drop expired]
    D --> M[combine<br>merge things that happen together]
    M --> A[decide<br>news, reminder or silent update]
    A --> E[OverviewEngine<br>emits overview-changed]
    E --> P[pill in the window]
    E --> N[notification]

Insights

A rule looks at an OverviewContext (Clock, Units, HourlySeries, SunTimes, DailyOutlook, AirSeries, Window) and returns an Insight or None. An Insight (core/overview/insight.py) holds the message, a level (calm, low, medium, high, extreme), a topic, the message key, the hour it is about, when it valid_until, and its fingerprint (rule, key, level, hour), which is how an insight is told to be "the same as before".

  • Every insight has a valid_until and is never shown after it.
  • RuleBook.run ignores a rule that fails (debug log only), so one bad rule never breaks the overview.
  • Rules convert imperial data to metric before comparing.
  • Priorities (OVERVIEW_PRIORITIES): storm, freezing, heavy precipitation, extreme feels-like, air quality, UV, precipitation, wind, fog, temperature swing, tomorrow, sun, calm. Safety first.

Rules registered in RuleBook.default(): StormRule, ExtremeFeelsRule, AirQualityRule, UvRule, PrecipitationRule, WindRule, FogRule, TemperatureSwingRule, TomorrowRule, SunRule and CalmRule, plus FirstHourRules built from an HourTest and a Phrasing.

Writing a rule

Build from what exists. "The first hour that …" is a FirstHourRule with an HourTest (HasCode, AtLeast, Below, AnyOf, AllOf, or a shared one such as IS_WET, IS_FOGGY, IS_WINDY) and a Phrasing. Subclass Rule only when that isn't enough, then register it in RuleBook.default(). Add a case to tests/test_overview_rules.py.

Wordings

Each message key maps to several wordings (4–5 for common messages, 2 for rare safety ones), all saying the same thing with the same placeholders. Rules only use keys: ctx.messages.say("rain.start", time=…, chance=…), or say_count for plurals. Each opening draws a new seed that picks the wording; silent updates keep it, so the phrasing never changes under the reader. Never join translated pieces into a sentence.

Merging

combine() turns insights that happen together into one sentence, in this order:

  1. TURNING_STORMY: rain leads a storm in the same wet spell (rain_stormy.start)
  2. FOLDS: a storm already says rain
  3. TURNING_HEAVY: rain, then heavy rain in the same spell (rain_heavier.easing)
  4. COMBINATIONS: a known pair, both now or both later within OVERVIEW_COMBINE_MINUTES (storm_wind.later)

The result counts as each of its parts, names its topics and covers the folded ones. Each merged sentence has its own message key.

Announcing

decide(insights, memory, showing, now) returns a Decision: what to show, why it opens, and when to run again.

  • A new insight is news and opens at once.
  • One said before opens only as a reminder, after OVERVIEW_REMIND_MINUTES for its level (extreme 30, high 60, medium 120), each next one OVERVIEW_REMIND_BACKOFF (2) times later, at most OVERVIEW_REMIND_MAX_MINUTES (240). Low and calm are said once.
  • Nothing opens within OVERVIEW_MIN_GAP_MINUTES (15) of the last opening, except new extreme news, unless the last opening was extreme too. Each opening shows one insight; the others due wait their turn.
  • AnnounceMemory remembers what was said per location and per part, so a storm that comes and goes counts once, and a merged insight counts as saying each thing in it.

The engine

OverviewEngine (state/overview_engine.py, the overview_engine singleton):

  • Lazy. The first run is OVERVIEW_FIRST_DELAY seconds after the first data load, later ones OVERVIEW_REFRESH_DELAY after each refresh, then again at the decision's wake_at (before an insight stops being true, or when a reminder is due).
  • Only one-shot GLib.timeout_add_seconds timers.
  • Its memory survives refreshes. A refresh never opens the pill or resets reminders. A location change, or turning off both the overview and notifications, starts over.
  • Runs only while show-overview or show-notifications is on. With both off it does nothing.
  • Emits overview-changed(announce: bool): open the overview, or only update its text. Read current(), heading, reason and topics.

Where it goes

One place at a time, decided in WeatherApplication._announce:

  • The main window can be seen (is_on_screen: visible and not suspended): the pill opens, if the overview is on.
  • Otherwise (minimized, hidden by compact mode, closed to the background): OverviewNotifications sends a notification, when notifications are on and should_notify says so: news of medium level or above or on OVERVIEW_NOTIFY_TOPICS, reminders of extreme ones.
  • One notification ID per topic (overview-<topic>). It is withdrawn when its topic is no longer true, the location changes, notifications are turned off, or the main window comes into view.
  • In debug mode the app logs where each opening went, for example Overview channel: storm (news, extreme) -> notification overview-storm.
  • There is no other notification. Don't add one per refresh.

The pill

CurrentCondition connects to overview-changed and changed::show-overview on map and disconnects on unmap. It shows the engine's heading (coloured by level), the insight's icon and message, and stays open for insight.show_seconds (15 s, plus 7 for high and 15 for extreme).

Testing

Rules are plain Python. Build an OverviewContext by hand and call RuleBook.default().run(ctx), as tests/test_overview_rules.py does, with fixed clocks.