DataTable: Add units for columns
This commit is contained in:
@ -8,19 +8,19 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Models.Dtos {
|
||||
public class AreaComUnderDeliveryData : DataTable<AreaComUnderDeliveryRow> {
|
||||
|
||||
private static readonly (string, string, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", 12),
|
||||
("Name", "Name", 40),
|
||||
("GivenName", "Vorname", 40),
|
||||
("Address", "Adresse", 60),
|
||||
("Plz", "PLZ", 10),
|
||||
("Locality", "Ort", 60),
|
||||
("VtrgIds", "Vertrag", 14),
|
||||
("Areas", "Fläche", 16),
|
||||
("DeliveryObligations", "Lieferpflicht", 22),
|
||||
("Weights", "Geliefert", 22),
|
||||
("UnderDeliveries", "Unterliefert", 22),
|
||||
("Percents", "Prozent", 16),
|
||||
private static readonly (string, string, string?, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", null, 12),
|
||||
("Name", "Name", null, 40),
|
||||
("GivenName", "Vorname", null, 40),
|
||||
("Address", "Adresse", null, 60),
|
||||
("Plz", "PLZ", null, 10),
|
||||
("Locality", "Ort", null, 60),
|
||||
("VtrgIds", "Vertrag", null, 14),
|
||||
("Areas", "Fläche", "m²", 16),
|
||||
("DeliveryObligations", "Lieferpflicht", "kg", 22),
|
||||
("Weights", "Geliefert", "kg", 22),
|
||||
("UnderDeliveries", "Unterliefert", "kg", 22),
|
||||
("Percents", "Prozent", "%", 16),
|
||||
};
|
||||
|
||||
public AreaComUnderDeliveryData(IEnumerable<AreaComUnderDeliveryRow> rows, int year) :
|
||||
@ -65,7 +65,7 @@ namespace Elwig.Models.Dtos {
|
||||
.Select(v => v.First < v.Second ? (int?)v.First - v.Second : null)
|
||||
.ToArray();
|
||||
public double?[] Percents => Weights.Zip(DeliveryObligations)
|
||||
.Select(v => v.First < v.Second ? (double?)Math.Round(v.First * 100.0 / v.Second - 100.0, 1) : null)
|
||||
.Select(v => v.First < v.Second ? (double?)v.First * 100.0 / v.Second - 100.0 : null)
|
||||
.ToArray();
|
||||
|
||||
public AreaComUnderDeliveryRow(IEnumerable<AreaComUnderDeliveryRowSingle> rows) {
|
||||
|
@ -18,15 +18,16 @@ namespace Elwig.Models.Dtos {
|
||||
public IEnumerable<Type?> ColumnFlatTypes { get; private set; }
|
||||
public IEnumerable<int> ColumnSpans { get; private set; }
|
||||
public IEnumerable<int?> ColumnWidths { get; private set; }
|
||||
public IEnumerable<string?[]> ColumnUnits { get; private set; }
|
||||
|
||||
private readonly PropertyInfo[] _properties;
|
||||
private readonly FieldInfo[] _fields;
|
||||
private readonly (string, PropertyInfo?, FieldInfo?)[] _map;
|
||||
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string, int?)>? colNames = null) {
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string, string?, int?)>? colNames = null) {
|
||||
_fields = typeof(T).GetFields();
|
||||
_properties = typeof(T).GetProperties();
|
||||
colNames ??= _properties.Select(p => p.Name).Union(_fields.Select(f => f.Name)).Select(i => (i, i, (int?)null)).ToList();
|
||||
colNames ??= _properties.Select(p => p.Name).Union(_fields.Select(f => f.Name)).Select(i => (i, i, (string?)null, (int?)null)).ToList();
|
||||
_map = colNames.Select(n => (n.Item2, _properties.FirstOrDefault(p => p?.Name == n.Item1, null), _fields.FirstOrDefault(f => f?.Name == n.Item1, null))).ToArray();
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
@ -42,27 +43,28 @@ namespace Elwig.Models.Dtos {
|
||||
return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Length :
|
||||
type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Length : 1;
|
||||
}).ToList();
|
||||
ColumnWidths = colNames.Select(c => c.Item3).ToList();
|
||||
ColumnWidths = colNames.Select(c => c.Item4).ToList();
|
||||
ColumnUnits = colNames.Select(c => c.Item3?.Split("|").Select(p => p.Length == 0 ? null : p).ToArray() ?? Array.Empty<string?>()).ToList();
|
||||
}
|
||||
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string)>? colNames = null) :
|
||||
this(name, fullName, rows, colNames?.Select(c => (c.Item1, c.Item2, (int?)null))) {
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string, string?)>? colNames = null) :
|
||||
this(name, fullName, rows, colNames?.Select(c => (c.Item1, c.Item2, c.Item3, (int?)null))) {
|
||||
}
|
||||
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string)>? colNames = null) :
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string, string?)>? colNames = null) :
|
||||
this(name, name, rows, colNames) {
|
||||
}
|
||||
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string, int?)>? colNames = null) :
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string, string?, int?)>? colNames = null) :
|
||||
this(name, name, rows, colNames) {
|
||||
}
|
||||
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string, int)>? colNames = null) :
|
||||
public DataTable(string name, IEnumerable<T> rows, IEnumerable<(string, string, string?, int)>? colNames = null) :
|
||||
this(name, name, rows, colNames) {
|
||||
}
|
||||
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string, int)>? colNames = null) :
|
||||
this(name, fullName, rows, colNames?.Select(c => (c.Item1, c.Item2, (int?)c.Item3))) {
|
||||
public DataTable(string name, string fullName, IEnumerable<T> rows, IEnumerable<(string, string, string?, int)>? colNames = null) :
|
||||
this(name, fullName, rows, colNames?.Select(c => (c.Item1, c.Item2, c.Item3, (int?)c.Item4))) {
|
||||
}
|
||||
|
||||
protected IEnumerable<(string, object?)> GetNamedRowData(T row) {
|
||||
|
@ -7,17 +7,16 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Models.Dtos {
|
||||
public class DeliveryConfirmationData : DataTable<DeliveryConfirmationRow> {
|
||||
|
||||
private static readonly (string, string)[] FieldNames = new[] {
|
||||
("LsNr", "LsNr."),
|
||||
("DPNr", "Pos."),
|
||||
("Variant", "Sorte"),
|
||||
("Attribute", "Attribut"),
|
||||
("Modifiers", "Zu-/Abschläge"),
|
||||
("QualityLevel", "Qualitätsstufe"),
|
||||
("Oe", "°Oe"),
|
||||
("Kmw", "°KMW"),
|
||||
("Buckets", "Flächenbindung"),
|
||||
("Weight", "Gewicht"),
|
||||
private static readonly (string, string, string?, int)[] FieldNames = new[] {
|
||||
("LsNr", "LsNr.", null, 26),
|
||||
("DPNr", "Pos.", null, 8),
|
||||
("Variant", "Sorte", null, 40),
|
||||
("Attribute", "Attribut", null, 20),
|
||||
("Modifiers", "Zu-/Abschläge", null, 30),
|
||||
("QualityLevel", "Qualitätsstufe", null, 25),
|
||||
("Gradation", "Gradation", "°Oe|°KMW", 32),
|
||||
("Buckets", "Flächenbindung", "|kg", 36),
|
||||
("Weight", "Gewicht", "kg", 16),
|
||||
};
|
||||
|
||||
private readonly int MgNr;
|
||||
@ -71,11 +70,10 @@ namespace Elwig.Models.Dtos {
|
||||
public string Variant;
|
||||
public string? Attribute;
|
||||
public string QualityLevel;
|
||||
public double Oe;
|
||||
public double Kmw;
|
||||
public (double Oe, double Kmw) Gradation;
|
||||
public string[] Modifiers;
|
||||
public int Weight;
|
||||
public (string, int)[] Buckets;
|
||||
public (string Name, int Value)[] Buckets;
|
||||
|
||||
public DeliveryConfirmationRow(DeliveryPart p) {
|
||||
var d = p.Delivery;
|
||||
@ -84,8 +82,7 @@ namespace Elwig.Models.Dtos {
|
||||
Variant = p.Variant.Name;
|
||||
Attribute = p.Attribute?.Name;
|
||||
QualityLevel = p.Quality.Name;
|
||||
Oe = p.Oe;
|
||||
Kmw = p.Kmw;
|
||||
Gradation = (p.Oe, p.Kmw);
|
||||
Modifiers = p.Modifiers
|
||||
.Select(m => m.Name)
|
||||
.ToArray();
|
||||
|
@ -8,18 +8,18 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Models.Dtos {
|
||||
public class MemberDeliveryPerVariantData : DataTable<MemberDeliveryPerVariantRow> {
|
||||
|
||||
private static readonly (string, string, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", 12),
|
||||
("Name", "Name", 40),
|
||||
("GivenName", "Vorname", 40),
|
||||
("Address", "Adresse", 60),
|
||||
("Plz", "PLZ", 10),
|
||||
("Locality", "Ort", 60),
|
||||
("SortIds", "Sorte", 12),
|
||||
("AttrIds", "Attribut", 16),
|
||||
("Weights", "Geliefert", 22),
|
||||
("Areas", "Fläche", 22),
|
||||
("Yields", "Ertrag", 22),
|
||||
private static readonly (string, string, string?, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", null, 12),
|
||||
("Name", "Name", null, 40),
|
||||
("GivenName", "Vorname", null, 40),
|
||||
("Address", "Adresse", null, 60),
|
||||
("Plz", "PLZ", null, 10),
|
||||
("Locality", "Ort", null, 60),
|
||||
("SortIds", "Sorte", null, 12),
|
||||
("AttrIds", "Attribut", null, 16),
|
||||
("Weights", "Geliefert", "kg", 22),
|
||||
("Areas", "Fläche", "m²", 22),
|
||||
("Yields", "Ertrag", "kg/ha", 22),
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,19 +7,19 @@ using System.Threading.Tasks;
|
||||
namespace Elwig.Models.Dtos {
|
||||
public class OverUnderDeliveryData : DataTable<OverUnderDeliveryRow> {
|
||||
|
||||
private static readonly (string, string, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", 12),
|
||||
("Name", "Name", 40),
|
||||
("GivenName", "Vorname", 40),
|
||||
("Address", "Adresse", 60),
|
||||
("Plz", "PLZ", 10),
|
||||
("Locality", "Ort", 60),
|
||||
("BusinessShares", "GA", 10),
|
||||
("DeliveryObligation", "Lieferpflicht", 22),
|
||||
("DeliveryRight", "Lieferrecht", 22),
|
||||
("Weight", "Geliefert", 22),
|
||||
("OverUnderDelivery", "Über-/Unterliefert", 35),
|
||||
("Percent", "Prozent", 16),
|
||||
private static readonly (string, string, string?, int)[] FieldNames = new[] {
|
||||
("MgNr", "MgNr.", null, 12),
|
||||
("Name", "Name", null, 40),
|
||||
("GivenName", "Vorname", null, 40),
|
||||
("Address", "Adresse", null, 60),
|
||||
("Plz", "PLZ", null, 10),
|
||||
("Locality", "Ort", null, 60),
|
||||
("BusinessShares", "GA", null, 10),
|
||||
("DeliveryObligation", "Lieferpflicht", "kg", 22),
|
||||
("DeliveryRight", "Lieferrecht", "kg", 22),
|
||||
("Weight", "Geliefert", "kg", 22),
|
||||
("OverUnderDelivery", "Über-/Unterliefert", "kg", 35),
|
||||
("Percent", "Prozent", "%", 16),
|
||||
};
|
||||
|
||||
public OverUnderDeliveryData(IEnumerable<OverUnderDeliveryRow> rows, int year) :
|
||||
@ -75,7 +75,7 @@ namespace Elwig.Models.Dtos {
|
||||
Weight > DeliveryRight ? Weight - DeliveryRight : null;
|
||||
[NotMapped]
|
||||
public double? Percent =>
|
||||
Weight < DeliveryObligation ? Math.Round(Weight * 100.0 / DeliveryObligation - 100.0, 1) :
|
||||
Weight > DeliveryRight ? Math.Round(Weight * 100.0 / DeliveryRight - 100, 1) : null;
|
||||
Weight < DeliveryObligation ? Weight * 100.0 / DeliveryObligation - 100.0 :
|
||||
Weight > DeliveryRight ? Weight * 100.0 / DeliveryRight - 100 : null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user