Exemple #1
0
        public IHttpActionResult GetChartTemplate(string id, [FromUri] int[] projectId, [FromUri] string format = null)
        {
            var result = _selectProjectListQuery.Execute(User.Identity.GetUserId(), projectId);

            if (result.Status != ProjectStatusDto.Ready)
            {
                return(Content(HttpStatusCode.NotFound, new { ProjectStatus = result.Status }));
            }

            var timer = Stopwatch.StartNew();

            int.TryParse(id, out var templateId);
            var chartTemplate = _plotTemplateService.GetChartTemplate(new ChartOwner(User.Identity.GetUserId(), User.Identity.Name), templateId, result.Projects);

            if (chartTemplate == null)
            {
                Log.Error($"Template {templateId} not found");
                return(NotFound());
            }
            timer.Restart();

            if (format?.ToLower() == "xlsx")
            {
                return(new ExcelHttpActionResult(_exporter.ToExcel(chartTemplate.Chart)));
            }

            var dto = chartTemplate.Chart.ToChartDto($"Template - {chartTemplate.Template.Name}");

            Log.Info($"ChartController.GetChartByTemplate: Plot({chartTemplate.Template.Name}, {chartTemplate.Template.PlotParameters}, ProjectIds: {string.Join(",", projectId)} UTC Time: {DateTime.UtcNow} toDto {timer.ElapsedMilliseconds} ms");

            return(Ok(dto));
        }
Exemple #2
0
        public IHttpActionResult GetChart(
            [FromUri] int[] projectId,
            [FromUri] PlotType plotType,
            [FromUri] string format = null)
        {
            Stopwatch timer = Stopwatch.StartNew();

            Log.Info($"ChartController.GetChart: ChartController.GetChart: Plot({plotType}, ProjectIds: {string.Join(",", projectId)} UTC Time: {DateTime.UtcNow}");
            var result = _selectProjectListQuery.Execute(User.Identity.GetUserId(), projectId);

            if (result.Status != ProjectStatusDto.Ready)
            {
                return(Content(HttpStatusCode.NotFound, new { ProjectStatus = result.Status }));
            }

            var parameters = _chartSettingProvider.MergeWithGlobal(User.Identity.GetUserId(), _chartSettingProvider.GetSettings(User.Identity.GetUserId()));

            var projectWithOneCycleExist        = result.Projects.HasProjectsWithOneCycle();
            var projectsSumCyclesGreaterThanMax = result.Projects.IsTotalProjectsCyclesGreaterThanMaximum(MaxSeriesPerPlot);

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

            var chart = _chartPlotterFactory(plotType).Plot(projectsSumCyclesGreaterThanMax,
                                                            new ChartPlotterContext
            {
                Parameters = parameters,
                ProjectIds = projectId,
                Trace      = User.Identity.Name
            });

            chart.PlotParameters = parameters;

            if (format?.ToLower() == "xlsx")
            {
                return(new ExcelHttpActionResult(_exporter.ToExcel(chart)));
            }

            var dto = chart.ToChartDto();

            Log.Info($"ChartController.GetChart: Plot({plotType}, {parameters}, ProjectIds: {string.Join(", ", projectId)} UTC Time: {DateTime.UtcNow} toDto {timer.ElapsedMilliseconds} ms");

            return(Ok(dto));
        }
Exemple #3
0
        public IHttpActionResult GetViewChart(int id, [FromUri] string format = null)
        {
            var timer  = Stopwatch.StartNew();
            var userId = User.Identity.GetUserId();

            var selectedView = _db.Views.First(v => v.UserId == userId && v.Id == id);

            if (selectedView == null)
            {
                return(NotFound());
            }

            var projectIds = selectedView.Projects.Select(p => p.Id).ToArray();
            var result     = _selectProjectListQuery.Execute(User.Identity.GetUserId(), projectIds);

            if (result.Status != ProjectStatusDto.Ready)
            {
                return(Content(HttpStatusCode.NotFound, new { result.Status }));
            }

            var chartTemplate = _plotTemplateService.GetChartTemplate(new ChartOwner(User.Identity.GetUserId(), User.Identity.Name), selectedView.PlotTemplateId, result.Projects);

            if (chartTemplate == null)
            {
                Log.Error($"Template {id} not found");
                return(NotFound());
            }

            if (format?.ToLower() == "xlsx")
            {
                return(new ExcelHttpActionResult(_exporter.ToExcel(chartTemplate.Chart)));
            }

            var dto = chartTemplate.Chart.ToChartDto($"View - {chartTemplate.Template.Name}");

            Log.Info($"View({selectedView.Id}, {selectedView.PlotTemplateId}): toDto {timer.ElapsedMilliseconds} ms");
            return(Ok(dto));
        }