[#34] Billing: Collapse data more compactly

This commit is contained in:
2024-02-20 23:14:00 +01:00
parent 56fdf62c5c
commit 9fec79ef8c
4 changed files with 30 additions and 16 deletions

View File

@ -287,27 +287,41 @@ namespace Elwig.Helpers.Billing {
var attributes = data
.Select(e => e.Key)
.Where(k => !k.StartsWith('/') && k.Contains('/'))
.Where(k => k.Length > 3 && k.Contains('/'))
.Select(k => k.Split('/')[1])
.Distinct()
.ToList();
foreach (var idx in attributes) {
var len = vaributes.Count(e => e.AttrId == idx);
var len = vaributes.Count(e => $"{e.AttrId}{(e.CultId != null && e.CultId != "" ? "-" : "")}{e.CultId}" == idx);
foreach (var (v, ks) in rev1) {
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.StartsWith('-') ? "" : "/") + idx] = v;
data[(idx.StartsWith('-') && !useDefault ? "" : "/") + idx] = v;
}
}
foreach (var (v, ks) in rev2) {
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.StartsWith('-') ? "" : "/") + idx] = v;
data[(idx.StartsWith('-') && !useDefault ? "" : "/") + idx] = v;
}
}
}
if (!useDefault)
return;
var keys = data.Select(p => p.Key).ToList();
foreach (var k in keys) {
if (k.Length == 3 && k.EndsWith('/') && !keys.Contains(k[..2])) {
data.Remove(k, out var val);
data.Add(k[..2], val);
} else if (k.Contains("/-")) {
data.Remove(k, out var val);
data.Add(k.Replace("/-", "-"), val);
}
}
}
public static JsonObject FromGraphEntries(

View File

@ -76,7 +76,7 @@ GROUP BY b.year, b.mgnr, b.sortid
ORDER BY year, mgnr, bucket;
PRAGMA schema_version = 1701;
PRAGMA writable_schame = OFF;
PRAGMA writable_schema = OFF;
----------------------------------------------------------------
@ -89,4 +89,4 @@ DELETE FROM area_commitment_type WHERE attrid = 'B';
UPDATE delivery_part SET cultid = 'B', attrid = NULL WHERE attrid = 'B';
DELETE FROM wine_attribute WHERE attrid = 'B';
UPDATE payment_variant SET data = REPLACE(REPLACE(data, '/B', '/-B'), '"/-B"', '"-B"');
UPDATE payment_variant SET data = REPLACE(REPLACE(REPLACE(data, '/B', '-B'), '/"', '"'), '/-', '-');

View File

@ -126,7 +126,7 @@ namespace Elwig.Windows {
Vaributes = Utils.GetVaributeList(Context, Year);
GraphEntries.ForEach(e => {
e.Vaributes.ForEach(v => {
var found = Vaributes.Find(a => a.Attribute?.AttrId == v.Attribute?.AttrId && a.Variety?.SortId == v.Variety?.SortId);
var found = Vaributes.Find(a => a.Variety?.SortId == v.Variety?.SortId && a.Attribute?.AttrId == v.Attribute?.AttrId && a.Cultivation?.CultId == v.Cultivation?.CultId);
if (found == null) return;
if (e.Abgewertet) {
found.AssignedAbgewGraphId = e.Id;

View File

@ -490,8 +490,8 @@ namespace Tests.HelperTests {
"mode": "elwig",
"version": 1,
"payment": {
"WR/": 0.75,
"default": "curve:1"
"default": "curve:1",
"WR": 0.75
},
"curves": [
{
@ -528,10 +528,10 @@ namespace Tests.HelperTests {
"mode": "elwig",
"version": 1,
"payment": {
"BP/": "curve:2",
"SA/": "curve:2",
"default": 0.75,
"/K": "curve:1"
"/K": "curve:1",
"BP": "curve:2",
"SA": "curve:2"
},
"curves": [
{
@ -576,9 +576,9 @@ namespace Tests.HelperTests {
"mode": "elwig",
"version": 1,
"payment": {
"BP/": "curve:2",
"SA/": "curve:2",
"default": 0.75,
"BP": "curve:2",
"SA": "curve:2",
"-B": "curve:1"
},
"curves": [
@ -627,8 +627,8 @@ namespace Tests.HelperTests {
"payment": {
"default": 0.75,
"/S": 0.3,
"-B": 0.2,
"/S-B": 0.4
"/S-B": 0.4,
"-B": 0.2
},
"curves": []
}