I’m trying to sum some values over a year. My code runs per day, so I need to sum these values after the calculations. The goal is then to export them back to SQL. I’ve already set up a table and I did manage to export some values to the table, but only the daily values and not the yearly yet.
// YEAR OVERVIEW
OptResultDataYear optResultDataYear = new OptResultDataYear();
// Variations in price
List<float> varprijs = new List<float> { 0.06f, 0.08f, 0.10f, 0.12f, 0.14f, 0.16f, 0.18f };
// Create dictionaries for storing the values
Dictionary<float, OptResultYear> yearlyResults = varPrijs.ToDictionary(co => co, co => new OptResultYear { AfdelingId = afd.AfdelingsId, variatiePrijs = co });
// SQL output
OptResultYear optResultYear= new OptResultYear();
for (DateTime date = startYear; date < endYear; date = date.AddDays(1))
{
foreach (float co in varprijs)
{
// Calculate the optimal results with the varPrijs
ResultScenDay optResultvar = await DayCalc.RunOcapOptimaalDayAsync(afd.AfdelingsId, date, 3600, (int)ScenarioType.Optimal, co, null); // per dag met uurdata.
// Analyze the code
optResultYear = analysePeriode.FillOptResultYear(afd.AfdelingsId, kenm.TeeltOppHa, date, optResultvar, co, null);
// Collect the required values
yearlyResults[co].OptTotalDos += (float)optResultYear.OptTotalDos;
yearlyResults[co].OptDos1 += (float)optResultYear.OptDos1;
yearlyResults[co].OptDos2 += (float)optResultYear.OptDos2;
yearlyResults[co].OptCost += (float)optResultYear.OptCost;
yearlyResults[co].OptProductie += (float)optResultYear.OptProductie;
yearlyResultsCO2[co].OptConcLp += (float)optResultYear.OptConcLp;
// Set the date for the last entry
yearlyResultsCO2[co].Datum = date;
}
}
The values on the right (the optResultYear.) do have values, and they are calculated as required. However, When adding them to my dictionary I only get NULL values.
Does anyone know how to resolve this or know a better option?
Markje is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1