public SetKpiResultRequest(string moduleId, string caseId, string variantId, Ecodistrict.Messaging.Data.OutputDetailed output)
 {
     this.method    = "setKpiResult";
     this.type      = "request";
     this.moduleId  = moduleId;
     this.caseId    = caseId;
     this.variantId = variantId;
     this.kpiId     = output.KpiId;
     //this.kpiValue = output.KpiValue;
     if (output != null)
     {
         this.kpiValueList = output.KpiValueList;
     }
 }
Ejemplo n.º 2
0
        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);
        }