public AnswersService(
     ILogger <AnswersService> logger,
     IInsightDashboardLocalizationService localizationService,
     IEFormCoreService coreHelper)
 {
     _logger = logger;
     _localizationService = localizationService;
     _coreHelper          = coreHelper;
 }
Пример #2
0
 public InterviewsService(
     ILogger <InterviewsService> logger,
     IInsightDashboardLocalizationService localizationService,
     IInterviewsExcelService interviewsExcelService,
     IDashboardService dashboardService)
 {
     _logger = logger;
     _localizationService    = localizationService;
     _interviewsExcelService = interviewsExcelService;
     _dashboardService       = dashboardService;
 }
 public InsightDashboardPnSettingsService(ILogger <InsightDashboardPnSettingsService> logger,
                                          IInsightDashboardLocalizationService localizationService,
                                          InsightDashboardPnDbContext dbContext,
                                          IPluginDbOptions <InsightDashboardBaseSettings> options,
                                          IHttpContextAccessor httpContextAccessor)
 {
     _logger              = logger;
     _dbContext           = dbContext;
     _options             = options;
     _httpContextAccessor = httpContextAccessor;
     _localizationService = localizationService;
 }
 public WordService(IDashboardService dashboardService, ILogger <DashboardService> logger, IInsightDashboardLocalizationService localizationService)
 {
     _dashboardService    = dashboardService;
     _logger              = logger;
     _localizationService = localizationService;
 }
Пример #5
0
        public static List <DashboardViewChartRawDataModel> ConvertSingleData(
            IInsightDashboardLocalizationService localizationService,
            List <DashboardViewChartDataSingleModel> singleData,
            bool isMulti,
            int answersCount)
        {
            const int columnsCount      = 1;
            var       result            = new List <DashboardViewChartRawDataModel>();
            var       data              = new DashboardViewChartRawDataModel();
            var       chartRawDataModel = new DashboardViewChartRawDataItemModel
            {
                RawValueName = string.Empty, // Empty location
            };

            // Headers
            data.RawHeaders.Add(
                localizationService.GetString("TotalPeriod"));

            // Rows
            var rawDataList = new List <DashboardViewChartRawDataValuesModel>();

            // Get row names
            foreach (var singleModel in singleData)
            {
                var rawDataValuesModel = new DashboardViewChartRawDataValuesModel
                {
                    ValueName = singleModel.Name,
                    Percents  = new decimal[columnsCount],
                    Amounts   = new decimal[columnsCount],
                };

                rawDataList.Add(rawDataValuesModel);
            }

            var totalRow = new DashboardViewChartRawDataValuesModel
            {
                ValueName = localizationService.GetString("Total"),
                Percents  = new decimal[columnsCount],
                Amounts   = new decimal[columnsCount],
            };

            rawDataList.Add(totalRow);

            // by Item
            if (isMulti)
            {
                var percentageList = new List <decimal>();
                for (var y = 0; y < singleData.Count; y++)
                {
                    var     dataSingleModel = singleData[y];
                    decimal percentage      = Math.Round((decimal)dataSingleModel.DataCount / (decimal)answersCount * 100m, 0, MidpointRounding.AwayFromZero);
                    percentageList.Add(percentage);
                    rawDataList[y].Percents[0] = percentage;
                    rawDataList[y].Amounts[0]  = dataSingleModel.DataCount;
                }
                // calculate total
                var lastRow = singleData.Count;

                rawDataList[lastRow].Percents[0] = percentageList.Sum(x => x);
                rawDataList[lastRow].Amounts[0]  = answersCount;
            }
            else
            {
                for (var y = 0; y < singleData.Count; y++)
                {
                    var dataSingleModel = singleData[y];
                    rawDataList[y].Percents[0] = (decimal)dataSingleModel.Value;
                    rawDataList[y].Amounts[0]  = dataSingleModel.DataCount;
                }
                // calculate total
                var lastRow = singleData.Count;

                rawDataList[lastRow].Percents[0] = singleData
                                                   .Where(x => x.Value != null)
                                                   .Sum(x => (decimal)x.Value);

                rawDataList[lastRow].Amounts[0] = singleData
                                                  .Sum(x => x.DataCount);
            }

            chartRawDataModel.RawDataValues = rawDataList;
            data.RawDataItems.Add(chartRawDataModel);
            result.Add(data);
            return(result);
        }
Пример #6
0
        public static List <DashboardViewChartRawDataModel> ConvertMultiData(
            IInsightDashboardLocalizationService localizationService,
            List <DashboardViewChartDataMultiModel> multiData,
            bool isLineData,
            bool isMulti)
        {
            var result = new List <DashboardViewChartRawDataModel>();
            var data   = new DashboardViewChartRawDataModel();

            if (multiData.Count == 0)
            {
                return(result);
            }

            var chartRawDataModel = new DashboardViewChartRawDataItemModel
            {
                RawValueName = string.Empty, // Empty location
            };

            // If it's data for line chart - it should be inverted
            if (isLineData)
            {
                // Get element with max columns
                var maxColumnsObject = multiData
                                       .OrderByDescending(item => item.Series.Count)
                                       .First();

                // Headers
                foreach (var dataSingleModel in maxColumnsObject.Series)
                {
                    data.RawHeaders.Add(dataSingleModel.Name); // Year name
                }

                // Rows
                var rawDataList = new List <DashboardViewChartRawDataValuesModel>();

                // Get row names
                foreach (var multiModel in multiData)
                {
                    var rawDataValuesModel = new DashboardViewChartRawDataValuesModel
                    {
                        ValueName = multiModel.Name,
                        Percents  = new decimal[maxColumnsObject.Series.Count],
                        Amounts   = new decimal[maxColumnsObject.Series.Count],
                    };

                    rawDataList.Add(rawDataValuesModel);
                }

                // Add total row
                var totalRow = new DashboardViewChartRawDataValuesModel
                {
                    ValueName = localizationService.GetString("Total"),
                    Percents  = new decimal[maxColumnsObject.Series.Count],
                    Amounts   = new decimal[maxColumnsObject.Series.Count],
                };

                rawDataList.Add(totalRow);

                // by Item
                for (var i = 0; i < multiData.Count; i++)
                {
                    var dataMultiModel = multiData[i];

                    // by week
                    for (var y = 0; y < dataMultiModel.Series.Count; y++)
                    {
                        var dataSingleModel = dataMultiModel.Series[y];

                        rawDataList[i].Amounts[y]  = dataSingleModel.DataCount;
                        rawDataList[i].Percents[y] = (decimal)dataSingleModel.Value;
                    }
                }


                // calculate total
                var lastRow = multiData.Count;
                for (var i = 0; i < maxColumnsObject.Series.Count; i++)
                {
                    decimal totalValue   = 0;
                    decimal totalAmounts = 0;
                    foreach (var rowData in rawDataList)
                    {
                        totalValue   += rowData.Percents[i];
                        totalAmounts += rowData.Amounts[i];
                    }

                    // find total
                    if (isMulti)
                    {
                        foreach (var dataMultiModel in multiData)
                        {
                            var seriesItem = dataMultiModel.Series[i];

                            if (seriesItem.AnswersDataCount > 0)
                            {
                                totalAmounts = seriesItem.AnswersDataCount;
                                break;
                            }
                        }
                    }
                    rawDataList[lastRow].Percents[i] = totalValue;
                    rawDataList[lastRow].Amounts[i]  = totalAmounts;
                }

                chartRawDataModel.RawDataValues = rawDataList;
            }
            else
            {
                // Headers
                foreach (var multiModel in multiData)
                {
                    data.RawHeaders.Add(multiModel.Name); // Year name
                }

                // Rows
                var rawDataList = new List <DashboardViewChartRawDataValuesModel>();

                // Get element with max rows
                var maxObject = multiData
                                .OrderByDescending(item => item.Series.Count)
                                .First();

                // Get row names
                foreach (var singleModel in maxObject.Series)
                {
                    var rawDataValuesModel = new DashboardViewChartRawDataValuesModel
                    {
                        ValueName = singleModel.Name,
                        Percents  = new decimal[multiData.Count],
                        Amounts   = new decimal[multiData.Count],
                    };

                    rawDataList.Add(rawDataValuesModel);
                }

                // Add total row
                var totalRow = new DashboardViewChartRawDataValuesModel
                {
                    ValueName = localizationService.GetString("Total"),
                    Percents  = new decimal[multiData.Count],
                    Amounts   = new decimal[multiData.Count],
                };

                rawDataList.Add(totalRow);

                // by week
                for (var i = 0; i < multiData.Count; i++)
                {
                    var dataMultiModel = multiData[i];

                    // by Item
                    for (var y = 0; y < maxObject.Series.Count; y++)
                    {
                        var maxObjectSingleModel = maxObject.Series[y];

                        // TODO: FIX
                        var singleModel = dataMultiModel.Series
                                          .FirstOrDefault(x => x.Name == maxObjectSingleModel.Name);

                        if (singleModel == null)
                        {
                            rawDataList[y].Percents[i] = 0;
                            rawDataList[y].Amounts[i]  = 0;
                        }
                        else
                        {
                            rawDataList[y].Percents[i] = (decimal)singleModel.Value;
                            rawDataList[y].Amounts[i]  = singleModel.DataCount;
                        }
                    }

                    // calculate total
                    var lastRow = maxObject.Series.Count;

                    rawDataList[lastRow].Percents[i] = dataMultiModel.Series
                                                       .Where(x => x.Value != null)
                                                       .Sum(x => (decimal)x.Value);

                    if (isMulti)
                    {
                        rawDataList[lastRow].Amounts[i] = dataMultiModel.AnswersCount;
                    }
                    else
                    {
                        rawDataList[lastRow].Amounts[i] = dataMultiModel.Series
                                                          .Sum(x => x.DataCount);
                    }
                }

                chartRawDataModel.RawDataValues = rawDataList;
            }

            data.RawDataItems.Add(chartRawDataModel);
            result.Add(data);
            return(result);
        }