//added a duplicate counter to deal with calculations where there is more 1 duplicate.

master
ttenden 2024-05-28 10:06:48 +02:00
parent c2e4f9d861
commit 178ba1ea5b
1 changed files with 9 additions and 5 deletions

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Transactions; using System.Transactions;
using FarmmapsApi; using FarmmapsApi;
@ -92,7 +93,7 @@ namespace FarmmapsKPI
int nrun = 1; int nrun = 1;
for (int run = 1; run <= nrun; run++) { for (int run = 1; run <= nrun; run++) {
for (int i = 0; i < fieldsInputs.Count; i++) for (int i = 0; i < fieldsInputs.Count; i++)
//for (int i = 6; i < 7; i++) // for testing //for (int i = 11; i < 13; i++) // for testing
{ {
watch.Restart(); watch.Restart();
input = fieldsInputs[i]; input = fieldsInputs[i];
@ -428,13 +429,15 @@ namespace FarmmapsKPI
Item itemi; Item itemi;
string id, idNext; string id, idNext;
double value, valueNext; double value, valueNext;
int DuplicateCounter;
value = 0; value = 0;
id = ""; id = "";
DuplicateCounter = 1;
for (int i = 0; i < KPIItems.Count; i++) for (int i = 0; i < KPIItems.Count; i++)
{ {
itemi = KPIItems[i]; itemi = KPIItems[i];
idNext = JsonConvert.DeserializeObject<KPIOutput>(itemi.Data.ToString()).id; idNext = JsonConvert.DeserializeObject<KPIOutput>(itemi.Data.ToString()).id;
valueNext = Convert.ToDouble(JsonConvert.DeserializeObject<KPIOutput>(itemi.Data.ToString()).value); //hoe doe ik dit voor een getal? valueNext = Convert.ToDouble(JsonConvert.DeserializeObject<KPIOutput>(itemi.Data.ToString()).value);
if (idNext != null) if (idNext != null)
{ {
if (id != idNext) if (id != idNext)
@ -446,8 +449,9 @@ namespace FarmmapsKPI
if (valueNext >= value) if (valueNext >= value)
{ {
//Remove the previous element from this list with same id but wrong value (valueNext > value) or duplicate value (valueNext == value). Presumes list is always sorted by kpiid, e.g. we may havce " //Remove the previous element from this list with same id but wrong value (valueNext > value) or duplicate value (valueNext == value). Presumes list is always sorted by kpiid, e.g. we may havce "
KPIItemsClean.RemoveAt(i - 1); KPIItemsClean.RemoveAt(i - DuplicateCounter); //added a duplicate counter to deal with calculations where there is more 1 duplicate.
KPIItemsClean.Add(itemi); KPIItemsClean.Add(itemi);
DuplicateCounter = DuplicateCounter + 1;
} }
else else
{ {