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;

                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;
            }
        }
Beispiel #3
0
        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;
            }
        }