private Ecodistrict.Messaging.Output.Outputs CalcCheesePriceKpi(Dictionary <string, Input> indata, CExcel exls) { Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs(); try { foreach (var input in indata) { //Set all input values switch (input.Key) { case "Cheddar_Price": //C3 cell exls.SetCellValue("Sheet1", "C3", input.Value); break; case "Gamle_Ole_Price": exls.SetCellValue("Sheet1", "C4", input.Value); break; case "Vasterbotten_Price": exls.SetCellValue("Sheet1", "C5", input.Value); break; case "Edamer_Price": exls.SetCellValue("Sheet1", "C6", input.Value); break; case "Maasdamer_Price": exls.SetCellValue("Sheet1", "C7", input.Value); break; case "Gouda_Price": exls.SetCellValue("Sheet1", "C8", input.Value); break; default: break; } } //Get the Kpi value var kpiValue = exls.GetCellValue("Sheet1", "C17"); //Put it in the calc result outputs.Add(new Ecodistrict.Messaging.Output.Kpi(kpiValue, "Min Cheese price Kpi", "SEK")); return(outputs); } catch (Exception ex) { throw new Exception(string.Format("Could not calculate the cheese price Kpi!\n{0}", ex)); } }
private bool GetProperties(CExcel exls, KeyValuePair <string, string> cellMapping, ref Dictionary <string, object> buildingDefaultValues) { try { buildingDefaultValues.Add(cellMapping.Key, exls.GetCellValue(sheet, cellMapping.Value)); } catch (Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}", cellMapping.Key), sourceFunction: "GetProperties", exception: ex); return(false); } return(true); }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Output output, out OutputDetailed outputDetailed) { output = null; outputDetailed = null; if (!CheckAndReportDistrictProp(process, process.CurrentData, inputResultName)) { return(false); } if (!SetProperties(process, exls, GreenCellMapping)) { return(false); } double kpiValue; kpiValue = Convert.ToDouble(exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId])); output = new 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) { 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 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) { 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; } }
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; //Check and prepare data //Dictionary<string, object> district_data; //GeoValue buildingsAsIS; if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } if (!CheckAndReportDistrictProp(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, generalCellMapping)) { return(false); } //Calculate kpi //NEW_CODE: Start with getting all default (Inital start) values from the excel Sheet for buildingdata Dictionary <string, object> buildingDefaultValues = new Dictionary <string, object>(); if (myBuildings != null && myBuildings.Count > 0) { if (!GetBuildingDefaultValues(exls, out buildingDefaultValues)) { return(false); } } outputDetailed = new Ecodistrict.Messaging.Data.OutputDetailed(process.KpiId); double kpiValue = 0; int noRenovatedBuildings = 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) { ++noRenovatedBuildings; } if (noRenovatedBuildings % 50 == 0) { SendStatusMessage(string.Format("{0} building processed", noRenovatedBuildings)); } //NEW_CODE: Reset all used building values if (buildingDefaultValues != null && !SetInputDataOneBuilding(buildingDefaultValues, exls, out changesMade)) { return(false); } kpiValue += kpiValuei; //TODO fix this below outputDetailed.KpiValueList.Add(new Ecodistrict.Messaging.Data.GeoObject("building", buildingData["building_id"] as string, process.KpiId, kpiValuei)); } if (noRenovatedBuildings > 0 && (process.KpiId != kpi_totalLCC)) { kpiValue /= Convert.ToDouble(noRenovatedBuildings); } output = new Ecodistrict.Messaging.Data.Output(process.KpiId, Math.Round(kpiValue, 1)); SendStatusMessage(string.Format("Totally {0} building processed", noRenovatedBuildings)); return(true); } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }