/*
         * public static string GetTargetValueDisplayForGrid(this GeospatialArea geospatialArea, PerformanceMeasure performanceMeasure)
         * {
         *  if (!performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).Any(x => x.GeospatialAreaPerformanceMeasureTargetValue.HasValue))
         *  {
         *      return "No Target Set";
         *  }
         *
         *  if (performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).Select(x => $"{x.GeospatialAreaPerformanceMeasureTargetValue}{x.GeospatialAreaPerformanceMeasureTargetValueLabel}").Distinct().Count() == 1)
         *  {
         *      //we know all targetValues are the same so just get the first geospatial target
         *      var geospatialAreaPerformanceMeasureTarget = performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).First(x => x.GeospatialAreaPerformanceMeasureTargetValue.HasValue);
         *      Check.EnsureNotNull(geospatialAreaPerformanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValue, "geospatialAreaPerformanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValue != null");
         *      var targetValue = geospatialAreaPerformanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValue.Value.ToString();
         *      var performanceMeasureMeasurementUnitType = geospatialAreaPerformanceMeasureTarget.PerformanceMeasure.MeasurementUnitType;
         *      var measurementUnit = performanceMeasureMeasurementUnitType == MeasurementUnitType.Number ? "" : performanceMeasureMeasurementUnitType.LegendDisplayName;
         *      return $"{targetValue} {measurementUnit}";
         *  }
         *  return "Target by Year";
         * }
         */

        public static string GetTargetValueDisplayForGrid(this GeospatialArea geospatialArea, PerformanceMeasure performanceMeasure)
        {
            PerformanceMeasureTargetValueTypeEnum performanceMeasureTargetValueTypeEnum = performanceMeasure.GetPerformanceMeasureTargetValueTypeForGeospatialArea(geospatialArea);

            switch (performanceMeasureTargetValueTypeEnum)
            {
            case PerformanceMeasureTargetValueTypeEnum.NoTarget:
                return("No Target");

            case PerformanceMeasureTargetValueTypeEnum.FixedTarget:
                var areaPerformanceMeasureFixedTarget =
                    performanceMeasure.GeospatialAreaPerformanceMeasureFixedTargets.SingleOrDefault(x =>
                                                                                                    x.GeospatialAreaID == geospatialArea.GeospatialAreaID);
                Check.EnsureNotNull(areaPerformanceMeasureFixedTarget);
                Check.EnsureNotNull(areaPerformanceMeasureFixedTarget.GeospatialAreaPerformanceMeasureTargetValue, "geospatialAreaPerformanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValue != null");
                var targetValue = areaPerformanceMeasureFixedTarget.GeospatialAreaPerformanceMeasureTargetValue.ToString();
                var performanceMeasureMeasurementUnitType = areaPerformanceMeasureFixedTarget.PerformanceMeasure.MeasurementUnitType;
                var measurementUnit = performanceMeasureMeasurementUnitType == MeasurementUnitType.Number ? "" : performanceMeasureMeasurementUnitType.LegendDisplayName;
                return($"{targetValue} {measurementUnit}");

            case PerformanceMeasureTargetValueTypeEnum.TargetPerYear:
                return("Target By Year");

            default:
                throw new NotImplementedException("There should never be a valid target value type here");
            }
        }
        public void DeleteOtherPerformanceMeasureTargetValueTypes(
            ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure,
            PerformanceMeasureTargetValueTypeEnum performanceMeasureTargetValueTypeEnum)
        {
            if (performanceMeasureTargetValueTypeEnum != PerformanceMeasureTargetValueTypeEnum.FixedTarget)
            {
                var overallTargetsToDelete = performanceMeasure.PerformanceMeasureFixedTargets.ToList();
                overallTargetsToDelete.ForEach(oa => oa.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }

            if (performanceMeasureTargetValueTypeEnum != PerformanceMeasureTargetValueTypeEnum.TargetPerYear)
            {
                var reportingPeriodTargetsToDelete = performanceMeasure.PerformanceMeasureReportingPeriodTargets.ToList();
                reportingPeriodTargetsToDelete.ForEach(oa => oa.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }
        }
Ejemplo n.º 3
0
        public static PerformanceMeasureTargetValueType ToType(PerformanceMeasureTargetValueTypeEnum enumValue)
        {
            switch (enumValue)
            {
            case PerformanceMeasureTargetValueTypeEnum.NoTarget:
                return(NoTarget);

            case PerformanceMeasureTargetValueTypeEnum.OverallTarget:
                return(OverallTarget);

            case PerformanceMeasureTargetValueTypeEnum.TargetPerReportingPeriod:
                return(TargetPerReportingPeriod);

            default:
                throw new ArgumentException(string.Format("Unable to map Enum: {0}", enumValue));
            }
        }
Ejemplo n.º 4
0
        public static PerformanceMeasureTargetValueType ToType(PerformanceMeasureTargetValueTypeEnum enumValue)
        {
            switch (enumValue)
            {
            case PerformanceMeasureTargetValueTypeEnum.FixedTarget:
                return(FixedTarget);

            case PerformanceMeasureTargetValueTypeEnum.NoTarget:
                return(NoTarget);

            case PerformanceMeasureTargetValueTypeEnum.TargetPerYear:
                return(TargetPerYear);

            default:
                throw new ArgumentException(string.Format("Unable to map Enum: {0}", enumValue));
            }
        }
        public void SetGoogleChartConfigurationForPerformanceMeasure(
            ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure,
            PerformanceMeasureTargetValueTypeEnum performanceMeasureTargetValueTypeEnum)
        {
            var geospatialAreasWithTargets = new List <ProjectFirmaModels.Models.GeospatialArea>();

            geospatialAreasWithTargets.AddRange(performanceMeasure.GeospatialAreaPerformanceMeasureFixedTargets.Select(x => x.GeospatialArea));
            geospatialAreasWithTargets.AddRange(performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Select(x => x.GeospatialArea));

            //Google Chart Configuration for the Performance Measure
            foreach (var pfSubcategory in performanceMeasure.PerformanceMeasureSubcategories)
            {
                var tempChartConfig = GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(pfSubcategory.ChartConfigurationJson);
                tempChartConfig.SeriesType = "bars";
                if (performanceMeasure.HasTargets())
                {
                    tempChartConfig.Series          = GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTargets();
                    pfSubcategory.GoogleChartTypeID = GoogleChartType.ComboChart.GoogleChartTypeID;
                }
                else
                {
                    tempChartConfig.Series          = null;
                    pfSubcategory.GoogleChartTypeID = GoogleChartType.ColumnChart.GoogleChartTypeID;
                }
                pfSubcategory.ChartConfigurationJson = JObject.FromObject(tempChartConfig).ToString();
                if (performanceMeasure.CanBeChartedCumulatively)
                {
                    var cumulativeChartConfigurationJson = GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(pfSubcategory.ChartConfigurationJson);
                    cumulativeChartConfigurationJson.SeriesType    = "bars";
                    pfSubcategory.CumulativeChartConfigurationJson = JObject.FromObject(cumulativeChartConfigurationJson).ToString();
                    pfSubcategory.CumulativeGoogleChartTypeID      = performanceMeasure.HasTargets() ? GoogleChartType.ComboChart.GoogleChartTypeID : GoogleChartType.ColumnChart.GoogleChartTypeID;
                }

                // We need to adjust the chart JSON for the the geospatial area as well if there are geospatial area targets for this performance measure by adding an additional line series to the configuration json
                if (geospatialAreasWithTargets.Any())
                {
                    var tempGeospatialChartConfig = GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(pfSubcategory.ChartConfigurationJson);
                    tempGeospatialChartConfig.SeriesType = "bars";
                    tempGeospatialChartConfig.Series     = performanceMeasure.HasTargets() ? GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTwoTargets() : GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTargets();
                    pfSubcategory.GeospatialAreaTargetChartConfigurationJson = JObject.FromObject(tempGeospatialChartConfig).ToString();
                    pfSubcategory.GeospatialAreaTargetGoogleChartTypeID      = GoogleChartType.ComboChart.GoogleChartTypeID;
                }
            }
        }
        public void DeleteOtherGeospatialAreaPerformanceMeasureTargetValueTypes(
            ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure,
            ProjectFirmaModels.Models.GeospatialArea geospatialArea,
            PerformanceMeasureTargetValueTypeEnum performanceMeasureTargetValueTypeEnum)
        {
            if (performanceMeasureTargetValueTypeEnum != PerformanceMeasureTargetValueTypeEnum.NoTarget)
            {
                var noTargetsToDelete = performanceMeasure.GeospatialAreaPerformanceMeasureNoTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).ToList();
                noTargetsToDelete.ForEach(oa => oa.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }

            if (performanceMeasureTargetValueTypeEnum != PerformanceMeasureTargetValueTypeEnum.FixedTarget)
            {
                var overallTargetsToDelete = performanceMeasure.GeospatialAreaPerformanceMeasureFixedTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).ToList();
                overallTargetsToDelete.ForEach(oa => oa.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }

            if (performanceMeasureTargetValueTypeEnum != PerformanceMeasureTargetValueTypeEnum.TargetPerYear)
            {
                var reportingPeriodTargetsToDelete = performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Where(x => x.GeospatialAreaID == geospatialArea.GeospatialAreaID).ToList();
                reportingPeriodTargetsToDelete.ForEach(oa => oa.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }
        }