Repository navigation
fix(eew): show every intensity the map paints in the legend #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||
| import 'dart:async'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/core/error/failure.dart'; | ||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/core/error/result.dart'; | ||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/core/realtime/realtime_source.dart'; | ||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/domain/eew.dart'; | ||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/domain/eew_town_levels.dart'; | ||||||||||||||||||||||||||||||||||||||
| import 'package:flutter/foundation.dart' show listEquals; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /// Raises an EEW payload's reported `max` when the ML model predicts a higher | ||||||||||||||||||||||||||||||||||||||
| /// nationwide township maximum before the alert reaches app consumers. | ||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||
| /// The reported value remains the minimum, including while the model loads or | ||||||||||||||||||||||||||||||||||||||
| /// cannot score a solution. Loading never delays a safety-critical alert; the | ||||||||||||||||||||||||||||||||||||||
| /// next fetch incorporates the model result once it is ready. | ||||||||||||||||||||||||||||||||||||||
| class EewMlMaxSource extends RealtimeSource<List<Eew>> { | ||||||||||||||||||||||||||||||||||||||
| EewMlMaxSource(this._source, this._model); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| final RealtimeSource<List<Eew>> _source; | ||||||||||||||||||||||||||||||||||||||
| final MlIntensityEstimator _model; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| Future<Result<List<Eew>>> fetch() async { | ||||||||||||||||||||||||||||||||||||||
| final result = await _source.fetch(); | ||||||||||||||||||||||||||||||||||||||
| final alerts = result.valueOrNull; | ||||||||||||||||||||||||||||||||||||||
| if (alerts == null || !alerts.any((alert) => !alert.isCancelled)) { | ||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (!_model.ready) { | ||||||||||||||||||||||||||||||||||||||
| unawaited(_model.prepare()); | ||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return switch (result) { | ||||||||||||||||||||||||||||||||||||||
| Ok(:final value, :final stale) => Ok( | ||||||||||||||||||||||||||||||||||||||
| await Future.wait(value.map(_withMlMaximum)), | ||||||||||||||||||||||||||||||||||||||
| stale: stale, | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
| Err(:final failure) => Err(failure), | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Future<Eew> _withMlMaximum(Eew alert) async { | ||||||||||||||||||||||||||||||||||||||
| if (alert.isCancelled) return alert; | ||||||||||||||||||||||||||||||||||||||
| final levels = await _model.townLevels(alert.info); | ||||||||||||||||||||||||||||||||||||||
| final paintedMax = levels == null ? null : highestPaintedLevel(levels); | ||||||||||||||||||||||||||||||||||||||
| if (paintedMax == null || paintedMax <= alert.info.max) return alert; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| return alert.copyWith(info: alert.info.copyWith(max: paintedMax)); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| DateTime? timestampOf(List<Eew> value) => _source.timestampOf(value); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| bool sameData(List<Eew>? a, List<Eew>? b) => listEquals(a, b); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| bool get servingFallback => _source.servingFallback; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| bool isIgnorableFailure(Failure failure) => | ||||||||||||||||||||||||||||||||||||||
| _source.isIgnorableFailure(failure); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| void pause() => _source.pause(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| void resume() => _source.resume(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| void networkChanged() => _source.networkChanged(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @override | ||||||||||||||||||||||||||||||||||||||
| void dispose() => _source.dispose(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,28 @@ Future<({Map<String, int> levels, bool fromModel})> eewTownLevels( | |
| fromModel: false, | ||
| ); | ||
| } | ||
|
|
||
| /// The highest level in [levels] that the wash actually paints, or null when | ||
| /// it paints none (every township at 0 is transparent). | ||
| /// | ||
| /// This is what the legend's ceiling has to follow, not the warning's reported | ||
| /// `max`: [eewTownLevels] scores townships itself — the ML model, or the | ||
| /// formula until it loads — and can put one higher than the round number the | ||
| /// alert reports. A colour painted on the map with no row beside it is read as | ||
| /// some other intensity, which is the one thing a legend may not do. | ||
| int? highestPaintedLevel(Map<String, int> levels) { | ||
| int? highest; | ||
| for (final level in levels.values) { | ||
| if (level <= 0) continue; | ||
| if (highest == null || level > highest) highest = level; | ||
| } | ||
| return highest; | ||
| } | ||
|
|
||
| /// Includes both the warning's maximum and every level painted on the map. | ||
| /// Returns null only when neither maximum is known. | ||
| int? legendCeiling({int? reportedMax, int? paintedMax}) { | ||
| if (reportedMax == null) return paintedMax; | ||
| if (paintedMax == null || reportedMax >= paintedMax) return reportedMax; | ||
| return paintedMax; | ||
| } | ||
|
Comment on lines
+75
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import 'package:dpip/core/realtime/realtime_notifier.dart'; | |
| import 'package:dpip/core/realtime/realtime_source.dart'; | ||
| import 'package:dpip/core/realtime/ticker.dart'; | ||
| import 'package:dpip/features/earthquake/data/earthquake_api.dart'; | ||
| import 'package:dpip/features/earthquake/data/eew_ml_max_source.dart'; | ||
| import 'package:dpip/features/earthquake/data/eew_realtime_source.dart'; | ||
| import 'package:dpip/features/earthquake/data/eew_repository_impl.dart'; | ||
| import 'package:dpip/features/earthquake/data/ml_intensity_service.dart'; | ||
|
|
@@ -59,8 +60,9 @@ List<SingleChildWidget> earthquakeProviders(SharedDeps deps) { | |
| // Held by the 強震監視器 while it is on screen: only then does the RTS feed | ||
| // need every frame, rather than the alerting ones the stream's sleep sends. | ||
| final rtsLiveDemand = RtsLiveDemand(); | ||
| // ML v1 township estimates. Nothing is fetched or built here: the monitor | ||
| // calls `prepare` the first time it opens. | ||
| // ML v1 township estimates. The EEW source starts loading it on the first | ||
| // alert, then republishes it if the model's nationwide maximum is higher; | ||
| // the monitor reuses the same service for its township wash. | ||
| final mlIntensity = MlIntensityService( | ||
| client: deps.apiClient, | ||
| store: MlModelStore(deps.database.durable), | ||
|
|
@@ -98,7 +100,7 @@ List<SingleChildWidget> earthquakeProviders(SharedDeps deps) { | |
| poll: api.getEewRealtime, | ||
| ) as RealtimeSource<List<Eew>>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| final eewChannel = RealtimeChannel<List<Eew>>( | ||
| source: eewSource, | ||
| source: EewMlMaxSource(eewSource, mlIntensity), | ||
| clock: deps.serverClock, | ||
| elapsed: SystemElapsed(), | ||
| ticker: const SystemTicker(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -108,6 +108,12 @@ class _ReportReplayPageState extends State<ReportReplayPage> { | |||||||||||||||||||||||||||||||||||||||||||||
| /// digits four times out of five. Assigned only when the second changes. | ||||||||||||||||||||||||||||||||||||||||||||||
| final ValueNotifier<int> _clockSecond = ValueNotifier(0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// The highest level the replay's wash paints — the legend's ceiling. The | ||||||||||||||||||||||||||||||||||||||||||||||
| /// estimate belongs to the map ([_ReplayMapState._updateAreaFill]; the | ||||||||||||||||||||||||||||||||||||||||||||||
| /// legend lives up here beside the back button), so it is written back the | ||||||||||||||||||||||||||||||||||||||||||||||
| /// same way [_tick] travels down. | ||||||||||||||||||||||||||||||||||||||||||||||
| final ValueNotifier<int?> _paintedMaxLevel = ValueNotifier(null); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void _syncClockSecond() { | ||||||||||||||||||||||||||||||||||||||||||||||
| final second = _session.clock.now().millisecondsSinceEpoch ~/ 1000; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (second == _clockSecond.value) return; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -165,6 +171,7 @@ class _ReportReplayPageState extends State<ReportReplayPage> { | |||||||||||||||||||||||||||||||||||||||||||||
| context.read<RealtimeService>().clock, | ||||||||||||||||||||||||||||||||||||||||||||||
| widget.replayTimestamp, | ||||||||||||||||||||||||||||||||||||||||||||||
| cwaOnly: () => cwaOnly.enabled, | ||||||||||||||||||||||||||||||||||||||||||||||
| mlIntensity: context.read<MlIntensityEstimator>(), | ||||||||||||||||||||||||||||||||||||||||||||||
| )..start(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _session.eew.addListener(_syncAnnouncement); | ||||||||||||||||||||||||||||||||||||||||||||||
| _immersive = context.read<MapImmersiveController>() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -301,6 +308,7 @@ class _ReportReplayPageState extends State<ReportReplayPage> { | |||||||||||||||||||||||||||||||||||||||||||||
| _clockSecond.dispose(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _immersive.removeListener(_onImmersiveChanged); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (_immersive.value) _immersive.exit(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _paintedMaxLevel.dispose(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _session.dispose(); | ||||||||||||||||||||||||||||||||||||||||||||||
| super.dispose(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -334,6 +342,7 @@ class _ReportReplayPageState extends State<ReportReplayPage> { | |||||||||||||||||||||||||||||||||||||||||||||
| tick: _tick, | ||||||||||||||||||||||||||||||||||||||||||||||
| clock: _session.clock, | ||||||||||||||||||||||||||||||||||||||||||||||
| eewIndex: _eewIndex, | ||||||||||||||||||||||||||||||||||||||||||||||
| paintedMaxLevel: _paintedMaxLevel, | ||||||||||||||||||||||||||||||||||||||||||||||
| immersive: immersive, | ||||||||||||||||||||||||||||||||||||||||||||||
| onImmersive: _immersive.enter, | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -382,18 +391,25 @@ class _ReportReplayPageState extends State<ReportReplayPage> { | |||||||||||||||||||||||||||||||||||||||||||||
| // not whether the user asked to see it. | ||||||||||||||||||||||||||||||||||||||||||||||
| CollapsibleMapLegend( | ||||||||||||||||||||||||||||||||||||||||||||||
| legend: ListenableBuilder( | ||||||||||||||||||||||||||||||||||||||||||||||
| listenable: _session.eew, | ||||||||||||||||||||||||||||||||||||||||||||||
| listenable: Listenable.merge([ | ||||||||||||||||||||||||||||||||||||||||||||||
| _session.eew, | ||||||||||||||||||||||||||||||||||||||||||||||
| _paintedMaxLevel, | ||||||||||||||||||||||||||||||||||||||||||||||
| ]), | ||||||||||||||||||||||||||||||||||||||||||||||
| builder: (context, _) { | ||||||||||||||||||||||||||||||||||||||||||||||
| final alerts = | ||||||||||||||||||||||||||||||||||||||||||||||
| _session.eew.alerts.uncancelled; | ||||||||||||||||||||||||||||||||||||||||||||||
| final maxEewLevel = alerts.isEmpty | ||||||||||||||||||||||||||||||||||||||||||||||
| final alertMax = alerts.isEmpty | ||||||||||||||||||||||||||||||||||||||||||||||
| ? null | ||||||||||||||||||||||||||||||||||||||||||||||
| : alerts | ||||||||||||||||||||||||||||||||||||||||||||||
| .map( | ||||||||||||||||||||||||||||||||||||||||||||||
| (alert) => | ||||||||||||||||||||||||||||||||||||||||||||||
| alert.info.max.clamp(0, 9), | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .reduce((a, b) => a > b ? a : b); | ||||||||||||||||||||||||||||||||||||||||||||||
| final maxEewLevel = legendCeiling( | ||||||||||||||||||||||||||||||||||||||||||||||
| reportedMax: alertMax, | ||||||||||||||||||||||||||||||||||||||||||||||
| paintedMax: _paintedMaxLevel.value, | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| return MapLegendCard( | ||||||||||||||||||||||||||||||||||||||||||||||
| child: IntensityLegend( | ||||||||||||||||||||||||||||||||||||||||||||||
| mode: alerts.isNotEmpty | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -524,6 +540,7 @@ class _ReplayMap extends StatefulWidget { | |||||||||||||||||||||||||||||||||||||||||||||
| required this.tick, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.clock, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.eewIndex, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.paintedMaxLevel, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.immersive, | ||||||||||||||||||||||||||||||||||||||||||||||
| required this.onImmersive, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -552,6 +569,9 @@ class _ReplayMap extends StatefulWidget { | |||||||||||||||||||||||||||||||||||||||||||||
| /// showing, not always the newest. | ||||||||||||||||||||||||||||||||||||||||||||||
| final int eewIndex; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// The highest level painted by the wash, for the page's legend. | ||||||||||||||||||||||||||||||||||||||||||||||
| final ValueNotifier<int?> paintedMaxLevel; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Whether the replay is in immersive mode. The map hides its own top-right | ||||||||||||||||||||||||||||||||||||||||||||||
| /// chrome with the rest of the page's. | ||||||||||||||||||||||||||||||||||||||||||||||
| final bool immersive; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1128,6 +1148,7 @@ class _ReplayMapState extends State<_ReplayMap> { | |||||||||||||||||||||||||||||||||||||||||||||
| // with no alert up it paints nothing, so the OSM detailed ground — | ||||||||||||||||||||||||||||||||||||||||||||||
| // which mounts directly beneath it — keeps showing. The grey island is | ||||||||||||||||||||||||||||||||||||||||||||||
| // [countyFillLayerId]'s job, restored just above. | ||||||||||||||||||||||||||||||||||||||||||||||
| widget.paintedMaxLevel.value = null; | ||||||||||||||||||||||||||||||||||||||||||||||
| await controller.setLayerProperties( | ||||||||||||||||||||||||||||||||||||||||||||||
| townFillLayerId, | ||||||||||||||||||||||||||||||||||||||||||||||
| const FillLayerProperties(fillColor: '#00000000', fillOpacity: 0), | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1146,6 +1167,7 @@ class _ReplayMapState extends State<_ReplayMap> { | |||||||||||||||||||||||||||||||||||||||||||||
| // A newer alert, serial or the model itself took over while this one | ||||||||||||||||||||||||||||||||||||||||||||||
| // was being scored — its own update paints, not this stale one. | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!mounted || key != _fillEewKey) return; | ||||||||||||||||||||||||||||||||||||||||||||||
| widget.paintedMaxLevel.value = highestPaintedLevel(estimate.levels); | ||||||||||||||||||||||||||||||||||||||||||||||
| final entries = <Object>[]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
1167
to
1171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
Comment on lines
1169
to
1171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| estimate.levels.forEach((code, level) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (level > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,9 +14,11 @@ import 'package:dpip/core/realtime/realtime_config.dart'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/core/realtime/replay_clock.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/core/realtime/ticker.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/data/earthquake_api.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/data/eew_ml_max_source.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/data/eew_replay_source.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/data/rts_replay_source.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/domain/eew.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/domain/eew_town_levels.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/domain/rts.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/presentation/eew_realtime_controller.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:dpip/features/earthquake/presentation/rts_realtime_controller.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,6 +46,7 @@ class ReplaySession { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Clock serverClock, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int replayTimestamp, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required bool Function() cwaOnly, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MlIntensityEstimator? mlIntensity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final api = EarthquakeApi(apiClient); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final clock = ReplayClock( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,7 +61,12 @@ class ReplaySession { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: 'rts-replay', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final eewChannel = RealtimeChannel<List<Eew>>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: EewReplaySource(api, clock, cwaOnly: cwaOnly), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: mlIntensity == null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? EewReplaySource(api, clock, cwaOnly: cwaOnly) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : EewMlMaxSource( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EewReplaySource(api, clock, cwaOnly: cwaOnly), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mlIntensity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
Comment on lines
+64
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clock: serverClock, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elapsed: SystemElapsed(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ticker: const SystemTicker(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -216,6 +216,11 @@ class RtsMapLayer with MapLayerDefaults implements MapLayer { | |||||||||||||||||||||
| /// Bumped on every feed notification, so the ranking card rebuilds with it. | ||||||||||||||||||||||
| final ValueNotifier<int> _rankingTick = ValueNotifier(0); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// The highest level the current wash paints — the legend must include it | ||||||||||||||||||||||
| /// even when the active alerts' model-derived maximum belongs to another | ||||||||||||||||||||||
| /// warning. | ||||||||||||||||||||||
| final ValueNotifier<int?> _paintedMaxLevel = ValueNotifier(null); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Brightness captured from the last context-bearing call ([buildLegend] / | ||||||||||||||||||||||
| /// [buildSheet]) — the render/data-push methods get no `BuildContext`, but | ||||||||||||||||||||||
| /// the intensity icons come in light/dark artwork and the area fill needs | ||||||||||||||||||||||
|
|
@@ -905,6 +910,7 @@ class RtsMapLayer with MapLayerDefaults implements MapLayer { | |||||||||||||||||||||
| // with no alert up it paints nothing, so the OSM detailed ground — | ||||||||||||||||||||||
| // which mounts directly beneath it — keeps showing. The grey island is | ||||||||||||||||||||||
| // [countyFillLayerId]'s job, restored just above. | ||||||||||||||||||||||
| _paintedMaxLevel.value = null; | ||||||||||||||||||||||
| await controller.setLayerProperties( | ||||||||||||||||||||||
| townFillLayerId, | ||||||||||||||||||||||
| const FillLayerProperties(fillColor: '#00000000', fillOpacity: 0), | ||||||||||||||||||||||
|
|
@@ -923,6 +929,7 @@ class RtsMapLayer with MapLayerDefaults implements MapLayer { | |||||||||||||||||||||
| // A newer alert, serial or the model itself took over while this one | ||||||||||||||||||||||
| // was being scored — its own update paints, not this stale one. | ||||||||||||||||||||||
| if (key != _fillEewKey) return; | ||||||||||||||||||||||
| _paintedMaxLevel.value = highestPaintedLevel(estimate.levels); | ||||||||||||||||||||||
| final entries = <Object>[]; | ||||||||||||||||||||||
| estimate.levels.forEach((code, level) { | ||||||||||||||||||||||
| if (level > 0) { | ||||||||||||||||||||||
|
|
@@ -964,14 +971,18 @@ class RtsMapLayer with MapLayerDefaults implements MapLayer { | |||||||||||||||||||||
| Widget buildLegend(BuildContext context) { | ||||||||||||||||||||||
| _captureBrightness(context); | ||||||||||||||||||||||
| return ListenableBuilder( | ||||||||||||||||||||||
| listenable: _eew, | ||||||||||||||||||||||
| listenable: Listenable.merge([_eew, _paintedMaxLevel]), | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| builder: (context, _) { | ||||||||||||||||||||||
| final alerts = (_eew.state.data ?? const <Eew>[]).uncancelled; | ||||||||||||||||||||||
| final maxEewLevel = alerts.isEmpty | ||||||||||||||||||||||
| final alertMax = alerts.isEmpty | ||||||||||||||||||||||
| ? null | ||||||||||||||||||||||
| : alerts | ||||||||||||||||||||||
| .map((alert) => alert.info.max.clamp(0, 9)) | ||||||||||||||||||||||
| .reduce((a, b) => a > b ? a : b); | ||||||||||||||||||||||
| final maxEewLevel = legendCeiling( | ||||||||||||||||||||||
| reportedMax: alertMax, | ||||||||||||||||||||||
| paintedMax: _paintedMaxLevel.value, | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
Comment on lines
+977
to
+985
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||
| return MapLegendCard( | ||||||||||||||||||||||
| child: IntensityLegend( | ||||||||||||||||||||||
| mode: _eewActive | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,11 @@ class IntensityLegend extends StatelessWidget { | |
| /// Highest discrete EEW level to show (`0`–`9`). Null shows the full scale. | ||
| /// Levels above it carry no information for the current warning and are | ||
| /// omitted to preserve map space. | ||
| /// | ||
| /// This includes the maximum of the *wash*, which may differ from an | ||
| /// incoming warning's original reported maximum. | ||
| /// A level the map paints but this scale omits would be read as another | ||
| /// intensity. | ||
|
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| final int? maxEewLevel; | ||
|
|
||
| /// Height of one scale cell / gradient step (px). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
fetch方法中,若_model.ready為false,會透過unawaited呼叫_model.prepare()。若在模型準備期間多次呼叫fetch,可能會導致_model.prepare()被重複執行。建議確保MlIntensityEstimator.prepare的實作是冪等的(idempotent),或者在fetch中加入防止重複呼叫的機制,以避免不必要的資源消耗。