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

This commit is contained in:
ttenden 2024-05-28 10:06:48 +02:00
parent c2e4f9d861
commit 178ba1ea5b

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Transactions;
using FarmmapsApi;
@ -92,7 +93,7 @@ namespace FarmmapsKPI
int nrun = 1;
for (int run = 1; run <= nrun; run++) {
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();
input = fieldsInputs[i];
@ -426,15 +427,17 @@ namespace FarmmapsKPI
//Remove duplicate KPI items
List<Item> KPIItemsClean = new List<Item>();
Item itemi;
string id, idNext;
double value, valueNext;
string id, idNext;
double value, valueNext;
int DuplicateCounter;
value = 0;
id = "";
DuplicateCounter = 1;
for (int i = 0; i < KPIItems.Count; i++)
{
itemi = KPIItems[i];
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 (id != idNext)
@ -446,8 +449,9 @@ namespace FarmmapsKPI
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 "
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);
DuplicateCounter = DuplicateCounter + 1;
}
else
{