protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { try { output = null; outputDetailed = null; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = "Kpi not available for this module"; return(false); } if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } string dbKpiId = kpi_kpi_mapping[process.KpiId]; double kpiValue = 0; var nw = process.CurrentData[inputDistrictName] as List <Object>; var districtData = nw[0] as Dictionary <string, Object>; if (!SetDistrictProperties(districtData, exls, propertyCellMapping_CalcSheet, sheetInput)) { return(false); } if (!SetDistrictProperties(districtData, exls, propertyCellMapping_MeasureSheet, sheetSettings)) { return(false); } double?val = exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId]) as double?; if (val == null) { return(false); } kpiValue = Math.Round((double)val, 1); output = new Ecodistrict.Messaging.Data.Output(process.KpiId, kpiValue); return(true); #region Old Code //Prepare AsIs data //if (process.As_IS_Data == null) //{ // process.CalcMessage = "No as is data"; // return false; //} ////string distrName = "District"; //string distrName = "District trafic area"; //if (!process.As_IS_Data.ContainsKey(distrName)) //{ // process.CalcMessage = "As is district information missing"; // return false; //} //Dictionary<string, object> dataAsIS ; //if (process.As_IS_Data[distrName] is Dictionary<string, object>) // dataAsIS = process.As_IS_Data[distrName] as Dictionary<string, object>; //else //{ // process.CalcMessage = "As is data received from data module is wrongly formated"; // return false; //} ////AsIS //if (process.IsAsIS) //{ // if (!dataAsIS.ContainsKey(dbKpiId)) // { // process.CalcMessage = "As is information missing"; // return false; // } // kpiValue = Convert.ToDouble(dataAsIS[dbKpiId]); //} ////Variant //else //{ // //Prepare Variant data // if (process.Variant_Data == null) // { // process.CalcMessage = "No variant data"; // return false; // } // if (!process.Variant_Data.ContainsKey(distrName)) // { // process.CalcMessage = "Variant district information missing"; // return false; // } // Dictionary<string, object> dataVariant; // if (process.Variant_Data[distrName] is Dictionary<string, object>) // dataVariant = process.Variant_Data[distrName] as Dictionary<string, object>; // else // { // process.CalcMessage = "Variant data received from data module is wrongly formated"; // return false; // } // //Set Data // if (!SetProperties(process, dataAsIS, exls, propertyCellMapping_AsIs)) // return false; // if (!SetProperties(process, dataVariant, exls, propertyCellMapping_General)) // return false; // //01 // bool used01; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use01, propertyCellMapping_01, exls, out used01)) // return false; // //02 // bool used02; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use02, propertyCellMapping_02, exls, out used02)) // return false; // //03 // bool used03; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use03, propertyCellMapping_03, exls, out used03)) // return false; // //04 // bool used04; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use04, propertyCellMapping_04, exls, out used04)) // return false; // //05 // bool used05; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use05, propertyCellMapping_05, exls, out used05)) // return false; // //06 // bool used06; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use06, propertyCellMapping_06, exls, out used06)) // return false; // //07 // bool used07; // if (used06) // { // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use07, propertyCellMapping_07_1, exls, out used07)) // return false; // } // else // { // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use07, propertyCellMapping_07_2, exls, out used07)) // return false; // } // //08 // bool used08; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use08, propertyCellMapping_08, exls, out used08)) // return false; // //09 // bool used09; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use09, propertyCellMapping_09, exls, out used09)) // return false; // //10 // bool used10; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use10, propertyCellMapping_10, exls, out used10)) // return false; // double? val = exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId]) as double?; // if (val == null) // return false; // kpiValue = Math.Round((double)val,1); //} //output = new Ecodistrict.Messaging.Data.Output(process.KpiId, kpiValue); //return true; #endregion } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { output = null; outputDetailed = null; bool perHeatedArea = false; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = String.Format("kpi not available for this module, requested kpi: {0}", process.KpiId); return(false); } switch (process.KpiId) { case kpi_gwp: case kpi_peu: break; case kpi_gwp_per_heated_area: case kpi_peu_per_heated_area: perHeatedArea = true; break; } if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } if (!CheckAndReportBuildingProp(process, process.CurrentData, inputBuildingName)) { return(false); } var nw = process.CurrentData[inputDistrictName] as List <object>; var districtdata = nw[0] as Dictionary <string, object>; var myBuildings = process.CurrentData[inputBuildingName] as List <object>; //Set common properties if (!SetDistrictProperties(districtdata, exls, districtCellMapping)) { return(false); } //Get all default building data data from Excel document var buildingDefaultValues = new Dictionary <string, object>(); if (myBuildings != null && myBuildings.Count > 0) { if (!GetBuildingDefaultValues(exls, out buildingDefaultValues)) { return(false); } } outputDetailed = new OutputDetailed(process.KpiId); double kpiValue = 0; int noOfRenovatedBuildings = 0; foreach (Dictionary <string, object> buildingData in myBuildings) { double kpiValuei; bool changesMade; if (!SetInputDataOneBuilding(buildingData, exls, out changesMade)) { return(false); } kpiValuei = Convert.ToDouble(exls.GetCellValue(sheet, kpiCellMapping[process.KpiId])); if (changesMade) { noOfRenovatedBuildings++; } if (noOfRenovatedBuildings % 50 == 0) { SendStatusMessage(string.Format("{0} building processed", noOfRenovatedBuildings)); } //Reset buildingdata do tefault if (buildingDefaultValues != null && !SetInputDataOneBuilding(buildingDefaultValues, exls, out changesMade)) { return(false); } if (perHeatedArea) { kpiValuei *= 1000; //From tonnes CO2 eq / m2 to kg CO2 eq/ m2 and MWh / m2 to kWh/ m2 resp. } kpiValue += kpiValuei; outputDetailed.KpiValueList.Add(new GeoObject("building", buildingData["building_id"] as string, process.KpiId, kpiValuei)); } if (noOfRenovatedBuildings > 0 & (process.KpiId == kpi_gwp | process.KpiId == kpi_peu)) { kpiValue /= 30.0 * Convert.ToDouble(noOfRenovatedBuildings); } else if (process.KpiId == kpi_gwp_per_heated_area | process.KpiId == kpi_peu_per_heated_area) { kpiValue /= 30.0 * Convert.ToDouble(250000); //TMP } output = new Ecodistrict.Messaging.Data.Output(process.KpiId, Math.Round(kpiValue, 1)); return(true); }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { try { output = null; outputDetailed = null; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = "kpi not avaiable for this module"; return(false); } if (process.CurrentData == null) { process.CalcMessage = "Data missing"; return(false); } if (!SetProperties(process, exls, propertyCellMapping_STGreen)) { return(false); } //if (process.KpiId == kpi_green) // if (!SetProperties(process, exls, propertyCellMapping_Green)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_biodiversity) | // (process.KpiId == kpi_social_value) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_BSK)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_social_value) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_SK)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_biodiversity)) // if (!SetProperties(process, exls, propertyCellMapping_B)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_social_value)) // if (!SetProperties(process, exls, propertyCellMapping_S)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_K)) // return false; //} //string outSheet = "EXISTING"; //if (process.Request.variantId != null) //{ // outSheet = "PLANNED"; //} //double? val = exls.GetCellValue(outSheet, kpiCellMapping[process.KpiId]) as double?; double?val = exls.GetCellValue(sheet, kpiCellMapping[process.KpiId]) as double?; if (val == null) { return(false); } double value = Math.Round((double)val, 2); //double value; //if (process.KpiId == kpi_green) // value = Math.Round((double)val, 2); //else // value = Math.Round((double)val * 100.0, 0); output = new Ecodistrict.Messaging.Data.Output(process.KpiId, value); return(true); } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }