Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+sandsack-rechenweg.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Sandsack helper now explains below its result how each Richtwert is calculated, with the values entered, including why it plans with wet sand at 2,0 t/m³ rather than dry sand at 1,2 to 1,6 t/m³ (#87).
Binary file modified docs/play/screenshots/21-sandsack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/21-sandsack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<ContentControl Content="{Binding Hoehe}" />
<ContentControl Content="{Binding Helfer}" />

<StackPanel x:Name="ResultPanel" Spacing="4" IsVisible="{Binding HasResults}">
<!-- Inset on the right so the overlay scroll bar, now that the explanation makes the page scroll,
never sits on the right-aligned values. -->
<StackPanel x:Name="ResultPanel" Spacing="4" Margin="0,0,8,0" IsVisible="{Binding HasResults}">
<TextBlock Classes="overline" Text="RICHTWERT" />
<ItemsControl x:Name="Results" ItemsSource="{Binding Results}">
<ItemsControl.ItemTemplate>
Expand All @@ -28,6 +30,22 @@
</StackPanel>

<TextBlock x:Name="Hinweis" Classes="secondary" TextWrapping="Wrap" Text="{Binding Hinweis}" />

<StackPanel x:Name="RechenwegPanel" Spacing="6" Margin="0,8,0,0">
<TextBlock Classes="overline" Text="SO WIRD GERECHNET" />
<ItemsControl x:Name="Rechenweg" ItemsSource="{Binding Rechenweg}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Spacing="6" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="x:String">
<TextBlock Classes="secondary" TextWrapping="Wrap" Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<TextBlock Classes="secondary" TextWrapping="Wrap"
Text="Richtwerte. Ersetzen keine Fachberatung." />
<TextBlock Classes="secondary" TextWrapping="Wrap"
Expand Down
154 changes: 154 additions & 0 deletions src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechenweg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using FwAssist.Core;

namespace FwAssist.Helpers.Sandsack;

/// <summary>
/// How the Sandsack helper gets to its Richtwerte, one German line per step, for the screen (#87).
/// Each line shows the rule, and once the values it needs are entered, it shows the user's own
/// numbers worked through. Every figure comes from <see cref="Sandsackvorgaben"/>, and every
/// result comes from <see cref="SandsackRechner"/>. The text cannot drift from the arithmetic.
/// </summary>
public static class SandsackRechenweg
{
private static readonly string Stufen = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.HoeheMeter));

private static readonly string SaeckeJeMeter = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.SaeckeJeMeter));

private static readonly string SandJeMeter = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.SandKubikmeterJeMeter));

private static readonly string Nass = Formatting.Number(Sandsackvorgaben.SandTonnenJeKubikmeter, 1);

private static readonly string TrockenMin = Formatting.Number(Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter, 1);

private static readonly string TrockenMax = Formatting.Number(Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter, 1);

private static readonly string Arbeitsgaenge = Formatting.Number(Sandsackvorgaben.ArbeitsgaengeJeSack);

private static readonly string Leistung = Formatting.Number(Sandsackvorgaben.SaeckeJeHelferUndStunde, 0);

private static readonly string Basisfaktor = Formatting.Number(Sandsackvorgaben.BasisbreiteJeHoehe, 0);

private static readonly string WarumNass =
$"Nasser Sand wiegt bis zu {Formatting.Number(SandsackRechner.NassMehrgewichtProzent, 0)} % mehr als trockener. "
+ "Gerechnet wird mit nassem Sand, damit Ladung und Fahrten reichen.";

/// <summary>Why every result errs towards too much.</summary>
public const string SichereSeite =
"Zur sicheren Seite gerechnet: Säcke „quer verlegt“, der obere Sandwert "
+ "und die langsamste Arbeitsleistung der Taschenkarte.";

/// <summary>
/// The steps, in the order the results are shown. A value that is <see langword="null"/> has
/// not been entered, or is not valid, and its steps show the rule alone.
/// </summary>
public static IReadOnlyList<string> Zeilen(decimal? laengeMeter, decimal? hoeheMeter, decimal? helfer)
{
if (hoeheMeter is not { } hoehe)
{
return
[
$"Höhe: aufgerundet auf die nächste Stufe der Tabelle, {Stufen} m.",
$"Sandsäcke: Länge × Säcke je m der Stufe ({SaeckeJeMeter}), aufgerundet.",
$"Sand: Länge × m³ je m der Stufe ({SandJeMeter}), aufgerundet auf 0,1 m³.",
$"Sand, nass: m³ × {Nass} t/m³.",
$"Sand, trocken: {TrockenMin} bis {TrockenMax} t/m³. {WarumNass}",
$"Arbeitszeit: Säcke × {Arbeitsgaenge} Arbeitsgänge (Füllen und Tragen, Verlegen) ÷ {Leistung} Säcke "
+ "je Helfer und Stunde ÷ Helfer, aufgerundet auf die Viertelstunde. Nur ganze Helfer zählen.",
$"Basisbreite: Höhe × {Basisfaktor}.",
SichereSeite,
];
}

var stufe = SandsackRechner.Stufe(hoehe);
var basis = SandsackRechner.Basisbreite(hoehe);
var hoeheZeile = $"Höhe: {Wie(hoehe)} m, gerechnet mit der Stufe {Formatting.Number(stufe.HoeheMeter, 1)} m "
+ $"(Stufen {Stufen} m).";
var basisZeile = $"Basisbreite: {Wie(hoehe)} m × {Basisfaktor} = {Formatting.Number(basis, 1)} m"
+ $"{Aufgerundet(hoehe * Sandsackvorgaben.BasisbreiteJeHoehe, basis)}.";

if (laengeMeter is not { } laenge)
{
return
[
hoeheZeile,
$"Sandsäcke: Länge × {Wie(stufe.SaeckeJeMeter)} je m, aufgerundet.",
$"Sand: Länge × {Wie(stufe.SandKubikmeterJeMeter)} m³ je m, aufgerundet auf 0,1 m³.",
$"Sand, nass: m³ × {Nass} t/m³.",
$"Sand, trocken: {TrockenMin} bis {TrockenMax} t/m³. {WarumNass}",
$"Arbeitszeit: Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde ÷ Helfer, "
+ "aufgerundet auf die Viertelstunde.",
basisZeile,
SichereSeite,
];
}

var saecke = SandsackRechner.Saecke(laenge, stufe);
var sand = SandsackRechner.SandKubikmeter(laenge, stufe);
var nass = SandsackRechner.SandTonnen(sand);
var (trockenMin, trockenMax) = SandsackRechner.SandTrockenTonnen(sand);
var sandText = Formatting.Number(sand, 1);

return
[
hoeheZeile,
$"Sandsäcke: {Wie(laenge)} m × {Wie(stufe.SaeckeJeMeter)} je m = {Formatting.Number(saecke, 0)}"
+ $"{Aufgerundet(laenge * stufe.SaeckeJeMeter, saecke)}.",
$"Sand: {Wie(laenge)} m × {Wie(stufe.SandKubikmeterJeMeter)} m³ je m = {sandText} m³"
+ $"{Aufgerundet(laenge * stufe.SandKubikmeterJeMeter, sand)}.",
$"Sand, nass: {sandText} m³ × {Nass} t/m³ = {Formatting.Number(nass, 1)} t.",
$"Sand, trocken: {sandText} m³ × {TrockenMin} bis {TrockenMax} t/m³ = "
+ $"{Formatting.Number(trockenMin, 1)} bis {Formatting.Number(trockenMax, 1)} t"
+ $"{TrockenAufgerundet(sand, trockenMin, trockenMax)}. {WarumNass}",
Arbeitszeit(saecke, helfer),
basisZeile,
SichereSeite,
];
}

/// <summary>A working time as the result shows it: "80 h", "5 h 45 min".</summary>
public static string Dauer(TimeSpan dauer)
{
var stunden = (int)dauer.TotalHours;
return dauer.Minutes == 0
? $"{Formatting.Number(stunden)} h"
: $"{Formatting.Number(stunden)} h {Formatting.Number(dauer.Minutes)} min";
}

private static string Arbeitszeit(decimal saecke, decimal? helfer)
{
var saeckeText = Formatting.Number(saecke, 0);
if (helfer is not { } anzahl)
{
return $"Arbeitszeit: {saeckeText} Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde ÷ Helfer, "
+ "aufgerundet auf die Viertelstunde.";
}

var ganze = Math.Floor(anzahl);
var zeit = SandsackRechner.Arbeitszeit(saecke, anzahl);
var viertelstunden = saecke * Sandsackvorgaben.ArbeitsgaengeJeSack * 4m
/ Sandsackvorgaben.SaeckeJeHelferUndStunde / ganze;
var gerundet = viertelstunden == Math.Floor(viertelstunden) ? string.Empty : ", aufgerundet auf die Viertelstunde";
var nurGanze = ganze == anzahl ? string.Empty : " Nur ganze Helfer zählen.";
return $"Arbeitszeit: {saeckeText} Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde "
+ $"÷ {Formatting.Number(ganze, 0)} Helfer = {Dauer(zeit)}{gerundet}.{nurGanze}";
}

private static string Aufgerundet(decimal exakt, decimal gerundet) =>
exakt == gerundet ? string.Empty : ", aufgerundet";

/// <summary>The rounding note for the dry range: it applies when either end was rounded up.</summary>
private static string TrockenAufgerundet(decimal kubikmeter, decimal min, decimal max) =>
kubikmeter * Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter == min
&& kubikmeter * Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter == max
? string.Empty
: ", aufgerundet";

/// <summary>A number with as many decimals as it was written with: "100", "0,8", "9,6".</summary>
private static string Wie(decimal value) => Formatting.Number(value, value.Scale);

/// <summary>
/// The figures of the table's rows, "0,5 / 1,0 / 1,5 / 2,0". No-break spaces keep the list on
/// one line, so a narrow phone never wraps it between two of its figures.
/// </summary>
private static string Liste(IEnumerable<decimal> values) => string.Join(" / ", values.Select(Wie));
}
18 changes: 18 additions & 0 deletions src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ public static decimal SandKubikmeter(decimal laengeMeter, Dammstufe stufe)
public static decimal SandTonnen(decimal kubikmeter) =>
RoundUp(kubikmeter * Sandsackvorgaben.SandTonnenJeKubikmeter, 1);

/// <summary>
/// What <paramref name="kubikmeter"/> of dry sand weigh, from TK's lightest to its heaviest dry
/// figure, in tonnes to one decimal. Both ends round up, as the wet weight does.
/// </summary>
public static (decimal Min, decimal Max) SandTrockenTonnen(decimal kubikmeter) =>
(RoundUp(kubikmeter * Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter, 1),
RoundUp(kubikmeter * Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter, 1));

/// <summary>
/// How much more wet sand weighs than the lightest dry sand, in whole percent: 2,0 t against
/// 1,2 t is 67 %.
/// </summary>
public static decimal NassMehrgewichtProzent =>
Math.Round(
((Sandsackvorgaben.SandTonnenJeKubikmeter / Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter) - 1m) * 100m,
0,
MidpointRounding.AwayFromZero);

/// <summary>
/// How long <paramref name="helfer"/> take to fill, carry and lay <paramref name="saecke"/>,
/// rounded up to the quarter hour. Part of a Helfer does not count: 2,5 Helfer work as 2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public sealed partial class SandsackViewModel : ObservableObject

private static readonly string MaxHoeheText = Formatting.Number(SandsackRechner.MaxHoeheMeter, 1);

private static readonly string Arbeitsweise =
$"Arbeitszeit für Füllen, Tragen und Verlegen, {Formatting.Number(Sandsackvorgaben.SaeckeJeHelferUndStunde, 0)} Säcke je Helfer und Stunde.";

private readonly IHelperSettings _settings;

public SandsackViewModel(IHelperSettings settings)
Expand Down Expand Up @@ -52,6 +49,10 @@ public SandsackViewModel(IHelperSettings settings)
[ObservableProperty]
private string _hinweis = string.Empty;

/// <summary>How the results are calculated, one step per line, with the values entered so far (#87).</summary>
[ObservableProperty]
private IReadOnlyList<string> _rechenweg = [];

[RelayCommand]
private void Reset()
{
Expand All @@ -60,30 +61,23 @@ private void Reset()
Helfer.Text = string.Empty;
}

private static string Dauer(TimeSpan dauer)
{
var stunden = (int)dauer.TotalHours;
return dauer.Minutes == 0
? $"{Formatting.Number(stunden)} h"
: $"{Formatting.Number(stunden)} h {Formatting.Number(dauer.Minutes)} min";
}

private NumberField Field(NumberFieldRule rule) =>
new(_settings, rule with { Key = $"{SandsackModule.HelperId}.{rule.Key}" }, Recalculate);

private void Recalculate()
{
Rechenweg = SandsackRechenweg.Zeilen(Laenge.Value, Hoehe.Value, Helfer.Value);
if (Hoehe.Value is not { } hoehe)
{
Hinweis = $"{Ratschlag} {Arbeitsweise}";
Hinweis = Ratschlag;
Results = [];
return;
}

var stufe = SandsackRechner.Stufe(hoehe);
Hinweis = $"Gerechnet für {Formatting.Number(stufe.HoeheMeter, 1)} m Höhe. "
+ $"Basisbreite mindestens {Formatting.Number(SandsackRechner.Basisbreite(hoehe), 1)} m. "
+ $"{Ratschlag} {Arbeitsweise}";
+ Ratschlag;

if (Laenge.Value is not { } laenge)
{
Expand All @@ -102,7 +96,7 @@ private void Recalculate()

if (Helfer.Value is { } helfer)
{
lines.Add(new("Arbeitszeit", Dauer(SandsackRechner.Arbeitszeit(saecke, helfer))));
lines.Add(new("Arbeitszeit", SandsackRechenweg.Dauer(SandsackRechner.Arbeitszeit(saecke, helfer))));
}

Results = lines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public static class Sandsackvorgaben
/// </summary>
public const decimal SandTonnenJeKubikmeter = 2m;

/// <summary>
/// TK, "Deichverteidigungsmaterialien", Sand: "Gewicht trocken 1.200 - 1.600 Kg/m³", the lower
/// end, in tonnes. Shown to explain the span only. No result is planned with it.
/// </summary>
public const decimal SandTrockenMinTonnenJeKubikmeter = 1.2m;

/// <summary>The upper end of TK's dry weight; see <see cref="SandTrockenMinTonnenJeKubikmeter"/>.</summary>
public const decimal SandTrockenMaxTonnenJeKubikmeter = 1.6m;

/// <summary>TK, "Sandsackdamm, normale Stabilität": "b = > 2*h".</summary>
public const decimal BasisbreiteJeHoehe = 2m;

Expand Down
24 changes: 21 additions & 3 deletions tests/FwAssist.Acceptance.Tests/DemoFlowRenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,35 @@ public void The_sandsack_fields_and_reset_stay_glove_sized_on_a_320_dp_phone()
}

// 780 dp is about what a 915 dp phone leaves between its status and navigation bars.
// The explanation below may scroll; the fields and every result may not.
[AvaloniaFact]
public void A_whole_sandsack_calculation_fits_without_scrolling()
public void A_whole_sandsack_result_fits_without_scrolling()
{
var phone = new PhoneRender();
phone.Window.Height = 780;
FilledSandsack(phone);

var form = phone.Window.GetVisualDescendants().OfType<ScrollViewer>().Single(s => s.Name == "Form");
var results = Named(phone, "ResultPanel");
var bottom = results.TranslatePoint(new Point(0, results.Bounds.Height), form);
Assert.NotNull(bottom);
Assert.True(
form.Extent.Height <= form.Viewport.Height + 1,
$"The form is {form.Extent.Height} high in a viewport of {form.Viewport.Height}");
bottom.Value.Y <= form.Viewport.Height + 1,
$"The results end at {bottom.Value.Y} in a viewport of {form.Viewport.Height}");
}

[AvaloniaFact]
public void The_sandsack_explains_its_calculation_below_the_result()
{
var phone = new PhoneRender();
var page = FilledSandsack(phone);

var lines = Named(phone, "Rechenweg").GetVisualDescendants().OfType<TextBlock>()
.Where(t => t.IsEffectivelyVisible)
.Select(t => t.Text ?? string.Empty)
.ToList();
Assert.Equal(page.Rechenweg, lines);
Assert.Contains(lines, l => l.StartsWith("Sand, trocken: 300,0 m³ × 1,2 bis 1,6 t/m³ = 360,0 bis 480,0 t.", StringComparison.Ordinal));
}

private static Control Named(PhoneRender phone, string name) =>
Expand Down
Loading