public PerformanceIndicatorMonthData(PerformanceIndicatorMonthLink link, double actual) { base.Link = link.Link; base.IndicatorId = link.IndicatorId; base.Month = link.Month; base.Year = link.Year; m_actual = actual; }
public bool Equals(PerformanceIndicatorMonthLink other) { // credit: http://stackoverflow.com/a/10454552/677735 if (other == null) { return(false); } return (( this.IndicatorId.Equals(other.IndicatorId) && this.Year.Equals(other.Year) && this.Month.Equals(other.Month) ) && ( this.Link == other.Link || this.Link != null && this.Link.Equals(other.Link) )); }
public void addMonthValue(int year, int month, IO.Swagger.Model.CorporateStructureLink link, int indicatorId, double actual) { PerformanceIndicatorMonthLink dataLink = new PerformanceIndicatorMonthLink(); dataLink.Year = year; dataLink.Month = month; dataLink.Link = new IO.Swagger.Model.CorporateStructureLink(link.ProductID, link.GeoAreaID, link.CustomerID, link.CompetitorID, link.SupplierID, link.PartnerID, link.OtherPlayerID, link.CompanyLegalEntityID, link.CompanyFunctionID); dataLink.IndicatorId = indicatorId; if (m_monthlyValues.ContainsKey(dataLink)) { m_monthlyValues[dataLink] += actual; } else { m_monthlyValues.Add(dataLink, actual); } }
private void calculateMonthlyLevelRows() { /* * Iterate all indicators and every used corporatefilter value * and generate "sum" row for this filter */ int minYear = m_monthlyValues.Keys.Min(x => x.Year); int maxYear = m_monthlyValues.Keys.Max(x => x.Year); List <int> distinctIndicators = m_monthlyValues.Keys.Select(x => x.IndicatorId).Distinct().ToList(); foreach (int indicatorId in distinctIndicators) { for (int selYear = minYear; selYear <= maxYear; selYear++) { for (int selMonth = 1; selMonth <= 12; selMonth++) { if (m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId).Count() == 0) { continue; } /* * If we have some items stored where filters are set (e.g. productid is something) * then aggregate those items to top level too. We assume they are not there yet */ PerformanceIndicatorMonthLink topLevelLink = new PerformanceIndicatorMonthLink(); topLevelLink.Year = selYear; topLevelLink.Month = selMonth; topLevelLink.IndicatorId = indicatorId; topLevelLink.Link = new IO.Swagger.Model.CorporateStructureLink(null, null, null, null, null, null, null, null, null); double totalValue = 0; foreach (PerformanceIndicatorMonthLink entryWithSomething in m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId && (x.Link.CompanyFunctionID != 0 || x.Link.CompanyLegalEntityID != 0 || x.Link.CompetitorID != 0 || x.Link.CustomerID != 0 || x.Link.GeoAreaID != 0 || x.Link.OtherPlayerID != 0 || x.Link.PartnerID != 0 || x.Link.ProductID != 0 || x.Link.SupplierID != 0) )) { totalValue += m_monthlyValues[entryWithSomething]; } if (m_monthlyValues.ContainsKey(topLevelLink)) { m_monthlyValues[topLevelLink] += totalValue; } else { m_monthlyValues.Add(topLevelLink, totalValue); } List <PerformanceIndicatorMonthLink> thisPeriodValues = m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId).ToList(); foreach (PerformanceIndicatorMonthLink entryWithSomething in thisPeriodValues) { if (entryWithSomething.Link.GeoAreaID != null) { PerformanceIndicatorMonthLink entryWithoutOtherLinks = new PerformanceIndicatorMonthLink(); entryWithoutOtherLinks.Year = selYear; entryWithoutOtherLinks.Month = selMonth; entryWithoutOtherLinks.IndicatorId = indicatorId; entryWithoutOtherLinks.Link = new IO.Swagger.Model.CorporateStructureLink(null, entryWithSomething.Link.GeoAreaID, null, null, null, null, null, null, null); if (!m_monthlyValues.ContainsKey(entryWithoutOtherLinks)) { totalValue = 0; foreach (PerformanceIndicatorMonthLink entryWithGeoAreaSet in m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId && x.Link.GeoAreaID == entryWithSomething.Link.GeoAreaID)) { totalValue += m_monthlyValues[entryWithGeoAreaSet]; } m_monthlyValues.Add(entryWithoutOtherLinks, totalValue); } } if (entryWithSomething.Link.PartnerID != null) { PerformanceIndicatorMonthLink entryWithoutOtherLinks = new PerformanceIndicatorMonthLink(); entryWithoutOtherLinks.Year = selYear; entryWithoutOtherLinks.Month = selMonth; entryWithoutOtherLinks.IndicatorId = indicatorId; entryWithoutOtherLinks.Link = new IO.Swagger.Model.CorporateStructureLink(null, null, null, null, null, entryWithSomething.Link.PartnerID, null, null, null); if (!m_monthlyValues.ContainsKey(entryWithoutOtherLinks)) { totalValue = 0; foreach (PerformanceIndicatorMonthLink entryWithPartnerSet in m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId && x.Link.PartnerID == entryWithSomething.Link.PartnerID)) { totalValue += m_monthlyValues[entryWithPartnerSet]; } m_monthlyValues.Add(entryWithoutOtherLinks, totalValue); } } if (entryWithSomething.Link.ProductID != null) { PerformanceIndicatorMonthLink entryWithoutOtherLinks = new PerformanceIndicatorMonthLink(); entryWithoutOtherLinks.Year = selYear; entryWithoutOtherLinks.Month = selMonth; entryWithoutOtherLinks.IndicatorId = indicatorId; entryWithoutOtherLinks.Link = new IO.Swagger.Model.CorporateStructureLink(entryWithSomething.Link.ProductID, null, null, null, null, null, null, null, null); if (!m_monthlyValues.ContainsKey(entryWithoutOtherLinks)) { totalValue = 0; foreach (PerformanceIndicatorMonthLink entryWithPartnerSet in m_monthlyValues.Keys.Where(x => x.Year == selYear && x.Month == selMonth && x.IndicatorId == indicatorId && x.Link.ProductID == entryWithSomething.Link.ProductID)) { totalValue += m_monthlyValues[entryWithPartnerSet]; } m_monthlyValues.Add(entryWithoutOtherLinks, totalValue); } } } } } } }