Selaa lähdekoodia

学情多个数据读取修改,以及修改数据预处理过程

zhouj1203@hotmail.com 4 vuotta sitten
vanhempi
commit
9a39df775b

+ 295 - 283
TEAMModelOS/Controllers/Analysis/AchievementController.cs

@@ -90,7 +90,7 @@ namespace TEAMModelOS.Controllers.Analysis
             //
             dict.TryGetValue("subjectCode", out object subjectCode);
             dict.TryGetValue("code", out object code);
-            List<ExamResult> exams = null;
+            List<ExamResult> exams = new List<ExamResult>();
             /*if (RedisHelper.Instance != null)
             {
                 exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
@@ -100,11 +100,16 @@ namespace TEAMModelOS.Controllers.Analysis
             {
                 exams = await FindExamResultRedis(dict, "FindExamResultRedis");
             }*/
-            if (RedisHelper.Exists(CacheCosmosPrefix + ""))
-            {
-                exams = RedisHelper.HGet<List<ExamResult>>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
-                //builder.Data(info);
+            List<string> subjectCouns = JsonApiHelper.FromApiJson<List<string>>(subjectCode.ToApiJson());
+            for (int i =0;i < subjectCouns.Count;i++ ) {
+                if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCouns[i]))
+                {
+                    ExamResult result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCouns[i], ShaHashHelper.GetSHA1(code.ToString()));
+                    //builder.Data(info);
+                    exams.Add(result);
+                }
             }
+            
 
             Dictionary<string, object> stuMap = new Dictionary<string, object>
             {
@@ -549,22 +554,19 @@ namespace TEAMModelOS.Controllers.Analysis
             List<Dictionary<string, dynamic>> scatterAnalysis = new List<Dictionary<string, dynamic>>();
             //Dictionary<string, object> scatterAnalysis = new Dictionary<string, object>();
             List<ExamResult> exams = new List<ExamResult>();
-            /*if (RedisHelper.Instance != null)
-            {
-                exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
-                    ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), timeoutSeconds, () => { return FindExamResultRedis(dict, "FindExamResultRedis"); });
-            }
-            else
-            {
-                exams = await FindExamResultRedis(dict, "FindExamResultRedis");
-            }*/
+
             dict.TryGetValue("subjectCode", out object subjectCode);
             dict.TryGetValue("code", out object code);
-            if (RedisHelper.Exists(CacheCosmosPrefix + ""))
-            {
-                exams = RedisHelper.HGet<List<ExamResult>>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
-                //builder.Data(info);
-            }
+           /* List<string> subjectCouns = JsonApiHelper.FromApiJson<List<string>>(subjectCode.ToApiJson());
+            for (int i = 0; i < subjectCouns.Count; i++)
+            {*/
+                if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
+                {
+                    ExamResult result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
+                    //builder.Data(info);
+                    exams.Add(result);
+                }
+            //}
             Dictionary<string, object> stuMap = new Dictionary<string, object>
             {
                 { "schoolCode", "Habook" }
@@ -758,7 +760,7 @@ namespace TEAMModelOS.Controllers.Analysis
             List<Paper> paper = new List<Paper>();
             if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
             {
-                Paper paper1 = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
+                Paper paper1 = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
                 paper.Add(paper1);              
             }
           
@@ -998,40 +1000,31 @@ namespace TEAMModelOS.Controllers.Analysis
 
             };*/
             List<ExamResult> exams = new List<ExamResult>();
-            /* if (RedisHelper.Instance != null)
-             {
-                 exams = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamResultRedis",
-                     ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(examMap)), timeoutSeconds, () => { return FindExamResultRedis(examMap, "FindExamResultRedis"); });
-             }
-             else
-             {
-                 exams = await FindExamResultRedis(examMap, "FindExamResultRedis");
-             }*/
-            if (RedisHelper.Exists(CacheCosmosPrefix + ""))
-            {
-                exams = RedisHelper.HGet<List<ExamResult>>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
-                //builder.Data(info);
-            }
+
+                if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + subjectCode.ToString()))
+                {
+                    ExamResult res = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
+                    exams.Add(res);
+                }
             List<Paper> paper = new List<Paper>();
-            if (RedisHelper.Exists(CacheCosmosPrefix + ""))
-            {
-                paper = RedisHelper.HGet<List<Paper>>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
-                //builder.Data(info);
-            }
-            /*if (RedisHelper.Instance != null)
-            {
-                paper = await RedisHelper.CacheShellAsync(CacheCosmosPrefix + "FindExamPaperRedis",
-                    ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(sub)), timeoutSeconds, () => { return FindExamPaperRedis(sub, "FindExamPaperRedis"); });
-            }
-            else
+            if (RedisHelper.Exists(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString()))
             {
-                paper = await FindExamPaperRedis(sub, "FindExamPaperRedis");
-            }*/
+
+                Paper papers = RedisHelper.HGet<Paper>(CacheCosmosPrefix + "paperInfo" + subjectCode.ToString(), ShaHashHelper.GetSHA1(code.ToString()));
+                paper.Add(papers);
+            }          
             Dictionary<string, object> stuMap = new Dictionary<string, object>
             {
                 { "schoolCode", "Habook" }
             };
-            List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
+            //List<Student> students = await azureCosmosDBRepository.FindByDict<Student>(stuMap);
+            List<Student> students = null;
+            if (RedisHelper.Exists(CacheCosmosPrefix + "students"))
+            {
+                students = RedisHelper.HGet<List<Student>>(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(schoolCode.ToString()));
+                //builder.Data(info);
+                //students.Add(student);
+            }
             HashSet<string> knowledge = new HashSet<string>();
             HashSet<string> area = new HashSet<string>();
             List<double> point = new List<double>();
@@ -1655,7 +1648,7 @@ namespace TEAMModelOS.Controllers.Analysis
         public async Task<BaseResponse> HomeStatistics(JosnRequest<Dictionary<string, object>> request)
         {
             ResponseBuilder builder = ResponseBuilder.custom();
-            Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
+            List<Dictionary<string, dynamic>> info = new List<Dictionary<string, dynamic>>();
             if (RedisHelper.Instance != null)
             {
 
@@ -1673,7 +1666,7 @@ namespace TEAMModelOS.Controllers.Analysis
             }
             return builder.build();
         }
-        public async Task<Dictionary<string, dynamic>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method) {
+        public async Task<List<Dictionary<string, dynamic>>> FindHomeStatisticsRedis(Dictionary<string, object> dict, string method) {
 
             //request.@params.TryGetValue("subjectCode", out object subjectCode);
             dict.TryGetValue("schoolCode", out object schoolCode);
@@ -1687,7 +1680,7 @@ namespace TEAMModelOS.Controllers.Analysis
             {
                 { "schoolCode", schoolCode.ToString()},
             };
-            await SaveRedisInfoAsync(eMap);
+            //await SaveRedisInfoAsync(eMap);
             //说明 同学校、同类型考试数据
             //List<ExamInfo> exams = await azureCosmosDBRepository.FindByDict<ExamInfo>(eMap);
             List<ExamInfo> exams = new List<ExamInfo>();
@@ -1701,19 +1694,25 @@ namespace TEAMModelOS.Controllers.Analysis
                 exams = await FindExamInfoRedis(eMap, "FindExamInfo");
             }
             List<ExamInfo> newInfo = new List<ExamInfo>();
-            //获取最新的考试信息
+            //获取各个学段最新的考试信息
             foreach (IGrouping<string, ExamInfo> group in exams.GroupBy(c => c.conditions.period))
-            {
-                 
+            {                 
                 ExamInfo examInfo = group.ToList().OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
                 newInfo.Add(examInfo);
             };
             //newInfo.Select(e => e.type.Equals("union"));
-            List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
+            //List<ExamInfo> unionInfo = newInfo.Where(e => e.type.Equals("union")).ToList();
             //exams.GroupBy(e => e.conditions.period);
             //ExamInfo info = exams.OrderByDescending(e => e.createTime).ToList().FirstOrDefault();
             //查询学校对应的年级信息
-            List<School> schools = await azureCosmosDBRepository.FindByDict<School>(SCMap);
+            //List<School> schools = await azureCosmosDBRepository.FindByDict<School>(SCMap);
+            List<School> schools = new List<School>();
+            if (RedisHelper.Exists(CacheCosmosPrefix + "schoolInfo"))
+            {
+                School sc = RedisHelper.HGet<School>(CacheCosmosPrefix + "schoolInfo",
+                    ShaHashHelper.GetSHA1(schoolCode.ToString()));
+                schools.Add(sc);
+            }
             HashSet<string> classList = new HashSet<string>();
             HashSet<string> subjectList = new HashSet<string>();
             List<List<List<string>>> AllPoint = new List<List<List<string>>>();
@@ -1746,282 +1745,295 @@ namespace TEAMModelOS.Controllers.Analysis
                         grades = p.grades;
                     }
                 });
+                List<Dictionary<string, object>> map = new List<Dictionary<string, object>>();
                 //循环处理不同年级考试信息
-                /*foreach (Grade g in grades) { 
-                    
-                }*/
-                foreach (ExamInfo e in newInfo)
+                foreach (Grade g in grades)
                 {
-                    List<ExamResult> simples = null ;
-                    if (RedisHelper.Exists(CacheCosmosPrefix + "results"))
-                    {
-                        simples = RedisHelper.HGet<List<ExamResult>>(CacheCosmosPrefix + "results", ShaHashHelper.GetSHA1(e.examCode));
-                    }
-                    //List<ExamResult> examResults = new List<ExamResult>();                    
-                    Dictionary<string, object> sub = new Dictionary<string, object>
+                    for (int i = 0; i < newInfo.Count; i++)
                     {
-                        { "code",  e.id}
-                    };
-                    Period = e.conditions.period;
-                    Grade = e.conditions.grade;
-                    List<string> subjects = new List<string>();
-                    List<List<string>> SubjectClassAverage = new List<List<string>>();
-                    List<List<string>> SubjectAverage = new List<List<string>>();
-                    //List<List<string>> SubjectClassAverage = new List<List<string>>();
-                    //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
-                   
-                    // 学生总分
-                    double coreSum = 0;
-                    int stuCount = e.stuCount;
-                    //初始化进行人数
-                    double iPersons = 0;
-                    //获取进线人数
-                    iPersons = stuCount * 0.4;
-                    //
-                    List<List<double>> subSum = new List<List<double>>();
-                    if (simples.IsEmpty()) continue;
-                    double weight = 0.5;
-                    weightSum += weight;
-                    int classLen = simples[0].classes.Count;
-                    for (int cls = 0; cls < classLen; cls++)
-                    {
-                        if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
+                        if (g.gradeCode.Equals(newInfo[i].conditions.grade))
                         {
-                            List<double> stuScore = new List<double>();
-                            int stdLen = indexs[1] - indexs[0] + 1;
-
-                            for (int i = 0; i < stdLen; i++)
+                            List<ExamResult> simples = new List<ExamResult>();
+                            for (int j = 0; j < newInfo[i].conditions.subject.Count; j++)
                             {
-                                stuScore.Add(0);
+                                ExamResult result = new ExamResult();
+                                if (RedisHelper.Exists(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j]))
+                                {
+                                    result = RedisHelper.HGet<ExamResult>(CacheCosmosPrefix + "examResult" + newInfo[i].conditions.subject[j],
+                                        ShaHashHelper.GetSHA1(newInfo[i].examCode));
+                                    simples.Add(result);
+                                }
                             }
-                            subSum.Add(stuScore);
-                        }
-                    }
 
-                    simples.ForEach(s =>
-                    {
-                        subjectList.Add(s.subjectCode);
-                        //计算试卷总分
-                        double sum = s.point.Sum();
-                        //int stuSum = 0;
-                        int classIndex = 0;
-                        List<string> ClassAverage = new List<string>();
-                        List<string> Average = new List<string>();
-                        List<string> passList = new List<string>();
-                        s.classes.ForEach(c =>
-                        {
-                            List<List<string>> classPRL = new List<List<string>>();
-
-                            //初始化班级总分
-                            double classPoint = 0;
-                            //初始化班级缺考人数
-                            int classCount = 0;
-                            //初始化班级平均得分率
-                            double points = 0;
-                            //初始化班级平均得分率
-                            double AveragePoints = 0;
-                            //初始化各班参考人数
-                            int counts = 0;
-                            //c.Keys遍历key值
-                            foreach (string key in c.Keys)
+                            //List<ExamResult> examResults = new List<ExamResult>();                    
+                            /*Dictionary<string, object> sub = new Dictionary<string, object>
                             {
-                                classList.Add(key);
+                                { "code",  newInfo[i].id}
+                            };*/
+                            Period = newInfo[i].conditions.period;
+                            Grade = newInfo[i].conditions.grade;
+                            List<string> subjects = new List<string>();
+                            List<List<string>> SubjectClassAverage = new List<List<string>>();
+                            List<List<string>> SubjectAverage = new List<List<string>>();
+                            //List<List<string>> SubjectClassAverage = new List<List<string>>();
+                            //List<ExamResult> simples = await azureCosmosDBRepository.FindByDict<ExamResult>(sub);
+
+                            // 学生总分
+                            double coreSum = 0;
+                            int stuCount = newInfo[i].stuCount;
+                            //初始化进行人数
+                            double iPersons = 0;
+                            //获取进线人数
+                            iPersons = stuCount * 0.4;
+                            //
+                            List<List<double>> subSum = new List<List<double>>();
+                            if (simples.IsEmpty()) continue;
+                            double weight = 0.5;
+                            weightSum += weight;
+                            int classLen = simples[0].classes.Count;
+                            for (int cls = 0; cls < classLen; cls++)
+                            {
+                                if (simples[0].classes[cls].TryGetValue(simples[0].classes[cls].Keys.ToArray<string>()[0], out int[] indexs))
+                                {
+                                    List<double> stuScore = new List<double>();
+                                    int stdLen = indexs[1] - indexs[0] + 1;
+
+                                    for (int n = 0; n < stdLen; n++)
+                                    {
+                                        stuScore.Add(0);
+                                    }
+                                    subSum.Add(stuScore);
+                                }
                             }
-                            //每个班级平均分
-                            foreach (int[] value in c.Values)
+
+                            simples.ForEach(s =>
                             {
-                                for (int i = value[0]; i <= value[1]; i++)
+                                subjectList.Add(s.subjectCode);
+                                //计算试卷总分
+                                double sum = s.point.Sum();
+                                //int stuSum = 0;
+                                int classIndex = 0;
+                                List<string> ClassAverage = new List<string>();
+                                List<string> Average = new List<string>();
+                                List<string> passList = new List<string>();
+                                s.classes.ForEach(c =>
                                 {
-                                    //初始化学生单科个人得分
-                                    double stuPoints = s.result[i].Sum();
+                                    List<List<string>> classPRL = new List<List<string>>();
+
+                                    //初始化班级总分
+                                    double classPoint = 0;
+                                    //初始化班级缺考人数
+                                    int classCount = 0;
+                                    //初始化班级平均得分率
+                                    double points = 0;
+                                    //初始化班级平均得分率
+                                    double AveragePoints = 0;
+                                    //初始化各班参考人数
+                                    int counts = 0;
+                                    //c.Keys遍历key值
+                                    foreach (string key in c.Keys)
+                                    {
+                                        classList.Add(key);
+                                    }
+                                    //每个班级平均分
+                                    foreach (int[] value in c.Values)
+                                    {
+                                        for (int i = value[0]; i <= value[1]; i++)
+                                        {
+                                            //初始化学生单科个人得分
+                                            double stuPoints = s.result[i].Sum();
 
-                                    subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
+                                            subSum[classIndex][i - value[0]] = stuPoints + subSum[classIndex][i - value[0]];
 
-                                    classPoint += s.result[i].Sum();
-                                    coreSum += s.result[i].Sum();
+                                            classPoint += s.result[i].Sum();
+                                            coreSum += s.result[i].Sum();
 
-                                    if (s.result[i].Sum() == 0)
+                                            if (s.result[i].Sum() == 0)
+                                            {
+                                                classCount++;
+                                            }
+                                        }
+                                        //每个班级实际参考人数
+                                        counts = value[1] - value[0] - classCount + 1;
+                                        //stuSum += counts;
+                                        points = Convert.ToDouble(classPoint) / counts / sum;
+                                        //计算每个班级平均得分
+                                        AveragePoints = Convert.ToDouble(classPoint) / counts;
+                                        ClassAverage.Add(points.ToString("0.000"));
+                                        Average.Add(AveragePoints.ToString());
+                                    }
+                                    classIndex += 1;
+                                });
+                                SubjectClassAverage.Add(ClassAverage);
+                                SubjectAverage.Add(Average);
+                                //subAverage = subjectPoint / ClassAverage.Count();
+                                //subjectAverage.Add(subAverage.ToString("0.00"));
+                            });
+                            double core = coreSum / stuCount * weight;
+                            CoreAverage.Add(core);
+                            AllPoint.Add(SubjectClassAverage);
+                            AllPointAverage.Add(SubjectAverage);
+
+                            //处理人数为整
+                            string ip = iPersons.ToString("0");
+                            //初始化进线分数
+                            int ipoint = 0;
+                            List<int> AllPoints = new List<int>();
+                            foreach (List<double> points in subSum)
+                            {
+                                foreach (int po in points)
+                                {
+                                    AllPoints.Add(po);
+                                }
+                            }
+                            for (int sn = 0; sn < subSum.Count; sn++)
+                            {
+                                for (int j = 0; j < subSum[sn].Count; j++)
+                                {
+                                    if (subSum[sn][j].Equals("0"))
                                     {
-                                        classCount++;
+                                        subSum[sn].Remove(subSum[sn][j]);
                                     }
                                 }
-                                //每个班级实际参考人数
-                                counts = value[1] - value[0] - classCount + 1;
-                                //stuSum += counts;
-                                points = Convert.ToDouble(classPoint) / counts / sum;
-                                //计算每个班级平均得分
-                                AveragePoints = Convert.ToDouble(classPoint) / counts;
-                                ClassAverage.Add(points.ToString("0.000"));
-                                Average.Add(AveragePoints.ToString());
                             }
-                            classIndex += 1;
-                        });
-                        SubjectClassAverage.Add(ClassAverage);
-                        SubjectAverage.Add(Average);
-                        //subAverage = subjectPoint / ClassAverage.Count();
-                        //subjectAverage.Add(subAverage.ToString("0.00"));
-                    });
-                    double core = coreSum / stuCount * weight;
-                    CoreAverage.Add(core);
-                    AllPoint.Add(SubjectClassAverage);
-                    AllPointAverage.Add(SubjectAverage);
-
-                    //处理人数为整
-                    string ip = iPersons.ToString("0");
-                    //初始化进线分数
-                    int ipoint = 0;
-                    List<int> AllPoints = new List<int>();
-                    foreach (List<double> points in subSum)
-                    {
-                        foreach (int po in points)
-                        {
-                            AllPoints.Add(po);
-                        }
-                    }
-                    for (int i = 0; i < subSum.Count; i++)
-                    {
-                        for (int j = 0; j < subSum[i].Count; j++)
-                        {
-                            if (subSum[i][j].Equals("0"))
+                            //计算成绩年级排名
+                            AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
+                            ipoint = AllPoints[int.Parse(ip)];
+                            int m = 0;
+                            List<List<string>> KeyLine = new List<List<string>>();
+                            foreach (List<double> points in subSum)
                             {
-                                subSum[i].Remove(subSum[i][j]);
+                                List<string> detail = new List<string>();
+                                double sum = points.Count;
+                                int l = 0;
+                                for (int mq = 0; mq < points.Count; mq++)
+                                {
+                                    if (points[i] > ipoint)
+                                    {
+                                        l++;
+                                    }
+                                }
+                                double Lines = l;
+                                detail.Add(Lines.ToString());
+                                detail.Add(points.Count.ToString());
+                                var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
+                                detail.Add(t3.ToString());
+                                KeyLine.Add(detail);
+                                m++;
                             }
+                            AllKeyLine.Add(KeyLine);
+
                         }
-                    }
-                    //计算成绩年级排名
-                    AllPoints.Sort(delegate (int s1, int s2) { return s2.CompareTo(s1); });
-                    ipoint = AllPoints[int.Parse(ip)];
-                    int m = 0;
-                    List<List<string>> KeyLine = new List<List<string>>();
-                    foreach (List<double> points in subSum)
-                    {
-                        List<string> detail = new List<string>();
-                        double sum = points.Count;
-                        int j = 0;
-                        for (int i = 0; i < points.Count; i++)
+                        //年级成就指标
+                        if (weightSum == 0)
                         {
-                            if (points[i] > ipoint)
-                            {
-                                j++;
-                            }
+                            weightSum = 1;
                         }
-                        double Lines = j;
-                        detail.Add(Lines.ToString());
-                        detail.Add(points.Count.ToString());
-                        var t3 = Math.Floor(Math.Round(decimal.Parse((Lines / sum).ToString("0.000")), 2) * 100);
-                        detail.Add(t3.ToString());
-                        KeyLine.Add(detail);
-                        m++;
-                    }
-                    AllKeyLine.Add(KeyLine);
-
-                }
-                //年级成就指标
-                if (weightSum == 0)
-                {
-                    weightSum = 1;
-                }
-                double index = CoreAverage.Sum() / weightSum;
-                List<List<double>> AveragePoint = new List<List<double>>();
-                List<List<double>> AverageClassPoint = new List<List<double>>();
-                //List<double> ClassCore = new List<double>();
-                int k = AllPoint.Count;
-                if (k > 0)
-                {
-                    for (int m = 0; m < AllPoint[0].Count; m++)
-                    {
-                        List<double> SubjectAverage = new List<double>();
-                        for (int n = 0; n < AllPoint[0][m].Count; n++)
+                        double index = CoreAverage.Sum() / weightSum;
+                        List<List<double>> AveragePoint = new List<List<double>>();
+                        List<List<double>> AverageClassPoint = new List<List<double>>();
+                        //List<double> ClassCore = new List<double>();
+                        int k = AllPoint.Count;
+                        if (k > 0)
                         {
-                            double startPoint = 0;
-                            for (int f = 0; f < k; f++)
+                            for (int m = 0; m < AllPoint[0].Count; m++)
                             {
-                                startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
+                                List<double> SubjectAverage = new List<double>();
+                                for (int n = 0; n < AllPoint[0][m].Count; n++)
+                                {
+                                    double startPoint = 0;
+                                    for (int f = 0; f < k; f++)
+                                    {
+                                        startPoint = double.Parse(AllPoint[f][m][n]) + startPoint;
+                                    }
+                                    SubjectAverage.Add(startPoint / k);
+                                }
+                                AveragePoint.Add(SubjectAverage);
                             }
-                            SubjectAverage.Add(startPoint / k);
                         }
-                        AveragePoint.Add(SubjectAverage);
-                    }
-                }
-                //每个班级成就指标
-                int p = AllPointAverage.Count;
-                if (p > 0)
-                {
-                    for (int m = 0; m < AllPointAverage[0].Count; m++)
-                    {
-                        List<double> SubjectAverage = new List<double>();
-                        for (int n = 0; n < AllPointAverage[0][m].Count; n++)
+                        //每个班级成就指标
+                        int p = AllPointAverage.Count;
+                        if (p > 0)
                         {
-                            double startPoint = 0;
-                            for (int f = 0; f < k; f++)
+                            for (int m = 0; m < AllPointAverage[0].Count; m++)
                             {
-                                startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
+                                List<double> SubjectAverage = new List<double>();
+                                for (int n = 0; n < AllPointAverage[0][m].Count; n++)
+                                {
+                                    double startPoint = 0;
+                                    for (int f = 0; f < k; f++)
+                                    {
+                                        startPoint = double.Parse(AllPointAverage[f][m][n]) + startPoint;
+                                    }
+                                    SubjectAverage.Add(startPoint / k);
+                                }
+                                AverageClassPoint.Add(SubjectAverage);
                             }
-                            SubjectAverage.Add(startPoint / k);
                         }
-                        AverageClassPoint.Add(SubjectAverage);
-                    }
-                }
-                int c = AverageClassPoint.Count;
-                List<double> ClassCore = new List<double>();
-                if (c > 0)
-                {
-                    for (int j = 0; j < AverageClassPoint[0].Count; j++)
-                    {
-                        double startAverage = 0;
-                        for (int f = 0; f < c; f++)
+                        int c = AverageClassPoint.Count;
+                        List<double> ClassCore = new List<double>();
+                        if (c > 0)
                         {
-                            startAverage = AverageClassPoint[f][j] + startAverage;
+                            for (int j = 0; j < AverageClassPoint[0].Count; j++)
+                            {
+                                double startAverage = 0;
+                                for (int f = 0; f < c; f++)
+                                {
+                                    startAverage = AverageClassPoint[f][j] + startAverage;
+                                }
+                                ClassCore.Add(startAverage / weightSum);
+                            }
                         }
-                        ClassCore.Add(startAverage / weightSum);
-                    }
-                }
-                //班级平均进线率
-                int ExamCount = AllKeyLine.Count;
-                List<List<double>> KeyLines = new List<List<double>>();
-                if (ExamCount > 0)
-                {
-                    for (int m = 0; m < AllKeyLine[0].Count; m++)
-                    {
-                        List<double> ClassLine = new List<double>();
-                        for (int n = 0; n < AllKeyLine[0][m].Count; n++)
+                        //班级平均进线率
+                        int ExamCount = AllKeyLine.Count;
+                        List<List<double>> KeyLines = new List<List<double>>();
+                        if (ExamCount > 0)
                         {
-                            double startPoint = 0;
-                            for (int f = 0; f < ExamCount; f++)
+                            for (int m = 0; m < AllKeyLine[0].Count; m++)
                             {
-                                startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
+                                List<double> ClassLine = new List<double>();
+                                for (int n = 0; n < AllKeyLine[0][m].Count; n++)
+                                {
+                                    double startPoint = 0;
+                                    for (int f = 0; f < ExamCount; f++)
+                                    {
+                                        startPoint = double.Parse(AllKeyLine[f][m][n]) + startPoint;
+                                    }
+                                    ClassLine.Add(startPoint / ExamCount);
+                                }
+                                KeyLines.Add(ClassLine);
                             }
-                            ClassLine.Add(startPoint / ExamCount);
                         }
-                        KeyLines.Add(ClassLine);
-                    }
+                        Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
+                        {
+                            { "Period",Period},
+                            { "Grade",Grade},
+                            { "index", index},
+                            { "className", classList },
+                            { "subjectName", subjectList },
+                            { "AveragePoint", AveragePoint },
+                            //{ "AverageClassPoint", AverageClassPoint },
+                            { "ClassCore", ClassCore },
+                            { "KeyLines",KeyLines}
+                        };
+                        map.Add(AveragePointMap);
+                    }   
                 }
-                Dictionary<string, object> AveragePointMap = new Dictionary<string, object>
-                {
-                    { "Period",Period},
-                    { "Grade",Grade},
-                    { "index", index},
-                    { "className", classList },
-                    { "subjectName", subjectList },
-                    { "AveragePoint", AveragePoint },
-                    //{ "AverageClassPoint", AverageClassPoint },
-                    { "ClassCore", ClassCore },
-                    { "KeyLines",KeyLines}
-                };
+
                 //Redis处理结果集
                 if (RedisHelper.Instance != null)
                 {
                     if (!RedisHelper.Exists(CacheCosmosPrefix + method))
                     {
-                        await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), AveragePointMap);
+                        await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), map);
                     }
                     else
                     {
-                        await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), AveragePointMap);
+                        await RedisHelper.HSetAsync(CacheCosmosPrefix + method, ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(dict)), map);
                         await RedisHelper.ExpireAsync(CacheCosmosPrefix + method, timeoutSeconds);
                     }
                 }
-                return AveragePointMap;
+                return map;
             }
             catch (Exception e)
             {

+ 26 - 9
TEAMModelOS/Controllers/Analysis/ChangeController.cs

@@ -14,6 +14,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
+using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Module.AzureBlob.Container;
 using TEAMModelOS.Service.Models;
 
@@ -27,6 +28,7 @@ namespace TEAMModelOS.Controllers.Analysis
         private readonly IWebHostEnvironment _hostingEnvironment;
         public AzureCosmosFactory _cosmosrepository;
         public AzureStorageFactory azureBlobDB;
+        private const string CacheCosmosPrefix = "Analysis:";
         public ChangeController(IWebHostEnvironment hostingEnvironment, AzureCosmosFactory cosmosDBRepository, AzureStorageFactory _azureBlobDB)
         {
             _hostingEnvironment = hostingEnvironment;
@@ -172,7 +174,7 @@ namespace TEAMModelOS.Controllers.Analysis
                     code = "88924E4C-F00D-4A1D-B2C3-234F930F29D4",
                     name = s.ex_name,
                     type = s.ex_type,
-                    examCode = "QCS",
+                    examCode = "QCSCS",
                     startTime = time,
                     endTime = edtime,
                     stuCount = int.Parse(count),
@@ -302,9 +304,9 @@ namespace TEAMModelOS.Controllers.Analysis
                 //ClassPoint.Add(StuPoint);
             });
             examAnswer.answer = stuAnswers;
-            examAnswer.code = examInfo.id;
-            paper.code = examInfo.id;
-            simple.code = examInfo.id;
+            examAnswer.code = examInfo.examCode;
+            paper.code = examInfo.examCode;
+            simple.code = examInfo.examCode;
             simple.classes = Classes;
             simple.ids = StuIds;
             simple.point = points;
@@ -320,12 +322,12 @@ namespace TEAMModelOS.Controllers.Analysis
                 { "examResult",simple},
                 { "examAnswer",examAnswer}
             };            
-            AzureBlobModel modle = await azureBlobDB.UploadFileByContainer("hbcn", keyValues.ToJson(), "exam", sc.schoolCode + examInfo.id + paper.subjectCode + ".json");
+            AzureBlobModel modle = await azureBlobDB.UploadFileByContainer("hbcn", keyValues.ToJson(), "exam", sc.schoolCode + examInfo.examCode + paper.subjectCode + ".json");
             //examInfo.blobUrl = modle.BlobUrl;
             //判定是否存储考试基本信息
             Dictionary<string, object> sub = new Dictionary<string, object>
                     {
-                        { "code",  examInfo.examCode}
+                        { "examCode",  examInfo.examCode}
                     };
             List<ExamInfo> eInfo = await _cosmosrepository.FindByDict<ExamInfo>(sub);
             if (eInfo.Count > 0)
@@ -339,7 +341,7 @@ namespace TEAMModelOS.Controllers.Analysis
                     else
                     {
                         e.conditions.subject = new List<string>{ paper.subjectCode };
-                        e.blobUrl.Add(modle.BlobUrl);
+                        e.blobUrl = new List<string> { modle.BlobUrl };
                     }
                 });
             }
@@ -347,8 +349,23 @@ namespace TEAMModelOS.Controllers.Analysis
                 examInfo.blobUrl = new List<string> { modle.BlobUrl };
                 await _cosmosrepository.Save(examInfo);
             }
-            
-           
+
+ 
+                //Redis处理考试结果数据集合
+                if (RedisHelper.Instance != null)
+                {
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "examResult" + simple.subjectCode, ShaHashHelper.GetSHA1(examInfo.examCode), simple);
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "students", ShaHashHelper.GetSHA1(sc.schoolCode), students);
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "paperInfo" + simple.subjectCode, ShaHashHelper.GetSHA1(examInfo.examCode), paper);
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "examAnswer" + simple.subjectCode, ShaHashHelper.GetSHA1(examInfo.examCode), examAnswer);
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "classInfo", ShaHashHelper.GetSHA1(sc.schoolCode), classrooms);
+                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "schoolInfo", ShaHashHelper.GetSHA1(sc.schoolCode), sc);
+                    //await RedisHelper.HSetAsync(CacheCosmosPrefix + "examInfo" + simple.subjectCode, ShaHashHelper.GetSHA1(examInfo.examCode), examInfo);
+                /*                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "results", ShaHashHelper.GetSHA1(examInfo.examCode), simples);
+                                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "papers", ShaHashHelper.GetSHA1(examInfo.examCode), papers);
+                                    await RedisHelper.HSetAsync(CacheCosmosPrefix + "answers", ShaHashHelper.GetSHA1(examInfo.examCode), answers);*/
+            }
+          
             //_examInfoService.SaveToCosmos(simple);
             //_cosmosrepository.Save(sc);
             /*_cosmosrepository.Save(simple);