Пример #1
0
        public async Task <IEnumerable <Pie> > GetChartList(string reportName, string categoryName)
        {
            CategoriesDal  categoriesDal = new CategoriesDal();
            ReportChartDal chartsDal     = new ReportChartDal();
            var            ChartsList    = new List <Pie>();
            Category       category      = categoriesDal.GetAllCategoriesIncludeReports().FirstOrDefault(r => r.CategoryName == categoryName);
            Report         report        = category.Reports.FirstOrDefault(r => r.ReportName == reportName);
            IEnumerable <ReportChartModel> reportsCarts = chartsDal.GetChartsList(r => r.ReportName == report.ReportId);

            foreach (var item in reportsCarts)
            {
                WorkItems workItemsData = await GetWorkItemData(item.QueryId);

                var ids = workItemsData.GetAllIds();
                WorkItemResponse response = null;
                foreach (var id in ids)
                {
                    var chartData = await HttpProvider.GetHttpRequest("_apis/wit/workItems?ids=" + id + "&fields=" + item.ColumnReferenceName);

                    var currentItem = JsonConvert.DeserializeObject <WorkItemResponse>(chartData);
                    if (response == null)
                    {
                        response = currentItem;
                    }
                    else
                    {
                        response.value.AddRange(currentItem.value);
                    }
                }

                var propName = item.ColumnReferenceName.Replace(".", "");

                var groupedData = response.value.GroupBy(p => p.fields.GetType().GetProperty(propName).GetValue(p.fields));

                List <Datum> PieLabels = new List <Datum>();
                int          total     = 0;
                foreach (var PieData in groupedData)
                {
                    total += PieData.Count();
                    PieLabels.Add(new Datum
                    {
                        Label = PieData.Key == null ? "No data" : PieData.Key.ToString(),
                        Value = PieData.Count()
                    });
                }

                var pie = new Pie
                {
                    Name         = item.ChartName,
                    Element      = "morris-donut-chart" + ChartsList.Count,
                    Type         = "Donut",
                    Data         = PieLabels.ToArray(),
                    TotalData    = total.ToString(),
                    DataShowType = item.DataShowType.ToString().ToLower()
                };
                ChartsList.Add(pie);
            }

            return(ChartsList);
        }
Пример #2
0
        public async Task <IEnumerable <Chart> > GetChartList(string reportName, string categoryName)
        {
            CategoriesDal  categoriesDal = new CategoriesDal();
            ReportChartDal chartsDal     = new ReportChartDal();
            var            ChartsList    = new List <Chart>();
            Category       category      = categoriesDal.GetAllCategoriesIncludeReports().FirstOrDefault(r => r.CategoryName == categoryName);
            Report         report        = category.Reports.FirstOrDefault(r => r.ReportName == reportName);
            IEnumerable <ReportChartModel> reportsCarts = chartsDal.GetChartsList(r => r.ReportName == report.ReportId);

            foreach (var item in reportsCarts)
            {
                try
                {
                    switch (item.ChartType)
                    {
                    case Entities.Enums.ChartType.Pie:
                        Pie pie = await GeneratPie(item, ChartsList.Count);

                        ChartsList.Add(pie);
                        break;

                    case Entities.Enums.ChartType.Line:
                        Linear linear = await GeneratLinear(item, ChartsList.Count);

                        ChartsList.Add(linear);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }

            return(ChartsList);
        }
Пример #3
0
        public IEnumerable <Category> GetCategoryList()
        {
            CategoriesDal categoriesDal = new CategoriesDal();

            return(categoriesDal.GetAllCategoriesIncludeReports());
        }