12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976 |
- using Azure.Storage.Blobs.Models;
- using DocumentFormat.OpenXml.Bibliography;
- using DocumentFormat.OpenXml.Office2010.Excel;
- using DocumentFormat.OpenXml.Wordprocessing;
- using HTEXLib;
- using HTEXLib.COMM.Helpers;
- using Microsoft.Azure.Amqp.Framing;
- using Newtonsoft.Json.Linq;
- using OpenXmlPowerTools;
- using StackExchange.Redis;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Diagnostics.PerformanceData;
- using System.IdentityModel.Tokens.Jwt;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Dtos;
- using static Azure.Core.HttpHeader;
- using static OpenXmlPowerTools.RevisionProcessor;
- using static TEAMModelOS.SDK.Models.Service.SystemService;
- namespace TEAMModelOS.SDK.Models.Service
- {
- public static class SystemService
- {
- static string cn_wb = @"
- IES晚报:
- 尊敬的{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime},您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
- 以下是报告的具体详细信息。
- 评测任务提交详情:
- {examList}
- 课堂教学出席详情:
- {lessonList}
- 个人课程名单变化详情:
- {cn_grouplistJoin}
- {cn_grouplistLeave}
- 如有布置作业任务,将于次日8点通过早报方式发送。
- ";
- static string cn_examList = "{examName}已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
- static string cn_lessonList = "{lessonName}课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}。";
- static string cn_grouplistJoin = "{grouplistName}已有总人数{memberCount},有{joinCount}加入。";
- static string cn_grouplistLeave = "{grouplistName}已有总人数{memberCount},有{joinCount}离开。";
- static string cn_zb = @"
- IES早报:
- 尊敬的{tmdname}您好,以下是您发布过的作业任务汇总报告。
- 以下是报告的具体详细信息。
- 作业任务提交详情:
- {cn_homeworkList}
- ";
- static string cn_homeworkList = "{homeworkName}已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
- public static async Task AccumulateDaily(AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos,CoreAPIHttpService coreAPIHttpService, DingDing dingDing)
- {
- DateTimeOffset now = DateTimeOffset.UtcNow;
- string day = now.ToString("yyyyMMdd");
- string homeworkYesterday = now.AddDays(-1).ToString("yyyyMMdd");
- List<string> keys = new List<string>();
- //当天评测发布的。
- //当天的个人评测提交数
- Dictionary<string, double?> exam_submit = new();
- SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-going:{day}");
- // Dictionary<string, double?> exam_going = new();
- if (exam_goingScores != null)
- {
- foreach (var score in exam_goingScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- // exam_going.Add(key, val);
- exam_submit.Add(key, val);
- keys.Add(key);
- }
- }
-
-
- ///需要再次获取 没有任何人提交的作业和评测任务。
- SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
- if (exam_submitScores != null)
- {
- foreach (var score in exam_submitScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- exam_submit.Add(key, val);
- keys.Add(key);
- }
- }
-
- //昨天发布的作业
- SortedSetEntry[] homework_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{homeworkYesterday}");
- Dictionary<string, double?> homework_submit = new();
- //Dictionary<string, double?> homework_going = new();
- if (homework_goingScores != null)
- {
- foreach (var score in homework_goingScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- //homework_going.Add(key, val);
- homework_submit.Add(key, val);
- keys.Add(key);
-
- }
- }
- //昨天的个人作业提交数
- SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{homeworkYesterday}");
-
- if (homework_submitScores != null)
- {
- foreach (var score in homework_submitScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- homework_submit.Add(key, val);
- keys.Add(key);
- }
- }
- //当天的个人名单加入人数
- Dictionary<string, double?> grouplist = new();
- SortedSetEntry[] grouplistScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:grouplist:{day}");
- if (grouplistScores != null)
- {
- foreach (var score in grouplistScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- grouplist.Add(key, val);
- keys.Add(key);
- }
- }
- //当天教师的开课数量Accumulate:Daily:teacher:lesson-create:20240527
- Dictionary<string, double?> lessoncreate = new();
- SortedSetEntry[] llessoncreateScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:lesson-create:{day}");
- if (llessoncreateScores != null)
- {
- foreach (var score in llessoncreateScores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- lessoncreate.Add(key, val);
- keys.Add(key);
- }
- }
- List<string> ids = new List<string>();
- keys.ForEach(x => {
- ids.Add(x.Split("::")[0]);
- });
- List<Teacher> teachers= new List<Teacher>();
- if (ids.IsNotEmpty())
- {
- string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
- if (result.list.IsNotEmpty())
- {
- teachers.AddRange(result.list);
- }
- }
- foreach (var teacher in teachers)
- {
- int examCount = 0,homeworkCount=0,lessonCount=0;
- StringBuilder examSB= new StringBuilder();
- foreach (var exam in exam_submit)
- {
- int sendTime = 20;
- string[] ks = exam.Key.Split("::");
- string tid = ks[0];
- string examId = ks[1];
- string examName = ks[3];
- if (tid.Equals(teacher.id)) {
- var tzt = now.GetGMTTime((int)teacher.timezone);
- if (tzt.Hour==sendTime)
- {
- string sql = $"select c.status from c where c.examId='{examId}' and c.pk='ExamClassResult'";
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamClassResult>("", $"ExamClassResult-{tid}");
- if (result.list.IsNotEmpty()) {
- var unsubmit = result.list.SelectMany(x => x.status).Where(x => x==1);
- var submit = result.list.SelectMany(x => x.status).Where(x => x==0);
- examCount++;
- examSB.Append(cn_examList.Replace("{examName}",examName).Replace("{submitCount}",$"{submit}").Replace("{unsubmitCount}",$"{unsubmit}"));
- }
- }
- }
- }
- foreach (var homework in homework_submit)
- {
- int sendTime = 8;
- string[] ks = homework.Key.Split("::");
- string tid = ks[0];
- string examId = ks[1];
- string examName = ks[3];
- if (tid.Equals(teacher.id))
- {
- var tzt = now.GetGMTTime((int)teacher.timezone);
- if (tzt.Hour==sendTime)
- {
- string sql = $"select c.status from c where c.examId='{examId}' and c.pk='ExamClassResult'";
- }
- }
- }
- }
- }
- public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, DingDing dingDing, Accumulate accumulate)
- {
- if (!string.IsNullOrWhiteSpace(accumulate.key) && !string.IsNullOrWhiteSpace(accumulate.target) &&
- !string.IsNullOrWhiteSpace(accumulate.id) && !string.IsNullOrWhiteSpace(accumulate.name) &&
- !string.IsNullOrWhiteSpace(accumulate.scope) && !string.IsNullOrWhiteSpace(accumulate.client))
- {
- await RecordAccumulateData(azureRedis, accumulate.key, accumulate.target, accumulate.id, accumulate.name, accumulate.scope, accumulate.client, accumulate.count);
- }
- else
- {
- await dingDing.SendBotMsg($"IES累计数据变更统计参数异常,{accumulate.ToJsonString()}", GroupNames.成都开发測試群組);
- }
- }
- /// <summary>
- /// 记录累计数据
- /// </summary>
- public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, string key, string target, string id, string name, string scope, string client, int count)
- {
- if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(target) &&
- !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) &&
- !string.IsNullOrWhiteSpace(scope)&& !string.IsNullOrWhiteSpace(client))
- {
- //处理UTC时差
- var nowTime = DateTimeOffset.UtcNow.GetGMTTime();
- int difference = (DayOfWeek.Sunday - nowTime.DayOfWeek + 7) % 7; //1-7的结果0-6
- var day = nowTime.ToString("yyyyMMdd");
- string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
- string member = $"{target}::{id}::{client}::{name}";
- await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
- await azureRedis.GetRedisClient(8).KeyExpireAsync(redisKey, new TimeSpan((difference+1)*24, 10, 0));
- //if (key.Equals("lesson") || key.StartsWith("login_"))
- //{
- // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
- // if (scope.Equals("school"))
- // {
- // member = $"ies::{id}::{name}";
- // }
- // else {
- // member = $"ies::ies::{name}";
- // }
- // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
- //}
- }
- }
- static double GetUserDuration(List<long> times )
- {
- if (times.IsNotEmpty())
- {
- if (times.Count>=2)
- {
- double totalDuration = 0;
- // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
- long ltime = times[0];
- for (int i = 1; i < times.Count; i++)
- {
- long ctime = times[i];
- //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
- long timeDifference = ctime - ltime;
- ///如果一小时内连续操作,则按真实时间累计
- if (timeDifference < 3600000)
- {
- totalDuration += timeDifference;
- }
- else
- { ///如果一小时内没有连续操作,则按象征性加10秒,以确保数据有效性。 如果因为一小时没有操作,则表示没有新的接口再次请求,当即就已经退出系统。否则后续仍然会有接口进入,并且带有时间戳
- totalDuration += 10000;
- }
- ltime = ctime;
- }
- return totalDuration;
- }
- else { return 10000; }
- }
- else {
- return 0;
- }
- }
- public static List<SchoolStick> CountSchoolStickiness(IEnumerable<IGrouping<string,ApiVisit>> schoolApiVisits, IEnumerable<ApiVisit> apiVisits)
- {
- List<SchoolStick> schoolStickiness = new List<SchoolStick>();
- foreach (var chinaSchoolKey in schoolApiVisits)
- {
- SchoolStick stickiness = new SchoolStick()
- {
- id = chinaSchoolKey.Key
-
- };
- var teachers = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("teacher")).GroupBy(x => x.userId);
- double hitaTime = 0, hiteachTime = 0, ies5TchTime = 0, otherTchTime = 0, ies5StuTime = 0, otherStuTime = 0;
- int hitaTch= 0, hiteachTch = 0, ies5Tch = 0, otherTch = 0, ies5Stu = 0, otherStu = 0;
- double hitaCount = 0, hiteachCount = 0, ies5TchCount = 0, otherTchCount = 0, ies5StuCount = 0, otherStuCount = 0;
- double lessonCount= chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson")).Count() ;
- int teacherCount= teachers.Count() ;
- foreach (var user in teachers)
- {
- TchStick tchStick = new TchStick()
- {
- id = user.Key,
- school= chinaSchoolKey.Key
- };
- //HiTA
- var teacherHitaVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hita"));
- var teacherHitaVisitCount = teacherHitaVisit.Count();
- if (teacherHitaVisitCount>0)
- { hitaTch+=1; }
- var teacherHitaVisitTime = GetUserDuration(teacherHitaVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
- hitaCount+=teacherHitaVisitCount;
- hitaTime+=teacherHitaVisitTime;
- tchStick.hita.count.value=teacherHitaVisitCount;
- tchStick.hita.duration.value=teacherHitaVisitTime;
- //Other
- var teacherOtherVisit = user.Where(x => !x.client.Equals("hita")&&!x.client.Equals("hiteach")&&!x.client.Equals("ies5"));
- var teacherOtherVisitCount= teacherOtherVisit.Count();
- var teacherOtherVisitTime= GetUserDuration(teacherOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
- if (teacherOtherVisitCount>0)
- { otherTch+=1; }
- otherTchCount+=teacherOtherVisitCount;
- otherTchTime+=teacherOtherVisitTime;
- tchStick.otherTch.count.value=teacherOtherVisitCount;
- tchStick.otherTch.duration.value=teacherOtherVisitTime;
- //HiTeach
- //教师访问hiteach 不带学校信息的
- var teacherHiteachVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hiteach") && string.IsNullOrWhiteSpace(x.school));
- //教师访问hiteach 包含学校信息的
- var teacherHiteachSchoolVisit = user.Where(x => x.client.Equals("hiteach"));
- //教师所有的Hiteach访问
- List<ApiVisit> teacherHiteachAllVisit = new List<ApiVisit>();
- teacherHiteachAllVisit.AddRange(teacherHiteachVisit);
- teacherHiteachAllVisit.AddRange(teacherHiteachSchoolVisit);
- var teacherHiteachAllVisitCount = teacherHiteachAllVisit.Count();
- if (teacherHiteachAllVisitCount>0)
- { hiteachTch+=1; }
- var teacherHiteachAllVisitTime = GetUserDuration(teacherHiteachAllVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
- hiteachCount+=teacherHiteachAllVisitCount;
- hiteachTime+=teacherHiteachAllVisitTime;
- tchStick.hiteach.count.value=teacherHiteachAllVisitCount;
- tchStick.hiteach.duration.value=teacherHiteachAllVisitTime;
- //IES5
- var teacherIes5Visit = user.Where(x => x.client.Equals("ies5"));
- var teacherIes5VisitCount= teacherIes5Visit.Count();
- if (teacherIes5VisitCount>0)
- { ies5Tch+=1; }
- var teacherIes5VisitTime = GetUserDuration(teacherIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
- ies5TchCount+=teacherIes5VisitCount;
- ies5TchTime+=teacherIes5VisitTime;
- tchStick.ies5Tch.count.value=teacherIes5VisitCount;
- tchStick.ies5Tch.duration.value=teacherIes5VisitTime;
- double lessonCountTch = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson") && x.userId.Equals(user.Key)).Count();
- tchStick.lesson.value=lessonCountTch;
- tchStick.tmd.count.value=tchStick.hita.count.value+tchStick.hiteach.count.value+tchStick.ies5Tch.count.value+tchStick.otherTch.count.value;
- tchStick.tmd.duration.value=tchStick.hita.duration.value+tchStick.hiteach.duration.value+tchStick.ies5Tch.duration.value+tchStick.otherTch.duration.value;
- tchStick.hita.userCount=1;
- tchStick.hiteach.userCount=1;
- tchStick.ies5Tch.userCount=1;
- tchStick.otherTch.userCount=1;
- tchStick.tmd.userCount=1;
- if (tchStick.hita.count.value>0 && tchStick.hita.duration.value>0)
- {
- tchStick.hita.stick.value= (tchStick.hita.duration.value/1000/tchStick.hita.count.value);
- }
- if (tchStick.ies5Tch.count.value>0 && tchStick.ies5Tch.duration.value>0)
- {
- tchStick.ies5Tch.stick.value= (tchStick.ies5Tch.duration.value/1000/tchStick.ies5Tch.count.value);
- }
- if (tchStick.otherTch.count.value>0 && tchStick.otherTch.duration.value>0)
- {
- tchStick.otherTch.stick.value= (tchStick.otherTch.duration.value/1000/tchStick.otherTch.count.value);
- }
- if (tchStick.hiteach.count.value>0 && tchStick.hiteach.duration.value>0)
- {
- tchStick.hiteach.stick.value= (tchStick.hiteach.duration.value/1000/tchStick.hiteach.count.value)+tchStick.lesson.value;
- }
- if (tchStick.tmd.count.value>0 && tchStick.tmd.duration.value>0)
- {
- tchStick.tmd.stick.value= (tchStick.tmd.duration.value/1000/tchStick.tmd.count.value)+ tchStick.lesson.value;
- }
- stickiness.tchSticks.Add(tchStick);
- }
- var student = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && (x.scope.Equals("student")||x.scope.Equals("tmduser"))).GroupBy(x => x.userId);
- var studentCount = student.Count();
- foreach (var user in student)
- {
- StuStick stuStick = new StuStick
- {
- id=user.Key,
- school=chinaSchoolKey.Key
- };
- var studentOtherVisit = user.Where(x => !x.client.Equals("ies5"));
- var studentOtherVisitCount = studentOtherVisit.Count();
- if (studentOtherVisitCount>0)
- { otherStu+=1; }
- double studentOtherVisitTime = GetUserDuration(studentOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList()) ;
- var studentIes5Visit = user.Where(x => x.client.Equals("ies5"));
- var studentIes5VisitCount = studentIes5Visit.Count();
- if (studentIes5VisitCount>0)
- { ies5Stu+=1; }
- double studentIes5VisitTime = GetUserDuration(studentIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
- ies5StuCount+=studentIes5VisitCount;
- ies5StuTime+=studentIes5VisitTime;
- otherStuCount+=studentOtherVisitCount;
- otherStuTime+=studentOtherVisitTime;
- stuStick.ies5Stu.count.value=studentIes5VisitCount;
- stuStick.ies5Stu.duration.value=studentIes5VisitTime;
- stuStick.otherStu.count.value=studentOtherVisitCount;
- stuStick.otherStu.duration.value=studentOtherVisitTime;
- stuStick.tmd.count.value= stuStick.ies5Stu.count.value+stuStick.otherStu.count.value;
- stuStick.tmd.duration.value= stuStick.ies5Stu.duration.value+stuStick.otherStu.duration.value;
- stuStick.ies5Stu.userCount=1;
- stuStick.otherStu.userCount=1;
- stuStick.tmd.userCount=1;
- if (stuStick.ies5Stu.count.value>0 && stuStick.ies5Stu.duration.value>0)
- {
- stuStick.ies5Stu.stick.value= (stuStick.ies5Stu.duration.value/1000/stuStick.ies5Stu.count.value);
- }
-
- if (stuStick.otherStu.count.value>0 && stuStick.otherStu.duration.value>0)
- {
- stuStick.otherStu.stick.value=(stuStick.otherStu.duration.value/1000/stuStick.otherStu.count.value);
- }
- if (stuStick.tmd.count.value>0 && stuStick.tmd.duration.value>0)
- {
- stuStick.tmd.stick.value=(stuStick.tmd.duration.value/1000/stuStick.tmd.count.value);
- }
- stickiness.stuSticks.Add(stuStick);
- }
- stickiness.hita.duration.value=hitaTime;
- stickiness.hiteach.duration.value=hiteachTime;
- stickiness.otherTch.duration.value=otherTchTime;
- stickiness.ies5Tch.duration.value=ies5TchTime;
- stickiness.tmd.duration.value=hitaTime+hiteachTime+otherTchTime+ies5TchTime+otherStuTime+ies5StuTime;
- stickiness.hita.userCount=hitaTch;
- stickiness.hiteach.userCount=hiteachTch;
- stickiness.ies5Tch.userCount=ies5Tch;
- stickiness.otherTch.userCount=otherTch;
- stickiness.ies5Stu.userCount=ies5Stu;
- stickiness.otherStu.userCount=otherStu;
- stickiness.hita.count.value=hitaCount;
- stickiness.hiteach.count.value=hiteachCount;
- stickiness.ies5Tch.count.value=ies5TchCount;
- stickiness.otherTch.count.value=otherTchCount;
- stickiness.ies5Stu.count.value=ies5StuCount;
- stickiness.otherStu.count.value=otherStuCount;
- stickiness.tmd.count.value=hitaCount+hiteachCount+ies5TchCount+otherTchCount+ies5StuCount+otherStuCount;
- stickiness.lesson.value=lessonCount;
- stickiness.tmd.userCount=teacherCount+studentCount;
- if(stickiness.hita.count.value>0 && stickiness.hita.duration.value>0)
- {
- stickiness.hita.stick.value=(stickiness.hita.userCount* stickiness.hita.count.value)/(stickiness.hita.duration.value/1000/stickiness.hita.count.value);
- }
- if (stickiness.ies5Stu.count.value>0 && stickiness.ies5Stu.duration.value>0)
- {
- stickiness.ies5Stu.stick.value=(stickiness.ies5Stu.userCount* stickiness.ies5Stu.count.value)/(stickiness.ies5Stu.duration.value/1000/stickiness.ies5Stu.count.value);
- }
- if (stickiness.ies5Tch.count.value>0 && stickiness.ies5Tch.duration.value>0)
- {
- stickiness.ies5Tch.stick.value=(stickiness.ies5Tch.userCount* stickiness.ies5Tch.count.value)/(stickiness.ies5Tch.duration.value/1000/stickiness.ies5Tch.count.value);
- }
- if (stickiness.otherStu.count.value>0 && stickiness.otherStu.duration.value>0)
- {
- stickiness.otherStu.stick.value=(stickiness.otherStu.userCount* stickiness.otherStu.count.value)/(stickiness.otherStu.duration.value/1000/stickiness.otherStu.count.value);
- }
- if (stickiness.otherTch.count.value>0 && stickiness.otherTch.duration.value>0)
- {
- stickiness.otherTch.stick.value=(stickiness.otherTch.userCount* stickiness.otherTch.count.value)/(stickiness.otherTch.duration.value/1000/stickiness.otherTch.count.value);
- }
- if (stickiness.hiteach.count.value>0 && stickiness.hiteach.duration.value>0)
- {
- stickiness.hiteach.stick.value=(stickiness.hiteach.userCount* stickiness.hiteach.count.value)/(stickiness.hiteach.duration.value/1000/stickiness.hiteach.count.value)+stickiness.lesson.value;
- }
- if (stickiness.tmd.count.value>0 && stickiness.tmd.duration.value>0)
- {
- stickiness.tmd.stick.value=(stickiness.tmd.userCount* stickiness.tmd.count.value)/(stickiness.tmd.duration.value/1000/stickiness.tmd.count.value)+ stickiness.lesson.value;
- }
- stickiness.tchSticks= OrderByTchStick(stickiness.tchSticks);
- stickiness.stuSticks= OrderByStuStick(stickiness.stuSticks);
- schoolStickiness.Add(stickiness);
- }
-
- return OrderBySchoolStick(schoolStickiness);
- }
- private static List<StuStick> OrderByStuStick(List<StuStick> stuStickiness)
- {
- // 假设visit已经填充了数据
- #region
- var rank_tmd_count = stuStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_count = stuStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_count = stuStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_duration = stuStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_duration = stuStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_duration = stuStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_stick = stuStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_stick = stuStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_stick = stuStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- stuStickiness.ForEach(x =>
- {
- #region
- if (x.tmd.count.value>0)
- {
- int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
- if (index_tmd_count!=-1)
- {
- x.tmd.count.rank = index_tmd_count + 1;
- }
- }
- if (x.ies5Stu.count.value>0)
- {
- int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
- if (index_ies5Stu_count!=-1)
- {
- x.ies5Stu.count.rank = index_ies5Stu_count + 1;
- }
- }
- if (x.otherStu.count.value>0)
- {
- int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
- if (index_otherStu_count!=-1)
- {
- x.otherStu.count.rank = index_otherStu_count + 1;
- }
- }
- #endregion
- #region
- if (x.tmd.duration.value> 0) {
- int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
- if (index_tmd_duration!=-1)
- {
- x.tmd.duration.rank = index_tmd_duration + 1;
- }
- }
- if (x.ies5Stu.duration.value>0) {
- int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
- if (index_ies5Stu_duration!=-1)
- {
- x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
- }
- }
- if (x.otherStu.duration.value>0) {
- int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
- if (index_otherStu_duration!=-1)
- {
- x.otherStu.duration.rank = index_otherStu_duration + 1;
- }
- }
- #endregion
- #region
- if (x.tmd.stick.value>0)
- {
- int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
- if (index_tmd_stick!=-1)
- {
- x.tmd.stick.rank = index_tmd_stick + 1;
- }
- }
- if (x.ies5Stu.stick.value>0)
- {
- int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
- if (index_ies5Stu_stick!=-1)
- {
- x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
- }
- }
- if (x.otherStu.stick.value>0)
- {
- int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
- if (index_otherStu_stick!=-1)
- {
- x.otherStu.stick.rank = index_otherStu_stick + 1;
- }
- }
- #endregion
- });
- return stuStickiness;
- }
- private static List<TchStick> OrderByTchStick(List<TchStick> tchStickiness)
- {
- // 假设visit已经填充了数据
- #region
- var rank_tmd_count = tchStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_count = tchStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_count = tchStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_count = tchStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_count = tchStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_lesson_count = tchStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_duration = tchStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_duration = tchStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_duration = tchStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_duration = tchStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_duration = tchStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_stick = tchStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_stick = tchStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_stick = tchStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_stick = tchStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_stick = tchStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- tchStickiness.ForEach(x => {
- #region
- int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
- if (index_tmd_count!=-1)
- {
- x.tmd.count.rank = index_tmd_count + 1;
- }
- int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
- if (index_hita_count!=-1)
- {
- x.hita.count.rank = index_hita_count + 1;
- }
- int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
- if (index_hiteach_count!=-1)
- {
- x.hiteach.count.rank = index_hiteach_count + 1;
- }
- int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
- if (index_ies5Tch_count!=-1)
- {
- x.ies5Tch.count.rank = index_ies5Tch_count + 1;
- }
- int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
- if (index_otherTch_count!=-1)
- {
- x.otherTch.count.rank = index_otherTch_count + 1;
- }
- int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
- if (index_lesson_count!=-1)
- {
- x.lesson.rank = index_lesson_count + 1;
- }
- #endregion
- #region
- int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
- if (index_tmd_duration!=-1)
- {
- x.tmd.duration.rank = index_tmd_duration + 1;
- }
- int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
- if (index_hita_duration!=-1)
- {
- x.hita.duration.rank = index_hita_duration + 1;
- }
- int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
- if (index_hiteach_duration!=-1)
- {
- x.hiteach.duration.rank = index_hiteach_duration + 1;
- }
- int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
- if (index_ies5Tch_duration!=-1)
- {
- x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
- }
- int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
- if (index_otherTch_duration!=-1)
- {
- x.otherTch.duration.rank = index_otherTch_duration + 1;
- }
-
- #endregion
- #region
- int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
- if (index_tmd_stick!=-1)
- {
- x.tmd.stick.rank = index_tmd_stick + 1;
- }
- int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
- if (index_hita_stick!=-1)
- {
- x.hita.stick.rank = index_hita_stick + 1;
- }
- int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
- if (index_hiteach_stick!=-1)
- {
- x.hiteach.stick.rank = index_hiteach_stick + 1;
- }
- int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
- if (index_ies5Tch_stick!=-1)
- {
- x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
- }
- int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
- if (index_otherTch_stick!=-1)
- {
- x.otherTch.stick.rank = index_otherTch_stick + 1;
- }
-
- #endregion
- });
- return tchStickiness;
- }
- private static List<SchoolStick> OrderBySchoolStick(List<SchoolStick> schoolStickiness)
- {
- // 假设visit已经填充了数据
- #region
- var rank_tmd_count = schoolStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_count = schoolStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_count = schoolStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_count = schoolStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_count = schoolStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_count = schoolStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_count = schoolStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_lesson_count = schoolStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_duration = schoolStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_duration = schoolStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_duration = schoolStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_duration = schoolStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_duration = schoolStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_duration = schoolStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_duration = schoolStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- #region
- var rank_tmd_stick = schoolStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hita_stick = schoolStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_hiteach_stick = schoolStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Tch_stick = schoolStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherTch_stick = schoolStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_ies5Stu_stick = schoolStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
- var rank_otherStu_stick = schoolStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
- #endregion
- schoolStickiness.ForEach(x => {
- #region
- if (x.tmd.count.value>0)
- {
- int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
- if (index_tmd_count!=-1)
- {
- x.tmd.count.rank = index_tmd_count + 1;
- }
- }
- if (x.hita.count.value>0)
- {
- int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
- if (index_hita_count!=-1)
- {
- x.hita.count.rank = index_hita_count + 1;
- }
- }
-
- if (x.hiteach.count.value>0)
- {
- int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
- if (index_hiteach_count!=-1)
- {
- x.hiteach.count.rank = index_hiteach_count + 1;
- }
- }
- if (x.ies5Tch.count.value>0)
- {
- int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
- if (index_ies5Tch_count!=-1)
- {
- x.ies5Tch.count.rank = index_ies5Tch_count + 1;
- }
- }
- if (x.otherTch.count.value>0)
- {
- int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
- if (index_otherTch_count!=-1)
- {
- x.otherTch.count.rank = index_otherTch_count + 1;
- }
- }
- if (x.ies5Stu.count.value>0)
- {
- int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
- if (index_ies5Stu_count!=-1)
- {
- x.ies5Stu.count.rank = index_ies5Stu_count + 1;
- }
- }
- if (x.otherStu.count.value>0)
- {
- int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
- if (index_otherStu_count!=-1)
- {
- x.otherStu.count.rank = index_otherStu_count + 1;
- }
- }
- if (x.lesson.value>0)
- {
- int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
- if (index_lesson_count!=-1)
- {
- x.lesson.rank = index_lesson_count + 1;
- }
- }
- #endregion
- #region
- if (x.tmd.duration.value>0)
- {
- int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
- if (index_tmd_duration!=-1)
- {
- x.tmd.duration.rank = index_tmd_duration + 1;
- }
- }
-
- if (x.hita.duration.value>0)
- {
- int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
- if (index_hita_duration!=-1)
- {
- x.hita.duration.rank = index_hita_duration + 1;
- }
- }
- if (x.hiteach.duration.value>0)
- {
- int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
- if (index_hiteach_duration!=-1)
- {
- x.hiteach.duration.rank = index_hiteach_duration + 1;
- }
- }
-
- if (x.ies5Tch.duration.value>0) {
- int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
- if (index_ies5Tch_duration!=-1)
- {
- x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
- }
- }
-
- if (x.otherTch.duration.value>0)
- {
- int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
- if (index_otherTch_duration!=-1)
- {
- x.otherTch.duration.rank = index_otherTch_duration + 1;
- }
- }
-
- if (x.ies5Stu.duration.value>0)
- {
- int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
- if (index_ies5Stu_duration!=-1)
- {
- x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
- }
- }
-
- if (x.otherStu.duration.value>0)
- {
- int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
- if (index_otherStu_duration!=-1)
- {
- x.otherStu.duration.rank = index_otherStu_duration + 1;
- }
- }
-
- #endregion
- #region
- if (x.tmd.stick.value>0)
- {
- int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
- if (index_tmd_stick!=-1)
- {
- x.tmd.stick.rank = index_tmd_stick + 1;
- }
- }
-
- if (x.hita.stick.value>0)
- {
- int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
- if (index_hita_stick!=-1)
- {
- x.hita.stick.rank = index_hita_stick + 1;
- }
- }
-
- if (x.hiteach.stick.value>0)
- {
- int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
- if (index_hiteach_stick!=-1)
- {
- x.hiteach.stick.rank = index_hiteach_stick + 1;
- }
- }
-
- if (x.ies5Tch.stick.value>0)
- {
- int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
- if (index_ies5Tch_stick!=-1)
- {
- x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
- }
- }
-
- if (x.otherTch.stick.value>0)
- {
- int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
- if (index_otherTch_stick!=-1)
- {
- x.otherTch.stick.rank = index_otherTch_stick + 1;
- }
- }
-
- if (x.ies5Stu.stick.value>0)
- {
- int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
- if (index_ies5Stu_stick!=-1)
- {
- x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
- }
- }
-
- if (x.otherStu.stick.value>0)
- {
- int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
- if (index_otherStu_stick!=-1)
- {
- x.otherStu.stick.rank = index_otherStu_stick + 1;
- }
- }
-
- #endregion
- });
- return schoolStickiness;
- }
- /// <summary>
- /// 结算访问日志
- /// </summary>
- public static async Task<(List<SchoolStick> chinaSchoolStickiness, List<SchoolStick> globalSchoolStickiness)> VisitSettle(List<string> times ,AzureStorageFactory _azureStorage,AzureRedisFactory _azureRedis, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, IPSearcher _ipSearcher) {
- List<SchoolStick> chinaSchoolStickiness = new List<SchoolStick>();
- List<SchoolStick> globalSchoolStickiness = new List<SchoolStick>();
- foreach (var timeDate in times)
- {
- List<ApiVisit> apiVisits = new List<ApiVisit>();
- if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date))
- {
-
- BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
- var content = result.Content.ToString();
- content= content.Substring(0, content.Length-2);
- if (content.EndsWith("}"))
- {
- content=$"[{content}]";
- }
- else
- {
- content=$"[{content}}}]";
- }
- apiVisits.AddRange(content.ToObject<List<ApiVisit>>());
- var dateNow = DateTimeOffset.Now.GetGMTTime(8);
- if ($"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
- { //当前小时一致的
- BlobDownloadResult resultHour = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}.log").DownloadContentAsync();
- var contentHour = resultHour.Content.ToString();
- contentHour= contentHour.Substring(0, contentHour.Length-2);
- if (contentHour.EndsWith("}"))
- {
- contentHour=$"[{contentHour}]";
- }
- else
- {
- contentHour=$"[{contentHour}}}]";
- }
- var httpLog = contentHour.ToObject<List<HttpLog>>();
- (ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) = await SystemService.ConvertHttpLog(httpLog, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, dateNow, false);
- apiVisits.AddRange(visits);
- }
- }
- //大陆学校
- var chinaApiVisits = apiVisits.Where(x => x.hostName.Equals("大陆站"));
- var chinaSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("大陆站")).GroupBy(x => x.school);
- List<SchoolStick> chinaStickiness = CountSchoolStickiness(chinaSchoolVisits, chinaApiVisits);
- chinaSchoolStickiness.AddRange(chinaStickiness);
- //国际学校
- var globalApiVisits = apiVisits.Where(x => x.hostName.Equals("国际站"));
- var globalSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("国际站")).GroupBy(x => x.school);
- List<SchoolStick> globalStickiness = CountSchoolStickiness(globalSchoolVisits, globalApiVisits);
- globalSchoolStickiness.AddRange(globalStickiness);
- }
- return (chinaSchoolStickiness, globalSchoolStickiness);
- }
- public static async Task<(ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)>
- ConvertHttpLog(List<HttpLog> logs, AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, DateTimeOffset gmt8Time, bool test = false)
- {
- ConcurrentBag<ApiVisit> visits = new ConcurrentBag<ApiVisit>();
- ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
- object lockObj = new object();
- await Parallel.ForEachAsync(logs, async (log, _) =>
- {
- if (!log.path.Contains("."))
- {
- string uuid = Guid.NewGuid().ToString();
- List<string> schoolMatch = new List<string>();
- List<string> useridMatch = new List<string>();
- var vist = new ApiVisit()
- {
- id=uuid,
- ip=log.ip,
- tid=log.tid,
- time= log.time,
- userId= log.id,
- school= log.school,
- tname= log.name,
- path = log.path,
- client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
- scope=log.scope,
- host= log.host,
- hostName=log.hostName,
- l=log.l,
- year = $"{gmt8Time:yyyy}",
- month = $"{gmt8Time:MM}",
- day = $"{gmt8Time:dd}",
- hour =$"{gmt8Time:HH}"
- };
- if (test)
- {
- var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
- //本地调试时间
- if (vist.ip.Equals("0.0.0.1"))
- {
- time= time.AddHours(8);
- }
- vist.year = $"{time:yyyy}";
- vist.month = $"{time:MM}";
- vist.day = $"{time:dd}";
- vist.hour =$"{time:HH}";
- }
- if (string.IsNullOrWhiteSpace(vist.userId))
- {
- //var jsonPathContext = new JsonPathContext();
- //jsonPathContext.ValueSystem= new JsonTextValueSystem();
- string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','code','studentId','student','studentid']";
- if (!log.param.ValueKind.Equals(JsonValueKind.Null)) {
- JObject jsonObject = JObject.Parse(log.param.GetRawText());
- //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
- var nodes_path = jsonObject.SelectTokens(path);
- foreach (var node in nodes_path)
- {
- // 只获取是字符串的
- if (node.Type.Equals(JTokenType.String))
- {
- switch (true)
- {
- case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
- {
- try
- {
- var jwt = new JwtSecurityToken($"{node}");
- string id = jwt.Payload.Sub;
- var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
- if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
- {
- vist.userId=id;
- vist.scope="teacher";
- vist.tname=name;
- useridMatch.Add(id);
- }
- }
- catch (Exception ex) { }
- break;
- }
- case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
- ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
- ||node.Path.Contains("userId"):
- {
- if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
- {
- vist.userId=$"{node}";
- vist.scope="teacher";
- useridMatch.Add($"{node}");
- }
- break;
- }
- case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
- {
- if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
- {
- vist.userId=$"{node}";
- vist.scope="student";
- useridMatch.Add($"{node}");
- }
- break;
- }
- case bool when node.Path.Contains("code"):
- {
- if (!string.IsNullOrWhiteSpace($"{node}"))
- {
- if (long.TryParse($"{node}", out long _id))
- {
- vist.userId=$"{node}";
- useridMatch.Add($"{node}");
- }
- else
- {
- string[] codes = $"{node}".Split("-");
- foreach (var _code in codes)
- {
- if (long.TryParse(_code, out long _codeid))
- {
- vist.userId=$"{node}";
- useridMatch.Add($"{_code}");
- break;
- }
- }
- }
- }
- break;
- }
- }
- }
- }
- if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
- {
- string s = log.param.ToJsonString().Replace("\\", "");
- Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
- Match matchtmdid = regextmdid.Match(s);
- if (matchtmdid.Success)
- {
- var t = matchtmdid.Groups[1].Value;
- if (!string.IsNullOrWhiteSpace(t))
- {
- vist.userId=t;
- vist.scope="teacher";
- useridMatch.Add(t);
- }
- }
- Regex regexname = new Regex("\"tmdname\":\"(.+?)\"");
- Match matchname = regexname.Match(s);
- if (matchname.Success)
- {
- var t = matchname.Groups[1].Value;
- if (!string.IsNullOrWhiteSpace(t))
- {
- vist.tname=t;
- }
- }
- }
- }
- }
- else
- {
- if (string.IsNullOrWhiteSpace($"{vist.scope}"))
- {
- vist.scope="teacher";
- uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
- }
- }
- if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false"))
- {
- vist.school="";
- string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
- if (!log.param.ValueKind.Equals(JsonValueKind.Null)) {
- JObject jsonObject = JObject.Parse(log.param.GetRawText());
- var nodes_path = jsonObject.SelectTokens(path);
- foreach (var node in nodes_path)
- {
- // 只获取是字符串的
- if (node.Type.Equals(JTokenType.String))
- {
- switch (true)
- {
- case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
- ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
- {
- if (!$"{node}".Contains("-")&& $"{node}".Length<=8 && $"{node}".Length>=1)
- {
- vist.school=$"{node}";
- schoolMatch.Add($"{node}");
- }
- break;
- }
- case bool when node.Path.Contains("code"):
- {
- if (!$"{node}".Contains("-")&& $"{node}".Length<=8&& $"{node}".Length>=1)
- {
- vist.school=$"{node}";
- schoolMatch.Add($"{node}");
- }
- else
- {
- string[] codes = $"{node}".Split("-");
- foreach (var _code in codes)
- {
- if ($"{_code}".Length<=8 && $"{_code}".Length>=1)
- {
- vist.school=$"{_code}";
- schoolMatch.Add($"{_code}");
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
- {
- string s = log.param.ToJsonString().Replace("\\", "");
- Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
- Match matchname = regexname.Match(s);
- if (matchname.Success)
- {
- var t = matchname.Groups[1].Value;
- if (!string.IsNullOrWhiteSpace(t))
- {
- vist.school=t;
- }
- }
- }
- }
- }
- //处理 client
- {
- if (!string.IsNullOrWhiteSpace(log.client))
- {
- if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="ies5";
- }
- if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="aclassone";
- }
- if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="habb";
- }
- if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="hiscan";
- }
- if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="hita";
- vist.scope="teacher";
- }
- if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="hiteachcc";
- }
- if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
- {
- vist.scope="teacher";
- vist.client="hiteach";
- }
- if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
- {
- vist.client="open";
- }
- }
- }
- //补全站点
- {
- if (
- (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
- {
- vist.hostName="国际站";
- vist.host="www.teammodel.net";
- vist.client="ies5";
- vist.l="Global";
- }
- else if (
- log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
- ||log.host.Equals("yx.teammodel.cn")||log.host.Equals("teammodelos-rc.chinacloudsites.cn")||log.host.Equals("rc.teammodel.cn")|| log.host.Equals("www.teammodel.cn"))
- {
- vist.hostName="大陆站";
- vist.host="www.teammodel.cn";
- vist.client="ies5"; vist.l="China";
- }
- else if ((log.host.Contains("localhost") && log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
- {
- vist.hostName="测试站";
- vist.host="test.teammodel.cn";
- vist.client="ies5";
- vist.l="China";
- }
- else if (
- (log.host.Equals("scyx.teammodel.cn") ||log.host.Equals("jinniu.teammodel.cn")))
- {
- vist.hostName="研修2.0";
- vist.host="scyx.teammodel.cn";
- vist.client="ability"; vist.l="China";
- }
- else if (
- log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn") ||log.host.Equals("zhiyin-test.teammodel.cn"))
- {
- vist.hostName="开放平台";
- vist.host="open.teammodel.cn";
- vist.client="open";
- vist.l="China";
- }
- else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
- {
- vist.hostName="国际站";
- vist.host="bi.teammodel.net";
- vist.client="bi";
- vist.scope="admin";
- vist.l="Global";
- }
- else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
- {
- vist.hostName="大陆站";
- vist.host="bi.teammodel.cn";
- vist.client="bi";
- vist.scope="admin";
- vist.l="China";
- }
- else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost") && (log.p.Equals("bi"))))
- {
- vist.hostName="测试站";
- vist.host="testbi.teammodel.cn";
- vist.client="bi";
- vist.scope="admin";
- vist.l="China";
- }
- else if (
- log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
- {
- vist.hostName="大陆站";
- vist.host="contest.teammodel.cn";
- vist.client="contest"; vist.l="China";
- }
- else if (
- log.host.Equals("hiteachcc.chinacloudsites.cn"))
- {
- vist.hostName="正式站";
- vist.host="hiteachcc.teammodel.cn";
- vist.client="hiteachcc";
- vist.l="China";
- }
- else if (log.host.Equals("appraisal.chinacloudsites.cn"))
- {
- vist.hostName="大陆站";
- vist.host="appraisal.teammodel.cn";
- vist.client="appraisal";
- vist.l="China";
- }
- else if ((log.host.Contains("localhost") && log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn") ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
- {
- vist.hostName="测试站";
- vist.host="appraisal-test.teammodel.cn";
- vist.client="appraisal";
- vist.l="China";
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(log.p))
- {
- vist.client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p;
- }
- else
- {
- vist.client="other";
- }
- if (log.host.EndsWith(".cn"))
- {
- vist.hostName="大陆站";
- vist.l="China";
- }
- else if (log.host.EndsWith(".net"))
- {
- vist.hostName="国际站";
- vist.l="Global";
- }
- else
- {
- vist.hostName="其他";
- vist.l="其他";
- }
- }
- }
- //补全产品端
- {
- //研修2.0
- if (log.path.Contains("research") || log.path.Contains("study") || log.path.Contains("standard-file"))
- {
- vist.client="ability";
- }
- if (log.path.Contains("teacher"))
- {
- vist.scope="teacher";
- }
- if (log.path.Contains("tmduser"))
- {
- vist.scope=Constant.ScopeTmdUser;
- }
- if (log.path.Contains("student/login"))
- {
- vist.scope=Constant.ScopeStudent;
- }
- if (log.path.StartsWith("/activity"))
- {
- vist.client="contest";
- }
- //小程序
- if (log.path.Contains("aclassone"))
- {
- vist.client="aclassone";
- }
- // /// <summary>
- /// ExamInfo qamode 書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
- /// </summary>
- //艺术评测
- if (log.path.Contains("art") ||log.path.Contains("aclassone/find-children-activity") ||log.path.Contains("aclassone/find-teacher-activity") ||log.path.Contains("aclassone/find-summary-activity") ||log.path.Contains("aclassone/upload-all") ||log.path.Contains("aclassone/delete"))
- {
- vist.client="art";
- }
- if (log.path.Contains("common/exam/upsert-record"))
- {
- JObject jobject = JObject.Parse(log.param.GetRawText());
- var jtokens = jobject.SelectTokens("$..artId");
- if (jtokens!=null && jtokens.Count()>0)
- {
- vist.client="art";
- vist.scope=Constant.ScopeStudent;
- }
- }
- if (log.path.Contains("habb"))
- {
- vist.client="habb";
- }
- //阅卷客户端
- if (log.path.Contains("hiscan"))
- {
- vist.client="hiscan";
- }
- if (log.path.Contains("hita"))
- {
- vist.client="hita";
- }
- if (log.path.Contains("hiteachcc"))
- {
- vist.client="hiteachcc";
- }
- if (log.path.Contains("sokrate"))
- {
- vist.client="sokrate";
- }
- if (log.path.Contains("sokrate") || log.path.Contains("score"))
- {
- vist.client="sokrate";
- }
- if (log.path.Contains("hiteach"))
- {
- vist.client="hiteach";
- }
- ///IES开放平台
- if (log.path.Contains("business") || log.path.Contains("biz") || log.path.Contains("openapi-config") || log.path.Contains("open-api"))
- {
- vist.client="open";
- }
- //从token的role 能否获取 开放平台
- //单点登录及第三方接口
- if (log.path.Contains("lepei") || log.path.Contains("sc/") || log.path.Contains("/sso") || log.path.Contains("sc-init")|| log.path.Contains("moofen") || log.path.Contains("data-push") || log.path.Contains("xkw")|| log.path.Contains("tianbo")
- || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding") || log.path.Contains("wechat")
- )
- {
- vist.client="sso-third";
- }
- }
- //处理IP转地区
- var region = await _ipSearcher.SearchIpAsync(vist.ip);
- if (string.IsNullOrWhiteSpace(region))
- {
- region="未知IP·未知IP·未知IP";
- }
- if (!string.IsNullOrWhiteSpace(region))
- {
- region= region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
- var regions = region.Split("·");
- if (regions.Length==4)
- {
- vist.area= regions[0];
- vist.province = regions[1];
- vist.city = regions[2];
- }
- if (regions.Length==3)
- {
- vist.area= regions[0];
- vist.province = regions[1];
- }
- if (regions.Length==2)
- {
- vist.area= regions[0];
- vist.province = regions[1];
- }
- if (regions.Length==1)
- {
- vist.area= regions[0];
- }
- }
- //处理地区转经纬度
- {
- IEnumerable<JToken> tokens = default;
- if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
- if (!(tokens.Any() && tokens.Count()>0))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
- if (!(tokens.Any() && tokens.Count()>0))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
- }
- if (!(tokens.Any() && tokens.Count()>0))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
- }
- }
- }
- else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
- {
- if (vist.area.Equals("中国"))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
- if (!(tokens.Any() && tokens.Count()>0))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
- }
- }
- else
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
- }
- }
- else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
- {
- if (vist.area.Equals("中国"))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
- if (!(tokens.Any() && tokens.Count()>0))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
- }
- }
- else
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
- }
- }
- else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
- {
- tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
- }
- if (tokens!=null && tokens.Any())
- {
- List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
- foreach (JToken token in tokens)
- {
- regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
- }
- var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
- if (!points.IsNotEmpty())
- {
- points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
- }
- if (string.IsNullOrWhiteSpace(vist.city))
- {
- vist.city=points?.FirstOrDefault()?.city;
- if (!string.IsNullOrWhiteSpace(vist.city) && vist.city.EndsWith("市"))
- {
- vist.city=vist.city.Replace("市", "");
- }
- }
- vist.lat=points?.FirstOrDefault()?.lat;
- vist.lng=points?.FirstOrDefault()?.lng;
- }
- else
- {
- if (vist.area.Equals("内网IP"))
- {
- if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
- {
- vist.lat="30.655821878416408";
- vist.lng="104.08153351042463";
- vist.area="中国";
- vist.province="四川";
- vist.city="成都";
- }
- else
- {
- vist.lat="25.044332";
- vist.lng="121.509062";
- vist.area="中国";
- vist.province="台湾";
- vist.city="台湾";
- }
- }
- else
- {
- vist.lat="30.655821878416408";
- vist.lng="104.08153351042463";
- vist.area="中国";
- vist.province="四川";
- vist.city="成都";
- }
- }
- }
- uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
- visits.Add(vist);
- }
- }
- );
- List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
- List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
- var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
- if (tmds.Any())
- {
- foreach (var tmd in tmds)
- {
- var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{tmd}");
- if (exists)
- {
- tmdexists.Add((tmd, exists, "teacher"));
- }
- else
- {
- exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
- tmdexists.Add((tmd, exists, "student"));
- }
- }
- }
- var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
- if (schs.Any())
- {
- foreach (var sch in schs)
- {
- var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{sch}");
- schexists.Add((sch, exists));
- }
- }
- foreach (var item in uuidInfo)
- {
- foreach (var tmd in item.tmdid)
- {
- var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
- if (tmdext.tmd!= null && tmdext.exists)
- {
- var vist = visits.Where(x => x.id.Equals(item.uuid));
- foreach (var vi in vist)
- {
- vi.userId=tmd;
- if (string.IsNullOrWhiteSpace(vi.scope))
- {
- vi.scope=tmdext.scope;
- }
- }
- break;
- }
- }
- foreach (var sch in item.school)
- {
- var schext = schexists.Find(x => x.sch.Equals(sch));
- if (schext.sch!= null && schext.exists)
- {
- var vist = visits.Where(x => x.id.Equals(item.uuid));
- foreach (var vi in vist)
- {
- vi.school=sch;
- }
- break;
- }
- }
- }
- return (visits, uuidInfo);
- }
- public class ApiVisit
- {
- public string id { get; set; }
- public string path { get; set; }
- /// <summary>
- /// 细分
- /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
- /// 产品端
- /// </summary>
- public string client { get; set; }
- /// <summary>
- /// 具体功能
- /// </summary>
- // public string func { get; set; }
- public string userId { get; set; }
- public string scope { get; set; }
- public string tname { get; set; }
- public string school { get; set; }
- public string ip { get; set; }
- //public string region { get; set; }
- public string area { get; set; }
- public string province { get; set; }
- public string city { get; set; } = "";
- public long time { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string host { get; set; }
- public string hostName { get; set; } = "其他";
- /// <summary>
- /// tokenid
- /// </summary>
- public string tid { get; set; }
- public string year { get; set; }
- public string month { get; set; }
- public string day { get; set; }
- public string hour { get; set; }
- //public RegionLngLat point { get; set; }
- public string lat { get; set; }
- public string lng { get; set; }
- public string l { get; set; }
- }
- public class HttpLog
- {
- public string ip { get; set; }
- public long time { get; set; }
- public string host { get; set; }
- public string hostName = "其他";
- public string tid { get; set; }
- public string path { get; set; }
- public string client { get; set; }
- public JsonElement param { get; set; }
- public string id { get; set; }
- public string name { get; set; }
- public string school { get; set; }
- public string p { get; set; }
- // public string ua { get; set; }
- // public string referer { get; set; }
- public string scope { get; set; }
- public string year { get; set; }
- public string month { get; set; }
- public string day { get; set; }
- public string hour { get; set; }
- public string l { get; set; }
- }
- public record RegionLngLat
- {
- public string country { get; set; }
- public string province { get; set; }
- public string city { get; set; }
- public string lat { get; set; }
- public string lng { get; set; }
- public string area { get; set; }
- public string m { get; set; } = "0";
- }
- public class CountData
- {
- public string pk { get; set; } = "";
- public string sk { get; set; } = "";
- public string sp { get; set; } = "";
- public int count { get; set; }
- }
- public class SchoolStick
- {
-
- /// <summary>
- /// 名字
- /// </summary>
- public string name { get; set; }
- public string picture { get; set; }
- /// <summary>
- /// 编码
- /// </summary>
- public string id { get; set; }
- public string last { get; set; }
- #region tmd
- public ClientStick tmd { get; set; } = new ClientStick();
- #endregion
- #region hiteach
- public ClientStick hiteach { get; set; } = new ClientStick();
- public Indicator lesson { get; set; } = new Indicator();
- #endregion
- #region hita
- public ClientStick hita { get; set; } = new ClientStick();
- #endregion
- #region ies5Teacher
- public ClientStick ies5Tch { get; set; } = new ClientStick();
- #endregion
- #region otherTeacher
- public ClientStick otherTch { get; set; } = new ClientStick();
- #endregion
- #region ies5Student
- public ClientStick ies5Stu { get; set; } = new ClientStick();
- #endregion
- #region otherStudent
- public ClientStick otherStu { get; set; } = new ClientStick();
- #endregion
- public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
- public List<StuStick> stuSticks { get; set; } = new List<StuStick>();
- }
- public class TchStick {
- public string school { get; set; }
- /// <summary>
- /// 名字
- /// </summary>
- public string name { get; set; }
- public string picture { get; set; }
- /// <summary>
- /// 编码
- /// </summary>
- public string id { get; set; }
- public string last { get; set; }
- #region tmd
- public ClientStick tmd { get; set; } = new ClientStick();
- #endregion
- #region hiteach
- public ClientStick hiteach { get; set; } = new ClientStick();
- public Indicator lesson { get; set; } = new Indicator();
- #endregion
- #region hita
- public ClientStick hita { get; set; } = new ClientStick();
- #endregion
- #region ies5Teacher
- public ClientStick ies5Tch { get; set; } = new ClientStick();
- #endregion
- #region otherTeacher
- public ClientStick otherTch { get; set; } = new ClientStick();
- #endregion
- }
- public class StuStick
- {
- public string school { get; set; }
- /// <summary>
- /// 名字
- /// </summary>
- public string name { get; set; }
- public string picture { get; set; }
- /// <summary>
- /// 编码
- /// </summary>
- public string id { get; set; }
- public string last { get; set; }
- #region tmd
- public ClientStick tmd { get; set; } = new ClientStick();
- #endregion
- #region ies5Student
- public ClientStick ies5Stu { get; set; } = new ClientStick();
- #endregion
- #region otherStudent
- public ClientStick otherStu { get; set; } = new ClientStick();
- #endregion
- }
- public class ClientStick
- {
- public int userCount { get; set; }
-
- public Indicator stick { get; set; } = new Indicator();
- public Indicator duration { get; set; } = new Indicator();
- public Indicator count { get; set; } = new Indicator();
- }
- public class Indicator
- {
- /// <summary>
- /// 值
- /// </summary>
- public double value { get; set; } = 0;
- /// <summary>
- /// 值的增减浮动
- /// </summary>
- public double range { get; set; } = 0;
- /// <summary>
- /// 排名
- /// </summary>
- public double rank { get; set; } = 0;
- /// <summary>
- /// 排名的上升下降
- /// </summary>
- public double updown { get; set; } = 0;
- }
- }
- }
|