zhouj1203@hotmail.com 1 tahun lalu
induk
melakukan
25c0a081c2

+ 2 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerArt.cs

@@ -406,12 +406,13 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                                 Portrait portrait = new()
                                 Portrait portrait = new()
                                 {
                                 {
                                     schoolCode = art.school,
                                     schoolCode = art.school,
-                                    periodId = art.period.id,
+                                    periodId = art.period?.id,
                                     subjectId = "subject_art"
                                     subjectId = "subject_art"
                                 };
                                 };
                                 //var period = scInfo.period.Where(x => x.id.Equals(art.period.id)).FirstOrDefault();
                                 //var period = scInfo.period.Where(x => x.id.Equals(art.period.id)).FirstOrDefault();
                                 List<(string ptype, string subId, List<(string name, List<string> kno)> knos)> knoledge = new();
                                 List<(string ptype, string subId, List<(string name, List<string> kno)> knos)> knoledge = new();
                                 //List<string> subs = new List<string> { "subject_painting", "subject_music" };
                                 //List<string> subs = new List<string> { "subject_painting", "subject_music" };
+                                if (exams.Count == 0) return; 
                                 foreach (var ss in art.subjects)
                                 foreach (var ss in art.subjects)
                                 {
                                 {
                                     knoledge.Add(await getKnowledge(art.periodType, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].code, client, ss.id, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].periodId));
                                     knoledge.Add(await getKnowledge(art.periodType, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].code, client, ss.id, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].periodId));

+ 15 - 15
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -869,11 +869,11 @@ namespace TEAMModelOS.Controllers
                     {
                     {
                         perName = ptype,
                         perName = ptype,
                         name = x.Key,
                         name = x.Key,
-                        max = x.score.Max(s => s),
-                        min = x.score.Min(s => s),
-                        excellent = Math.Round(x.score.Where(s => s >= 80).Count() * 1.0 / x.count, 2),
-                        pass = Math.Round(x.score.Where(s => s >= 60).Count() * 1.0 / x.count, 2),
-                        average = Math.Round(x.score.Sum() * 1.0 / x.count, 2)
+                        max = x.score.Any() ? x.score.Max(s => s) : 0,
+                        min = x.score.Any() ? x.score.Min(s => s) : 0,
+                        excellent = x.score.Any() ? Math.Round(x.score.Where(s => s >= 80).Count() * 1.0 / x.count, 2) : 0,
+                        pass = x.score.Any() ? Math.Round(x.score.Where(s => s >= 60).Count() * 1.0 / x.count, 2) : 0,
+                        average = x.score.Any() ? Math.Round(x.score.Sum() * 1.0 / x.count, 2) : 0
                     });
                     });
                     var pschoolScore = psc.GroupBy(g => (g.code, g.artId, g.examId, g.classes)).Select(x => new
                     var pschoolScore = psc.GroupBy(g => (g.code, g.artId, g.examId, g.classes)).Select(x => new
                     {
                     {
@@ -895,11 +895,11 @@ namespace TEAMModelOS.Controllers
                         }).GroupBy(g => g.subjectId).Select(n => new
                         }).GroupBy(g => g.subjectId).Select(n => new
                         {
                         {
                             subjectId = n.Key,
                             subjectId = n.Key,
-                            max = n.ToList().SelectMany(c => c.scores).ToList().Max(s => s),
-                            min = n.ToList().SelectMany(c => c.scores).ToList().Min(s => s),
-                            excellent = Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 80).Count() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2),
-                            pass = Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 60).Count() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2),
-                            average = Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Sum() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2)
+                            max = n.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? n.ToList().SelectMany(c => c.scores).ToList().Max(s => s) : 0,
+                            min = n.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? n.ToList().SelectMany(c => c.scores).ToList().Min(s => s) : 0,
+                            excellent = n.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 80).Count() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2) : 0,
+                            pass = n.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 60).Count() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2): 0,
+                            average = n.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(n.ToList().SelectMany(c => c.scores).ToList().Sum() * 1.0 / n.ToList().SelectMany(c => c.scores).ToList().Count, 2) : 0
                         })
                         })
                     });
                     });
                     scCount = pschoolScore.Count();
                     scCount = pschoolScore.Count();
@@ -1285,11 +1285,11 @@ namespace TEAMModelOS.Controllers
             }).GroupBy(g => g.subjectId).Select(z => new
             }).GroupBy(g => g.subjectId).Select(z => new
             {
             {
                 name = z.Key,
                 name = z.Key,
-                max = z.ToList().SelectMany(c => c.scores).ToList().Max(s => s),
-                min = z.ToList().SelectMany(c => c.scores).ToList().Min(s => s),
-                excellent = Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 80).Count() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2),
-                pass = Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 60).Count() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2),
-                average = Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Sum() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2),
+                max = z.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? z.ToList().SelectMany(c => c.scores).ToList().Max(s => s) : 0,
+                min = z.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? z.ToList().SelectMany(c => c.scores).ToList().Min(s => s) : 0,
+                excellent = z.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 80).Count() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2) : 0,
+                pass = z.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Where(s => s >= 60).Count() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2) : 0,
+                average = z.ToList().SelectMany(c => c.scores).ToList().Count > 0 ? Math.Round(z.ToList().SelectMany(c => c.scores).ToList().Sum() * 1.0 / z.ToList().SelectMany(c => c.scores).ToList().Count, 2) : 0,
                 perName = periodType.GetString()
                 perName = periodType.GetString()
 
 
             });
             });