Add wind analysis: header pill, fetch/validate menu, speed-plot overlay
Portiert das Wind-System des HTML-Demonstrators (Doku 3.8) vollstaendig: Open-Meteo-Winddaten, interpoliert zwischen Druckflaechen- und festen Nabenhoehen-Stuetzpunkten auf die tatsaechliche Zielhoehe. Domain (lib/domain/wind/wind_math.dart, reines Dart): Hoehen- Interpolation (linear + zirkulaer fuer Windrichtung), Peilung zwischen zwei Punkten, Kopf-/Rueckenwind-Komponente pro Flugleg - 1:1 uebernommen aus interpolateWindAtHeight()/bearingBetween()/headTailwindComponent() des Demonstrators, per Unit-Tests abgesichert. Service (lib/services/wind/wind_service.dart): zwei getrennte, fokussierte Open-Meteo-Requests statt eines kombinierten (Doku 4.10 - ein 35-Variablen-Request verursachte im Demonstrator Modellauswahl- Fehler). Drei Verbraucher: Kopfleisten-Pille (120 m AGL ueber Referenzort), gebuendelter Wegpunkt-Fetch (ein Request fuer alle Koordinaten via Open-Meteos Mehrfach-Location-Syntax) und das Validierungspanel (rohe Messwerte je Nabenhoehe/Druckflaeche). Per MockClient getestet (kein echter Netzwerkzugriff in Tests). UI: - HeaderWindPill (TopModeBar, nur ausserhalb Fly-Modus): zeigt Windrichtung/-geschwindigkeit, Antippen schaltet perspektivisch die Wind-Marker der Wegpunkte um (Zustand vorbereitet, HTML-Demonstrator: showPerWaypointWind). - WaypointListPanel: "Fetch wind"/"Validate"-Buttons im Panel-Header, neue WIND-Spalte in der Liste. - WindValidatePanel: neue Vollbild-Route (gleiches Muster wie WaypointListPanel) mit Rohdaten je Hoehenstufe inkl. Boeen (Doku 4.9: Boeen nur hier, nicht in der Wegpunktanzeige) und Interpolationsergebnis. - FullValueChart (Speed-Tab): Kopf-/Rueckenwind-Diamanten pro Leg samt gestrichelter Nulllinie sowie gestrichelte Bodengeschwindigkeits- Stufenlinie. Bug gefunden und gefixt waehrend der Emulator-Verifikation: die Y-Achsen-Autoskalierung klemmte weiterhin auf den gueltigen Drehrad- Wertebereich (13-25 m/s), wodurch nahe Null liegende Windkomponenten (bei schwachem Wind der Normalfall) ausserhalb des sichtbaren Bereichs lagen und weder Diamanten noch Nulllinie zu sehen waren. Der HTML- Demonstrator klemmt computeSpeedChartRange() bewusst nicht auf SPD_MIN/ SPD_MAX; das Klemmen in FullValueChart._range() jetzt entsprechend entfernt. Waypoint-Modell um windSpeedMs/windDirFromDeg/windElevationM erweitert (nullable, reine Planungshilfe - der Encoder liest diese Felder nie, Doku 3.2). currentMissionProvider bekommt replaceAll() fuer den gebuendelten Wind-Fetch, der alle Wegpunkte gleichzeitig aktualisiert. Verifiziert: flutter analyze (0 issues), flutter test (44/44, davon 14 neue Wind-Mathematik- und 6 neue WindService-Tests), manuell auf Pixel_10a-Emulator mit echtem Open-Meteo-Netzwerkzugriff - Kopfleisten- Pille zeigt Live-Wind, Fetch/Validate fuellen Liste bzw. oeffnen das Validierungspanel mit echten Messwerten, Speed-Plot zeigt nach dem Fix Diamanten/Nulllinie/Bodengeschwindigkeit korrekt skaliert. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
7a26002a63
commit
1b13c45cac
@@ -27,6 +27,8 @@ class FullValueChart extends StatefulWidget {
|
||||
required this.pxPerUnit,
|
||||
required this.unit,
|
||||
required this.onChanged,
|
||||
this.legWind,
|
||||
this.groundSpeeds,
|
||||
});
|
||||
|
||||
final List<Waypoint> waypoints;
|
||||
@@ -41,6 +43,14 @@ class FullValueChart extends StatefulWidget {
|
||||
final String unit;
|
||||
final void Function(int index, double value) onChanged;
|
||||
|
||||
/// Kopf-/Rueckenwind-Komponente pro Leg (nur Speed-Tab, Doku 3.8) -
|
||||
/// Laenge waypoints.length - 1, null wo noch kein Wind geladen ist.
|
||||
final List<double?>? legWind;
|
||||
|
||||
/// Erreichbare Bodengeschwindigkeit pro Leg (nur Speed-Tab), gleiche
|
||||
/// Laenge/Null-Semantik wie [legWind].
|
||||
final List<double?>? groundSpeeds;
|
||||
|
||||
static const _distance = Distance(roundResult: false);
|
||||
|
||||
static List<double> cumulativeDistances(List<Waypoint> waypoints) {
|
||||
@@ -66,9 +76,14 @@ class _FullValueChartState extends State<FullValueChart> {
|
||||
static const _hitToleranceX = 28.0;
|
||||
|
||||
({double lo, double hi}) _range() {
|
||||
if (widget.values.isEmpty) return (lo: widget.min, hi: widget.max);
|
||||
final dataMin = widget.values.reduce(math.min);
|
||||
final dataMax = widget.values.reduce(math.max);
|
||||
final allVals = <double>[
|
||||
...widget.values,
|
||||
for (final v in widget.legWind ?? const <double?>[]) ?v,
|
||||
for (final v in widget.groundSpeeds ?? const <double?>[]) ?v,
|
||||
];
|
||||
if (allVals.isEmpty) return (lo: widget.min, hi: widget.max);
|
||||
final dataMin = allVals.reduce(math.min);
|
||||
final dataMax = allVals.reduce(math.max);
|
||||
final span = dataMax - dataMin;
|
||||
final pad = math.max(span * 0.35, widget.step * 2);
|
||||
var lo = dataMin - pad;
|
||||
@@ -79,8 +94,11 @@ class _FullValueChartState extends State<FullValueChart> {
|
||||
lo = mid - minSpan / 2;
|
||||
hi = mid + minSpan / 2;
|
||||
}
|
||||
if (lo < widget.min) lo = widget.min;
|
||||
if (hi > widget.max) hi = widget.max;
|
||||
// Nicht auf widget.min/max (gueltiger Drohnen-Geschwindigkeitsbereich)
|
||||
// klemmen: Windkomponenten/Bodengeschwindigkeit (Doku 3.8) sind keine
|
||||
// gueltigen Soll-Geschwindigkeiten und duerfen den sichtbaren Bereich
|
||||
// durchaus unter min bzw. ueber max ziehen (HTML-Demonstrator:
|
||||
// computeSpeedChartRange() klemmt ebenfalls nicht auf SPD_MIN/SPD_MAX).
|
||||
if (hi <= lo) {
|
||||
lo = widget.min;
|
||||
hi = widget.max;
|
||||
@@ -154,6 +172,8 @@ class _FullValueChartState extends State<FullValueChart> {
|
||||
lo: range.lo,
|
||||
hi: range.hi,
|
||||
unit: widget.unit,
|
||||
legWind: widget.legWind,
|
||||
groundSpeeds: widget.groundSpeeds,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -173,6 +193,8 @@ class _ChartPainter extends CustomPainter {
|
||||
required this.lo,
|
||||
required this.hi,
|
||||
required this.unit,
|
||||
this.legWind,
|
||||
this.groundSpeeds,
|
||||
});
|
||||
|
||||
final List<Waypoint> waypoints;
|
||||
@@ -184,6 +206,8 @@ class _ChartPainter extends CustomPainter {
|
||||
final double lo;
|
||||
final double hi;
|
||||
final String unit;
|
||||
final List<double?>? legWind;
|
||||
final List<double?>? groundSpeeds;
|
||||
|
||||
static const _padX = 50.0;
|
||||
static const _padY = 20.0;
|
||||
@@ -238,6 +262,8 @@ class _ChartPainter extends CustomPainter {
|
||||
v += step;
|
||||
}
|
||||
|
||||
_paintWindAndGroundSpeed(canvas, boxW, boxH);
|
||||
|
||||
// Verbindungslinien (rot bei nicht fliegbarer Steig-/Sinkrate).
|
||||
for (var i = 0; i < n - 1; i++) {
|
||||
final bad = i < legBad.length && legBad[i];
|
||||
@@ -269,10 +295,136 @@ class _ChartPainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wind-Diamanten je Leg (Kopf-/Rueckenwind-Komponente) und die daraus
|
||||
/// erreichbare Bodengeschwindigkeit als gestrichelte Stufenlinie - nur auf
|
||||
/// dem Speed-Tab genutzt (Doku 3.8, windHtml/groundSpeedHtml im HTML-
|
||||
/// Demonstrator). Vor den eigentlichen Soll-Werte-Punkten gezeichnet,
|
||||
/// damit diese immer obenauf liegen.
|
||||
void _paintWindAndGroundSpeed(Canvas canvas, double boxW, double boxH) {
|
||||
final wind = legWind;
|
||||
if (wind != null && wind.any((v) => v != null)) {
|
||||
final wZeroY = _yAt(0, boxH);
|
||||
_drawDashedLine(
|
||||
canvas,
|
||||
Offset(_padX, wZeroY),
|
||||
Offset(boxW - _padX, wZeroY),
|
||||
Paint()
|
||||
..color = Colors.white.withValues(alpha: 0.4)
|
||||
..strokeWidth = 1.5,
|
||||
dashWidth: 3,
|
||||
gapWidth: 4,
|
||||
);
|
||||
final zeroLabel = TextPainter(
|
||||
text: TextSpan(
|
||||
text: '0 (no wind effect on track)',
|
||||
style: TextStyle(color: Colors.white.withValues(alpha: 0.55), fontSize: 10),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
)..layout();
|
||||
zeroLabel.paint(canvas, Offset(_padX, wZeroY - 5 - zeroLabel.height));
|
||||
|
||||
final windPts = <Offset>[];
|
||||
for (var i = 0; i < wind.length; i++) {
|
||||
final w = wind[i];
|
||||
if (w == null) continue;
|
||||
final mx = (_xAt(i, boxW) + _xAt(i + 1, boxW)) / 2;
|
||||
final my = _yAt(w, boxH);
|
||||
windPts.add(Offset(mx, my));
|
||||
|
||||
final isTail = w >= 0;
|
||||
final color = isTail ? const Color(0xFF3ECF8E) : const Color(0xFFE2574A);
|
||||
final diamond = Path()
|
||||
..moveTo(mx, my - 7)
|
||||
..lineTo(mx + 7, my)
|
||||
..lineTo(mx, my + 7)
|
||||
..lineTo(mx - 7, my)
|
||||
..close();
|
||||
canvas.drawPath(diamond, Paint()..color = color);
|
||||
canvas.drawPath(
|
||||
diamond,
|
||||
Paint()
|
||||
..color = const Color(0xFF0C0C0C)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1,
|
||||
);
|
||||
|
||||
final valueLabel = TextPainter(
|
||||
text: TextSpan(
|
||||
text: '${isTail ? '+' : ''}${w.toStringAsFixed(1)}',
|
||||
style: TextStyle(color: color, fontSize: 11, fontWeight: FontWeight.w600),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
)..layout();
|
||||
valueLabel.paint(
|
||||
canvas,
|
||||
Offset(mx - valueLabel.width / 2, my - 12 - valueLabel.height),
|
||||
);
|
||||
}
|
||||
|
||||
final connectPaint = Paint()
|
||||
..color = Colors.white.withValues(alpha: 0.25)
|
||||
..strokeWidth = 1;
|
||||
for (var i = 0; i < windPts.length - 1; i++) {
|
||||
_drawDashedLine(canvas, windPts[i], windPts[i + 1], connectPaint,
|
||||
dashWidth: 2, gapWidth: 3);
|
||||
}
|
||||
}
|
||||
|
||||
final ground = groundSpeeds;
|
||||
if (ground != null) {
|
||||
double? prevLevelY;
|
||||
final groundPaint = Paint()
|
||||
..color = const Color(0xFF94BBE9).withValues(alpha: 0.55)
|
||||
..strokeWidth = 1.5;
|
||||
for (var i = 0; i < ground.length; i++) {
|
||||
final g = ground[i];
|
||||
if (g == null) {
|
||||
prevLevelY = null;
|
||||
continue;
|
||||
}
|
||||
final gy = _yAt(g, boxH);
|
||||
final gx0 = _xAt(i, boxW);
|
||||
final gx1 = _xAt(i + 1, boxW);
|
||||
_drawDashedLine(canvas, Offset(gx0, gy), Offset(gx1, gy), groundPaint,
|
||||
dashWidth: 5, gapWidth: 3);
|
||||
if (prevLevelY != null) {
|
||||
_drawDashedLine(canvas, Offset(gx0, prevLevelY), Offset(gx0, gy),
|
||||
groundPaint, dashWidth: 5, gapWidth: 3);
|
||||
}
|
||||
prevLevelY = gy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _drawDashedLine(
|
||||
Canvas canvas,
|
||||
Offset p1,
|
||||
Offset p2,
|
||||
Paint paint, {
|
||||
double dashWidth = 4,
|
||||
double gapWidth = 3,
|
||||
}) {
|
||||
final total = (p2 - p1).distance;
|
||||
if (total == 0) return;
|
||||
final direction = (p2 - p1) / total;
|
||||
var traveled = 0.0;
|
||||
while (traveled < total) {
|
||||
final segEnd = math.min(traveled + dashWidth, total);
|
||||
canvas.drawLine(
|
||||
p1 + direction * traveled,
|
||||
p1 + direction * segEnd,
|
||||
paint,
|
||||
);
|
||||
traveled += dashWidth + gapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _ChartPainter oldDelegate) =>
|
||||
oldDelegate.values != values ||
|
||||
oldDelegate.activeIndex != activeIndex ||
|
||||
oldDelegate.lo != lo ||
|
||||
oldDelegate.hi != hi;
|
||||
oldDelegate.hi != hi ||
|
||||
oldDelegate.legWind != legWind ||
|
||||
oldDelegate.groundSpeeds != groundSpeeds;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user