Tests mit Prozentualer Umverteilung bei der Stärke
This commit is contained in:
parent
b704dbc30e
commit
8435545bec
@ -2,8 +2,8 @@
|
||||
{
|
||||
public class GeneralSettings
|
||||
{
|
||||
|
||||
public int MaxAllowedUploadSizeInMB { get; set; } = 10;
|
||||
|
||||
public string ImageUploadDir { get; set; } = "images";
|
||||
|
||||
public string SerialPort { get; set; } = "COM5";
|
||||
|
||||
@ -31,15 +31,30 @@ else
|
||||
<h6>
|
||||
Stärke
|
||||
</h6>
|
||||
<div class="btn-group" role="group">
|
||||
<button @onclick="() => SetIntensity(-60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -60 ? "" : "outline-")success"><i class="bi bi-peace fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(-40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -40 ? "" : "outline-")success"><i class="bi bi-dash fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(-20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -20 ? "" : "outline-")success"><i class="bi bi-dash"></i></button>
|
||||
<button @onclick="() => SetIntensity(0)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity == 0 ? "" : "")warning"><i class="bi bi-circle"></i></button>
|
||||
<button @onclick="() => SetIntensity(20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 20 ? "" : "outline-")danger"><i class="bi bi-plus"></i></button>
|
||||
<button @onclick="() => SetIntensity(40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 40 ? "" : "outline-")danger"><i class="bi bi-plus fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 60 ? "" : "outline-")danger"><i class="bi bi-radioactive fs-5"></i></button>
|
||||
</div>
|
||||
@if (!UseNewIntensityCalc)
|
||||
{
|
||||
<div class="btn-group" role="group">
|
||||
<button @onclick="() => SetIntensity(-60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -60 ? "" : "outline-")success"><i class="bi bi-peace fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(-40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -40 ? "" : "outline-")success"><i class="bi bi-dash fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(-20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -20 ? "" : "outline-")success"><i class="bi bi-dash"></i></button>
|
||||
<button @onclick="() => SetIntensity(0)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity == 0 ? "" : "")warning"><i class="bi bi-circle"></i></button>
|
||||
<button @onclick="() => SetIntensity(20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 20 ? "" : "outline-")danger"><i class="bi bi-plus"></i></button>
|
||||
<button @onclick="() => SetIntensity(40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 40 ? "" : "outline-")danger"><i class="bi bi-plus fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensity(60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 60 ? "" : "outline-")danger"><i class="bi bi-radioactive fs-5"></i></button>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="btn-group" role="group">
|
||||
<button @onclick="() => SetIntensityPercentual(-3)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -3 ? "" : "outline-")success"><i class="bi bi-peace fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(-2)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -2 ? "" : "outline-")success"><i class="bi bi-dash fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(-1)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -1 ? "" : "outline-")success"><i class="bi bi-dash"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(0)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity == 0 ? "" : "")warning"><i class="bi bi-circle"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(1)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 1 ? "" : "outline-")danger"><i class="bi bi-plus"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(2)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 2 ? "" : "outline-")danger"><i class="bi bi-plus fs-5"></i></button>
|
||||
<button @onclick="() => SetIntensityPercentual(3)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 3 ? "" : "outline-")danger"><i class="bi bi-radioactive fs-5"></i></button>
|
||||
</div>
|
||||
}
|
||||
</p>
|
||||
|
||||
@if (ErrorMessage != null)
|
||||
@ -48,12 +63,12 @@ else
|
||||
@ErrorMessage
|
||||
</div>
|
||||
}
|
||||
@if(CocktailCode != null)
|
||||
@if (CocktailCode != null)
|
||||
{
|
||||
<div class="alert alert-dark" style="white-space: pre-line" role="alert">
|
||||
@CocktailCode
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<button class="btn btn-primary" @onclick=CreateCocktailCode>Lets goooooo!</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -120,6 +135,8 @@ else
|
||||
|
||||
private int DrinkIntensity = 0;
|
||||
|
||||
private bool UseNewIntensityCalc = false;
|
||||
|
||||
private string? ErrorMessage;
|
||||
private string? CocktailCode;
|
||||
|
||||
@ -181,6 +198,9 @@ else
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Erstellt den für die Arduino-Steuerung erforderlichen Code
|
||||
/// </summary>
|
||||
private void CreateCocktailCode()
|
||||
{
|
||||
CocktailCode = null;
|
||||
@ -196,50 +216,93 @@ else
|
||||
if (Filler.Type == Filler.FillerType.Pump)
|
||||
{
|
||||
line = $"P{Filler.Pos}={Zutat.Menge}";
|
||||
} else if (Filler.Type == Filler.FillerType.Pourer)
|
||||
}
|
||||
else if (Filler.Type == Filler.FillerType.Pourer)
|
||||
{
|
||||
line = $"F{Filler.Pos}={Zutat.Menge}";
|
||||
}
|
||||
lines.Add(line);
|
||||
}
|
||||
|
||||
lines.Add("ZIEL");
|
||||
CocktailCode = String.Join("\r\n", lines.ToArray());
|
||||
lines.Add("ZIEL");
|
||||
CocktailCode = String.Join("\r\n", lines.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setzt die Alkoholintensität
|
||||
/// Setzt die Alkoholintensität und berechnet die Mengen für ModifiedCocktail entsprechend neu
|
||||
/// </summary>
|
||||
/// <param name="intensity">Zugabe/Abzug von Alkohol in Prozent</param>
|
||||
private void SetIntensity(int intensity)
|
||||
{
|
||||
DrinkIntensity = intensity;
|
||||
if (ModifiedCocktail != null && SelectedCocktail != null)
|
||||
if (ModifiedCocktail == null || SelectedCocktail == null) return;
|
||||
|
||||
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||
{
|
||||
|
||||
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||
int OriginalMenge = SelectedCocktail.Cocktailflaschen.First(scf => scf.Id == cf.Id).Menge;
|
||||
if (cf.Flasche.Alkoholisch)
|
||||
{
|
||||
int OriginalMenge = SelectedCocktail.Cocktailflaschen.First(scf => scf.FlascheID == cf.FlascheID).Menge;
|
||||
if (cf.Flasche.Alkoholisch)
|
||||
{
|
||||
cf.Menge = OriginalMenge + (OriginalMenge * intensity / 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
cf.Menge = OriginalMenge - (OriginalMenge * intensity / 100);
|
||||
}
|
||||
cf.Menge = OriginalMenge + (OriginalMenge * intensity / 100);
|
||||
}
|
||||
|
||||
// Durch das anteilige Umrechnen ändert sich die Gesamtmenge, daher passen wir die Mengen nochmal an
|
||||
int AktGesMenge = ModifiedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||
int OrigMenge = SelectedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||
else
|
||||
{
|
||||
cf.Menge = (int)((float)cf.Menge / AktGesMenge * OrigMenge);
|
||||
cf.Menge = OriginalMenge - (OriginalMenge * intensity / 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Durch das anteilige Umrechnen ändert sich die Gesamtmenge, daher passen wir die Mengen nochmal an
|
||||
int AktGesMenge = ModifiedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||
int OrigMenge = SelectedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||
{
|
||||
cf.Menge = (int)((float)cf.Menge / AktGesMenge * OrigMenge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ToDo: Ggf. noch Rundungsfehler drin oder wirklich noch grobe Fehler in der Mathematik.. Gesamtmenge passt irgendwie nicht.
|
||||
/// <summary>
|
||||
/// Ändert die Alkoholintensität basierend auf den Prozentwerten anstatt der Menge
|
||||
/// </summary>
|
||||
/// <param name="intensitylevel">Intensitätslevel (z.B. -1, 0, 1,2 ...)</param>
|
||||
private void SetIntensityPercentual(int intensitylevel)
|
||||
{
|
||||
DrinkIntensity = intensitylevel;
|
||||
if (ModifiedCocktail == null || SelectedCocktail == null) return;
|
||||
int DivideParts = 4; // Gibt an, in wieviele Teile die nicht-alkoholische Gesamtmenge aufgeteilt wird. Sollte mindestens 1 oder 2 mehr als das Max.Intensitätslevel sein
|
||||
float IncreasePerLevel_pct; // Gibt an, um welchen Anteil in % die alkoholischen Getränke steigen.
|
||||
|
||||
float SumAlcoholic_ml = SelectedCocktail.Cocktailflaschen.Where(cf => cf.Flasche.Alkoholisch).Sum(cf => cf.Menge); // Summe in ml der Alkoholhaltigen Zutaten
|
||||
float SumNonAlcoholic_ml = SelectedCocktail.Cocktailflaschen.Where(cf => !cf.Flasche.Alkoholisch).Sum(cf => cf.Menge); // Summe in ml der Alkoholfreien Zutaten
|
||||
float SumTotal = SumAlcoholic_ml + SumNonAlcoholic_ml;
|
||||
float SumAlcoholic_pct = SumAlcoholic_ml / SumTotal * 100; //Prozentwert an alkoholhaltigen Zutaten
|
||||
float SumNonAlcoholic_pct = SumNonAlcoholic_ml / SumTotal * 100; //Prozentwert an alkoholhaltigen Zutaten
|
||||
float SumBasis_ml = intensitylevel >= 0 ? SumNonAlcoholic_ml : SumAlcoholic_ml; // Wenn Intensität > 0, dann ist Summenbasis nichtalkoholisch, ansonsten alkoholisch
|
||||
if (intensitylevel >= 0)
|
||||
{
|
||||
/// Wenn alkoholhaltiges 30% ausmacht, teilen wir den Rest (alkoholfreis, 70%) durch die o.g. DivideParts, damit wir wissen um wieviel Prozent pro Stufe wir erhöhen können
|
||||
IncreasePerLevel_pct = SumNonAlcoholic_pct / DivideParts;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cocktail abschwächen, daher teilen wir in die andere Richtung auf
|
||||
IncreasePerLevel_pct = SumAlcoholic_pct / DivideParts;
|
||||
}
|
||||
|
||||
|
||||
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||
{
|
||||
float OrigMenge = SelectedCocktail.Cocktailflaschen.First(f => f.Id == cf.Id).Menge;
|
||||
// Herausfinden, wieviel Prozent die Zutat in ihrem Bereich (Alkoholisch/Nichtalkoholisch) ausmacht
|
||||
float ZutatIncrease_pct = IncreasePerLevel_pct / SumBasis_ml * cf.Menge;
|
||||
float ZutatMenge_pct = (float)OrigMenge / SumTotal * 100;
|
||||
// Neue Menge in Prozent: ZutatMenge_pct + ZutatIncrease_pct
|
||||
if (!cf.Flasche.Alkoholisch ^ intensitylevel < 0 )
|
||||
{
|
||||
ZutatIncrease_pct *= -1;
|
||||
}
|
||||
cf.Menge = (int)Math.Round(OrigMenge / ZutatMenge_pct * (ZutatMenge_pct + (ZutatIncrease_pct * intensitylevel)), 0, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
BIN
CocktailWeb/_Docs/ProzentualeVerteilung.xlsx
Normal file
BIN
CocktailWeb/_Docs/ProzentualeVerteilung.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user