public static List <GoogleChartSeries> CalculateChartSeriesFromCurrentChartSeries(object currentChartSeries, ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure, ProjectFirmaModels.Models.GeospatialArea geospatialArea) { // this was needed to ensure that the graphs on the geospatial detail page display appropriately for performance measure targets. // It attempts to be as friendly as we can to the current chart series that the user/tenant might have set // this is also here to catch situations where there are PM targets and Geospatial targets exists(specifically for cumulative charts on geospatial pages) if (currentChartSeries == null || (performanceMeasure.HasTargets() && performanceMeasure.HasGeospatialAreaTargets(geospatialArea))) { var chartSeries = new List <GoogleChartSeries>(); //add series for the PM targets if (performanceMeasure.HasTargets()) { chartSeries.Add(new GoogleChartSeries(GoogleChartType.LineChart, GoogleChartAxisType.Primary)); } //add another series for the Geospatial targets if (performanceMeasure.HasGeospatialAreaTargets(geospatialArea)) { chartSeries.Add(new GoogleChartSeries(GoogleChartType.LineChart, GoogleChartAxisType.Primary)); } //add final series to have rest of the data default to bar(column) chartSeries.Add(new GoogleChartSeries(GoogleChartType.ColumnChart, GoogleChartAxisType.Primary)); return(chartSeries); } var isListOfGoogleChartSeries = currentChartSeries is List <GoogleChartSeries>; var deserializedChartSeries = !isListOfGoogleChartSeries?JsonConvert.DeserializeObject <List <GoogleChartSeries> >(currentChartSeries.ToString()) : (List <GoogleChartSeries>)currentChartSeries; return(deserializedChartSeries); }
public void UpdateModel(ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure) { var performanceMeasureSubcategoriesFromDatabase = HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureSubcategories.Local; var performanceMeasureSubcategoryOptionsFromDatabase = HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureSubcategoryOptions.Local; var performanceMeasureSubcategoriesToUpdate = PerformanceMeasureSubcategorySimples.Select(x => { var performanceMeasureSubcategory = new PerformanceMeasureSubcategory(new ProjectFirmaModels.Models.PerformanceMeasure(String.Empty, default(int), default(int), false, PerformanceMeasureDataSourceType.Project.PerformanceMeasureDataSourceTypeID, false, false), x.PerformanceMeasureSubcategoryDisplayName); performanceMeasureSubcategory.PerformanceMeasure = performanceMeasure; performanceMeasureSubcategory.PerformanceMeasureSubcategoryID = x.PerformanceMeasureSubcategoryID; performanceMeasureSubcategory.PerformanceMeasureSubcategoryOptions = x.PerformanceMeasureSubcategoryOptions.OrderBy(y => y.SortOrder).Select( (y, index) => new PerformanceMeasureSubcategoryOption( new PerformanceMeasureSubcategory(new ProjectFirmaModels.Models.PerformanceMeasure(String.Empty, default(int), default(int), false, PerformanceMeasureDataSourceType.Project.PerformanceMeasureDataSourceTypeID, false, false), String.Empty), y.PerformanceMeasureSubcategoryOptionName, false) { PerformanceMeasureSubcategory = performanceMeasure.PerformanceMeasureSubcategories.SingleOrDefault(z => z.PerformanceMeasureSubcategoryID == x.PerformanceMeasureSubcategoryID), PerformanceMeasureSubcategoryOptionID = y.PerformanceMeasureSubcategoryOptionID, SortOrder = index + 1, ShowOnFactSheet = y.ShowOnFactSheet }).ToList(); var chartConfigurationJson = JObject.FromObject(performanceMeasure.GetDefaultPerformanceMeasureChartConfigurationJson()).ToString(); performanceMeasureSubcategory.ChartConfigurationJson = chartConfigurationJson; performanceMeasureSubcategory.GoogleChartTypeID = performanceMeasure.HasTargets() ? GoogleChartType.ComboChart.GoogleChartTypeID : GoogleChartType.ColumnChart.GoogleChartTypeID; if (performanceMeasure.CanBeChartedCumulatively) { var cumulativeChartConfigurationJson = JObject.FromObject(performanceMeasure.GetDefaultPerformanceMeasureChartConfigurationJson()).ToString(); performanceMeasureSubcategory.CumulativeChartConfigurationJson = cumulativeChartConfigurationJson; performanceMeasureSubcategory.CumulativeGoogleChartTypeID = performanceMeasure.HasTargets() ? GoogleChartType.ComboChart.GoogleChartTypeID : GoogleChartType.ColumnChart.GoogleChartTypeID; } return(performanceMeasureSubcategory); }).ToList(); var performanceMeasureSubcategoryOptionsToUpdate = performanceMeasureSubcategoriesToUpdate.SelectMany(x => x.PerformanceMeasureSubcategoryOptions).ToList(); performanceMeasure.PerformanceMeasureSubcategories.SelectMany(x => x.PerformanceMeasureSubcategoryOptions).ToList().Merge( performanceMeasureSubcategoryOptionsToUpdate, performanceMeasureSubcategoryOptionsFromDatabase, (x, y) => x.PerformanceMeasureSubcategoryOptionID == y.PerformanceMeasureSubcategoryOptionID, (x, y) => { x.PerformanceMeasureSubcategoryOptionName = y.PerformanceMeasureSubcategoryOptionName; x.SortOrder = y.SortOrder; x.ShowOnFactSheet = y.ShowOnFactSheet; }, HttpRequestStorage.DatabaseEntities); performanceMeasure.PerformanceMeasureSubcategories.Merge(performanceMeasureSubcategoriesToUpdate, performanceMeasureSubcategoriesFromDatabase, (x, y) => x.PerformanceMeasureSubcategoryID == y.PerformanceMeasureSubcategoryID, (x, y) => { x.PerformanceMeasureSubcategoryDisplayName = y.PerformanceMeasureSubcategoryDisplayName; }, HttpRequestStorage.DatabaseEntities); }
public void SetGoogleChartConfigurationForGeospatialAreaPerformanceMeasure(ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure, ProjectFirmaModels.Models.GeospatialArea geospatialArea) { // Google Chart Configuration if (performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Any() || performanceMeasure.GeospatialAreaPerformanceMeasureFixedTargets.Any()) { foreach (var pfSubcategory in performanceMeasure.PerformanceMeasureSubcategories) { var tempChartConfig = GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(pfSubcategory.ChartConfigurationJson); tempChartConfig.SeriesType = "bars"; tempChartConfig.Series = performanceMeasure.HasGeospatialAreaTargets(geospatialArea) && performanceMeasure.HasTargets() ? GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTwoTargets() : GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTargets(); pfSubcategory.GeospatialAreaTargetChartConfigurationJson = JObject.FromObject(tempChartConfig).ToString(); pfSubcategory.GeospatialAreaTargetGoogleChartTypeID = performanceMeasure.HasGeospatialAreaTargets(geospatialArea) ? GoogleChartType.ComboChart.GoogleChartTypeID : GoogleChartType.ColumnChart.GoogleChartTypeID; 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; } } } }
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; } } }