Skip to content

fix(eew): show every intensity the map paints in the legend - #659

Open
whes1015 wants to merge 2 commits into
mainfrom
fix/eew-legend-painted-ceiling
Open

whes1015 wants to merge 2 commits into
mainfrom
fix/eew-legend-painted-ceiling

Conversation

@whes1015

@whes1015 whes1015 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

這個 PR 做了什麼

地震速報的圖例上限改成跟著「地圖實際塗到的最高震度」,而不是警報自己回報的 max。

前一個 PR(#656)讓圖例在速報時只顯示到預估最高震度,但地圖的著色是 eewTownLevels 自己算的(ML 模型,模型還沒好時用公式),它可以算得比警報回報的整數級更高。結果就是 #ET-2026-0199 討論串裡烤大鴨 11/05 貼的那張圖:資訊欄和圖例只到 2 級,地圖上卻有 3 級的顏色——圖例少一格,那個顏色就被讀成別的震度。

改動內容

正式程式碼:

  • lib/features/earthquake/domain/eew_town_levels.dart:新增 highestPaintedLevel()(掃過整張 368 鄉鎮的預估、忽略透明的 0)與 legendCeiling()(回報值與實際著色取較高者;兩者都不知道時回 null,顯示完整色階)。
  • lib/features/map/presentation/layers/rts_layer.dart:_updateAreaFill 把著色到的最高級別寫進 _paintedMaxLevel,沒有速報時清成 null;buildLegend 改成同時聽這個 notifier,用 legendCeiling 算上限。
  • lib/features/earthquake/presentation/pages/report_replay_page.dart:回放頁的 _ReplayMapState 走同一條路,把著色上限交回頁面上方的圖例。
  • lib/shared/widgets/intensity_legend.dart:只補 maxEewLevel 的註解,說明它是「著色的上限」而不是警報回報值,沒有行為改動。

測試:

  • test/features/earthquake/domain/eew_town_levels_test.dart:新增兩則——highestPaintedLevel 要忽略 0 級的鄉鎮;legendCeiling 在地圖算得比回報值高時要取地圖那個值。

刻意沒做的:

  • 沒重做圖例 UI,也沒動左側「各地震度排行」和下方卡片(討論串的結論是那邊才有真正的空間問題)。
  • 沒做「點開看完整色階」的互動,維持原本就沒有這個入口的狀態。

相關 issue

怎麼驗

  • tool/dev/analyze.sh:通過(dart format --set-exit-if-changed 與 flutter analyze 都沒有問題)。
  • tool/dev/test.sh:本機 3670 個測試通過;另有 test/tool/*_script_test.dart 共 10 個失敗(Expected: <7> Actual: <126>,執行暫存腳本時拿不到執行權限)。我把 origin/main(07c0c3d)開成乾淨的 worktree 重跑 test/tool/run_script_test.dart,同樣的測試以相同錯誤失敗,確認與這個改動無關、是本機環境的問題。tool/check/commits.sh origin/main..HEAD 通過。
  • 沒有實機或模擬器驗證畫面:圖例高度跟著著色上限變動這件事,只有在一場「模型算得比警報回報高」的速報裡才看得到。要請有裝 app 的人在一場速報裡對一下圖例最高那一格和地圖上最深的顏色。

檢查清單

  • tool/check/commits.sh origin/main..HEAD 通過
  • 一個 commit 一件事
  • mise exec -- flutter analyze 與 mise exec -- flutter test 通過 —— analyze 通過、測試只有上述與改動無關的 10 個環境失敗
  • 新的使用者可見字串都走 AppLocalizations,沒有寫死(這次沒有新增字串)
  • CI 全部通過(Android、iOS、build、codecov 都是 pass,Instrumented 是 skipped)
  • 沒有 UI 尺寸/顏色改動;圖例既有的深淺色與 spacing 都沒動

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.66102% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.65%. Comparing base (20a7d08) to head (8b66295).

Files with missing lines Patch % Lines
...ib/features/earthquake/data/eew_ml_max_source.dart 84.37% 5 Missing ⚠️
...ib/features/map/presentation/layers/rts_layer.dart 33.33% 4 Missing ⚠️
...thquake/presentation/pages/report_replay_page.dart 72.72% 3 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lowrt

lowrt commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

這次改為在 EEW 資料進入 realtime channel 時處理:

  • 模型可用時,計算全部鄉鎮的 ML 預測震度,並以其中最大值替換 EewInfo.max
  • 首頁、地震頁、強震監視器、重播、圖例、無定位時的排序與前景播報會共用同一個 ML 最大震度
  • 模型尚未載入時不延遲警報,暫時保留 payload 值並啟動模型載入
  • 模型無法估算或警報已取消時保留 payload 值
  • 移除前一版只在圖例末端替換最大震度的邏輯
  • 新增 ML 最大震度資料來源測試,包含 ML 結果低於 payload 的情況

Commit: 3e6b7d1

@lowrt lowrt added this to the v26.5 milestone Nov 12, 2026
@YinCheng0106 YinCheng0106 added android Issues or pull requests related to the Android platform. ios Issues or pull requests related to the iOS platform. labels Nov 13, 2026
@lowrt
lowrt force-pushed the fix/eew-legend-painted-ceiling branch 2 times, most recently from 18aa455 to 52c0bcd Compare November 14, 2026 00:48
Platform: all

Fix(zh-Hant): 修正地震速報的圖例最高只到警報回報的震度、地圖卻塗到更高一級時,顏色與圖例對不上的問題
Fix(en-US): fix the map legend stopping below an intensity the map does paint
@lowrt
lowrt force-pushed the fix/eew-legend-painted-ceiling branch from 52c0bcd to 37ca275 Compare November 17, 2026 10:46

@whes1015 whes1015 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先不核准。

全國最大震度會被模型結果直接覆蓋,比氣象署回報低、甚至全部鄉鎮都是 0 時也會變成 0。這個數字會進卡片、前景播報,以及沒有定位估計時的排序。圖例上限的比較寫了兩份,「地圖塗得比回報高」的單元測試也被拿掉了。Android、iOS、build 還在跑。

  1. lib/features/earthquake/data/eew_ml_max_source.dart:46 — 不要用 reduce 的結果覆蓋 info.max。取 payload 與 highestPaintedLevel 的較高者;後者是 null(沒有鄉鎮大於 0,或模型沒算出來)就留 payload。現在的測試把 7 改成 5,請改成維持 7,並補「模型較高」和「全 0保留 payload」兩則。ET-2026-0199 要修的是地圖塗得比回報高、圖例少一格,不是把官方最大震度往下修。模型載入前先顯示 payload,下一次 fetch 再換成比較低的值,速報進行中畫面上的震度會往下跳。

  2. lib/features/map/presentation/layers/rts_layer.dart:982 和 lib/features/earthquake/presentation/pages/report_replay_page.dart:409 各寫了一次同樣的上限。第一個 commit 的 legendCeiling,和第二個 commit 刪掉的「塗色比回報高時取地圖」測試,就是在鎖這件事。請把 helper 放回 eew_town_levels.dart,兩處改呼叫它,測試補回去。模型還沒好時走公式,這段比較仍然是圖例不會少格的唯一保證。

說明還在寫已經不在程式裡的 legendCeiling() 呼叫方式,跟 head 上的兩個 commit 對不上,請一併改掉。

Agent 代 whes1015 審核(Discord 靈靈 ⇛ 臺南新營 要求)

Platform: all

Fix(zh-Hant): 地震速報改用 ML 模型預測的全國最大震度
Fix(en-US): use the ML model's nationwide maximum intensity for EEW
@lowrt
lowrt force-pushed the fix/eew-legend-painted-ceiling branch from 37ca275 to 8b66295 Compare November 18, 2026 13:17

@whes1015 whes1015 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先前那三點這版都對過了,程式沒有還要改的問題。

  • 全國最大震度只會往上抬。lib/features/earthquake/data/eew_ml_max_source.dart 裡 paintedMax == null || paintedMax <= alert.info.max 時保留警報原值:模型較低、鄉鎮全是 0、模型還沒載入、算不出來、已取消,都不會把氣象署的值蓋掉。對應測試有蓋到。
  • 圖例上限收成 legendCeiling()(eew_town_levels.dart),地圖與回放都叫它,著色到的級數不會再少一格。
  • highestPaintedLevel、legendCeiling 的測試有補回來,另外加了 EewMlMaxSource 的測試。

這支是 whes1015 開的,這個帳號不能自己核准。Android、iOS 這次看還在跑;build、changes、code-review、codecov 是過的。

補充,不擋:更新日誌寫「改用 ML 模型預測的全國最大震度」,程式是取較高者,氣象署較高時不會改。取消警報那則測試的模型震度是 5、原值是 7,沒擋取消也會過。

Agent 代 whes1015 審核(Discord ・ω・ (竹子) ⇛ 新竹竹東 要求)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Issues or pull requests related to the Android platform. ios Issues or pull requests related to the iOS platform. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants