Exemple #1
0
        ////////////////////////////////////////////////////////////
        // Public Methods/Atributes
        ////////////////////////////////////////////////////////////

        public ChartTemplate GetChartTemplate(ChartOwner owner, int templateId, IList <Project> projects)
        {
            var templateUserId   = _db.Users.AsNoTracking().First(u => u.UserName == GlobalTemplatesUser);
            var selectedTemplate = _db.GetAllUserPlotTemplates(owner.Id, templateUserId.Id).FirstOrDefault(item => item.Id == templateId);

            if (selectedTemplate == null)
            {
                return(null);
            }

            var template   = JsonConvert.DeserializeObject <Dqdv.Types.Plot.PlotTemplate>(selectedTemplate.Content);
            var parameters = _chartSettingProvider.MergeWithGlobal(owner.Id, template.PlotParameters);
            //parameters = _chartSettingProvider.MergePlotParameters(parameters, _chartSettingProvider.GetSettings(owner.Id));
            var currentTemp  = _cacheProvider.Get($"PlotParameters_{owner.Id}_Template") as TemplateTempSettings;
            var tempSettings = new TemplateTempSettings
            {
                Id             = templateId,
                PlotParameters = parameters //_chartSettingProvider.MergePlotParameters(parameters, _chartSettingProvider.GetSettings(owner.Id))
            };

            if (currentTemp == null)
            {
                _cacheProvider.Set($"PlotParameters_{owner.Id}_Template", tempSettings);
                _chartSettingProvider.SetSettings(owner.Id, tempSettings.PlotParameters);

                parameters = tempSettings.PlotParameters;
            }
            else
            {
                if (currentTemp.Id != templateId)
                {
                    _cacheProvider.Set($"PlotParameters_{owner.Id}_Template", tempSettings);
                }
                else
                {
                    parameters = _chartSettingProvider.GetSettings(owner.Id);
                }
            }

            var projectWithOneCycleExist = projects.HasProjectsWithOneCycle();
            var cyclesMaxVerified        = projects.IsTotalProjectsCyclesGreaterThanMaximum(MaxSeriesPerPlot);

            parameters.PointSize = projectWithOneCycleExist ? PointSizeOnOneCyclePlots : parameters.PointSize;
            parameters.MaxCycles = cyclesMaxVerified ? MaxSeriesPerPlot : parameters.MaxCycles;

            var timer = Stopwatch.StartNew();
            var chart = _templatePlotter.Plot(template, parameters, projects, owner.Name);

            Log.Info($"PlotTemplateService.GetChartTemplate: Plot({template.Name}, {parameters}): plot {timer.ElapsedMilliseconds} ms");

            chart.SelectedTemplateName         = templateId.ToString();
            chart.PlotParameters               = parameters;
            chart.PlotParameters.IsInitialized = true;

            return(new ChartTemplate
            {
                Chart = chart,
                Template = template
            });
        }
Exemple #2
0
        ////////////////////////////////////////////////////////////
        // Private Methods/Atributes
        ////////////////////////////////////////////////////////////

        private IEnumerable <DataLayer.PlotTemplate> GetAllUserPlotTemplates(string templateUserId)
        {
            return(_db.GetAllUserPlotTemplates(User.Identity.GetUserId(), templateUserId));
        }