|
@@ -0,0 +1,264 @@
|
|
|
|
+using Azure.Cosmos;
|
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
|
|
+using DocumentFormat.OpenXml.Math;
|
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
+using NUnit.Framework.Constraints;
|
|
|
|
+using System;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using TEAMModelBI.Models;
|
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI.BITable;
|
|
|
|
+
|
|
|
|
+namespace TEAMModelBI.Tool.CosmosBank
|
|
|
|
+{
|
|
|
|
+ public static class StatsWay
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="cosmosClient"></param>
|
|
|
|
+ /// <param name="scId"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public static async Task<StatsInfo> upSingleSc(CosmosClient cosmosClient, string scId)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ StatsInfo statsInfo = new() { id = $"{scId}" };
|
|
|
|
+
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
|
+ var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
|
|
|
|
+ var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek"); //计算上周开始/结束时间
|
|
|
|
+ var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm"); //计算上学期开始/结束时间
|
|
|
|
+ var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term"); //计算本学期开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth"); //上月开始/结束时间
|
|
|
|
+ var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month"); //本月开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
|
|
|
|
+ var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year"); //计算今年开始/结束时间
|
|
|
|
+
|
|
|
|
+ string currSql = "select value(count(c.id)) from c";
|
|
|
|
+ string dayWhereSql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
|
|
|
|
+ string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
|
|
|
|
+ string monthWhereSql = $"c.createTime >= {mthS} and c.createTime <= {mthE}";
|
|
|
|
+
|
|
|
|
+ ScBase scBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<ScBase>(statsInfo.id, new PartitionKey("Base"));
|
|
|
|
+ statsInfo.name = scBase.name;
|
|
|
|
+ statsInfo.picture = scBase.picture;
|
|
|
|
+ statsInfo.size = scBase.size;
|
|
|
|
+ statsInfo.scCreateTime = scBase.createTime;
|
|
|
|
+
|
|
|
|
+ string tchSql = $"{currSql} where ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'";
|
|
|
|
+ statsInfo.tch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", tchSql, code: $"Teacher-{scBase.id}");
|
|
|
|
+ statsInfo.dayTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and {dayWhereSql} ", code: $"Teacher-{scBase.id}");
|
|
|
|
+ statsInfo.weekTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and {weekWhereSql}", code: $"Teacher-{scBase.id}");
|
|
|
|
+ statsInfo.monthTch = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{tchSql} and {monthWhereSql}", code: $"Teacher-{scBase.id}");
|
|
|
|
+
|
|
|
|
+ statsInfo.stu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", currSql, code: $"Base-{scBase.id}");
|
|
|
|
+ statsInfo.dayStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {dayWhereSql}", code: $"Base-{scBase.id}");
|
|
|
|
+ statsInfo.weekStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {weekWhereSql}", code: $"Base-{scBase.id}");
|
|
|
|
+ statsInfo.monthStu = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"{currSql} where {monthWhereSql}", code: $"Base-{scBase.id}");
|
|
|
|
+
|
|
|
|
+ statsInfo.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, code: $"Room-{scBase.id}");
|
|
|
|
+ statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)", code: $"Room-{scBase.id}");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ statsInfo.lesson = await GetLessStats(cosmosClient, statsInfo.id);
|
|
|
|
+ statsInfo.activity = await GetActStats(cosmosClient, statsInfo.id);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return statsInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 课例
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="cosmosClient"></param>
|
|
|
|
+ /// <param name="id"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public static async Task<LessonStats> GetLessStats(CosmosClient cosmosClient, string id)
|
|
|
|
+ {
|
|
|
|
+ LessonStats lessStats = new();
|
|
|
|
+
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
|
+
|
|
|
|
+ var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1)); //昨天开始时间
|
|
|
|
+ var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间
|
|
|
|
+
|
|
|
|
+ var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek"); //计算上周开始/结束时间
|
|
|
|
+ var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm"); //计算上学期开始/结束时间
|
|
|
|
+ var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term"); //计算本学期开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth"); //上月开始/结束时间
|
|
|
|
+ var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month"); //本月开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
|
|
|
|
+ var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year"); //计算今年开始/结束时间
|
|
|
|
+
|
|
|
|
+ string currSql = "select value(count(c.id)) from c where c.pk='LessonRecord'";
|
|
|
|
+ lessStats.open = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 0", code: $"LessonRecord-{id}");
|
|
|
|
+ lessStats.less = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} and c.upload = 1", code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ string lastDaySql = $"{currSql} and c.startTime >= {lastDayS} and c.startTime <= {lastDayS}";
|
|
|
|
+ lessStats.lastDay = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDaySql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string daySql = $"{currSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
|
|
|
|
+ lessStats.day = await JointlySingleQuery.GetValueInt(cosmosClient, "School", daySql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string lastWeekSql = $"{currSql} and c.startTime >= {lastWeekS} and c.startTime <= {lastWeekE}";
|
|
|
|
+ lessStats.lastWeek = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastWeekSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string weekSql = $"{currSql} and c.startTime >= {weekS} and c.startTime <= {weekE}";
|
|
|
|
+ lessStats.week = await JointlySingleQuery.GetValueInt(cosmosClient, "School", weekSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string lastTermSql = $"{currSql} and c.startTime >= {lastTermS} and c.startTime <= {lastTermE}";
|
|
|
|
+ lessStats.lastTerm = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastTermSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string termSql = $"{currSql} and c.startTime >= {termS} and c.startTime <= {termE}";
|
|
|
|
+ lessStats.term = await JointlySingleQuery.GetValueInt(cosmosClient, "School", termSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ string InterSql = "select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
|
|
|
|
+ string lastDayInterSql = $"{InterSql} and c.startTime >= {lastDayS} and c.startTime <= {lastdayE}";
|
|
|
|
+ lessStats.lastDayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastDayInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string dayInterSql = $"{InterSql} and c.startTime >= {dayS} and c.startTime <= {dayE}";
|
|
|
|
+ lessStats.dayInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", dayInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string lastMthInterSql = $"{InterSql} and c.startTime >= {lastMthS} and c.startTime <= {LastmthE}";
|
|
|
|
+ lessStats.lastMonthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastMthInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string mthInterSql = $"{InterSql} and c.startTime >= {mthS} and c.startTime <= {mthE}";
|
|
|
|
+ lessStats.monthInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", mthInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string lastYearInterSql = $"{InterSql} and c.startTime >= {lastYearS} and c.startTime <= {lastYearE}";
|
|
|
|
+ lessStats.lastYearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", lastYearInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+ string yearInterSql = $"{InterSql} and c.startTime >= {yearS} and c.startTime <= {yearE}";
|
|
|
|
+ lessStats.yearInter = await JointlySingleQuery.GetValueInt(cosmosClient, "School", yearInterSql, code: $"LessonRecord-{id}");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return lessStats;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 统计学校活动
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="cosmosClient"></param>
|
|
|
|
+ /// <param name="scId"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public static async Task<ActivityStats> GetActStats(CosmosClient cosmosClient, string scId)
|
|
|
|
+ {
|
|
|
|
+ ActivityStats actStats = new();
|
|
|
|
+
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
|
+
|
|
|
|
+ var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1)); //昨天开始时间
|
|
|
|
+ var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间
|
|
|
|
+
|
|
|
|
+ var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek"); //计算上周开始/结束时间
|
|
|
|
+ var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
|
|
|
|
+
|
|
|
|
+ var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm"); //计算上学期开始/结束时间
|
|
|
|
+ var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term"); //计算本学期开始/结束时间
|
|
|
|
+
|
|
|
|
+ string currSql = "select value(count(c.id)) from c ";
|
|
|
|
+ int exam = 0;
|
|
|
|
+ int survey = 0;
|
|
|
|
+ int vote = 0;
|
|
|
|
+ int homework = 0;
|
|
|
|
+
|
|
|
|
+ int lastDay = 0;
|
|
|
|
+ int dayCnt = 0;
|
|
|
|
+ int lastWeek = 0;
|
|
|
|
+ int week = 0;
|
|
|
|
+ int lastTerm = 0;
|
|
|
|
+ int term = 0;
|
|
|
|
+
|
|
|
|
+ string lastDaySql = $"c.createTime >= {lastDayS} and c.createTime <= {lastdayE}";
|
|
|
|
+ string daySql = $"c.createTime >= {dayS} and c.createTime <= {dayE}";
|
|
|
|
+ string lastWeekSql = $"c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE}";
|
|
|
|
+ string weekSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
|
|
|
|
+ string lastTermSql = $"c.createTime >= {lastTermS} and c.createTime <= {lastTermE}";
|
|
|
|
+ string termSql = $"c.createTime >= {termS} and c.createTime <= {termE}";
|
|
|
|
+ foreach (var type in StaticValue.activityTypes)
|
|
|
|
+ {
|
|
|
|
+ switch (type)
|
|
|
|
+ {
|
|
|
|
+ case "Exam":
|
|
|
|
+ exam += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam'", code: $"Exam-{scId}");
|
|
|
|
+ lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastDaySql}", code: $"Exam-{scId}");
|
|
|
|
+ dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {daySql}", code: $"Exam-{scId}");
|
|
|
|
+ lastWeek+= await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastWeekSql}", code: $"Exam-{scId}");
|
|
|
|
+ week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {weekSql}", code: $"Exam-{scId}");
|
|
|
|
+ lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {lastTermSql}", code: $"Exam-{scId}");
|
|
|
|
+ term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Exam' and {termSql}", code: $"Exam-{scId}");
|
|
|
|
+ break;
|
|
|
|
+ case "Survey":
|
|
|
|
+ survey += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey'", code: $"Survey-{scId}");
|
|
|
|
+ lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastDaySql}", code: $"Survey-{scId}");
|
|
|
|
+ dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {daySql}", code: $"Survey-{scId}");
|
|
|
|
+ lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastWeekSql}", code: $"Survey-{scId}");
|
|
|
|
+ week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {weekSql}", code: $"Survey-{scId}");
|
|
|
|
+ lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {lastTermSql}", code: $"Survey-{scId}");
|
|
|
|
+ term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Survey' and {termSql}", code: $"Survey-{scId}");
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ case "Vote":
|
|
|
|
+ vote += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote'", code: $"Vote-{scId}");
|
|
|
|
+ lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastDaySql}", code: $"Vote-{scId}");
|
|
|
|
+ dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {daySql}", code: $"Vote-{scId}");
|
|
|
|
+ lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastWeekSql}", code: $"Vote-{scId}");
|
|
|
|
+ week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {weekSql}", code: $"Vote-{scId}");
|
|
|
|
+ lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {lastTermSql}", code: $"Vote-{scId}");
|
|
|
|
+ term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Vote' and {termSql}", code: $"Vote-{scId}");
|
|
|
|
+ break;
|
|
|
|
+ case "Homework":
|
|
|
|
+ homework += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework'", code: $"Homework-{scId}");
|
|
|
|
+ lastDay += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastDaySql}", code: $"Homework-{scId}");
|
|
|
|
+ dayCnt += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {daySql}", code: $"Homework-{scId}");
|
|
|
|
+ lastWeek += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastWeekSql}", code: $"Homework-{scId}");
|
|
|
|
+ week += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {weekSql}", code: $"Homework-{scId}");
|
|
|
|
+ lastTerm += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {lastTermSql}", code: $"Homework-{scId}");
|
|
|
|
+ term += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{currSql} where c.pk='Homework' and {termSql}", code: $"Homework-{scId}");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ actStats.cnt = (exam + survey + vote + homework);
|
|
|
|
+ actStats.exam = exam;
|
|
|
|
+ actStats.survey = survey;
|
|
|
|
+ actStats.vote = vote;
|
|
|
|
+ actStats.homework = homework;
|
|
|
|
+ actStats.lastDay = lastDay;
|
|
|
|
+ actStats.dayCnt = dayCnt;
|
|
|
|
+ actStats.lastWeek = lastWeek;
|
|
|
|
+ actStats.week = week;
|
|
|
|
+ actStats.lastTerm = lastTerm;
|
|
|
|
+ actStats.term = term;
|
|
|
|
+
|
|
|
|
+ return actStats;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static async Task<StudyStats> GetStudyStats(CosmosClient cosmosClient, string scId)
|
|
|
|
+ {
|
|
|
|
+ StudyStats studyStats = new();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return studyStats;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|