|
@@ -1757,6 +1757,164 @@ namespace TEAMModelBI.Controllers.BITest
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public async Task<IActionResult> SetStatsZero()
|
|
|
+ {
|
|
|
+
|
|
|
+ return Ok(new { });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 每天00:00执行统计清零方法;zore时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="_azureCosmos"></param>
|
|
|
+ /// <param name="_dingDing"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task SetStatsZeroPoint(AzureCosmosFactory _azureCosmos,DingDing _dingDing)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ DateTimeOffset dateOff = DateTimeOffset.UtcNow;
|
|
|
+ long upTime = dateOff.ToUnixTimeMilliseconds();
|
|
|
+ var (DayS, DayE) = TimeHelper.GetStartOrEnd(dateOff); //今天开始时间结束时间
|
|
|
+ var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateOff, "lastweek"); //计算上周开始/结束时间
|
|
|
+ var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateOff, "week"); //计算本周开始/结束时间
|
|
|
+ var (lastMonthS, lastMonthE) = TimeHelper.GetStartOrEnd(dateOff, "lastMonth"); //上月开始/结束时间
|
|
|
+ var (monthS, monthE) = TimeHelper.GetStartOrEnd(dateOff, "month"); //本月开始/结束时间
|
|
|
+ var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateOff, "lastterm"); //计算上学期开始/结束时间
|
|
|
+ var (termS, termE) = TimeHelper.GetStartOrEnd(dateOff, "term"); //计算本学期开始/结束时间
|
|
|
+
|
|
|
+ var (weekDayS, weekDayE) = TimeHelper.GetLongToTime(weekS, weekE);
|
|
|
+ var (lWeekDayS, lWeekDayE) = TimeHelper.GetLongToTime(lastWeekS, lastWeekE);
|
|
|
+ var (lTermDayS, lTermDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
|
|
|
+ var (termDayS, termDayE) = TimeHelper.GetLongToTime(lastTermS, lastTermE);
|
|
|
+ var (lMonthS, lMonthE) = TimeHelper.GetLongToTime(lastMonthS, lastMonthE);
|
|
|
+ var (monthDayS, monthDayE) = TimeHelper.GetLongToTime(monthS, monthE);
|
|
|
+ var lastDay = dateOff.AddDays(-1);
|
|
|
+ int lmthDay = TimeHelper.GetDateDay(lMonthE);
|
|
|
+
|
|
|
+ int termDay = 0;
|
|
|
+
|
|
|
+ List<Task<ItemResponse<StatsInfo>>> statsInfos = new();
|
|
|
+ List<StatsInfo> tempStatsInfos = new();
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<StatsInfo>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
|
|
|
+ {
|
|
|
+ tempStatsInfos.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tempStatsInfos.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in tempStatsInfos)
|
|
|
+ {
|
|
|
+ if (termDayE.Year == dateOff.Year)
|
|
|
+ termDay = dateOff.DayOfYear;
|
|
|
+ else
|
|
|
+ termDay = item.activity.year.Count;
|
|
|
+ StatsInfo lastStatsInfo = null;
|
|
|
+
|
|
|
+ var lastSts = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{dateOff.Year - 1}-{item.schoolId}", new PartitionKey("Statistics"));
|
|
|
+ if (lastSts.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(lastSts.ContentStream);
|
|
|
+ lastStatsInfo = fileJson.ToObject<StatsInfo>();
|
|
|
+ }
|
|
|
+
|
|
|
+ var tchList = DenseMatrix.OfColumns(new List<List<double>>() { item.tchYear });
|
|
|
+ item.dayTch = ((int)item.tchYear[lastDay.DayOfYear]);
|
|
|
+ item.weekTch = ((int)tchList.SubMatrix(weekDayS.DayOfYear, 7, 0, tchList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.monthTch = ((int)tchList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, tchList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.tchUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+
|
|
|
+ var stuList = DenseMatrix.OfColumns(new List<List<double>>() { item.stuYear });
|
|
|
+ item.dayStu = ((int)item.stuYear[lastDay.DayOfYear]);
|
|
|
+ item.weekStu = ((int)stuList.SubMatrix(weekDayS.DayOfYear, 7, 0, stuList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.monthStu = ((int)stuList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, stuList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.stuUpTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+
|
|
|
+ var lessList = DenseMatrix.OfColumns(new List<List<double>>() { item.lesson.year });
|
|
|
+ item.lesson.lastDay = item.lesson.day;
|
|
|
+ item.lesson.lastWeek = ((int)lessList.SubMatrix(lWeekDayS.DayOfYear, 7, 0, lessList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.lesson.week = ((int)lessList.SubMatrix(weekDayS.DayOfYear, 7, 0, lessList.ColumnCount).ColumnSums().Sum());
|
|
|
+
|
|
|
+ if (lTermDayS.Year < dateOff.Year)
|
|
|
+ {
|
|
|
+ if (lastStatsInfo != null)
|
|
|
+ {
|
|
|
+ var lessYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.lesson.year, item.lesson.year });
|
|
|
+ item.lesson.lastTerm = ((int)lessYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.lesson.term = ((int)lessList.SubMatrix(termDayS.DayOfYear, termDay, 0, 1).ColumnSums().Sum());
|
|
|
+
|
|
|
+ item.lesson.day = 0;
|
|
|
+ item.lesson.lastMonth = ((int)lessList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, lessList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.lesson.month += ((int)lessList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, lessList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.lesson.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+
|
|
|
+ var interList = DenseMatrix.OfColumns(new List<List<double>>() { item.lesson.yearInters });
|
|
|
+ item.lesson.lastDayInter = ((int)item.lesson.yearInters[lastDay.DayOfYear]);
|
|
|
+ item.lesson.dayInter = 0;
|
|
|
+ item.lesson.lastMonthInter = ((int)interList.SubMatrix(lMonthS.DayOfYear, lmthDay, 0, interList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.lesson.monthInter = ((int)interList.SubMatrix(monthDayS.DayOfYear, (dateOff.DayOfYear - monthDayS.DayOfYear), 0, interList.ColumnCount).ColumnSums().Sum());
|
|
|
+
|
|
|
+ if (lastStatsInfo != null)
|
|
|
+ {
|
|
|
+ var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.lesson.yearInters });
|
|
|
+ item.lesson.lastYearInter = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, 366, 0, 1).ColumnSums().Sum());
|
|
|
+ }
|
|
|
+
|
|
|
+ item.lesson.yearInter = ((int)item.lesson.yearInters.Sum());
|
|
|
+
|
|
|
+ item.activity.dayCnt = ((int)item.activity.year[dateOff.DayOfYear]);
|
|
|
+ item.activity.lastDay = ((int)item.activity.year[lastDay.DayOfYear]);
|
|
|
+ var actList = DenseMatrix.OfColumns(new List<List<double>>() { item.activity.year });
|
|
|
+ item.activity.lastWeek = ((int)actList.SubMatrix(lWeekDayS.DayOfYear, 7, 0, actList.ColumnCount).ColumnSums().Sum());
|
|
|
+ item.activity.week = ((int)actList.SubMatrix(weekDayS.DayOfYear, 7, 0, actList.ColumnCount).ColumnSums().Sum());
|
|
|
+
|
|
|
+ if (lMonthS.Year == dateOff.Year)
|
|
|
+ item.activity.lastMonth = ((int)actList.SubMatrix(lMonthS.DayOfYear, lMonthE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var lastMthYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.activity.year });
|
|
|
+ item.activity.lastMonth = ((int)lastMthYer.SubMatrix(lMonthS.DayOfYear, lMonthE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
|
|
|
+ }
|
|
|
+
|
|
|
+ item.activity.month = ((int)actList.SubMatrix(monthDayS.DayOfYear, monthDayE.DayOfYear, 0, actList.ColumnCount).ColumnSums().Sum());
|
|
|
+
|
|
|
+ if (lastStatsInfo != null)
|
|
|
+ {
|
|
|
+ var actYer = DenseMatrix.OfColumns(new List<List<double>>() { lastStatsInfo.activity.year });
|
|
|
+ item.activity.lastTerm = ((int)actYer.SubMatrix(lTermDayS.DayOfYear, lTermDayE.DayOfYear, 0, 1).ColumnSums().Sum());
|
|
|
+ }
|
|
|
+
|
|
|
+ item.activity.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+
|
|
|
+
|
|
|
+ statsInfos.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<StatsInfo>(item, item.id, new PartitionKey("Statistics")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (statsInfos.Count < 256)
|
|
|
+ await Task.WhenAll(statsInfos);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (statsInfos.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<StatsInfo>>> itemResponses = statsInfos.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(itemResponses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI, SetStatsZeroPoint() \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 测试依据类型增/减量统计方法
|
|
|
/// </summary>
|