[#34] Third step of not using Bio as Attribute

This commit is contained in:
2024-02-20 21:16:06 +01:00
parent f8ee478a9e
commit 56fdf62c5c
7 changed files with 215 additions and 77 deletions

View File

@ -284,26 +284,27 @@ namespace Elwig.Helpers.Billing {
}
}
}
var attributes = data
.Select(e => e.Key)
.Where(k => k.Length > 3 && k.Contains('/'))
.Where(k => !k.StartsWith('/') && k.Contains('/'))
.Select(k => k.Split('/')[1])
.Distinct()
.ToList();
foreach (var idx in attributes) {
var len = vaributes.Count(e => e.AttrId == idx);
foreach (var (v, ks) in rev1) {
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
var myKs = ks.Where(k => k.EndsWith($"/{idx}")).ToList();
if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) {
foreach (var k in myKs) data.Remove(k);
data[$"/{idx}"] = v;
data[(idx.StartsWith('-') ? "" : "/") + idx] = v;
}
}
foreach (var (v, ks) in rev2) {
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
var myKs = ks.Where(k => k.EndsWith($"/{idx}")).ToList();
if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) {
foreach (var k in myKs) data.Remove(k);
data[$"/{idx}"] = v;
data[(idx.StartsWith('-') ? "" : "/") + idx] = v;
}
}
}
@ -333,10 +334,12 @@ namespace Elwig.Helpers.Billing {
continue;
}
foreach (var c in entry.Vaributes) {
var v = new RawVaribute(c.Variety!.SortId, c.Attribute?.AttrId ?? "", c.Cultivation?.CultId);
if (v.CultId == "") v.CultId = null;
if (entry.Abgewertet) {;
qualityWei[c.ToString()] = node.DeepClone();
qualityWei[v.ToString()] = node.DeepClone();
} else {
payment[c.ToString()] = node.DeepClone();
payment[v.ToString()] = node.DeepClone();
}
}
}

View File

@ -123,10 +123,10 @@ namespace Elwig.Helpers.Billing {
}
protected async Task CalculatePrices(SqliteConnection cnx) {
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string? AttrId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
var parts = new List<(int Year, int DId, int DPNr, int BktNr, string SortId, string? AttrId, string? CultId, string Discr, int Value, double Oe, double Kmw, string QualId)>();
using (var cmd = cnx.CreateCommand()) {
cmd.CommandText = $"""
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, d.attrid, b.discr, b.value, d.oe, d.kmw, d.qualid
SELECT d.year, d.did, d.dpnr, b.bktnr, d.sortid, d.attrid, d.cultid, b.discr, b.value, d.oe, d.kmw, d.qualid
FROM delivery_part_bucket b
JOIN v_delivery d ON (d.year, d.did, d.dpnr) = (b.year, b.did, b.dpnr)
WHERE b.year = {Year}
@ -135,8 +135,9 @@ namespace Elwig.Helpers.Billing {
while (await reader.ReadAsync()) {
parts.Add((
reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3),
reader.GetString(4), reader.IsDBNull(5) ? null : reader.GetString(5), reader.GetString(6),
reader.GetInt32(7), reader.GetDouble(8), reader.GetDouble(9), reader.GetString(10)
reader.GetString(4), reader.IsDBNull(5) ? null : reader.GetString(5),
reader.IsDBNull(6) ? null : reader.GetString(6), reader.GetString(7),
reader.GetInt32(8), reader.GetDouble(9), reader.GetDouble(10), reader.GetString(11)
));
}
}
@ -145,9 +146,9 @@ namespace Elwig.Helpers.Billing {
foreach (var part in parts) {
var ungeb = part.Discr == "_";
var payAttrId = (part.Discr is "" or "_") ? null : part.Discr;
var attrId = part.AttrId == "B" ? "B" : payAttrId; // FIXME
var attrId = payAttrId; // FIXME
var geb = !ungeb; // FIXME && payAttrId == part.AttrId;
var price = Data.CalculatePrice(part.SortId, attrId, part.QualId, geb, part.Oe, part.Kmw);
var price = Data.CalculatePrice(part.SortId, attrId, part.CultId, part.QualId, geb, part.Oe, part.Kmw);
var priceL = PaymentVariant.Season.DecToDb(price);
inserts.Add((part.Year, part.DId, part.DPNr, part.BktNr, priceL, priceL * part.Value));
}

View File

@ -45,8 +45,8 @@ namespace Elwig.Helpers.Billing {
return dict;
}
public decimal CalculatePrice(string sortid, string? attrid, string qualid, bool gebunden, double oe, double kmw) {
var curve = GetQualityCurve(qualid, sortid, attrid) ?? GetCurve(sortid, attrid);
public decimal CalculatePrice(string sortid, string? attrid, string? cultid, string qualid, bool gebunden, double oe, double kmw) {
var curve = GetQualityCurve(qualid, sortid, attrid, cultid) ?? GetCurve(sortid, attrid, cultid);
return GetCurveValueAt((gebunden ? curve.Gebunden : null) ?? curve.Normal, curve.Mode == CurveMode.Oe ? oe : kmw);
}
@ -60,12 +60,12 @@ namespace Elwig.Helpers.Billing {
throw new InvalidOperationException();
}
protected Curve GetCurve(string sortid, string? attrid) {
return PaymentData[new(sortid, attrid ?? "", null)];
protected Curve GetCurve(string sortid, string? attrid, string? cultid) {
return PaymentData[new(sortid, attrid ?? "", cultid ?? "")];
}
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
return QualityData.TryGetValue(new(qualid, sortid, attrid ?? "", null), out var curve) ? curve : null;
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid, string? cultid) {
return QualityData.TryGetValue(new(qualid, sortid, attrid ?? "", cultid ?? ""), out var curve) ? curve : null;
}
}
}