Browse Source

处理数组越界

zhouj1203@hotmail.com 4 years ago
parent
commit
87c79c7dd8
1 changed files with 104 additions and 99 deletions
  1. 104 99
      TEAMModelFunction/TriggerExam.cs

+ 104 - 99
TEAMModelFunction/TriggerExam.cs

@@ -523,100 +523,103 @@ namespace TEAMModelFunction
                 int plcount = 0;
                 //存放并去重知识点
                 HashSet<string> kname = new HashSet<string>();
-                info.papers[no].knowledge.ForEach(kno =>
-                {
-                    kno.ForEach(k =>
+                if (info.papers[no].knowledge.Count > 0) {
+                    info.papers[no].knowledge.ForEach(kno =>
                     {
-                        kname.Add(k);
+                        kno.ForEach(k =>
+                        {
+                            kname.Add(k);
+                        });
                     });
-                });
-                List<string> knowledgeName = new List<string>();
-                foreach (string cla in kname)
-                {
-                    knowledgeName.Add(cla);
-                }
-                for (int k = 0; k < knowledgeName.Count; k++)
-                {
-                    if (null == knowledgeName[k])
+                    List<string> knowledgeName = new List<string>();
+                    foreach (string cla in kname)
                     {
-                        knowledgeName.Remove(knowledgeName[k]);
+                        knowledgeName.Add(cla);
+                    }
+                    for (int k = 0; k < knowledgeName.Count; k++)
+                    {
+                        if (null == knowledgeName[k])
+                        {
+                            knowledgeName.Remove(knowledgeName[k]);
+                        }
                     }
-                }
 
-                foreach (ExamClassResult classResult in classResults)
-                {
-                    if (classResult.subjectId.Equals(subject.id))
+                    foreach (ExamClassResult classResult in classResults)
                     {
-                        //List<int> phc = new List<int>();
-                        List<int> ph = new List<int>();
-                        List<int> pl = new List<int>();
-                        List<int> pc = new List<int>();
-                        List<double> persent = new List<double>();
-                        for (int i = 0; i < knowledgeName.Count; i++)
+                        if (classResult.subjectId.Equals(subject.id))
                         {
-                            //初始化单个知识点得分
-                            double score = 0;
-                            double allScore = 0;
-                            int n = 0;
-                            int phCount = 0;
-                            int plCount = 0;
-                            int pCount = 0;
-                            foreach (List<string> str in info.papers[no].knowledge)
+                            //List<int> phc = new List<int>();
+                            List<int> ph = new List<int>();
+                            List<int> pl = new List<int>();
+                            List<int> pc = new List<int>();
+                            List<double> persent = new List<double>();
+                            for (int i = 0; i < knowledgeName.Count; i++)
                             {
-                                if (str.Contains(knowledgeName[i]))
+                                //初始化单个知识点得分
+                                double score = 0;
+                                double allScore = 0;
+                                int n = 0;
+                                int phCount = 0;
+                                int plCount = 0;
+                                int pCount = 0;
+                                foreach (List<string> str in info.papers[no].knowledge)
                                 {
-                                    var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
-                                    allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
-                                    foreach (string id in classResult.studentIds)
+                                    if (str.Contains(knowledgeName[i]))
                                     {
-                                        int index = classResult.studentIds.IndexOf(id);
-                                        if (classResult.studentScores.Count > 0)
+                                        var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
+                                        allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
+                                        foreach (string id in classResult.studentIds)
                                         {
-                                            if (classResult.studentScores[index].Count > 0)
+                                            int index = classResult.studentIds.IndexOf(id);
+                                            if (classResult.studentScores.Count > 0)
                                             {
-                                                score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
-                                                if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
+                                                if (classResult.studentScores[index].Count > 0)
                                                 {
-                                                    if (classResult.studentScores[index][n] <= 0)
+                                                    score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
+                                                    if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
                                                     {
-                                                        phCount++;
+                                                        if (classResult.studentScores[index][n] <= 0)
+                                                        {
+                                                            phCount++;
+                                                        }
+                                                        phcount++;
+                                                        continue;
+                                                    }
+                                                    if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
+                                                    {
+                                                        if (classResult.studentScores[index][n] <= 0)
+                                                        {
+                                                            plCount++;
+                                                        }
+                                                        plcount++;
+                                                        continue;
                                                     }
-                                                    phcount++;
-                                                    continue;
-                                                }
-                                                if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
-                                                {
                                                     if (classResult.studentScores[index][n] <= 0)
                                                     {
-                                                        plCount++;
+                                                        pCount++;
                                                     }
-                                                    plcount++;
-                                                    continue;
-                                                }
-                                                if (classResult.studentScores[index][n] <= 0)
-                                                {
-                                                    pCount++;
                                                 }
                                             }
-                                        }
 
+                                        }
                                     }
+                                    n++;
                                 }
-                                n++;
+                                pc.Add(pCount);
+                                ph.Add(phCount);
+                                pl.Add(plCount);
+                                double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
+                                persent.Add(allScore > 0 ? per / allScore : 0);
                             }
-                            pc.Add(pCount);
-                            ph.Add(phCount);
-                            pl.Add(plCount);
-                            double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
-                            persent.Add(allScore > 0 ? per / allScore : 0);
+                            classResult.phc = ph;
+                            classResult.plc = pl;
+                            classResult.pc = pc;
+                            classResult.krate = persent;
                         }
-                        classResult.phc = ph;
-                        classResult.plc = pl;
-                        classResult.pc = pc;
-                        classResult.krate = persent;
+                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
                     }
-                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
                 }
+                
             }
             catch (Exception ex)
             {
@@ -657,53 +660,55 @@ namespace TEAMModelFunction
                             int phCount = 0;
                             int plCount = 0;
                             int pCount = 0;
-                            foreach (int str in info.papers[no].field)
-                            {
-                                if (str == knowledgeName[i])
+                            if (info.papers[no].field.Count > 0) {
+                                foreach (int str in info.papers[no].field)
                                 {
-                                    var itemPersent = 1;
-                                    allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
-                                    foreach (string id in classResult.studentIds)
+                                    if (str == knowledgeName[i])
                                     {
-                                        int index = classResult.studentIds.IndexOf(id);
-                                        if (classResult.studentScores.Count > 0)
+                                        var itemPersent = 1;
+                                        allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
+                                        foreach (string id in classResult.studentIds)
                                         {
-                                            if (classResult.studentScores[index].Count > 0)
+                                            int index = classResult.studentIds.IndexOf(id);
+                                            if (classResult.studentScores.Count > 0)
                                             {
-                                                score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
-                                                if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
+                                                if (classResult.studentScores[index].Count > 0)
                                                 {
-                                                    if (classResult.studentScores[index][n] <= 0)
+                                                    score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
+                                                    if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
                                                     {
-                                                        phCount++;
+                                                        if (classResult.studentScores[index][n] <= 0)
+                                                        {
+                                                            phCount++;
+                                                        }
+                                                        phcount++;
+                                                        continue;
+                                                    }
+                                                    if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
+                                                    {
+                                                        if (classResult.studentScores[index][n] <= 0)
+                                                        {
+                                                            plCount++;
+                                                        }
+                                                        plcount++;
+                                                        continue;
                                                     }
-                                                    phcount++;
-                                                    continue;
-                                                }
-                                                if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
-                                                {
                                                     if (classResult.studentScores[index][n] <= 0)
                                                     {
-                                                        plCount++;
+                                                        pCount++;
                                                     }
-                                                    plcount++;
-                                                    continue;
-                                                }
-                                                if (classResult.studentScores[index][n] <= 0)
-                                                {
-                                                    pCount++;
                                                 }
                                             }
                                         }
                                     }
+                                    n++;
                                 }
-                                n++;
-                            }
-                            pc.Add(pCount);
-                            ph.Add(phCount);
-                            pl.Add(plCount);
-                            double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
-                            persent.Add(allScore > 0 ? per / allScore : 0);
+                                pc.Add(pCount);
+                                ph.Add(phCount);
+                                pl.Add(plCount);
+                                double per = classResult.studentIds.Count > 0 ? Math.Round(score / classResult.studentIds.Count, 2) : 0;
+                                persent.Add(allScore > 0 ? per / allScore : 0);
+                            }                           
                         }
                         classResult.fphc = ph;
                         classResult.fplc = pl;