Ver código fonte

產品分析 IOT統計API 欄位計算方式修正

jeff 2 anos atrás
pai
commit
08eafd7c7f

+ 5 - 0
TEAMModelOS.SDK/Models/Cosmos/School/ProductAnalysis.cs

@@ -110,6 +110,7 @@ namespace TEAMModelOS.SDK.Models
         public int deviceCnt { get; set; } //機器數(不重複)
         public int deviceNoAuth { get; set; } //無機器授權數
         public int deviceAuth { get; set; } //有安裝機器授權數
+        public int tmidCnt { get; set; } //TMID數(不重複)
         public int lessonRecord { get; set; } //課堂記錄數
         public int useIES { get; set; } //使用IES課程
         public int useIES5Resource { get; set; } //課堂中取用IES5資源數
@@ -143,9 +144,13 @@ namespace TEAMModelOS.SDK.Models
         public ProdAnalysis()
         {
             deviceList = new List<string>();
+            deviceNoAuthList = new List<string>();
+            deviceAuthList = new List<string>();
             tmidList = new List<string>();
         }
         public List<string> deviceList { get; set; } //機器ID列表
+        public List<string> deviceNoAuthList { get; set; } //無機器授權ID列表
+        public List<string> deviceAuthList { get; set; } //有安裝機器授權ID列表
         public List<string> tmidList { get; set; } //TMID列表
     }
 

+ 34 - 6
TEAMModelOS.SDK/Models/Service/BI/BIProdAnalysis.cs

@@ -39,7 +39,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                 var redisClinet8 = _azureRedis.GetRedisClient(8);
                 var datetime = DateTimeOffset.UtcNow;
                 var ynow = datetime.Year;
-                List<string> calPropList = new List<string>() { "deviceNoAuth", "deviceAuth", "lessonRecord", "useIES", "useIES5Resource", "useWebIrs", "useDeviceIrs", "useHaboard", "useHita", "lessonLengMin", "stuShow", "stuLessonLengMin", "tGreen", "lTypeCoop", "lTypeIact", "lTypeMis", "lTypeTst", "lTypeDif", "lessonCnt928", "lessonCntId", "lessonCntDevice", "lessonCntIdDevice", "mission", "missionFin", "item", "interact" }; //要計算的ProdAnalysis欄位列表
+                List<string> calPropList = new List<string>() { "lessonRecord", "useIES", "useIES5Resource", "useWebIrs", "useDeviceIrs", "useHaboard", "useHita", "lessonLengMin", "stuShow", "stuLessonLengMin", "tGreen", "lTypeCoop", "lTypeIact", "lTypeMis", "lTypeTst", "lTypeDif", "lessonCnt928", "lessonCntId", "lessonCntDevice", "lessonCntIdDevice", "mission", "missionFin", "item", "interact" }; //要計算的ProdAnalysis欄位列表
                 //取得CS Redis TeachingData (IOT紀錄只有三個月分)
                 List<IotTeachingData> IotTeachingDataList = new List<IotTeachingData>();
                 if (y.Equals(ynow.ToString()))
@@ -126,29 +126,32 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             switch (IotTeachingDatRow.authType)
                             {
                                 case "0": //928授權
-                                    prodAnalysisRow.deviceNoAuth++;
+                                    if (!prodAnalysisRow.deviceNoAuthList.Contains(IotTeachingDatRow.deviceId)) prodAnalysisRow.deviceNoAuthList.Add(IotTeachingDatRow.deviceId);
                                     prodAnalysisRow.lessonCnt928++;
                                     break;
 
                                 case "1": //ID授權
-                                    prodAnalysisRow.deviceNoAuth++;
+                                    if (!prodAnalysisRow.deviceNoAuthList.Contains(IotTeachingDatRow.deviceId)) prodAnalysisRow.deviceNoAuthList.Add(IotTeachingDatRow.deviceId);
                                     prodAnalysisRow.lessonCntId++;
                                     break;
 
                                 case "2": //機器授權
-                                    prodAnalysisRow.deviceAuth++;
+                                    if (!prodAnalysisRow.deviceAuthList.Contains(IotTeachingDatRow.deviceId)) prodAnalysisRow.deviceAuthList.Add(IotTeachingDatRow.deviceId);
                                     prodAnalysisRow.lessonCntDevice++;
                                     break;
 
                                 case "3": //ID+機器授權
-                                    prodAnalysisRow.deviceAuth++;
+                                    if (!prodAnalysisRow.deviceAuthList.Contains(IotTeachingDatRow.deviceId)) prodAnalysisRow.deviceAuthList.Add(IotTeachingDatRow.deviceId);
                                     prodAnalysisRow.lessonCntIdDevice++;
                                     break;
                             }
+                            prodAnalysisRow.deviceNoAuth = prodAnalysisRow.deviceNoAuthList.Count;
+                            prodAnalysisRow.deviceAuth = prodAnalysisRow.deviceAuthList.Count;
                             if (!string.IsNullOrWhiteSpace(IotTeachingDatRow.tmid) && !prodAnalysisRow.tmidList.Contains(IotTeachingDatRow.tmid))
                             {
                                 prodAnalysisRow.tmidList.Add(IotTeachingDatRow.tmid);
                             }
+                            prodAnalysisRow.tmidCnt = prodAnalysisRow.tmidList.Count;
                             prodAnalysisRow.lessonRecord++;
                             if (IotTeachingDatRow.useIES.Equals("1")) prodAnalysisRow.useIES++;
                             prodAnalysisRow.useIES5Resource += IotTeachingDatRow.useIES5Resource;
@@ -158,7 +161,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             if (IotTeachingDatRow.useHita.Equals("1")) prodAnalysisRow.useHita++;
                             prodAnalysisRow.lessonLengMin += IotTeachingDatRow.lessonLengMin;
                             prodAnalysisRow.stuShow += IotTeachingDatRow.stuShow;
-                            prodAnalysisRow.stuLessonLengMin = prodAnalysisRow.lessonLengMin * prodAnalysisRow.stuShow;
+                            prodAnalysisRow.stuLessonLengMin += IotTeachingDatRow.lessonLengMin * IotTeachingDatRow.stuShow;
                             if (IotTeachingDatRow.tPoint >= 70) prodAnalysisRow.tGreen++;
                             if (IotTeachingDatRow.lTypeCoop.Equals("1")) prodAnalysisRow.lTypeCoop++;
                             if (IotTeachingDatRow.lTypeIact.Equals("1")) prodAnalysisRow.lTypeIact++;
@@ -259,7 +262,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             cosmosAllSchSumDay.dateTime = dateTime.ToUnixTimeSeconds();
                             cosmosAllSchSumDay.deviceList = cosmosAllSchSumDay.deviceList.Union(cosmosSchRow.deviceList).ToList();
                             cosmosAllSchSumDay.deviceCnt = cosmosAllSchSumDay.deviceList.Count;
+                            cosmosAllSchSumDay.deviceAuthList = cosmosAllSchSumDay.deviceAuthList.Union(cosmosSchRow.deviceAuthList).ToList();
+                            cosmosAllSchSumDay.deviceAuth = cosmosAllSchSumDay.deviceAuthList.Count;
+                            cosmosAllSchSumDay.deviceNoAuthList = cosmosAllSchSumDay.deviceNoAuthList.Union(cosmosSchRow.deviceNoAuthList).ToList();
+                            cosmosAllSchSumDay.deviceNoAuth = cosmosAllSchSumDay.deviceNoAuthList.Count;
                             cosmosAllSchSumDay.tmidList = cosmosAllSchSumDay.tmidList.Union(cosmosSchRow.tmidList).ToList();
+                            cosmosAllSchSumDay.tmidCnt = cosmosAllSchSumDay.tmidList.Count;
                             if (cosmosAllSchSumDayDic.ContainsKey(toolType)) cosmosAllSchSumDayDic[toolType] = cosmosAllSchSumDay;
                             else cosmosAllSchSumDayDic.Add(toolType, cosmosAllSchSumDay);
                         }
@@ -327,7 +335,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                         }
                                         SchDataNow.deviceList = SchDataNow.deviceList.Union(SchDataTodo.deviceList).ToList();
                                         SchDataNow.deviceCnt = SchDataNow.deviceList.Count;
+                                        SchDataNow.deviceAuthList = SchDataNow.deviceAuthList.Union(SchDataTodo.deviceAuthList).ToList();
+                                        SchDataNow.deviceAuth = SchDataNow.deviceAuthList.Count;
+                                        SchDataNow.deviceNoAuthList = SchDataNow.deviceNoAuthList.Union(SchDataTodo.deviceNoAuthList).ToList();
+                                        SchDataNow.deviceNoAuth = SchDataNow.deviceNoAuthList.Count;
                                         SchDataNow.tmidList = SchDataNow.tmidList.Union(SchDataTodo.tmidList).ToList();
+                                        SchDataNow.tmidCnt = SchDataNow.tmidList.Count;
                                     }
                                     //無此校資料 => 該校資料放入
                                     else
@@ -405,7 +418,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             cosmosAllSchSumMonth.dateTime = dateTime.ToUnixTimeSeconds();
                             cosmosAllSchSumMonth.deviceList = cosmosAllSchSumMonth.deviceList.Union(cosmosSchRow.deviceList).ToList();
                             cosmosAllSchSumMonth.deviceCnt = cosmosAllSchSumMonth.deviceList.Count;
+                            cosmosAllSchSumMonth.deviceAuthList = cosmosAllSchSumMonth.deviceAuthList.Union(cosmosSchRow.deviceAuthList).ToList();
+                            cosmosAllSchSumMonth.deviceAuth = cosmosAllSchSumMonth.deviceAuthList.Count;
+                            cosmosAllSchSumMonth.deviceNoAuthList = cosmosAllSchSumMonth.deviceNoAuthList.Union(cosmosSchRow.deviceNoAuthList).ToList();
+                            cosmosAllSchSumMonth.deviceNoAuth = cosmosAllSchSumMonth.deviceNoAuthList.Count;
                             cosmosAllSchSumMonth.tmidList = cosmosAllSchSumMonth.tmidList.Union(cosmosSchRow.tmidList).ToList();
+                            cosmosAllSchSumMonth.tmidCnt = cosmosAllSchSumMonth.tmidList.Count;
                             if (cosmosAllSchSumMonthDic.ContainsKey(toolType)) cosmosAllSchSumMonthDic[toolType] = cosmosAllSchSumMonth;
                             else cosmosAllSchSumMonthDic.Add(toolType, cosmosAllSchSumMonth);
                         }
@@ -451,7 +469,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                     }
                                     SchDataNow.deviceList = SchDataNow.deviceList.Union(SchDataTodo.deviceList).ToList();
                                     SchDataNow.deviceCnt = SchDataNow.deviceList.Count;
+                                    SchDataNow.deviceAuthList = SchDataNow.deviceAuthList.Union(SchDataTodo.deviceAuthList).ToList();
+                                    SchDataNow.deviceAuth = SchDataNow.deviceAuthList.Count;
+                                    SchDataNow.deviceNoAuthList = SchDataNow.deviceNoAuthList.Union(SchDataTodo.deviceNoAuthList).ToList();
+                                    SchDataNow.deviceNoAuth = SchDataNow.deviceNoAuthList.Count;
                                     SchDataNow.tmidList = SchDataNow.tmidList.Union(SchDataTodo.tmidList).ToList();
+                                    SchDataNow.tmidCnt = SchDataNow.tmidList.Count;
                                 }
                                 //無此校資料 => 該校資料放入
                                 else
@@ -519,7 +542,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             SchDataNow.dateTime = dateTime.ToUnixTimeSeconds();
                             SchDataNow.deviceList = SchDataNow.deviceList.Union(yearCosmosSchData.deviceList).ToList();
                             SchDataNow.deviceCnt = SchDataNow.deviceList.Count;
+                            SchDataNow.deviceAuthList = SchDataNow.deviceAuthList.Union(yearCosmosSchData.deviceAuthList).ToList();
+                            SchDataNow.deviceAuth = SchDataNow.deviceAuthList.Count;
+                            SchDataNow.deviceNoAuthList = SchDataNow.deviceNoAuthList.Union(yearCosmosSchData.deviceNoAuthList).ToList();
+                            SchDataNow.deviceNoAuth = SchDataNow.deviceNoAuthList.Count;
                             SchDataNow.tmidList = SchDataNow.tmidList.Union(yearCosmosSchData.tmidList).ToList();
+                            SchDataNow.tmidCnt = SchDataNow.tmidList.Count;
                         }
                         await _azureCosmosClient.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ProdAnalysisCosmos>(SchDataNow);
                     }