コード例 #1
0
        public HorizBarChart GetCategoryAverages()
        {
            TokenManager tm            = new TokenManager();
            var          aggregationID = tm.PayloadInt("aggreg");

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

            var dict = new Dictionary <string, List <decimal> >();

            using (CSET_Context db = new CSET_Context())
            {
                var assessmentList = db.AGGREGATION_ASSESSMENT.Where(x => x.Aggregation_Id == aggregationID)
                                     .Include(x => x.Assessment_).OrderBy(x => x.Assessment_.Assessment_Date)
                                     .ToList();

                foreach (var a in assessmentList)
                {
                    db.LoadStoredProc("[usp_getStandardsResultsByCategory]")
                    .WithSqlParam("assessment_id", a.Assessment_Id)
                    .ExecuteStoredProc((handler) =>
                    {
                        // usp_getStandardsResultsByCategory 15
                        var procResults = (List <usp_getStandardsResultsByCategory>)handler.ReadToList <usp_getStandardsResultsByCategory>();

                        foreach (var procResult in procResults)
                        {
                            if (!dict.ContainsKey(procResult.Question_Group_Heading))
                            {
                                dict.Add(procResult.Question_Group_Heading, new List <decimal>());
                            }
                            if (procResult.Actualcr > 0)
                            {
                                dict[procResult.Question_Group_Heading].Add(procResult.prc);
                            }
                        }
                    });
                }
            }

            var catList = dict.Keys.ToList();

            catList.Sort();


            var response = new HorizBarChart();
            var ds       = new ChartDataSet();

            response.datasets.Add(ds);
            response.labels.AddRange(catList);
            foreach (string cat in catList)
            {
                ds.data.Add((float)dict[cat].DefaultIfEmpty(0).Average());
            }

            return(response);
        }
コード例 #2
0
        public HorizBarChart GetOverallComparison()
        {
            TokenManager tm            = new TokenManager();
            var          aggregationID = tm.PayloadInt("aggreg");

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

            var response = new HorizBarChart();

            response.reportTitle = "Overall Comparison";
            var statTypes = new List <string>()
            {
                "Overall", "Standards", "Components"
            };

            response.labels.AddRange(statTypes);


            using (CSET_Context db = new CSET_Context())
            {
                var assessmentList = db.AGGREGATION_ASSESSMENT.Where(x => x.Aggregation_Id == aggregationID)
                                     .Include(x => x.Assessment_).OrderBy(x => x.Assessment_.Assessment_Date)
                                     .ToList();

                foreach (var a in assessmentList)
                {
                    db.LoadStoredProc("[GetCombinedOveralls]")
                    .WithSqlParam("assessment_id", a.Assessment_Id)
                    .ExecuteStoredProc((handler) =>
                    {
                        var result = handler.ReadToList <GetCombinedOveralls>();
                        var g      = (List <GetCombinedOveralls>)result;

                        Dictionary <string, double> dict = new Dictionary <string, double>();
                        dict["Standards"] = 0;

                        foreach (GetCombinedOveralls row in g)
                        {
                            if (row.StatType == "Requirement" || row.StatType == "Questions")
                            {
                                dict["Standards"] += row.Value;
                            }
                            else
                            {
                                dict[row.StatType] = row.Value;
                            }
                        }

                        var ds = new ChartDataSet
                        {
                            label = a.Alias
                        };
                        response.datasets.Add(ds);
                        foreach (var statType in statTypes)
                        {
                            ds.data.Add((float)dict[statType]);
                        }
                    });
                }
            }

            return(response);
        }
コード例 #3
0
        public HorizBarChart GetOverallAverages()
        {
            TokenManager tm            = new TokenManager();
            var          aggregationID = tm.PayloadInt("aggreg");

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

            var response = new HorizBarChart();

            response.reportTitle = "Overall Average Summary";


            Dictionary <string, List <double> > dict = new Dictionary <string, List <double> >
            {
                ["Questions"]   = new List <double>(),
                ["Requirement"] = new List <double>(),
                ["Overall"]     = new List <double>(),
                ["Components"]  = new List <double>()
            };


            using (CSET_Context db = new CSET_Context())
            {
                var assessmentList = db.AGGREGATION_ASSESSMENT.Where(x => x.Aggregation_Id == aggregationID)
                                     .Include(x => x.Assessment_).OrderBy(x => x.Assessment_.Assessment_Date)
                                     .ToList();

                foreach (var a in assessmentList)
                {
                    db.LoadStoredProc("[GetCombinedOveralls]")
                    .WithSqlParam("assessment_id", a.Assessment_Id)
                    .ExecuteStoredProc((handler) =>
                    {
                        var procResults = (List <GetCombinedOveralls>)handler.ReadToList <GetCombinedOveralls>();

                        foreach (var procResult in procResults)
                        {
                            if (dict.ContainsKey(procResult.StatType))
                            {
                                dict[procResult.StatType].Add(procResult.Value);
                            }
                        }
                    });
                }

                var ds = new ChartDataSet();
                response.datasets.Add(ds);

                response.labels.Add("Overall");
                ds.data.Add((float)dict["Overall"].DefaultIfEmpty(0).Average());

                response.labels.Add("Standards");
                ds.data.Add(
                    (float)dict["Questions"].DefaultIfEmpty(0).Average()
                    + (float)dict["Requirement"].DefaultIfEmpty(0).Average());

                response.labels.Add("Components");
                ds.data.Add((float)dict["Components"].DefaultIfEmpty(0).Average());

                return(response);
            }
        }
コード例 #4
0
        public HorizBarChart CategoryPercentCompare()
        {
            TokenManager tm            = new TokenManager();
            var          aggregationID = tm.PayloadInt("aggreg");

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

            DataTable dt = new DataTable();

            dt.Columns.Add("AssessmentId", typeof(int));
            dt.Columns.Add("Alias");

            using (CSET_Context db = new CSET_Context())
            {
                var assessmentList = db.AGGREGATION_ASSESSMENT.Where(x => x.Aggregation_Id == aggregationID)
                                     .Include(x => x.Assessment_).OrderBy(x => x.Assessment_.Assessment_Date)
                                     .ToList();

                foreach (var a in assessmentList)
                {
                    var row = dt.NewRow();
                    row["AssessmentId"] = a.Assessment_Id;
                    row["Alias"]        = a.Alias;
                    dt.Rows.Add(row);

                    var percentages = GetCategoryPercentages(a.Assessment_Id, db);

                    foreach (usp_getStandardsResultsByCategory pct in percentages)
                    {
                        if (!dt.Columns.Contains(pct.Question_Group_Heading))
                        {
                            dt.Columns.Add(pct.Question_Group_Heading, typeof(float));
                        }

                        row[pct.Question_Group_Heading] = pct.prc;
                    }
                }

                // build the response
                List <string> categories = dt.Columns.Cast <DataColumn>()
                                           .OrderBy(x => x.ColumnName)
                                           .Select(x => x.ColumnName)
                                           .ToList();

                categories.Remove("AssessmentId");
                categories.Remove("Alias");


                var response = new HorizBarChart();
                response.reportTitle = "Category Percent Comparisons";

                foreach (string category in categories)
                {
                    response.labels.Add(category);
                }

                foreach (DataRow rowAssessment in dt.Rows)
                {
                    var ds = new ChartDataSet();
                    response.datasets.Add(ds);
                    ds.label = rowAssessment["Alias"].ToString();

                    foreach (string category in categories)
                    {
                        ds.data.Add(rowAssessment[category] != DBNull.Value ? (float)rowAssessment[category] : 0f);
                    }
                }

                return(response);
            }
        }