bit of code simplification

master
Pepijn van Oort 2024-02-16 14:52:48 +01:00
parent 619cb5e92c
commit 39ee3263a7
1 changed files with 122 additions and 111 deletions

View File

@ -396,42 +396,46 @@ namespace FarmmapsKPI
{ {
if (kpio.id != kpioPrevious.id) if (kpio.id != kpioPrevious.id)
{ {
KPIelementsOfBalance kPIelementsOfBalance = kpio.data.values;
if (kpio.id == "B1") if (kpio.id == "B1")
{ {
//Make a new dataList = new line to be written //Make a new dataList = new line to be written
dataList = new List<string> { };
//Fill the datalist with this kpi //Fill the datalist with this kpi
dataList.Add(kpio.parentName); dataList = new List<string>
dataList.Add(cropfieldItem.Code); {
dataList.Add(kpio.data.area); kpio.parentName,
dataList.Add(kpio.data.cropTypeCode); cropfieldItem.Code,
dataList.Add(kpio.data.cropTypeName); kpio.data.area,
dataList.Add(kpio.id); kpio.data.cropTypeCode,
dataList.Add(kpio.quantity); // in KPI output quantity is what we call KPIvariable in headerlist of csv file kpio.data.cropTypeName,
dataList.Add(kpio.value); kpio.id,
dataList.Add(kpio.unit); kpio.quantity, // in KPI output quantity is what we call KPIvariable in headerlist of csv file
dataList.Add(kpio.targetValue); kpio.value,
dataList.Add(kpio.thresholdValue); kpio.unit,
kpio.targetValue,
kpio.thresholdValue
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
KPIelementsOfBalance kPIelementsOfBalance = kpio.data.values;
foreach (string elementName in kpio.B1elements) foreach (string elementName in kpio.B1elements)
{ {
// get B1element from the element called values // get B1element from the element called values
dataList = new List<string> { };
string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null); string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null);
dataList.Add(kpio.parentName); dataList = new List<string>
dataList.Add(cropfieldItem.Code); {
dataList.Add(kpio.data.area); kpio.parentName,
dataList.Add(kpio.data.cropTypeCode); cropfieldItem.Code,
dataList.Add(kpio.data.cropTypeName); kpio.data.area,
dataList.Add(kpio.id); kpio.data.cropTypeCode,
dataList.Add(elementName); // specific output variable name for B1 element kpio.data.cropTypeName,
dataList.Add(elementValue); // specific output value name for B1 element kpio.id,
dataList.Add(kpio.unit); elementName, // specific output variable name for B1 element
dataList.Add(""); elementValue, // specific output value name for B1 element
dataList.Add(""); kpio.unit,
"",
""
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
} }
@ -439,39 +443,42 @@ namespace FarmmapsKPI
else if (kpio.id == "B2") else if (kpio.id == "B2")
{ {
//Make a new dataList = new line to be written //Make a new dataList = new line to be written
dataList = new List<string> { }; dataList = new List<string>
//Fill the datalist with this kpi {
dataList.Add(kpio.parentName); //Fill the datalist with this kpi
dataList.Add(cropfieldItem.Code); kpio.parentName,
dataList.Add(kpio.data.area); cropfieldItem.Code,
dataList.Add(kpio.data.cropTypeCode); kpio.data.area,
dataList.Add(kpio.data.cropTypeName); kpio.data.cropTypeCode,
dataList.Add(kpio.id); kpio.data.cropTypeName,
dataList.Add(kpio.quantity); // in KPI output quantity is what we call KPIvariable in headerlist of csv file kpio.id,
dataList.Add(kpio.value); kpio.quantity, // in KPI output quantity is what we call KPIvariable in headerlist of csv file
dataList.Add(kpio.unit); kpio.value,
dataList.Add(kpio.targetValue); kpio.unit,
dataList.Add(kpio.thresholdValue); kpio.targetValue,
kpio.thresholdValue
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
KPIelementsOfBalance kPIelementsOfBalance = kpio.data.values;
foreach (string elementName in kpio.B2elements) foreach (string elementName in kpio.B2elements)
{ {
// get B1element from the element called values // get B1element from the element called values
dataList = new List<string> { };
string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null); string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null);
dataList.Add(kpio.parentName); dataList = new List<string>
dataList.Add(cropfieldItem.Code); {
dataList.Add(kpio.data.area); kpio.parentName,
dataList.Add(kpio.data.cropTypeCode); cropfieldItem.Code,
dataList.Add(kpio.data.cropTypeName); kpio.data.area,
dataList.Add(kpio.id); kpio.data.cropTypeCode,
dataList.Add(elementName); // specific output variable name for B2 element kpio.data.cropTypeName,
dataList.Add(elementValue); // specific output value name for B2 element kpio.id,
dataList.Add(kpio.unit); elementName, // specific output variable name for B2 element
dataList.Add(""); elementValue, // specific output value name for B2 element
dataList.Add(""); kpio.unit,
"",
""
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
} }
@ -480,39 +487,41 @@ namespace FarmmapsKPI
else if (kpio.id == "C1") //TtD else if (kpio.id == "C1") //TtD
{ {
//Make a new dataList = new line to be written //Make a new dataList = new line to be written
dataList = new List<string> { }; dataList = new List<string>
//Fill the datalist with this kpi {
dataList.Add(kpio.parentName); kpio.parentName,
dataList.Add(cropfieldItem.Code); cropfieldItem.Code,
dataList.Add(kpio.data.area); kpio.data.area,
dataList.Add(kpio.data.cropTypeCode); kpio.data.cropTypeCode,
dataList.Add(kpio.data.cropTypeName); kpio.data.cropTypeName,
dataList.Add(kpio.id); kpio.id,
dataList.Add(kpio.quantity); // in KPI output quantity is what we call KPIvariable in headerlist of csv file kpio.quantity, // in KPI output quantity is what we call KPIvariable in headerlist of csv file
dataList.Add(kpio.value); kpio.value,
dataList.Add(kpio.unit); kpio.unit,
dataList.Add(kpio.targetValue); kpio.targetValue,
dataList.Add(kpio.thresholdValue); kpio.thresholdValue
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
KPIelementsOfBalance kPIelementsOfBalance = kpio.data.values;
foreach (string elementName in kpio.C1elements) foreach (string elementName in kpio.C1elements)
{ {
// get C1element from the element called values // get C1element from the element called values
dataList = new List<string> { };
string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null); string elementValue = (string)kPIelementsOfBalance.GetType().GetProperty(elementName).GetValue(kPIelementsOfBalance, null);
dataList.Add(kpio.parentName); dataList = new List<string>
dataList.Add(cropfieldItem.Code); {
dataList.Add(kpio.data.area); kpio.parentName,
dataList.Add(kpio.data.cropTypeCode); cropfieldItem.Code,
dataList.Add(kpio.data.cropTypeName); kpio.data.area,
dataList.Add(kpio.id); kpio.data.cropTypeCode,
dataList.Add(elementName); // specific output variable name for C1 element kpio.data.cropTypeName,
dataList.Add(elementValue); // specific output value name for C1 element kpio.id,
dataList.Add(kpio.unit); elementName, // specific output variable name for C1 element
dataList.Add(""); elementValue, // specific output value name for C1 element
dataList.Add(""); kpio.unit,
"",
""
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
} }
@ -527,26 +536,27 @@ namespace FarmmapsKPI
{ {
if (mbp_KPIvariable == "aquaticLife") { mbp_KPIvalue = e.aquaticLife; } else if (mbp_KPIvariable == "groundWater") { mbp_KPIvalue = e.groundWater; } else if (mbp_KPIvariable == "soilLife") { mbp_KPIvalue = e.soilLife; } else { mbp_KPIvalue = ""; } if (mbp_KPIvariable == "aquaticLife") { mbp_KPIvalue = e.aquaticLife; } else if (mbp_KPIvariable == "groundWater") { mbp_KPIvalue = e.groundWater; } else if (mbp_KPIvariable == "soilLife") { mbp_KPIvalue = e.soilLife; } else { mbp_KPIvalue = ""; }
//Make a new dataList = new line to be written //Make a new dataList = new line to be written
dataList = new List<string> { }; dataList = new List<string>
//Fill the datalist with this kpi {
dataList.Add(kpio.parentName); kpio.parentName,
dataList.Add(cropfieldItem.Code); cropfieldItem.Code,
dataList.Add(kpio.data.area); kpio.data.area,
dataList.Add(kpio.data.cropTypeCode); kpio.data.cropTypeCode,
dataList.Add(kpio.data.cropTypeName); kpio.data.cropTypeName,
dataList.Add(kpio.id); //"E1" kpio.id, //"E1"
dataList.Add(kpio.quantity); // "mbp" kpio.quantity, // "mbp"
dataList.Add(""); // not here the value "", // not here the value
dataList.Add(""); // not here KPIunit for this indicator "", // not here KPIunit for this indicator
dataList.Add(""); // not here KPItargetvalue for this indicator "", // not here KPItargetvalue for this indicator
dataList.Add(""); // not here KPIthresholdValue for this indicator "", // not here KPIthresholdValue for this indicator
dataList.Add(e.productCode); e.productCode,
dataList.Add(e.productName); e.productName,
dataList.Add(e.quantity); e.quantity,
dataList.Add(e.unitCode); e.unitCode,
dataList.Add(e.date); e.date,
dataList.Add(mbp_KPIvariable); mbp_KPIvariable,
dataList.Add(mbp_KPIvalue); mbp_KPIvalue
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
} }
@ -554,20 +564,21 @@ namespace FarmmapsKPI
} }
else else
{ {
//Make a new dataList = new line to be written //Any other KPI, example A1 or D1, with just 1 record to write
dataList = new List<string> { }; dataList = new List<string>
//Fill the datalist with this kpi {
dataList.Add(kpio.parentName); kpio.parentName,
dataList.Add(cropfieldItem.Code); cropfieldItem.Code,
dataList.Add(kpio.data.area); kpio.data.area,
dataList.Add(kpio.data.cropTypeCode); kpio.data.cropTypeCode,
dataList.Add(kpio.data.cropTypeName); kpio.data.cropTypeName,
dataList.Add(kpio.id); kpio.id,
dataList.Add(kpio.quantity); // in KPI output quantity is what we call KPIvariable in headerlist of csv file kpio.quantity,
dataList.Add(kpio.value); kpio.value,
dataList.Add(kpio.unit); kpio.unit,
dataList.Add(kpio.targetValue); kpio.targetValue,
dataList.Add(kpio.thresholdValue); kpio.thresholdValue
};
//Write the datalist to a line to the streamwrieter sw for the output csv file //Write the datalist to a line to the streamwrieter sw for the output csv file
sw.WriteLine(string.Join(",", dataList)); sw.WriteLine(string.Join(",", dataList));
} }