Example #1
0
 public PerformanceMeasureSimple(PerformanceMeasure performanceMeasure)
     : this(
         performanceMeasure.PerformanceMeasureID,
         performanceMeasure.MeasurementUnitTypeID,
         performanceMeasure.PerformanceMeasureDisplayName,
         performanceMeasure.MeasurementUnitType.MeasurementUnitTypeDisplayName,
         performanceMeasure.HasRealSubcategories(),
         performanceMeasure.GetDefinitionAndGuidanceUrl())
 {
 }
Example #2
0
        public static List <GoogleChartJson> MakeGoogleChartJsons(PerformanceMeasure performanceMeasure, GeospatialArea geospatialArea, List <ProjectPerformanceMeasureReportingPeriodValue> projectPerformanceMeasureReportingPeriodValues)
        {
            var performanceMeasureSubcategoryOptionReportedValues = projectPerformanceMeasureReportingPeriodValues.SelectMany(x => x.PerformanceMeasureSubcategoryOptionReportedValues).GroupBy(x => x.PerformanceMeasureSubcategory);
            // This was changed to only use the performance measure reporting period from the actuals. Requested in PF#1901: https://projects.sitkatech.com/projects/projectfirma/cards/1901
            var performanceMeasureReportingPeriods = performanceMeasure.GetPerformanceMeasureReportingPeriodsFromActuals();
            var googleChartJsons = new List <GoogleChartJson>();

            bool hasTargets = performanceMeasure.HasTargets();
            bool hasGeospatialAreaTargets = false;

            if (geospatialArea != null)
            {
                hasGeospatialAreaTargets = performanceMeasure.GetGeospatialAreaTargetValueType(geospatialArea) != PerformanceMeasureTargetValueType.NoTarget;
            }

            if (performanceMeasureSubcategoryOptionReportedValues.Any())
            {
                foreach (var groupedBySubcategory in performanceMeasureSubcategoryOptionReportedValues.Where(x => x.Key.ShowOnChart()))
                {
                    var performanceMeasureSubcategory = groupedBySubcategory.Key;
                    Check.RequireNotNull(performanceMeasureSubcategory.ChartConfigurationJson, "All PerformanceMeasure Subcategories need to have a Google Chart Configuration Json");
                    var groupedBySubcategoryOption = groupedBySubcategory.GroupBy(c => new Tuple <string, int>(c.ChartName, c.SortOrder)).ToList(); // Item1 is ChartName, Item2 is SortOrder
                    var chartColumns = performanceMeasure.HasRealSubcategories() ? groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => x.Key.Item1).ToList() : new List <string> {
                        performanceMeasure.GetDisplayName()
                    };

                    var reverseTooltipOrder = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;

                    var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, hasTargets, hasGeospatialAreaTargets, geospatialArea, groupedBySubcategoryOption, chartColumns, performanceMeasure.IsSummable, reverseTooltipOrder, false);
                    var legendTitle          = performanceMeasure.HasRealSubcategories() ? performanceMeasureSubcategory.PerformanceMeasureSubcategoryDisplayName : performanceMeasure.GetDisplayName();
                    var chartName            = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}";
                    var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x =>
                                                                                                                 x.SaveChartConfiguration(performanceMeasure,
                                                                                                                                          performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.ChartConfiguration));

                    var resetConfigurationUrl =
                        SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x =>
                                                                                          x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.ChartConfiguration));

                    GoogleChartConfiguration chartConfiguration;
                    GoogleChartType          chartType;
                    if (hasGeospatialAreaTargets)
                    {
                        chartConfiguration = JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.GeospatialAreaTargetChartConfigurationJson);
                        chartType          = performanceMeasureSubcategory.GeospatialAreaTargetGoogleChartType;
                    }
                    else
                    {
                        chartConfiguration = JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.ChartConfigurationJson);
                        chartType          = performanceMeasureSubcategory.GoogleChartType;
                    }
                    if (performanceMeasureSubcategory.PerformanceMeasure.IsSummable)
                    {
                        chartConfiguration.Tooltip = new GoogleChartTooltip(true);
                    }

                    chartConfiguration.Series =
                        GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                     performanceMeasure, geospatialArea);

                    var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration,
                                                              chartType, googleChartDataTable,
                                                              chartColumns, saveConfigurationUrl, resetConfigurationUrl, false);
                    googleChartJsons.Add(googleChartJson);
                }

                // Add Cumulative charts if appropriate
                if (performanceMeasure.CanBeChartedCumulatively)
                {
                    foreach (var groupedBySubcategory in performanceMeasureSubcategoryOptionReportedValues.Where(x => x.Key.ShowOnCumulativeChart()))
                    {
                        var performanceMeasureSubcategory = groupedBySubcategory.Key;
                        var groupedBySubcategoryOption    = groupedBySubcategory.GroupBy(c => new Tuple <string, int>(c.ChartName, c.SortOrder)).ToList(); // Item1 is ChartName, Item2 is SortOrder
                        var chartColumns = performanceMeasure.HasRealSubcategories() ? groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => x.Key.Item1).ToList() : new List <string> {
                            performanceMeasure.GetDisplayName()
                        };

                        var reverseTooltipOrder  = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;
                        var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, hasTargets, hasGeospatialAreaTargets, geospatialArea, groupedBySubcategoryOption, chartColumns, performanceMeasure.IsSummable, reverseTooltipOrder, true);
                        var legendTitle          = performanceMeasure.HasRealSubcategories() ? performanceMeasureSubcategory.PerformanceMeasureSubcategoryDisplayName : performanceMeasure.GetDisplayName();
                        var chartName            = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}Cumulative";
                        var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.SaveChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                        var resetConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                        var chartConfiguration = !string.IsNullOrEmpty(performanceMeasureSubcategory.CumulativeChartConfigurationJson) ? JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.CumulativeChartConfigurationJson) : GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(performanceMeasureSubcategory.ChartConfigurationJson);

                        if (performanceMeasureSubcategory.PerformanceMeasure.IsSummable)
                        {
                            chartConfiguration.Tooltip = new GoogleChartTooltip(true);
                        }

                        chartConfiguration.Series =
                            GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                         performanceMeasure, geospatialArea);

                        var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration, performanceMeasureSubcategory.CumulativeGoogleChartType ?? GoogleChartType.ColumnChart, googleChartDataTable, chartColumns, saveConfigurationUrl, resetConfigurationUrl, true);
                        googleChartJsons.Add(googleChartJson);
                    }
                }
            }
            else if (performanceMeasure.HasTargets())
            {
                //build chart for just for targets if there is no project data
                var performanceMeasureSubcategory = performanceMeasure.PerformanceMeasureSubcategories.First();
                var legendTitle        = performanceMeasure.GetDisplayName();
                var chartName          = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}";
                var chartConfiguration = performanceMeasure.GetDefaultPerformanceMeasureChartConfigurationJson();
                chartConfiguration.Series =
                    GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                 performanceMeasure, geospatialArea);
                var chartColumns = new List <string> {
                    performanceMeasure.GetDisplayName()
                };
                var reverseTooltipOrder  = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;
                var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, true, false, null, new List <IGrouping <Tuple <string, int>, PerformanceMeasureReportingPeriodSubcategoryOptionReportedValue> >(), chartColumns, false, reverseTooltipOrder, false);
                var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.SaveChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                var resetConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration, GoogleChartType.LineChart, googleChartDataTable, chartColumns, saveConfigurationUrl, resetConfigurationUrl, false);
                googleChartJsons.Add(googleChartJson);
            }

            return(googleChartJsons);
        }