SystemService.cs 168 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257
  1. using Azure.Storage.Blobs.Models;
  2. using HTEX.Complex.Service.AzureRedis;
  3. using Newtonsoft.Json.Linq;
  4. using System.Buffers;
  5. using System.Collections.Concurrent;
  6. using System.IdentityModel.Tokens.Jwt;
  7. using System.Reflection.Metadata;
  8. using System.Text.Encodings.Web;
  9. using System.Text;
  10. using System.Text.Json;
  11. using System.Text.RegularExpressions;
  12. using TEAMModelOS.SDK;
  13. namespace HTEX.Complex.Service
  14. {
  15. public static class SystemService
  16. {
  17. public const double timeWeight = 0.7;
  18. public const double countWeight = 0.3;
  19. static double GetUserDuration(List<long> times)
  20. {
  21. if (times.IsNotEmpty())
  22. {
  23. if (times.Count>=2)
  24. {
  25. double totalDuration = 0;
  26. // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
  27. long ltime = times[0];
  28. for (int i = 1; i < times.Count; i++)
  29. {
  30. long ctime = times[i];
  31. //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
  32. long timeDifference = ctime - ltime;
  33. ///如果一小时内连续操作,则按真实时间累计
  34. if (timeDifference < 3600000)
  35. {
  36. totalDuration += timeDifference;
  37. }
  38. else
  39. { ///如果一小时内没有连续操作,则按象征性加10秒,以确保数据有效性。 如果因为一小时没有操作,则表示没有新的接口再次请求,当即就已经退出系统。否则后续仍然会有接口进入,并且带有时间戳
  40. totalDuration += 10000;
  41. }
  42. ltime = ctime;
  43. }
  44. return totalDuration;
  45. }
  46. else { return 10000; }
  47. }
  48. else
  49. {
  50. return 0;
  51. }
  52. }
  53. public static List<SchoolStick> CountSchoolStickiness(IEnumerable<IGrouping<string, ApiVisit>> schoolApiVisits, IEnumerable<ApiVisit> apiVisits, List<SchoolStick> bygoneStickiness)
  54. {
  55. List<SchoolStick> schoolStickiness = new List<SchoolStick>();
  56. //用于做标准化值的最大最小度量值
  57. double max_sch_hita_c = 0, max_sch_hiteach_c = 0, max_sch_ies5Tch_c = 0, max_sch_otherTch_c = 0, max_sch_ies5Stu_c = 0, max_sch_otherStu_c = 0;
  58. double max_sch_hita_d = 0, max_sch_hiteach_d = 0, max_sch_ies5Tch_d = 0, max_sch_otherTch_d = 0, max_sch_ies5Stu_d = 0, max_sch_otherStu_d = 0;
  59. double min_sch_hita_c = 0, min_sch_hiteach_c = 0, min_sch_ies5Tch_c = 0, min_sch_otherTch_c = 0, min_sch_ies5Stu_c = 0, min_sch_otherStu_c = 0;
  60. double min_sch_hita_d = 0, min_sch_hiteach_d = 0, min_sch_ies5Tch_d = 0, min_sch_otherTch_d = 0, min_sch_ies5Stu_d = 0, min_sch_otherStu_d = 0;
  61. double max_tch_hita_c = 0, max_tch_hiteach_c = 0, max_tch_ies5Tch_c = 0, max_tch_otherTch_c = 0;
  62. double max_tch_hita_d = 0, max_tch_hiteach_d = 0, max_tch_ies5Tch_d = 0, max_tch_otherTch_d = 0;
  63. double min_tch_hita_c = 0, min_tch_hiteach_c = 0, min_tch_ies5Tch_c = 0, min_tch_otherTch_c = 0;
  64. double min_tch_hita_d = 0, min_tch_hiteach_d = 0, min_tch_ies5Tch_d = 0, min_tch_otherTch_d = 0;
  65. foreach (var chinaSchoolKey in schoolApiVisits)
  66. {
  67. SchoolStick stickiness = new SchoolStick()
  68. {
  69. id = chinaSchoolKey.Key
  70. };
  71. var teachers = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("teacher")).GroupBy(x => x.userId);
  72. double hitaTime = 0, hiteachTime = 0, ies5TchTime = 0, otherTchTime = 0, ies5StuTime = 0, otherStuTime = 0;
  73. int hitaTch = 0, hiteachTch = 0, ies5Tch = 0, otherTch = 0, ies5Stu = 0, otherStu = 0;
  74. double hitaCount = 0, hiteachCount = 0, ies5TchCount = 0, otherTchCount = 0, ies5StuCount = 0, otherStuCount = 0;
  75. double lessonCount = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson")).Count();
  76. int teacherCount = teachers.Count();
  77. double max_stu_ies5Stu_c = 0, max_stu_otherStu_c = 0;
  78. double max_stu_ies5Stu_d = 0, max_stu_otherStu_d = 0;
  79. double min_stu_ies5Stu_c = 0, min_stu_otherStu_c = 0;
  80. double min_stu_ies5Stu_d = 0, min_stu_otherStu_d = 0;
  81. foreach (var user in teachers)
  82. {
  83. TchStick tchStick = new TchStick()
  84. {
  85. id = user.Key,
  86. school= chinaSchoolKey.Key
  87. };
  88. //HiTA
  89. var teacherHitaVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hita"));
  90. var teacherHitaVisitCount = teacherHitaVisit.Count();
  91. if (teacherHitaVisitCount>0)
  92. { hitaTch+=1; }
  93. var teacherHitaVisitTime = GetUserDuration(teacherHitaVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  94. hitaCount+=teacherHitaVisitCount;
  95. hitaTime+=teacherHitaVisitTime;
  96. tchStick.hita.count.value=teacherHitaVisitCount;
  97. tchStick.hita.duration.value=teacherHitaVisitTime;
  98. //Other
  99. var teacherOtherVisit = user.Where(x => !x.client.Equals("hita")&&!x.client.Equals("hiteach")&&!x.client.Equals("ies5"));
  100. var teacherOtherVisitCount = teacherOtherVisit.Count();
  101. var teacherOtherVisitTime = GetUserDuration(teacherOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  102. if (teacherOtherVisitCount>0)
  103. { otherTch+=1; }
  104. otherTchCount+=teacherOtherVisitCount;
  105. otherTchTime+=teacherOtherVisitTime;
  106. tchStick.otherTch.count.value=teacherOtherVisitCount;
  107. tchStick.otherTch.duration.value=teacherOtherVisitTime;
  108. //HiTeach
  109. //教师访问hiteach 不带学校信息的
  110. var teacherHiteachVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hiteach") && string.IsNullOrWhiteSpace(x.school));
  111. //教师访问hiteach 包含学校信息的
  112. var teacherHiteachSchoolVisit = user.Where(x => x.client.Equals("hiteach"));
  113. //教师所有的Hiteach访问
  114. List<ApiVisit> teacherHiteachAllVisit = new List<ApiVisit>();
  115. teacherHiteachAllVisit.AddRange(teacherHiteachVisit);
  116. teacherHiteachAllVisit.AddRange(teacherHiteachSchoolVisit);
  117. var teacherHiteachAllVisitCount = teacherHiteachAllVisit.Count();
  118. if (teacherHiteachAllVisitCount>0)
  119. { hiteachTch+=1; }
  120. var teacherHiteachAllVisitTime = GetUserDuration(teacherHiteachAllVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  121. hiteachCount+=teacherHiteachAllVisitCount;
  122. hiteachTime+=teacherHiteachAllVisitTime;
  123. tchStick.hiteach.count.value=teacherHiteachAllVisitCount;
  124. tchStick.hiteach.duration.value=teacherHiteachAllVisitTime;
  125. //IES5
  126. var teacherIes5Visit = user.Where(x => x.client.Equals("ies5"));
  127. var teacherIes5VisitCount = teacherIes5Visit.Count();
  128. if (teacherIes5VisitCount>0)
  129. { ies5Tch+=1; }
  130. var teacherIes5VisitTime = GetUserDuration(teacherIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  131. ies5TchCount+=teacherIes5VisitCount;
  132. ies5TchTime+=teacherIes5VisitTime;
  133. tchStick.ies5Tch.count.value=teacherIes5VisitCount;
  134. tchStick.ies5Tch.duration.value=teacherIes5VisitTime;
  135. double lessonCountTch = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson") && x.userId.Equals(user.Key)).Count();
  136. tchStick.lesson.value=lessonCountTch;
  137. tchStick.teacher.count.value=tchStick.hita.count.value+tchStick.hiteach.count.value+tchStick.ies5Tch.count.value+tchStick.otherTch.count.value;
  138. tchStick.teacher.duration.value=tchStick.hita.duration.value+tchStick.hiteach.duration.value+tchStick.ies5Tch.duration.value+tchStick.otherTch.duration.value;
  139. tchStick.hita.userCount=1;
  140. tchStick.hiteach.userCount=1;
  141. tchStick.ies5Tch.userCount=1;
  142. tchStick.otherTch.userCount=1;
  143. tchStick.teacher.userCount=1;
  144. //if (tchStick.hita.count.value>0 && tchStick.hita.duration.value>0)
  145. //{
  146. // tchStick.hita.stick.value= (tchStick.hita.duration.value/1000/tchStick.hita.count.value * tchStick.hita.count.value/tchStick.teacher.count.value);
  147. //}
  148. //if (tchStick.ies5Tch.count.value>0 && tchStick.ies5Tch.duration.value>0)
  149. //{
  150. // tchStick.ies5Tch.stick.value= (tchStick.ies5Tch.duration.value/1000/tchStick.ies5Tch.count.value * tchStick.ies5Tch.count.value/tchStick.teacher.count.value);
  151. //}
  152. //if (tchStick.otherTch.count.value>0 && tchStick.otherTch.duration.value>0)
  153. //{
  154. // tchStick.otherTch.stick.value= (tchStick.otherTch.duration.value/1000/tchStick.otherTch.count.value);
  155. //}
  156. //if (tchStick.hiteach.count.value>0 && tchStick.hiteach.duration.value>0)
  157. //{
  158. // tchStick.hiteach.stick.value= (tchStick.hiteach.duration.value/1000/tchStick.hiteach.count.value)+(tchStick.lesson.value*100);
  159. //}
  160. //if (tchStick.teacher.count.value>0 && tchStick.teacher.duration.value>0)
  161. //{
  162. // tchStick.teacher.stick.value= (tchStick.teacher.duration.value/1000/tchStick.teacher.count.value)+ (tchStick.lesson.value*100);
  163. //}
  164. #region
  165. if (tchStick.hita.count.value>0)
  166. {
  167. if (min_tch_hita_c ==0)
  168. {
  169. min_tch_hita_c= tchStick.hita.count.value;
  170. }
  171. else if (min_tch_hita_c>tchStick.hita.count.value)
  172. {
  173. min_tch_hita_c=tchStick.hita.count.value;
  174. }
  175. if (tchStick.hita.count.value>max_tch_hita_c)
  176. {
  177. max_tch_hita_c= tchStick.hita.count.value;
  178. }
  179. }
  180. if (tchStick.hiteach.count.value>0)
  181. {
  182. if (min_tch_hiteach_c ==0)
  183. {
  184. min_tch_hiteach_c= tchStick.hiteach.count.value;
  185. }
  186. else if (min_tch_hiteach_c>tchStick.hiteach.count.value)
  187. {
  188. min_tch_hiteach_c=tchStick.hiteach.count.value;
  189. }
  190. if (tchStick.hiteach.count.value>max_tch_hiteach_c)
  191. {
  192. max_tch_hiteach_c= tchStick.hiteach.count.value;
  193. }
  194. }
  195. if (tchStick.ies5Tch.count.value>0)
  196. {
  197. if (min_tch_ies5Tch_c ==0)
  198. {
  199. min_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  200. }
  201. else if (min_tch_ies5Tch_c>tchStick.ies5Tch.count.value)
  202. {
  203. min_tch_ies5Tch_c=tchStick.ies5Tch.count.value;
  204. }
  205. if (tchStick.ies5Tch.count.value>max_tch_ies5Tch_c)
  206. {
  207. max_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  208. }
  209. }
  210. if (tchStick.otherTch.count.value>0)
  211. {
  212. if (min_tch_otherTch_c ==0)
  213. {
  214. min_tch_otherTch_c= tchStick.otherTch.count.value;
  215. }
  216. else if (min_tch_otherTch_c>tchStick.otherTch.count.value)
  217. {
  218. min_tch_otherTch_c=tchStick.otherTch.count.value;
  219. }
  220. if (tchStick.otherTch.count.value>max_tch_otherTch_c)
  221. {
  222. max_tch_otherTch_c= tchStick.otherTch.count.value;
  223. }
  224. }
  225. if (tchStick.hita.duration.value>0)
  226. {
  227. if (min_tch_hita_d ==0)
  228. {
  229. min_tch_hita_d= tchStick.hita.duration.value;
  230. }
  231. else if (min_tch_hita_d>tchStick.hita.duration.value)
  232. {
  233. min_tch_hita_d=tchStick.hita.duration.value;
  234. }
  235. if (tchStick.hita.duration.value>max_tch_hita_d)
  236. {
  237. max_tch_hita_d= tchStick.hita.duration.value;
  238. }
  239. }
  240. if (tchStick.hiteach.duration.value>0)
  241. {
  242. if (min_tch_hiteach_d ==0)
  243. {
  244. min_tch_hiteach_d= tchStick.hiteach.duration.value;
  245. }
  246. else if (min_tch_hiteach_d>tchStick.hiteach.duration.value)
  247. {
  248. min_tch_hiteach_d=tchStick.hiteach.duration.value;
  249. }
  250. if (tchStick.hiteach.duration.value>max_tch_hiteach_d)
  251. {
  252. max_tch_hiteach_d= tchStick.hiteach.duration.value;
  253. }
  254. }
  255. if (tchStick.ies5Tch.duration.value>0)
  256. {
  257. if (min_tch_ies5Tch_d ==0)
  258. {
  259. min_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  260. }
  261. else if (min_tch_ies5Tch_d>tchStick.ies5Tch.duration.value)
  262. {
  263. min_tch_ies5Tch_d=tchStick.ies5Tch.duration.value;
  264. }
  265. if (tchStick.ies5Tch.duration.value>max_tch_ies5Tch_d)
  266. {
  267. max_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  268. }
  269. }
  270. if (tchStick.otherTch.duration.value>0)
  271. {
  272. if (min_tch_otherTch_d ==0)
  273. {
  274. min_tch_otherTch_d= tchStick.otherTch.duration.value;
  275. }
  276. else if (min_tch_otherTch_d>tchStick.otherTch.duration.value)
  277. {
  278. min_tch_otherTch_d=tchStick.otherTch.duration.value;
  279. }
  280. if (tchStick.otherTch.duration.value>max_tch_otherTch_d)
  281. {
  282. max_tch_otherTch_d= tchStick.otherTch.duration.value;
  283. }
  284. }
  285. #endregion
  286. stickiness.tchSticks.Add(tchStick);
  287. }
  288. 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);
  289. var studentCount = student.Count();
  290. foreach (var user in student)
  291. {
  292. StuStick stuStick = new StuStick
  293. {
  294. id=user.Key,
  295. school=chinaSchoolKey.Key
  296. };
  297. var studentOtherVisit = user.Where(x => !x.client.Equals("ies5"));
  298. var studentOtherVisitCount = studentOtherVisit.Count();
  299. if (studentOtherVisitCount>0)
  300. { otherStu+=1; }
  301. double studentOtherVisitTime = GetUserDuration(studentOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  302. var studentIes5Visit = user.Where(x => x.client.Equals("ies5"));
  303. var studentIes5VisitCount = studentIes5Visit.Count();
  304. if (studentIes5VisitCount>0)
  305. { ies5Stu+=1; }
  306. double studentIes5VisitTime = GetUserDuration(studentIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  307. ies5StuCount+=studentIes5VisitCount;
  308. ies5StuTime+=studentIes5VisitTime;
  309. otherStuCount+=studentOtherVisitCount;
  310. otherStuTime+=studentOtherVisitTime;
  311. stuStick.ies5Stu.count.value=studentIes5VisitCount;
  312. stuStick.ies5Stu.duration.value=studentIes5VisitTime;
  313. stuStick.otherStu.count.value=studentOtherVisitCount;
  314. stuStick.otherStu.duration.value=studentOtherVisitTime;
  315. stuStick.student.count.value= stuStick.ies5Stu.count.value+stuStick.otherStu.count.value;
  316. stuStick.student.duration.value= stuStick.ies5Stu.duration.value+stuStick.otherStu.duration.value;
  317. stuStick.ies5Stu.userCount=1;
  318. stuStick.otherStu.userCount=1;
  319. stuStick.student.userCount=1;
  320. //if (stuStick.ies5Stu.count.value>0 && stuStick.ies5Stu.duration.value>0)
  321. //{
  322. // stuStick.ies5Stu.stick.value= (stuStick.ies5Stu.duration.value/1000/stuStick.ies5Stu.count.value);
  323. //}
  324. //if (stuStick.otherStu.count.value>0 && stuStick.otherStu.duration.value>0)
  325. //{
  326. // stuStick.otherStu.stick.value=(stuStick.otherStu.duration.value/1000/stuStick.otherStu.count.value);
  327. //}
  328. //if (stuStick.student.count.value>0 && stuStick.student.duration.value>0)
  329. //{
  330. // stuStick.student.stick.value=(stuStick.student.duration.value/1000/stuStick.student.count.value);
  331. //}
  332. #region
  333. if (stuStick.otherStu.count.value>0)
  334. {
  335. if (min_stu_otherStu_c ==0)
  336. {
  337. min_stu_otherStu_c= stuStick.otherStu.count.value;
  338. }
  339. else if (min_stu_otherStu_c>stuStick.otherStu.count.value)
  340. {
  341. min_stu_otherStu_c=stuStick.otherStu.count.value;
  342. }
  343. if (stuStick.otherStu.count.value>max_stu_otherStu_c)
  344. {
  345. max_stu_otherStu_c= stuStick.otherStu.count.value;
  346. }
  347. }
  348. if (stuStick.ies5Stu.count.value>0)
  349. {
  350. if (min_stu_ies5Stu_c ==0)
  351. {
  352. min_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  353. }
  354. else if (min_stu_ies5Stu_c>stuStick.ies5Stu.count.value)
  355. {
  356. min_stu_ies5Stu_c=stuStick.ies5Stu.count.value;
  357. }
  358. if (stuStick.ies5Stu.count.value>max_stu_ies5Stu_c)
  359. {
  360. max_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  361. }
  362. }
  363. if (stuStick.otherStu.duration.value>0)
  364. {
  365. if (min_stu_otherStu_d ==0)
  366. {
  367. min_stu_otherStu_d= stuStick.otherStu.duration.value;
  368. }
  369. else if (min_stu_otherStu_d>stuStick.otherStu.duration.value)
  370. {
  371. min_stu_otherStu_d=stuStick.otherStu.duration.value;
  372. }
  373. if (stuStick.otherStu.duration.value>max_stu_otherStu_d)
  374. {
  375. max_stu_otherStu_d= stuStick.otherStu.duration.value;
  376. }
  377. }
  378. if (stuStick.ies5Stu.duration.value>0)
  379. {
  380. if (min_stu_ies5Stu_d ==0)
  381. {
  382. min_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  383. }
  384. else if (min_stu_ies5Stu_d>stuStick.ies5Stu.duration.value)
  385. {
  386. min_stu_ies5Stu_d=stuStick.ies5Stu.duration.value;
  387. }
  388. if (stuStick.ies5Stu.duration.value>max_stu_ies5Stu_d)
  389. {
  390. max_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  391. }
  392. }
  393. #endregion
  394. stickiness.stuSticks.Add(stuStick);
  395. }
  396. //时长
  397. stickiness.hita.duration.value=hitaTime;
  398. stickiness.hiteach.duration.value=hiteachTime;
  399. stickiness.otherTch.duration.value=otherTchTime;
  400. stickiness.ies5Tch.duration.value=ies5TchTime;
  401. stickiness.ies5Stu.duration.value=ies5StuTime;
  402. stickiness.otherStu.duration.value=otherStuTime;
  403. stickiness.teacher.duration.value=hitaTime+hiteachTime+otherTchTime+ies5TchTime;
  404. stickiness.student.duration.value=otherStuTime+ies5StuTime;
  405. //用户数
  406. stickiness.hita.userCount=hitaTch;
  407. stickiness.hiteach.userCount=hiteachTch;
  408. stickiness.ies5Tch.userCount=ies5Tch;
  409. stickiness.otherTch.userCount=otherTch;
  410. stickiness.ies5Stu.userCount=ies5Stu;
  411. stickiness.otherStu.userCount=otherStu;
  412. stickiness.teacher.userCount=teacherCount;
  413. stickiness.student.userCount=studentCount;
  414. //访问数
  415. stickiness.hita.count.value=hitaCount;
  416. stickiness.hiteach.count.value=hiteachCount;
  417. stickiness.ies5Tch.count.value=ies5TchCount;
  418. stickiness.otherTch.count.value=otherTchCount;
  419. stickiness.ies5Stu.count.value=ies5StuCount;
  420. stickiness.otherStu.count.value=otherStuCount;
  421. stickiness.teacher.count.value=hitaCount+hiteachCount+ies5TchCount+otherTchCount;
  422. stickiness.student.count.value=ies5StuCount+otherStuCount;
  423. //开课数
  424. stickiness.lesson.value=lessonCount;
  425. //if (stickiness.hita.count.value>0 && stickiness.hita.duration.value>0)
  426. //{
  427. // stickiness.hita.stick.value=(stickiness.hita.userCount* stickiness.hita.count.value)/(stickiness.hita.duration.value/1000/stickiness.hita.count.value);
  428. //}
  429. //if (stickiness.ies5Stu.count.value>0 && stickiness.ies5Stu.duration.value>0)
  430. //{
  431. // stickiness.ies5Stu.stick.value=(stickiness.ies5Stu.userCount* stickiness.ies5Stu.count.value)/(stickiness.ies5Stu.duration.value/1000/stickiness.ies5Stu.count.value);
  432. //}
  433. //if (stickiness.ies5Tch.count.value>0 && stickiness.ies5Tch.duration.value>0)
  434. //{
  435. // stickiness.ies5Tch.stick.value=(stickiness.ies5Tch.userCount* stickiness.ies5Tch.count.value)/(stickiness.ies5Tch.duration.value/1000/stickiness.ies5Tch.count.value);
  436. //}
  437. //if (stickiness.otherStu.count.value>0 && stickiness.otherStu.duration.value>0)
  438. //{
  439. // stickiness.otherStu.stick.value=(stickiness.otherStu.userCount* stickiness.otherStu.count.value)/(stickiness.otherStu.duration.value/1000/stickiness.otherStu.count.value);
  440. //}
  441. //if (stickiness.otherTch.count.value>0 && stickiness.otherTch.duration.value>0)
  442. //{
  443. // stickiness.otherTch.stick.value=(stickiness.otherTch.userCount* stickiness.otherTch.count.value)/(stickiness.otherTch.duration.value/1000/stickiness.otherTch.count.value);
  444. //}
  445. //if (stickiness.hiteach.count.value>0 && stickiness.hiteach.duration.value>0)
  446. //{
  447. // stickiness.hiteach.stick.value=(stickiness.hiteach.userCount* stickiness.hiteach.count.value)/(stickiness.hiteach.duration.value/1000/stickiness.hiteach.count.value)+stickiness.lesson.value;
  448. //}
  449. //if (stickiness.teacher.count.value>0 && stickiness.teacher.duration.value>0)
  450. //{
  451. // stickiness.teacher.stick.value=(stickiness.teacher.userCount* stickiness.teacher.count.value)/(stickiness.teacher.duration.value/1000/stickiness.teacher.count.value)+ stickiness.lesson.value;
  452. //}
  453. //if (stickiness.student.count.value>0 && stickiness.student.duration.value>0)
  454. //{
  455. // stickiness.student.stick.value=(stickiness.student.userCount* stickiness.student.count.value)/(stickiness.student.duration.value/1000/stickiness.student.count.value)+ stickiness.lesson.value;
  456. //}
  457. #region
  458. if (stickiness.hita.count.value>0)
  459. {
  460. if (min_sch_hita_c ==0)
  461. {
  462. min_sch_hita_c= stickiness.hita.count.value;
  463. }
  464. else if (min_sch_hita_c>stickiness.hita.count.value)
  465. {
  466. min_sch_hita_c=stickiness.hita.count.value;
  467. }
  468. if (stickiness.hita.count.value>max_sch_hita_c)
  469. {
  470. max_sch_hita_c= stickiness.hita.count.value;
  471. }
  472. }
  473. if (stickiness.hiteach.count.value>0)
  474. {
  475. if (min_sch_hiteach_c ==0)
  476. {
  477. min_sch_hiteach_c= stickiness.hiteach.count.value;
  478. }
  479. else if (min_sch_hiteach_c>stickiness.hiteach.count.value)
  480. {
  481. min_sch_hiteach_c=stickiness.hiteach.count.value;
  482. }
  483. if (stickiness.hiteach.count.value>max_sch_hiteach_c)
  484. {
  485. max_sch_hiteach_c= stickiness.hiteach.count.value;
  486. }
  487. }
  488. if (stickiness.ies5Tch.count.value>0)
  489. {
  490. if (min_sch_ies5Tch_c ==0)
  491. {
  492. min_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  493. }
  494. else if (min_sch_ies5Tch_c>stickiness.ies5Tch.count.value)
  495. {
  496. min_sch_ies5Tch_c=stickiness.ies5Tch.count.value;
  497. }
  498. if (stickiness.ies5Tch.count.value>max_sch_ies5Tch_c)
  499. {
  500. max_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  501. }
  502. }
  503. if (stickiness.otherTch.count.value>0)
  504. {
  505. if (min_sch_otherTch_c ==0)
  506. {
  507. min_sch_otherTch_c= stickiness.otherTch.count.value;
  508. }
  509. else if (min_sch_otherTch_c>stickiness.otherTch.count.value)
  510. {
  511. min_sch_otherTch_c=stickiness.otherTch.count.value;
  512. }
  513. if (stickiness.otherTch.count.value>max_sch_otherTch_c)
  514. {
  515. max_sch_otherTch_c= stickiness.otherTch.count.value;
  516. }
  517. }
  518. if (stickiness.otherStu.count.value>0)
  519. {
  520. if (min_sch_otherStu_c ==0)
  521. {
  522. min_sch_otherStu_c= stickiness.otherStu.count.value;
  523. }
  524. else if (min_sch_otherStu_c>stickiness.otherStu.count.value)
  525. {
  526. min_sch_otherStu_c=stickiness.otherStu.count.value;
  527. }
  528. if (stickiness.otherStu.count.value>max_sch_otherStu_c)
  529. {
  530. max_sch_otherStu_c= stickiness.otherStu.count.value;
  531. }
  532. }
  533. if (stickiness.ies5Stu.count.value>0)
  534. {
  535. if (min_sch_ies5Stu_c ==0)
  536. {
  537. min_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  538. }
  539. else if (min_sch_ies5Stu_c>stickiness.ies5Stu.count.value)
  540. {
  541. min_sch_ies5Stu_c=stickiness.ies5Stu.count.value;
  542. }
  543. if (stickiness.ies5Stu.count.value>max_sch_ies5Stu_c)
  544. {
  545. max_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  546. }
  547. }
  548. if (stickiness.hita.duration.value>0)
  549. {
  550. if (min_sch_hita_d ==0)
  551. {
  552. min_sch_hita_d= stickiness.hita.duration.value;
  553. }
  554. else if (min_sch_hita_d>stickiness.hita.duration.value)
  555. {
  556. min_sch_hita_d=stickiness.hita.duration.value;
  557. }
  558. if (stickiness.hita.duration.value>max_sch_hita_d)
  559. {
  560. max_sch_hita_d= stickiness.hita.duration.value;
  561. }
  562. }
  563. if (stickiness.hiteach.duration.value>0)
  564. {
  565. if (min_sch_hiteach_d ==0)
  566. {
  567. min_sch_hiteach_d= stickiness.hiteach.duration.value;
  568. }
  569. else if (min_sch_hiteach_d>stickiness.hiteach.duration.value)
  570. {
  571. min_sch_hiteach_d=stickiness.hiteach.duration.value;
  572. }
  573. if (stickiness.hiteach.duration.value>max_sch_hiteach_d)
  574. {
  575. max_sch_hiteach_d= stickiness.hiteach.duration.value;
  576. }
  577. }
  578. if (stickiness.ies5Tch.duration.value>0)
  579. {
  580. if (min_sch_ies5Tch_d ==0)
  581. {
  582. min_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  583. }
  584. else if (min_sch_ies5Tch_d>stickiness.ies5Tch.duration.value)
  585. {
  586. min_sch_ies5Tch_d=stickiness.ies5Tch.duration.value;
  587. }
  588. if (stickiness.ies5Tch.duration.value>max_sch_ies5Tch_d)
  589. {
  590. max_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  591. }
  592. }
  593. if (stickiness.otherTch.duration.value>0)
  594. {
  595. if (min_sch_otherTch_d ==0)
  596. {
  597. min_sch_otherTch_d= stickiness.otherTch.duration.value;
  598. }
  599. else if (min_sch_otherTch_d>stickiness.otherTch.duration.value)
  600. {
  601. min_sch_otherTch_d=stickiness.otherTch.duration.value;
  602. }
  603. if (stickiness.otherTch.duration.value>max_sch_otherTch_d)
  604. {
  605. max_sch_otherTch_d= stickiness.otherTch.duration.value;
  606. }
  607. }
  608. if (stickiness.otherStu.duration.value>0)
  609. {
  610. if (min_sch_otherStu_d ==0)
  611. {
  612. min_sch_otherStu_d= stickiness.otherStu.duration.value;
  613. }
  614. else if (min_sch_otherStu_d>stickiness.otherStu.duration.value)
  615. {
  616. min_sch_otherStu_d=stickiness.otherStu.duration.value;
  617. }
  618. if (stickiness.otherStu.duration.value>max_sch_otherStu_d)
  619. {
  620. max_sch_otherStu_d= stickiness.otherStu.duration.value;
  621. }
  622. }
  623. if (stickiness.ies5Stu.duration.value>0)
  624. {
  625. if (min_sch_ies5Stu_d ==0)
  626. {
  627. min_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  628. }
  629. else if (min_sch_ies5Stu_d>stickiness.ies5Stu.duration.value)
  630. {
  631. min_sch_ies5Stu_d=stickiness.ies5Stu.duration.value;
  632. }
  633. if (stickiness.ies5Stu.duration.value>max_sch_ies5Stu_d)
  634. {
  635. max_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  636. }
  637. }
  638. #endregion
  639. var bygoneStickinessSchool = bygoneStickiness?.Find(x => x.id.Equals(chinaSchoolKey.Key));
  640. stickiness.tchSticks= OrderByTchStick(stickiness.tchSticks, bygoneStickinessSchool?.tchSticks);
  641. stickiness.stuSticks= OrderByStuStick(stickiness.stuSticks, bygoneStickinessSchool?.stuSticks);
  642. schoolStickiness.Add(stickiness);
  643. }
  644. return OrderBySchoolStick(schoolStickiness, bygoneStickiness);
  645. }
  646. private static List<StuStick> OrderByStuStick(List<StuStick> currentStickiness, List<StuStick>? bygoneStickiness)
  647. {
  648. // 假设visit已经填充了数据
  649. #region
  650. var rank_tmd_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  651. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  652. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  653. #endregion
  654. #region
  655. var rank_tmd_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  656. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  657. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  658. #endregion
  659. #region
  660. var rank_tmd_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  661. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  662. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  663. #endregion
  664. currentStickiness.ForEach(x =>
  665. {
  666. #region
  667. if (x.student.count.value>0)
  668. {
  669. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.student.count.value);
  670. if (index_tmd_count!=-1)
  671. {
  672. x.student.count.rank = index_tmd_count + 1;
  673. }
  674. }
  675. if (x.ies5Stu.count.value>0)
  676. {
  677. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  678. if (index_ies5Stu_count!=-1)
  679. {
  680. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  681. }
  682. }
  683. if (x.otherStu.count.value>0)
  684. {
  685. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  686. if (index_otherStu_count!=-1)
  687. {
  688. x.otherStu.count.rank = index_otherStu_count + 1;
  689. }
  690. }
  691. #endregion
  692. #region
  693. if (x.student.duration.value> 0)
  694. {
  695. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.student.duration.value);
  696. if (index_tmd_duration!=-1)
  697. {
  698. x.student.duration.rank = index_tmd_duration + 1;
  699. }
  700. }
  701. if (x.ies5Stu.duration.value>0)
  702. {
  703. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  704. if (index_ies5Stu_duration!=-1)
  705. {
  706. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  707. }
  708. }
  709. if (x.otherStu.duration.value>0)
  710. {
  711. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  712. if (index_otherStu_duration!=-1)
  713. {
  714. x.otherStu.duration.rank = index_otherStu_duration + 1;
  715. }
  716. }
  717. #endregion
  718. #region
  719. if (x.student.stick.value>0)
  720. {
  721. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.student.stick.value);
  722. if (index_tmd_stick!=-1)
  723. {
  724. x.student.stick.rank = index_tmd_stick + 1;
  725. }
  726. }
  727. if (x.ies5Stu.stick.value>0)
  728. {
  729. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  730. if (index_ies5Stu_stick!=-1)
  731. {
  732. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  733. }
  734. }
  735. if (x.otherStu.stick.value>0)
  736. {
  737. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  738. if (index_otherStu_stick!=-1)
  739. {
  740. x.otherStu.stick.rank = index_otherStu_stick + 1;
  741. }
  742. }
  743. #endregion
  744. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  745. if (bygone!=null)
  746. {
  747. #region tmd
  748. //人数上升下降
  749. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  750. //访问数量上升下降
  751. x.student.count.range= x.student.count.value-bygone.student.count.value;
  752. //访问数量排名上升下降
  753. x.student.count.updown= -(x.student.count.rank-bygone.student.count.rank);
  754. //停留时长上升下降
  755. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  756. //停留时长排名上升下降
  757. x.student.duration.updown=-(x.student.duration.rank-bygone.student.duration.rank);
  758. //访问指数上升下降
  759. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  760. //访问指数排名上升下降
  761. x.student.stick.updown=-(x.student.stick.rank-bygone.student.stick.rank);
  762. #endregion
  763. #region otherStu
  764. //人数上升下降
  765. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  766. //访问数量上升下降
  767. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  768. //访问数量排名上升下降
  769. x.otherStu.count.updown= -(x.otherStu.count.rank-bygone.otherStu.count.rank);
  770. //停留时长上升下降
  771. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  772. //停留时长排名上升下降
  773. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  774. //访问指数上升下降
  775. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  776. //访问指数排名上升下降
  777. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  778. #endregion
  779. #region ies5Stu
  780. //人数上升下降
  781. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  782. //访问数量上升下降
  783. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  784. //访问数量排名上升下降
  785. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  786. //停留时长上升下降
  787. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  788. //停留时长排名上升下降
  789. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  790. //访问指数上升下降
  791. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  792. //访问指数排名上升下降
  793. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  794. #endregion
  795. }
  796. else
  797. {
  798. #region tmd
  799. //人数上升下降
  800. x.student.userUpdown= x.student.userCount;
  801. //访问数量上升下降
  802. x.student.count.range= x.student.count.value;
  803. //访问数量排名上升下降
  804. x.student.count.updown= x.student.count.rank;
  805. //停留时长上升下降
  806. x.student.duration.range=x.student.duration.value;
  807. //停留时长排名上升下降
  808. x.student.duration.updown=x.student.duration.rank;
  809. //访问指数上升下降
  810. x.student.stick.range=x.student.stick.value;
  811. //访问指数排名上升下降
  812. x.student.stick.updown=x.student.stick.rank;
  813. #endregion
  814. #region otherStu
  815. //人数上升下降
  816. x.otherStu.userUpdown= x.otherStu.userCount;
  817. //访问数量上升下降
  818. x.otherStu.count.range= x.otherStu.count.value;
  819. //访问数量排名上升下降
  820. x.otherStu.count.updown= x.otherStu.count.rank;
  821. //停留时长上升下降
  822. x.otherStu.duration.range=x.otherStu.duration.value;
  823. //停留时长排名上升下降
  824. x.otherStu.duration.updown=x.otherStu.duration.rank;
  825. //访问指数上升下降
  826. x.otherStu.stick.range=x.otherStu.stick.value;
  827. //访问指数排名上升下降
  828. x.otherStu.stick.updown=x.otherStu.stick.rank;
  829. #endregion
  830. #region ies5Stu
  831. //人数上升下降
  832. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  833. //访问数量上升下降
  834. x.ies5Stu.count.range= x.ies5Stu.count.value;
  835. //访问数量排名上升下降
  836. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  837. //停留时长上升下降
  838. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  839. //停留时长排名上升下降
  840. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  841. //访问指数上升下降
  842. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  843. //访问指数排名上升下降
  844. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  845. #endregion
  846. }
  847. });
  848. //当前时间没有的
  849. var disappears = bygoneStickiness?.Where(x => x.student.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  850. if (disappears!=null && disappears.Count()>0)
  851. {
  852. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  853. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  854. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  855. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  856. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  857. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  858. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  859. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  860. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  861. foreach (var disappear in disappears)
  862. {
  863. //下降
  864. // y 5 t0
  865. disappear.student.stick.updown= -disappear.student.stick.rank;
  866. disappear.student.stick.range= -disappear.student.stick.value;
  867. disappear.student.stick.value=0;
  868. disappear.student.stick.rank=rank_tmd_stick_Max+1;
  869. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  870. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  871. disappear.ies5Stu.stick.value=0;
  872. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  873. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  874. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  875. disappear.otherStu.stick.value=0;
  876. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  877. disappear.student.count.updown= -disappear.student.count.rank;
  878. disappear.student.count.range= -disappear.student.count.value;
  879. disappear.student.count.value=0;
  880. disappear.student.count.rank=rank_tmd_count_Max+1;
  881. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  882. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  883. disappear.ies5Stu.count.value=0;
  884. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  885. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  886. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  887. disappear.otherStu.count.value=0;
  888. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  889. disappear.student.duration.updown= -disappear.student.duration.rank;
  890. disappear.student.duration.range= -disappear.student.duration.value;
  891. disappear.student.duration.value=0;
  892. disappear.student.duration.rank=rank_tmd_duration_Max+1;
  893. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  894. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  895. disappear.ies5Stu.duration.value=0;
  896. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  897. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  898. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  899. disappear.otherStu.duration.value=0;
  900. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  901. currentStickiness.Add(disappear);
  902. }
  903. }
  904. currentStickiness= currentStickiness.OrderByDescending(x => x.student.stick.value).ToList();
  905. return currentStickiness;
  906. }
  907. private static List<TchStick> OrderByTchStick(List<TchStick> currentStickiness, List<TchStick>? bygoneStickiness)
  908. {
  909. // 假设visit已经填充了数据
  910. #region
  911. var rank_tmd_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  912. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  913. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  914. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  915. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  916. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  917. #endregion
  918. #region
  919. var rank_tmd_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  920. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  921. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  922. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  923. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  924. #endregion
  925. #region
  926. var rank_tmd_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  927. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  928. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  929. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  930. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  931. #endregion
  932. currentStickiness.ForEach(x =>
  933. {
  934. #region
  935. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.teacher.count.value);
  936. if (index_tmd_count!=-1)
  937. {
  938. x.teacher.count.rank = index_tmd_count + 1;
  939. }
  940. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  941. if (index_hita_count!=-1)
  942. {
  943. x.hita.count.rank = index_hita_count + 1;
  944. }
  945. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  946. if (index_hiteach_count!=-1)
  947. {
  948. x.hiteach.count.rank = index_hiteach_count + 1;
  949. }
  950. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  951. if (index_ies5Tch_count!=-1)
  952. {
  953. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  954. }
  955. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  956. if (index_otherTch_count!=-1)
  957. {
  958. x.otherTch.count.rank = index_otherTch_count + 1;
  959. }
  960. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  961. if (index_lesson_count!=-1)
  962. {
  963. x.lesson.rank = index_lesson_count + 1;
  964. }
  965. #endregion
  966. #region
  967. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.teacher.duration.value);
  968. if (index_tmd_duration!=-1)
  969. {
  970. x.teacher.duration.rank = index_tmd_duration + 1;
  971. }
  972. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  973. if (index_hita_duration!=-1)
  974. {
  975. x.hita.duration.rank = index_hita_duration + 1;
  976. }
  977. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  978. if (index_hiteach_duration!=-1)
  979. {
  980. x.hiteach.duration.rank = index_hiteach_duration + 1;
  981. }
  982. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  983. if (index_ies5Tch_duration!=-1)
  984. {
  985. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  986. }
  987. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  988. if (index_otherTch_duration!=-1)
  989. {
  990. x.otherTch.duration.rank = index_otherTch_duration + 1;
  991. }
  992. #endregion
  993. #region
  994. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.teacher.stick.value);
  995. if (index_tmd_stick!=-1)
  996. {
  997. x.teacher.stick.rank = index_tmd_stick + 1;
  998. }
  999. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  1000. if (index_hita_stick!=-1)
  1001. {
  1002. x.hita.stick.rank = index_hita_stick + 1;
  1003. }
  1004. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  1005. if (index_hiteach_stick!=-1)
  1006. {
  1007. x.hiteach.stick.rank = index_hiteach_stick + 1;
  1008. }
  1009. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  1010. if (index_ies5Tch_stick!=-1)
  1011. {
  1012. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  1013. }
  1014. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  1015. if (index_otherTch_stick!=-1)
  1016. {
  1017. x.otherTch.stick.rank = index_otherTch_stick + 1;
  1018. }
  1019. #endregion
  1020. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  1021. if (bygone!=null)
  1022. {
  1023. #region
  1024. x.lesson.range=x.lesson.value-bygone.lesson.value;
  1025. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  1026. #endregion
  1027. #region tmd
  1028. //人数上升下降
  1029. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  1030. //访问数量上升下降
  1031. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  1032. //访问数量排名上升下降
  1033. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  1034. //停留时长上升下降
  1035. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  1036. //停留时长排名上升下降
  1037. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  1038. //访问指数上升下降
  1039. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  1040. //访问指数排名上升下降
  1041. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  1042. #endregion
  1043. #region hita
  1044. //人数上升下降
  1045. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  1046. //访问数量上升下降
  1047. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  1048. //访问数量排名上升下降
  1049. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  1050. //停留时长上升下降
  1051. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  1052. //停留时长排名上升下降
  1053. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  1054. //访问指数上升下降
  1055. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  1056. //访问指数排名上升下降
  1057. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  1058. #endregion
  1059. #region hiteach
  1060. //人数上升下降
  1061. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  1062. //访问数量上升下降
  1063. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  1064. //访问数量排名上升下降
  1065. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  1066. //停留时长上升下降
  1067. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  1068. //停留时长排名上升下降
  1069. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  1070. //访问指数上升下降
  1071. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  1072. //访问指数排名上升下降
  1073. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  1074. #endregion
  1075. #region otherTch
  1076. //人数上升下降
  1077. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  1078. //访问数量上升下降
  1079. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  1080. //访问数量排名上升下降
  1081. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  1082. //停留时长上升下降
  1083. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  1084. //停留时长排名上升下降
  1085. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  1086. //访问指数上升下降
  1087. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  1088. //访问指数排名上升下降
  1089. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  1090. #endregion
  1091. #region ies5Tch
  1092. //人数上升下降
  1093. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  1094. //访问数量上升下降
  1095. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  1096. //访问数量排名上升下降
  1097. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  1098. //停留时长上升下降
  1099. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  1100. //停留时长排名上升下降
  1101. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  1102. //访问指数上升下降
  1103. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  1104. //访问指数排名上升下降
  1105. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  1106. #endregion
  1107. }
  1108. else
  1109. {
  1110. #region
  1111. x.lesson.range=x.lesson.value;
  1112. x.lesson.updown=x.lesson.rank;
  1113. #endregion
  1114. #region tmd
  1115. //人数上升下降
  1116. x.teacher.userUpdown= x.teacher.userCount;
  1117. //访问数量上升下降
  1118. x.teacher.count.range= x.teacher.count.value;
  1119. //访问数量排名上升下降
  1120. x.teacher.count.updown= x.teacher.count.rank;
  1121. //停留时长上升下降
  1122. x.teacher.duration.range=x.teacher.duration.value;
  1123. //停留时长排名上升下降
  1124. x.teacher.duration.updown=x.teacher.duration.rank;
  1125. //访问指数上升下降
  1126. x.teacher.stick.range=x.teacher.stick.value;
  1127. //访问指数排名上升下降
  1128. x.teacher.stick.updown=x.teacher.stick.rank;
  1129. #endregion
  1130. #region hita
  1131. //人数上升下降
  1132. x.hita.userUpdown= x.hita.userCount;
  1133. //访问数量上升下降
  1134. x.hita.count.range= x.hita.count.value;
  1135. //访问数量排名上升下降
  1136. x.hita.count.updown= x.hita.count.rank;
  1137. //停留时长上升下降
  1138. x.hita.duration.range=x.hita.duration.value;
  1139. //停留时长排名上升下降
  1140. x.hita.duration.updown=x.hita.duration.rank;
  1141. //访问指数上升下降
  1142. x.hita.stick.range=x.hita.stick.value;
  1143. //访问指数排名上升下降
  1144. x.hita.stick.updown=x.hita.stick.rank;
  1145. #endregion
  1146. #region hiteach
  1147. //人数上升下降
  1148. x.hiteach.userUpdown= x.hiteach.userCount;
  1149. //访问数量上升下降
  1150. x.hiteach.count.range= x.hiteach.count.value;
  1151. //访问数量排名上升下降
  1152. x.hiteach.count.updown= x.hiteach.count.rank;
  1153. //停留时长上升下降
  1154. x.hiteach.duration.range=x.hiteach.duration.value;
  1155. //停留时长排名上升下降
  1156. x.hiteach.duration.updown=x.hiteach.duration.rank;
  1157. //访问指数上升下降
  1158. x.hiteach.stick.range=x.hiteach.stick.value;
  1159. //访问指数排名上升下降
  1160. x.hiteach.stick.updown=x.hiteach.stick.rank;
  1161. #endregion
  1162. #region otherTch
  1163. //人数上升下降
  1164. x.otherTch.userUpdown= x.otherTch.userCount;
  1165. //访问数量上升下降
  1166. x.otherTch.count.range= x.otherTch.count.value;
  1167. //访问数量排名上升下降
  1168. x.otherTch.count.updown= x.otherTch.count.rank;
  1169. //停留时长上升下降
  1170. x.otherTch.duration.range=x.otherTch.duration.value;
  1171. //停留时长排名上升下降
  1172. x.otherTch.duration.updown=x.otherTch.duration.rank;
  1173. //访问指数上升下降
  1174. x.otherTch.stick.range=x.otherTch.stick.value;
  1175. //访问指数排名上升下降
  1176. x.otherTch.stick.updown=x.otherTch.stick.rank;
  1177. #endregion
  1178. #region ies5Tch
  1179. //人数上升下降
  1180. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  1181. //访问数量上升下降
  1182. x.ies5Tch.count.range= x.ies5Tch.count.value;
  1183. //访问数量排名上升下降
  1184. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  1185. //停留时长上升下降
  1186. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  1187. //停留时长排名上升下降
  1188. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  1189. //访问指数上升下降
  1190. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  1191. //访问指数排名上升下降
  1192. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  1193. #endregion
  1194. }
  1195. });
  1196. //当前时间没有的
  1197. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  1198. if (disappears!=null && disappears.Count()>0)
  1199. {
  1200. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  1201. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  1202. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  1203. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  1204. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  1205. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  1206. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  1207. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  1208. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  1209. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  1210. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  1211. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  1212. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  1213. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  1214. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  1215. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  1216. foreach (var disappear in disappears)
  1217. {
  1218. disappear.lesson.updown=-disappear.lesson.rank;
  1219. disappear.lesson.range=-disappear.lesson.value;
  1220. disappear.lesson.value=0;
  1221. disappear.lesson.rank=rank_lesson_Max+1;
  1222. //下降
  1223. // y 5 t0
  1224. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  1225. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  1226. disappear.teacher.stick.value=0;
  1227. disappear.teacher.stick.rank=rank_tmd_stick_Max+1;
  1228. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  1229. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  1230. disappear.hiteach.stick.value=0;
  1231. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  1232. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  1233. disappear.hita.stick.range= -disappear.hita.stick.value;
  1234. disappear.hita.stick.value=0;
  1235. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  1236. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  1237. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  1238. disappear.ies5Tch.stick.value=0;
  1239. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  1240. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  1241. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  1242. disappear.otherTch.stick.value=0;
  1243. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  1244. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  1245. disappear.teacher.count.range= -disappear.teacher.count.value;
  1246. disappear.teacher.count.value=0;
  1247. disappear.teacher.count.rank=rank_tmd_count_Max+1;
  1248. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  1249. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  1250. disappear.hiteach.count.value=0;
  1251. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  1252. disappear.hita.count.updown= -disappear.hita.count.rank;
  1253. disappear.hita.count.range= -disappear.hita.count.value;
  1254. disappear.hita.count.value=0;
  1255. disappear.hita.count.rank=rank_hita_count_Max+1;
  1256. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  1257. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  1258. disappear.ies5Tch.count.value=0;
  1259. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  1260. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  1261. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  1262. disappear.otherTch.count.value=0;
  1263. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  1264. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  1265. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  1266. disappear.teacher.duration.value=0;
  1267. disappear.teacher.duration.rank=rank_tmd_duration_Max+1;
  1268. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  1269. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  1270. disappear.hiteach.duration.value=0;
  1271. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  1272. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  1273. disappear.hita.duration.range= -disappear.hita.duration.value;
  1274. disappear.hita.duration.value=0;
  1275. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  1276. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  1277. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  1278. disappear.ies5Tch.duration.value=0;
  1279. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  1280. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  1281. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  1282. disappear.otherTch.duration.value=0;
  1283. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  1284. currentStickiness.Add(disappear);
  1285. }
  1286. }
  1287. currentStickiness= currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  1288. return currentStickiness;
  1289. }
  1290. /// <summary>
  1291. ///
  1292. /// </summary>
  1293. /// <param name="currentStickiness">现在的</param>
  1294. /// <param name="bygoneStickiness">过去的</param>
  1295. /// <returns></returns>
  1296. private static List<SchoolStick> OrderBySchoolStick(List<SchoolStick> currentStickiness, List<SchoolStick>? bygoneStickiness)
  1297. {
  1298. // 假设visit已经填充了数据
  1299. #region
  1300. var rank_teacher_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  1301. var rank_student_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  1302. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  1303. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  1304. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  1305. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  1306. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1307. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1308. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  1309. #endregion
  1310. #region
  1311. var rank_teacher_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1312. var rank_student_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1313. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1314. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1315. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1316. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1317. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1318. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1319. #endregion
  1320. #region
  1321. var rank_teacher_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1322. var rank_student_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1323. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1324. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1325. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1326. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1327. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1328. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1329. #endregion
  1330. currentStickiness.ForEach(x =>
  1331. {
  1332. #region
  1333. if (x.teacher.count.value>0)
  1334. {
  1335. int index_teacher_count = rank_teacher_count.FindIndex(i => i==x.teacher.count.value);
  1336. if (index_teacher_count!=-1)
  1337. {
  1338. x.teacher.count.rank = index_teacher_count + 1;
  1339. }
  1340. }
  1341. if (x.student.count.value>0)
  1342. {
  1343. int index_student_count = rank_student_count.FindIndex(i => i==x.student.count.value);
  1344. if (index_student_count!=-1)
  1345. {
  1346. x.student.count.rank = index_student_count + 1;
  1347. }
  1348. }
  1349. if (x.hita.count.value>0)
  1350. {
  1351. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  1352. if (index_hita_count!=-1)
  1353. {
  1354. x.hita.count.rank = index_hita_count + 1;
  1355. }
  1356. }
  1357. if (x.hiteach.count.value>0)
  1358. {
  1359. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  1360. if (index_hiteach_count!=-1)
  1361. {
  1362. x.hiteach.count.rank = index_hiteach_count + 1;
  1363. }
  1364. }
  1365. if (x.ies5Tch.count.value>0)
  1366. {
  1367. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  1368. if (index_ies5Tch_count!=-1)
  1369. {
  1370. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  1371. }
  1372. }
  1373. if (x.otherTch.count.value>0)
  1374. {
  1375. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  1376. if (index_otherTch_count!=-1)
  1377. {
  1378. x.otherTch.count.rank = index_otherTch_count + 1;
  1379. }
  1380. }
  1381. if (x.ies5Stu.count.value>0)
  1382. {
  1383. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  1384. if (index_ies5Stu_count!=-1)
  1385. {
  1386. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  1387. }
  1388. }
  1389. if (x.otherStu.count.value>0)
  1390. {
  1391. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  1392. if (index_otherStu_count!=-1)
  1393. {
  1394. x.otherStu.count.rank = index_otherStu_count + 1;
  1395. }
  1396. }
  1397. if (x.lesson.value>0)
  1398. {
  1399. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  1400. if (index_lesson_count!=-1)
  1401. {
  1402. x.lesson.rank = index_lesson_count + 1;
  1403. }
  1404. }
  1405. #endregion
  1406. #region
  1407. if (x.teacher.duration.value>0)
  1408. {
  1409. int index_teacher_duration = rank_teacher_duration.FindIndex(i => i==x.teacher.duration.value);
  1410. if (index_teacher_duration!=-1)
  1411. {
  1412. x.teacher.duration.rank = index_teacher_duration + 1;
  1413. }
  1414. }
  1415. if (x.student.duration.value>0)
  1416. {
  1417. int index_student_duration = rank_student_duration.FindIndex(i => i==x.student.duration.value);
  1418. if (index_student_duration!=-1)
  1419. {
  1420. x.student.duration.rank = index_student_duration + 1;
  1421. }
  1422. }
  1423. if (x.hita.duration.value>0)
  1424. {
  1425. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  1426. if (index_hita_duration!=-1)
  1427. {
  1428. x.hita.duration.rank = index_hita_duration + 1;
  1429. }
  1430. }
  1431. if (x.hiteach.duration.value>0)
  1432. {
  1433. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  1434. if (index_hiteach_duration!=-1)
  1435. {
  1436. x.hiteach.duration.rank = index_hiteach_duration + 1;
  1437. }
  1438. }
  1439. if (x.ies5Tch.duration.value>0)
  1440. {
  1441. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  1442. if (index_ies5Tch_duration!=-1)
  1443. {
  1444. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  1445. }
  1446. }
  1447. if (x.otherTch.duration.value>0)
  1448. {
  1449. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  1450. if (index_otherTch_duration!=-1)
  1451. {
  1452. x.otherTch.duration.rank = index_otherTch_duration + 1;
  1453. }
  1454. }
  1455. if (x.ies5Stu.duration.value>0)
  1456. {
  1457. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  1458. if (index_ies5Stu_duration!=-1)
  1459. {
  1460. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  1461. }
  1462. }
  1463. if (x.otherStu.duration.value>0)
  1464. {
  1465. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  1466. if (index_otherStu_duration!=-1)
  1467. {
  1468. x.otherStu.duration.rank = index_otherStu_duration + 1;
  1469. }
  1470. }
  1471. #endregion
  1472. #region
  1473. if (x.teacher.stick.value>0)
  1474. {
  1475. int index_teacher_stick = rank_teacher_stick.FindIndex(i => i==x.teacher.stick.value);
  1476. if (index_teacher_stick!=-1)
  1477. {
  1478. x.teacher.stick.rank = index_teacher_stick + 1;
  1479. }
  1480. }
  1481. if (x.student.stick.value>0)
  1482. {
  1483. int index_student_stick = rank_student_stick.FindIndex(i => i==x.student.stick.value);
  1484. if (index_student_stick!=-1)
  1485. {
  1486. x.student.stick.rank = index_student_stick + 1;
  1487. }
  1488. }
  1489. if (x.hita.stick.value>0)
  1490. {
  1491. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  1492. if (index_hita_stick!=-1)
  1493. {
  1494. x.hita.stick.rank = index_hita_stick + 1;
  1495. }
  1496. }
  1497. if (x.hiteach.stick.value>0)
  1498. {
  1499. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  1500. if (index_hiteach_stick!=-1)
  1501. {
  1502. x.hiteach.stick.rank = index_hiteach_stick + 1;
  1503. }
  1504. }
  1505. if (x.ies5Tch.stick.value>0)
  1506. {
  1507. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  1508. if (index_ies5Tch_stick!=-1)
  1509. {
  1510. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  1511. }
  1512. }
  1513. if (x.otherTch.stick.value>0)
  1514. {
  1515. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  1516. if (index_otherTch_stick!=-1)
  1517. {
  1518. x.otherTch.stick.rank = index_otherTch_stick + 1;
  1519. }
  1520. }
  1521. if (x.ies5Stu.stick.value>0)
  1522. {
  1523. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  1524. if (index_ies5Stu_stick!=-1)
  1525. {
  1526. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  1527. }
  1528. }
  1529. if (x.otherStu.stick.value>0)
  1530. {
  1531. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  1532. if (index_otherStu_stick!=-1)
  1533. {
  1534. x.otherStu.stick.rank = index_otherStu_stick + 1;
  1535. }
  1536. }
  1537. #endregion
  1538. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  1539. if (bygone!=null)
  1540. {
  1541. #region
  1542. x.lesson.range=x.lesson.value-bygone.lesson.value;
  1543. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  1544. #endregion
  1545. #region student
  1546. //人数上升下降
  1547. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  1548. //访问数量上升下降
  1549. x.student.count.range= x.student.count.value-bygone.student.count.value;
  1550. //访问数量排名上升下降
  1551. x.student.count.updown= -(x.student.count.rank - bygone.student.count.rank);
  1552. //停留时长上升下降
  1553. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  1554. //停留时长排名上升下降
  1555. x.student.duration.updown=-(x.student.duration.rank - bygone.student.duration.rank);
  1556. //访问指数上升下降
  1557. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  1558. //访问指数排名上升下降
  1559. x.student.stick.updown=-(x.student.stick.rank - bygone.student.stick.rank);
  1560. #endregion
  1561. #region teacher
  1562. //人数上升下降
  1563. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  1564. //访问数量上升下降
  1565. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  1566. //访问数量排名上升下降
  1567. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  1568. //停留时长上升下降
  1569. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  1570. //停留时长排名上升下降
  1571. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  1572. //访问指数上升下降
  1573. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  1574. //访问指数排名上升下降
  1575. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  1576. #endregion
  1577. #region hita
  1578. //人数上升下降
  1579. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  1580. //访问数量上升下降
  1581. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  1582. //访问数量排名上升下降
  1583. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  1584. //停留时长上升下降
  1585. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  1586. //停留时长排名上升下降
  1587. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  1588. //访问指数上升下降
  1589. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  1590. //访问指数排名上升下降
  1591. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  1592. #endregion
  1593. #region hiteach
  1594. //人数上升下降
  1595. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  1596. //访问数量上升下降
  1597. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  1598. //访问数量排名上升下降
  1599. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  1600. //停留时长上升下降
  1601. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  1602. //停留时长排名上升下降
  1603. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  1604. //访问指数上升下降
  1605. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  1606. //访问指数排名上升下降
  1607. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  1608. #endregion
  1609. #region otherTch
  1610. //人数上升下降
  1611. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  1612. //访问数量上升下降
  1613. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  1614. //访问数量排名上升下降
  1615. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  1616. //停留时长上升下降
  1617. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  1618. //停留时长排名上升下降
  1619. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  1620. //访问指数上升下降
  1621. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  1622. //访问指数排名上升下降
  1623. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  1624. #endregion
  1625. #region otherStu
  1626. //人数上升下降
  1627. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  1628. //访问数量上升下降
  1629. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  1630. //访问数量排名上升下降
  1631. x.otherStu.count.updown= -(x.otherStu.count.rank - bygone.otherStu.count.rank);
  1632. //停留时长上升下降
  1633. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  1634. //停留时长排名上升下降
  1635. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  1636. //访问指数上升下降
  1637. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  1638. //访问指数排名上升下降
  1639. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  1640. #endregion
  1641. #region ies5Stu
  1642. //人数上升下降
  1643. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  1644. //访问数量上升下降
  1645. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  1646. //访问数量排名上升下降
  1647. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  1648. //停留时长上升下降
  1649. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  1650. //停留时长排名上升下降
  1651. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  1652. //访问指数上升下降
  1653. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  1654. //访问指数排名上升下降
  1655. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  1656. #endregion
  1657. #region ies5Tch
  1658. //人数上升下降
  1659. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  1660. //访问数量上升下降
  1661. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  1662. //访问数量排名上升下降
  1663. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  1664. //停留时长上升下降
  1665. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  1666. //停留时长排名上升下降
  1667. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  1668. //访问指数上升下降
  1669. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  1670. //访问指数排名上升下降
  1671. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  1672. #endregion
  1673. }
  1674. else
  1675. {
  1676. #region
  1677. x.lesson.range=x.lesson.value;
  1678. x.lesson.updown=x.lesson.rank;
  1679. #endregion
  1680. #region teacher
  1681. //人数上升下降
  1682. x.teacher.userUpdown= x.teacher.userCount;
  1683. //访问数量上升下降
  1684. x.teacher.count.range= x.teacher.count.value;
  1685. //访问数量排名上升下降
  1686. x.teacher.count.updown= x.teacher.count.rank;
  1687. //停留时长上升下降
  1688. x.teacher.duration.range=x.teacher.duration.value;
  1689. //停留时长排名上升下降
  1690. x.teacher.duration.updown=x.teacher.duration.rank;
  1691. //访问指数上升下降
  1692. x.teacher.stick.range=x.teacher.stick.value;
  1693. //访问指数排名上升下降
  1694. x.teacher.stick.updown=x.teacher.stick.rank;
  1695. #endregion
  1696. #region student
  1697. //人数上升下降
  1698. x.student.userUpdown= x.student.userCount;
  1699. //访问数量上升下降
  1700. x.student.count.range= x.student.count.value;
  1701. //访问数量排名上升下降
  1702. x.student.count.updown= x.student.count.rank;
  1703. //停留时长上升下降
  1704. x.student.duration.range=x.student.duration.value;
  1705. //停留时长排名上升下降
  1706. x.student.duration.updown=x.student.duration.rank;
  1707. //访问指数上升下降
  1708. x.student.stick.range=x.student.stick.value;
  1709. //访问指数排名上升下降
  1710. x.student.stick.updown=x.student.stick.rank;
  1711. #endregion
  1712. #region hita
  1713. //人数上升下降
  1714. x.hita.userUpdown= x.hita.userCount;
  1715. //访问数量上升下降
  1716. x.hita.count.range= x.hita.count.value;
  1717. //访问数量排名上升下降
  1718. x.hita.count.updown= x.hita.count.rank;
  1719. //停留时长上升下降
  1720. x.hita.duration.range=x.hita.duration.value;
  1721. //停留时长排名上升下降
  1722. x.hita.duration.updown=x.hita.duration.rank;
  1723. //访问指数上升下降
  1724. x.hita.stick.range=x.hita.stick.value;
  1725. //访问指数排名上升下降
  1726. x.hita.stick.updown=x.hita.stick.rank;
  1727. #endregion
  1728. #region hiteach
  1729. //人数上升下降
  1730. x.hiteach.userUpdown= x.hiteach.userCount;
  1731. //访问数量上升下降
  1732. x.hiteach.count.range= x.hiteach.count.value;
  1733. //访问数量排名上升下降
  1734. x.hiteach.count.updown= x.hiteach.count.rank;
  1735. //停留时长上升下降
  1736. x.hiteach.duration.range=x.hiteach.duration.value;
  1737. //停留时长排名上升下降
  1738. x.hiteach.duration.updown=x.hiteach.duration.rank;
  1739. //访问指数上升下降
  1740. x.hiteach.stick.range=x.hiteach.stick.value;
  1741. //访问指数排名上升下降
  1742. x.hiteach.stick.updown=x.hiteach.stick.rank;
  1743. #endregion
  1744. #region otherTch
  1745. //人数上升下降
  1746. x.otherTch.userUpdown= x.otherTch.userCount;
  1747. //访问数量上升下降
  1748. x.otherTch.count.range= x.otherTch.count.value;
  1749. //访问数量排名上升下降
  1750. x.otherTch.count.updown= x.otherTch.count.rank;
  1751. //停留时长上升下降
  1752. x.otherTch.duration.range=x.otherTch.duration.value;
  1753. //停留时长排名上升下降
  1754. x.otherTch.duration.updown=x.otherTch.duration.rank;
  1755. //访问指数上升下降
  1756. x.otherTch.stick.range=x.otherTch.stick.value;
  1757. //访问指数排名上升下降
  1758. x.otherTch.stick.updown=x.otherTch.stick.rank;
  1759. #endregion
  1760. #region otherStu
  1761. //人数上升下降
  1762. x.otherStu.userUpdown= x.otherStu.userCount;
  1763. //访问数量上升下降
  1764. x.otherStu.count.range= x.otherStu.count.value;
  1765. //访问数量排名上升下降
  1766. x.otherStu.count.updown= x.otherStu.count.rank;
  1767. //停留时长上升下降
  1768. x.otherStu.duration.range=x.otherStu.duration.value;
  1769. //停留时长排名上升下降
  1770. x.otherStu.duration.updown=x.otherStu.duration.rank;
  1771. //访问指数上升下降
  1772. x.otherStu.stick.range=x.otherStu.stick.value;
  1773. //访问指数排名上升下降
  1774. x.otherStu.stick.updown=x.otherStu.stick.rank;
  1775. #endregion
  1776. #region ies5Stu
  1777. //人数上升下降
  1778. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  1779. //访问数量上升下降
  1780. x.ies5Stu.count.range= x.ies5Stu.count.value;
  1781. //访问数量排名上升下降
  1782. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  1783. //停留时长上升下降
  1784. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  1785. //停留时长排名上升下降
  1786. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  1787. //访问指数上升下降
  1788. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  1789. //访问指数排名上升下降
  1790. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  1791. #endregion
  1792. #region ies5Tch
  1793. //人数上升下降
  1794. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  1795. //访问数量上升下降
  1796. x.ies5Tch.count.range= x.ies5Tch.count.value;
  1797. //访问数量排名上升下降
  1798. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  1799. //停留时长上升下降
  1800. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  1801. //停留时长排名上升下降
  1802. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  1803. //访问指数上升下降
  1804. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  1805. //访问指数排名上升下降
  1806. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  1807. #endregion
  1808. }
  1809. });
  1810. //当前时间没有的
  1811. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  1812. if (disappears!=null && disappears.Count()>0)
  1813. {
  1814. double rank_student_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  1815. double rank_student_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  1816. double rank_student_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  1817. double rank_teacher_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  1818. double rank_teacher_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  1819. double rank_teacher_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  1820. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  1821. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  1822. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  1823. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  1824. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  1825. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  1826. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  1827. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  1828. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  1829. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  1830. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  1831. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  1832. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  1833. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  1834. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  1835. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  1836. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  1837. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  1838. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  1839. foreach (var disappear in disappears)
  1840. {
  1841. disappear.lesson.updown=-disappear.lesson.rank;
  1842. disappear.lesson.range=-disappear.lesson.value;
  1843. disappear.lesson.value=0;
  1844. disappear.lesson.rank=rank_lesson_Max+1;
  1845. //下降
  1846. // y 5 t0
  1847. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  1848. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  1849. disappear.teacher.stick.value=0;
  1850. disappear.teacher.stick.rank=rank_teacher_stick_Max+1;
  1851. disappear.student.stick.updown= -disappear.student.stick.rank;
  1852. disappear.student.stick.range= -disappear.student.stick.value;
  1853. disappear.student.stick.value=0;
  1854. disappear.student.stick.rank=rank_student_stick_Max+1;
  1855. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  1856. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  1857. disappear.hiteach.stick.value=0;
  1858. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  1859. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  1860. disappear.hita.stick.range= -disappear.hita.stick.value;
  1861. disappear.hita.stick.value=0;
  1862. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  1863. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  1864. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  1865. disappear.ies5Stu.stick.value=0;
  1866. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  1867. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  1868. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  1869. disappear.ies5Tch.stick.value=0;
  1870. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  1871. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  1872. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  1873. disappear.otherStu.stick.value=0;
  1874. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  1875. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  1876. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  1877. disappear.otherTch.stick.value=0;
  1878. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  1879. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  1880. disappear.teacher.count.range= -disappear.teacher.count.value;
  1881. disappear.teacher.count.value=0;
  1882. disappear.teacher.count.rank=rank_teacher_count_Max+1;
  1883. disappear.student.count.updown= -disappear.student.count.rank;
  1884. disappear.student.count.range= -disappear.student.count.value;
  1885. disappear.student.count.value=0;
  1886. disappear.student.count.rank=rank_student_count_Max+1;
  1887. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  1888. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  1889. disappear.hiteach.count.value=0;
  1890. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  1891. disappear.hita.count.updown= -disappear.hita.count.rank;
  1892. disappear.hita.count.range= -disappear.hita.count.value;
  1893. disappear.hita.count.value=0;
  1894. disappear.hita.count.rank=rank_hita_count_Max+1;
  1895. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  1896. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  1897. disappear.ies5Stu.count.value=0;
  1898. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  1899. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  1900. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  1901. disappear.ies5Tch.count.value=0;
  1902. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  1903. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  1904. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  1905. disappear.otherStu.count.value=0;
  1906. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  1907. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  1908. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  1909. disappear.otherTch.count.value=0;
  1910. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  1911. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  1912. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  1913. disappear.teacher.duration.value=0;
  1914. disappear.teacher.duration.rank=rank_teacher_duration_Max+1;
  1915. disappear.student.duration.updown= -disappear.student.duration.rank;
  1916. disappear.student.duration.range= -disappear.student.duration.value;
  1917. disappear.student.duration.value=0;
  1918. disappear.student.duration.rank=rank_student_duration_Max+1;
  1919. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  1920. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  1921. disappear.hiteach.duration.value=0;
  1922. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  1923. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  1924. disappear.hita.duration.range= -disappear.hita.duration.value;
  1925. disappear.hita.duration.value=0;
  1926. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  1927. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  1928. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  1929. disappear.ies5Stu.duration.value=0;
  1930. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  1931. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  1932. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  1933. disappear.ies5Tch.duration.value=0;
  1934. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  1935. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  1936. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  1937. disappear.otherStu.duration.value=0;
  1938. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  1939. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  1940. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  1941. disappear.otherTch.duration.value=0;
  1942. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  1943. currentStickiness.Add(disappear);
  1944. }
  1945. }
  1946. currentStickiness = currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  1947. return currentStickiness;
  1948. }
  1949. /// <summary>
  1950. /// 结算访问日志
  1951. /// </summary>
  1952. public static async Task
  1953. VisitSettle(List<string> times, AzureStorageFactory _azureStorage, AzureRedisFactory _azureRedis, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, IPSearcher _ipSearcher, string force)
  1954. {
  1955. foreach (var timeDate in times)
  1956. {
  1957. List<Stick> chinaSticks = new List<Stick>();
  1958. List<Stick> globalSticks = new List<Stick>();
  1959. if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date))
  1960. {
  1961. var blobClientChina = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json");
  1962. var blobClientGlobal = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json");
  1963. bool g = true, c = true;
  1964. if (blobClientChina.Exists() && force.Equals("0"))
  1965. {
  1966. c=false;
  1967. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json").DownloadContentAsync();
  1968. var contentBygone = result.Content.ToString();
  1969. var chinaStick = contentBygone.ToObject<Stick>();
  1970. chinaSticks.Add(chinaStick);
  1971. }
  1972. if (blobClientGlobal.Exists()&& force.Equals("0"))
  1973. {
  1974. g=false;
  1975. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json").DownloadContentAsync();
  1976. var contentBygone = result.Content.ToString();
  1977. var globalStick = contentBygone.ToObject<Stick>();
  1978. globalSticks.Add(globalStick);
  1979. }
  1980. if (g||c)
  1981. {
  1982. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
  1983. var content = result.Content.ToString();
  1984. content= content.Substring(0, content.Length-2);
  1985. if (content.EndsWith("}"))
  1986. {
  1987. content=$"[{content}]";
  1988. }
  1989. else
  1990. {
  1991. content=$"[{content}}}]";
  1992. }
  1993. List<ApiVisit> apiVisits = new List<ApiVisit>();
  1994. apiVisits.AddRange(content.ToObject<List<ApiVisit>>());
  1995. var dateNow = DateTimeOffset.Now.GetGMTTime(8);
  1996. if ($"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  1997. { //当前小时一致的
  1998. BlobDownloadResult resultHour = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}.log").DownloadContentAsync();
  1999. var contentHour = resultHour.Content.ToString();
  2000. contentHour= contentHour.Substring(0, contentHour.Length-2);
  2001. if (contentHour.EndsWith("}"))
  2002. {
  2003. contentHour=$"[{contentHour}]";
  2004. }
  2005. else
  2006. {
  2007. contentHour=$"[{contentHour}}}]";
  2008. }
  2009. var httpLog = contentHour.ToObject<List<HttpLog>>();
  2010. (ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) = await SystemService.ConvertHttpLog(httpLog, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, dateNow, false);
  2011. apiVisits.AddRange(visits);
  2012. }
  2013. if (c)
  2014. {
  2015. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "China");
  2016. //大陆学校
  2017. var chinaApiVisits = apiVisits.Where(x => x.hostName.Equals("大陆站"));
  2018. var chinaSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("大陆站")).GroupBy(x => x.school);
  2019. List<SchoolStick> chinaStickiness = CountSchoolStickiness(chinaSchoolVisits, chinaApiVisits, apiVisitsBygone.schoolSticks);
  2020. Stick stickc = new Stick();
  2021. stickc.schoolSticks=chinaStickiness;
  2022. chinaSticks.Add(stickc);
  2023. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  2024. {
  2025. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickc.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/cday.json", true);
  2026. }
  2027. }
  2028. if (g)
  2029. {
  2030. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "Global");
  2031. //国际学校
  2032. var globalApiVisits = apiVisits.Where(x => x.hostName.Equals("国际站"));
  2033. var globalSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("国际站")).GroupBy(x => x.school);
  2034. List<SchoolStick> globalStickiness = CountSchoolStickiness(globalSchoolVisits, globalApiVisits, apiVisitsBygone.schoolSticks);
  2035. Stick stickg = new Stick();
  2036. stickg.schoolSticks=globalStickiness;
  2037. globalSticks.Add(stickg);
  2038. //如果是当天的 ,则不能保存
  2039. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  2040. {
  2041. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickg.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/gday.json", true);
  2042. }
  2043. }
  2044. }
  2045. else
  2046. {
  2047. continue;
  2048. }
  2049. }
  2050. }
  2051. }
  2052. public static async Task<Stick> GetBygoneSettleData(AzureStorageFactory _azureStorage, DateTimeOffset date, string cg)
  2053. {
  2054. //过去一天的数据
  2055. var bygone = date.AddDays(-1);
  2056. Stick apiVisitsBygone = new Stick();
  2057. try
  2058. {
  2059. cg=cg.Contains("China", StringComparison.OrdinalIgnoreCase) ? "cday.json" : "gday.json";
  2060. BlobDownloadResult chinaResultBygone = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{bygone:yyyy}/{bygone:MM}/{bygone:dd}/{cg}").DownloadContentAsync();
  2061. var contentBygone = chinaResultBygone.Content.ToString();
  2062. apiVisitsBygone= contentBygone.ToObject<Stick>();
  2063. }
  2064. catch
  2065. { //可能出现异常,因为文件不存在。第一次初始化,前一天的数据没有 }
  2066. }
  2067. return apiVisitsBygone;
  2068. }
  2069. public static async Task<(ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)>
  2070. ConvertHttpLog(List<HttpLog> logs, AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, DateTimeOffset gmt8Time, bool test = false)
  2071. {
  2072. ConcurrentBag<ApiVisit> visits = new ConcurrentBag<ApiVisit>();
  2073. ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
  2074. object lockObj = new object();
  2075. await Parallel.ForEachAsync(logs, async (log, _) =>
  2076. {
  2077. if (!log.path.Contains("."))
  2078. {
  2079. string uuid = Guid.NewGuid().ToString();
  2080. List<string> schoolMatch = new List<string>();
  2081. List<string> useridMatch = new List<string>();
  2082. var vist = new ApiVisit()
  2083. {
  2084. id=uuid,
  2085. ip=log.ip,
  2086. tid=log.tid,
  2087. time= log.time,
  2088. userId= log.id,
  2089. picture=log.picture,
  2090. school= log.school,
  2091. tname= log.name,
  2092. path = log.path,
  2093. client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
  2094. scope=log.scope,
  2095. host= log.host,
  2096. hostName=log.hostName,
  2097. l=log.l,
  2098. year = $"{gmt8Time:yyyy}",
  2099. month = $"{gmt8Time:MM}",
  2100. day = $"{gmt8Time:dd}",
  2101. hour =$"{gmt8Time:HH}"
  2102. };
  2103. if (test)
  2104. {
  2105. var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
  2106. //本地调试时间
  2107. if (vist.ip.Equals("0.0.0.1"))
  2108. {
  2109. time= time.AddHours(8);
  2110. }
  2111. vist.year = $"{time:yyyy}";
  2112. vist.month = $"{time:MM}";
  2113. vist.day = $"{time:dd}";
  2114. vist.hour =$"{time:HH}";
  2115. }
  2116. if (string.IsNullOrWhiteSpace(vist.userId))
  2117. {
  2118. //var jsonPathContext = new JsonPathContext();
  2119. //jsonPathContext.ValueSystem= new JsonTextValueSystem();
  2120. string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','creatorId','creator','code','studentId','student','studentid']";
  2121. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  2122. {
  2123. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  2124. //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
  2125. var nodes_path = jsonObject.SelectTokens(path);
  2126. foreach (var node in nodes_path)
  2127. {
  2128. // 只获取是字符串的
  2129. if (node.Type.Equals(JTokenType.String))
  2130. {
  2131. switch (true)
  2132. {
  2133. case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
  2134. {
  2135. try
  2136. {
  2137. var jwt = new JwtSecurityToken($"{node}");
  2138. string id = jwt.Payload.Sub;
  2139. var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
  2140. var picture = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("picture"))?.Value;
  2141. if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
  2142. {
  2143. vist.userId=id;
  2144. vist.scope="teacher";
  2145. vist.tname=name;
  2146. vist.picture=picture;
  2147. useridMatch.Add(id);
  2148. }
  2149. }
  2150. catch (Exception ex) { }
  2151. break;
  2152. }
  2153. case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
  2154. ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
  2155. ||node.Path.Contains("userId"):
  2156. {
  2157. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  2158. {
  2159. vist.userId=$"{node}";
  2160. vist.scope="teacher";
  2161. useridMatch.Add($"{node}");
  2162. }
  2163. break;
  2164. }
  2165. case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
  2166. {
  2167. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  2168. {
  2169. vist.userId=$"{node}";
  2170. vist.scope="student";
  2171. useridMatch.Add($"{node}");
  2172. }
  2173. break;
  2174. }
  2175. case bool when node.Path.Contains("code"):
  2176. {
  2177. if (!string.IsNullOrWhiteSpace($"{node}"))
  2178. {
  2179. if (long.TryParse($"{node}", out long _id))
  2180. {
  2181. vist.userId=$"{node}";
  2182. useridMatch.Add($"{node}");
  2183. }
  2184. else
  2185. {
  2186. string[] codes = $"{node}".Split("-");
  2187. foreach (var _code in codes)
  2188. {
  2189. if (long.TryParse(_code, out long _codeid))
  2190. {
  2191. vist.userId=$"{node}";
  2192. useridMatch.Add($"{_code}");
  2193. break;
  2194. }
  2195. }
  2196. }
  2197. }
  2198. break;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  2204. {
  2205. string s = log.param.ToJsonString().Replace("\\", "");
  2206. Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
  2207. Match matchtmdid = regextmdid.Match(s);
  2208. if (matchtmdid.Success)
  2209. {
  2210. var t = matchtmdid.Groups[1].Value;
  2211. if (!string.IsNullOrWhiteSpace(t))
  2212. {
  2213. vist.userId=t;
  2214. vist.scope="teacher";
  2215. useridMatch.Add(t);
  2216. }
  2217. }
  2218. Regex regexname = new Regex("\"tmdname\":\"(.+?)\"");
  2219. Match matchname = regexname.Match(s);
  2220. if (matchname.Success)
  2221. {
  2222. var t = matchname.Groups[1].Value;
  2223. if (!string.IsNullOrWhiteSpace(t))
  2224. {
  2225. vist.tname=t;
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. else
  2232. {
  2233. if (string.IsNullOrWhiteSpace($"{vist.scope}"))
  2234. {
  2235. vist.scope="teacher";
  2236. uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
  2237. }
  2238. }
  2239. if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false"))
  2240. {
  2241. vist.school="";
  2242. string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
  2243. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  2244. {
  2245. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  2246. var nodes_path = jsonObject.SelectTokens(path);
  2247. foreach (var node in nodes_path)
  2248. {
  2249. // 只获取是字符串的
  2250. if (node.Type.Equals(JTokenType.String))
  2251. {
  2252. switch (true)
  2253. {
  2254. case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
  2255. ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
  2256. {
  2257. if (!$"{node}".Contains("-")&& $"{node}".Length<=8 && $"{node}".Length>=1)
  2258. {
  2259. vist.school=$"{node}";
  2260. schoolMatch.Add($"{node}");
  2261. }
  2262. break;
  2263. }
  2264. case bool when node.Path.Contains("code"):
  2265. {
  2266. if (!$"{node}".Contains("-")&& $"{node}".Length<=8&& $"{node}".Length>=1)
  2267. {
  2268. vist.school=$"{node}";
  2269. schoolMatch.Add($"{node}");
  2270. }
  2271. else
  2272. {
  2273. string[] codes = $"{node}".Split("-");
  2274. foreach (var _code in codes)
  2275. {
  2276. if ($"{_code}".Length<=8 && $"{_code}".Length>=1)
  2277. {
  2278. vist.school=$"{_code}";
  2279. schoolMatch.Add($"{_code}");
  2280. break;
  2281. }
  2282. }
  2283. }
  2284. break;
  2285. }
  2286. }
  2287. }
  2288. }
  2289. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  2290. {
  2291. string s = log.param.ToJsonString().Replace("\\", "");
  2292. Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
  2293. Match matchname = regexname.Match(s);
  2294. if (matchname.Success)
  2295. {
  2296. var t = matchname.Groups[1].Value;
  2297. if (!string.IsNullOrWhiteSpace(t))
  2298. {
  2299. vist.school=t;
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. //处理 client
  2306. {
  2307. if (!string.IsNullOrWhiteSpace(log.client))
  2308. {
  2309. if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
  2310. {
  2311. vist.client="ies5";
  2312. }
  2313. if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
  2314. {
  2315. vist.client="aclassone";
  2316. }
  2317. if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
  2318. {
  2319. vist.client="habb";
  2320. }
  2321. if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
  2322. {
  2323. vist.client="hiscan";
  2324. }
  2325. if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
  2326. {
  2327. vist.client="hita";
  2328. vist.scope="teacher";
  2329. }
  2330. if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
  2331. {
  2332. vist.client="hiteachcc";
  2333. }
  2334. if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
  2335. {
  2336. vist.scope="teacher";
  2337. vist.client="hiteach";
  2338. }
  2339. if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
  2340. {
  2341. vist.client="open";
  2342. }
  2343. }
  2344. }
  2345. //补全站点
  2346. {
  2347. if (
  2348. (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
  2349. {
  2350. vist.hostName="国际站";
  2351. vist.host="www.teammodel.net";
  2352. vist.client="ies5";
  2353. vist.l="Global";
  2354. }
  2355. else if (
  2356. log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
  2357. ||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"))
  2358. {
  2359. vist.hostName="大陆站";
  2360. vist.host="www.teammodel.cn";
  2361. vist.client="ies5"; vist.l="China";
  2362. }
  2363. else if ((log.host.Contains("localhost") && log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
  2364. {
  2365. vist.hostName="测试站";
  2366. vist.host="test.teammodel.cn";
  2367. vist.client="ies5";
  2368. vist.l="China";
  2369. }
  2370. else if (
  2371. (log.host.Equals("scyx.teammodel.cn") ||log.host.Equals("jinniu.teammodel.cn")))
  2372. {
  2373. vist.hostName="研修2.0";
  2374. vist.host="scyx.teammodel.cn";
  2375. vist.client="ability"; vist.l="China";
  2376. }
  2377. else if (
  2378. log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn") ||log.host.Equals("zhiyin-test.teammodel.cn"))
  2379. {
  2380. vist.hostName="开放平台";
  2381. vist.host="open.teammodel.cn";
  2382. vist.client="open";
  2383. vist.l="China";
  2384. }
  2385. else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
  2386. {
  2387. vist.hostName="国际站";
  2388. vist.host="bi.teammodel.net";
  2389. vist.client="bi";
  2390. vist.scope="admin";
  2391. vist.l="Global";
  2392. }
  2393. else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
  2394. {
  2395. vist.hostName="大陆站";
  2396. vist.host="bi.teammodel.cn";
  2397. vist.client="bi";
  2398. vist.scope="admin";
  2399. vist.l="China";
  2400. }
  2401. else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost") && (log.p.Equals("bi"))))
  2402. {
  2403. vist.hostName="测试站";
  2404. vist.host="testbi.teammodel.cn";
  2405. vist.client="bi";
  2406. vist.scope="admin";
  2407. vist.l="China";
  2408. }
  2409. else if (
  2410. log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
  2411. {
  2412. vist.hostName="大陆站";
  2413. vist.host="contest.teammodel.cn";
  2414. vist.client="contest"; vist.l="China";
  2415. }
  2416. else if (
  2417. log.host.Equals("hiteachcc.chinacloudsites.cn"))
  2418. {
  2419. vist.hostName="正式站";
  2420. vist.host="hiteachcc.teammodel.cn";
  2421. vist.client="hiteachcc";
  2422. vist.l="China";
  2423. }
  2424. else if (log.host.Equals("appraisal.chinacloudsites.cn"))
  2425. {
  2426. vist.hostName="大陆站";
  2427. vist.host="appraisal.teammodel.cn";
  2428. vist.client="appraisal";
  2429. vist.l="China";
  2430. }
  2431. else if ((log.host.Contains("localhost") && log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn") ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
  2432. {
  2433. vist.hostName="测试站";
  2434. vist.host="appraisal-test.teammodel.cn";
  2435. vist.client="appraisal";
  2436. vist.l="China";
  2437. }
  2438. else
  2439. {
  2440. if (!string.IsNullOrWhiteSpace(log.p))
  2441. {
  2442. vist.client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p;
  2443. }
  2444. else
  2445. {
  2446. vist.client="other";
  2447. }
  2448. if (log.host.EndsWith(".cn"))
  2449. {
  2450. vist.hostName="大陆站";
  2451. vist.l="China";
  2452. }
  2453. else if (log.host.EndsWith(".net"))
  2454. {
  2455. vist.hostName="国际站";
  2456. vist.l="Global";
  2457. }
  2458. else
  2459. {
  2460. vist.hostName="其他";
  2461. vist.l="其他";
  2462. }
  2463. }
  2464. }
  2465. //补全产品端
  2466. {
  2467. //研修2.0
  2468. if (log.path.Contains("research") || log.path.Contains("study") || log.path.Contains("standard-file"))
  2469. {
  2470. vist.client="ability";
  2471. }
  2472. if (log.path.Contains("teacher"))
  2473. {
  2474. vist.scope="teacher";
  2475. }
  2476. if (log.path.Contains("tmduser"))
  2477. {
  2478. vist.scope="tmduser";
  2479. }
  2480. if (log.path.Contains("student/login"))
  2481. {
  2482. vist.scope="student";
  2483. }
  2484. if (log.path.StartsWith("/activity"))
  2485. {
  2486. vist.client="contest";
  2487. }
  2488. //小程序
  2489. if (log.path.Contains("aclassone"))
  2490. {
  2491. vist.client="aclassone";
  2492. }
  2493. // /// <summary>
  2494. /// ExamInfo qamode 書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
  2495. /// </summary>
  2496. //艺术评测
  2497. 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"))
  2498. {
  2499. vist.client="art";
  2500. }
  2501. if (log.path.Contains("common/exam/upsert-record"))
  2502. {
  2503. JObject jobject = JObject.Parse(log.param.GetRawText());
  2504. var jtokens = jobject.SelectTokens("$..artId");
  2505. if (jtokens!=null && jtokens.Count()>0)
  2506. {
  2507. vist.client="art";
  2508. vist.scope="student";
  2509. }
  2510. }
  2511. if (log.path.Contains("habb"))
  2512. {
  2513. vist.client="habb";
  2514. }
  2515. //阅卷客户端
  2516. if (log.path.Contains("hiscan"))
  2517. {
  2518. vist.client="hiscan";
  2519. }
  2520. if (log.path.Contains("hita"))
  2521. {
  2522. vist.client="hita";
  2523. }
  2524. if (log.path.Contains("hiteachcc"))
  2525. {
  2526. vist.client="hiteachcc";
  2527. }
  2528. if (log.path.Contains("sokrate"))
  2529. {
  2530. vist.client="sokrate";
  2531. }
  2532. if (log.path.Contains("sokrate") || log.path.Contains("score"))
  2533. {
  2534. vist.client="sokrate";
  2535. }
  2536. if (log.path.Contains("hiteach"))
  2537. {
  2538. vist.client="hiteach";
  2539. }
  2540. ///IES开放平台
  2541. if (log.path.Contains("business") || log.path.Contains("biz") || log.path.Contains("openapi-config") || log.path.Contains("open-api"))
  2542. {
  2543. vist.client="open";
  2544. }
  2545. //从token的role 能否获取 开放平台
  2546. //单点登录及第三方接口
  2547. 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")
  2548. || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding") || log.path.Contains("wechat")
  2549. )
  2550. {
  2551. vist.client="sso-third";
  2552. }
  2553. }
  2554. //处理IP转地区
  2555. var region = await _ipSearcher.SearchIpAsync(vist.ip);
  2556. if (string.IsNullOrWhiteSpace(region))
  2557. {
  2558. region="未知IP·未知IP·未知IP";
  2559. }
  2560. if (!string.IsNullOrWhiteSpace(region))
  2561. {
  2562. region= region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
  2563. var regions = region.Split("·");
  2564. if (regions.Length==4)
  2565. {
  2566. vist.area= regions[0];
  2567. vist.province = regions[1];
  2568. vist.city = regions[2];
  2569. }
  2570. if (regions.Length==3)
  2571. {
  2572. vist.area= regions[0];
  2573. vist.province = regions[1];
  2574. }
  2575. if (regions.Length==2)
  2576. {
  2577. vist.area= regions[0];
  2578. vist.province = regions[1];
  2579. }
  2580. if (regions.Length==1)
  2581. {
  2582. vist.area= regions[0];
  2583. }
  2584. }
  2585. //处理地区转经纬度
  2586. {
  2587. IEnumerable<JToken> tokens = default;
  2588. if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  2589. {
  2590. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
  2591. if (!(tokens.Any() && tokens.Count()>0))
  2592. {
  2593. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
  2594. if (!(tokens.Any() && tokens.Count()>0))
  2595. {
  2596. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
  2597. }
  2598. if (!(tokens.Any() && tokens.Count()>0))
  2599. {
  2600. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
  2601. }
  2602. }
  2603. }
  2604. else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  2605. {
  2606. if (vist.area.Equals("中国"))
  2607. {
  2608. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
  2609. if (!(tokens.Any() && tokens.Count()>0))
  2610. {
  2611. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  2612. }
  2613. }
  2614. else
  2615. {
  2616. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
  2617. }
  2618. }
  2619. else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  2620. {
  2621. if (vist.area.Equals("中国"))
  2622. {
  2623. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
  2624. if (!(tokens.Any() && tokens.Count()>0))
  2625. {
  2626. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  2627. }
  2628. }
  2629. else
  2630. {
  2631. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
  2632. }
  2633. }
  2634. else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  2635. {
  2636. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
  2637. }
  2638. if (tokens!=null && tokens.Any())
  2639. {
  2640. List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
  2641. foreach (JToken token in tokens)
  2642. {
  2643. regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
  2644. }
  2645. var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
  2646. if (!points.IsNotEmpty())
  2647. {
  2648. points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
  2649. }
  2650. if (string.IsNullOrWhiteSpace(vist.city))
  2651. {
  2652. vist.city=points?.FirstOrDefault()?.city;
  2653. if (!string.IsNullOrWhiteSpace(vist.city) && vist.city.EndsWith("市"))
  2654. {
  2655. vist.city=vist.city.Replace("市", "");
  2656. }
  2657. }
  2658. vist.lat=points?.FirstOrDefault()?.lat;
  2659. vist.lng=points?.FirstOrDefault()?.lng;
  2660. }
  2661. else
  2662. {
  2663. if (vist.area.Equals("内网IP"))
  2664. {
  2665. if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
  2666. {
  2667. vist.lat="30.655821878416408";
  2668. vist.lng="104.08153351042463";
  2669. vist.area="中国";
  2670. vist.province="四川";
  2671. vist.city="成都";
  2672. }
  2673. else
  2674. {
  2675. vist.lat="25.044332";
  2676. vist.lng="121.509062";
  2677. vist.area="中国";
  2678. vist.province="台湾";
  2679. vist.city="台湾";
  2680. }
  2681. }
  2682. else
  2683. {
  2684. vist.lat="30.655821878416408";
  2685. vist.lng="104.08153351042463";
  2686. vist.area="中国";
  2687. vist.province="四川";
  2688. vist.city="成都";
  2689. }
  2690. }
  2691. }
  2692. uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
  2693. visits.Add(vist);
  2694. }
  2695. }
  2696. );
  2697. List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
  2698. List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
  2699. var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
  2700. if (tmds.Any())
  2701. {
  2702. foreach (var tmd in tmds)
  2703. {
  2704. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{tmd}");
  2705. if (exists)
  2706. {
  2707. tmdexists.Add((tmd, exists, "teacher"));
  2708. }
  2709. else
  2710. {
  2711. exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
  2712. tmdexists.Add((tmd, exists, "student"));
  2713. }
  2714. }
  2715. }
  2716. var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
  2717. if (schs.Any())
  2718. {
  2719. foreach (var sch in schs)
  2720. {
  2721. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{sch}");
  2722. schexists.Add((sch, exists));
  2723. }
  2724. }
  2725. foreach (var item in uuidInfo)
  2726. {
  2727. foreach (var tmd in item.tmdid)
  2728. {
  2729. var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
  2730. if (tmdext.tmd!= null && tmdext.exists)
  2731. {
  2732. var vist = visits.Where(x => x.id.Equals(item.uuid));
  2733. foreach (var vi in vist)
  2734. {
  2735. vi.userId=tmd;
  2736. if (string.IsNullOrWhiteSpace(vi.scope))
  2737. {
  2738. vi.scope=tmdext.scope;
  2739. }
  2740. }
  2741. break;
  2742. }
  2743. }
  2744. foreach (var sch in item.school)
  2745. {
  2746. var schext = schexists.Find(x => x.sch.Equals(sch));
  2747. if (schext.sch!= null && schext.exists)
  2748. {
  2749. var vist = visits.Where(x => x.id.Equals(item.uuid));
  2750. foreach (var vi in vist)
  2751. {
  2752. vi.school=sch;
  2753. }
  2754. break;
  2755. }
  2756. }
  2757. }
  2758. return (visits, uuidInfo);
  2759. }
  2760. public class ApiVisit
  2761. {
  2762. public string id { get; set; }
  2763. public string path { get; set; }
  2764. /// <summary>
  2765. /// 细分
  2766. /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
  2767. /// 产品端
  2768. /// </summary>
  2769. public string client { get; set; }
  2770. /// <summary>
  2771. /// 具体功能
  2772. /// </summary>
  2773. // public string func { get; set; }
  2774. public string userId { get; set; }
  2775. public string picture { get; set; }
  2776. public string scope { get; set; }
  2777. public string tname { get; set; }
  2778. public string school { get; set; }
  2779. public string ip { get; set; }
  2780. //public string region { get; set; }
  2781. public string area { get; set; }
  2782. public string province { get; set; }
  2783. public string city { get; set; } = "";
  2784. public long time { get; set; }
  2785. /// <summary>
  2786. ///
  2787. /// </summary>
  2788. public string host { get; set; }
  2789. public string hostName { get; set; } = "其他";
  2790. /// <summary>
  2791. /// tokenid
  2792. /// </summary>
  2793. public string tid { get; set; }
  2794. public string year { get; set; }
  2795. public string month { get; set; }
  2796. public string day { get; set; }
  2797. public string hour { get; set; }
  2798. //public RegionLngLat point { get; set; }
  2799. public string lat { get; set; }
  2800. public string lng { get; set; }
  2801. public string l { get; set; }
  2802. }
  2803. public class HttpLog
  2804. {
  2805. public string ip { get; set; }
  2806. public long time { get; set; }
  2807. public string host { get; set; }
  2808. public string hostName = "其他";
  2809. public string tid { get; set; }
  2810. public string path { get; set; }
  2811. public string client { get; set; }
  2812. public JsonElement param { get; set; }
  2813. public string id { get; set; }
  2814. public string name { get; set; }
  2815. public string picture { get; set; }
  2816. public string school { get; set; }
  2817. public string p { get; set; }
  2818. // public string ua { get; set; }
  2819. // public string referer { get; set; }
  2820. public string scope { get; set; }
  2821. public string year { get; set; }
  2822. public string month { get; set; }
  2823. public string day { get; set; }
  2824. public string hour { get; set; }
  2825. public string l { get; set; }
  2826. }
  2827. public record RegionLngLat
  2828. {
  2829. public string country { get; set; }
  2830. public string province { get; set; }
  2831. public string city { get; set; }
  2832. public string lat { get; set; }
  2833. public string lng { get; set; }
  2834. public string area { get; set; }
  2835. public string m { get; set; } = "0";
  2836. }
  2837. public class CountData
  2838. {
  2839. public string pk { get; set; } = "";
  2840. public string sk { get; set; } = "";
  2841. public string sp { get; set; } = "";
  2842. public int count { get; set; }
  2843. }
  2844. public class SchoolStick
  2845. {
  2846. /// <summary>
  2847. /// 名字
  2848. /// </summary>
  2849. public string name { get; set; }
  2850. public string picture { get; set; }
  2851. /// <summary>
  2852. /// 编码
  2853. /// </summary>
  2854. public string id { get; set; }
  2855. public string last { get; set; }
  2856. #region teacher
  2857. public ClientStick teacher { get; set; } = new ClientStick();
  2858. #endregion
  2859. #region student
  2860. public ClientStick student { get; set; } = new ClientStick();
  2861. #endregion
  2862. #region hiteach
  2863. public ClientStick hiteach { get; set; } = new ClientStick();
  2864. public Indicator lesson { get; set; } = new Indicator();
  2865. #endregion
  2866. #region hita
  2867. public ClientStick hita { get; set; } = new ClientStick();
  2868. #endregion
  2869. #region ies5Teacher
  2870. public ClientStick ies5Tch { get; set; } = new ClientStick();
  2871. #endregion
  2872. #region otherTeacher
  2873. public ClientStick otherTch { get; set; } = new ClientStick();
  2874. #endregion
  2875. #region ies5Student
  2876. public ClientStick ies5Stu { get; set; } = new ClientStick();
  2877. #endregion
  2878. #region otherStudent
  2879. public ClientStick otherStu { get; set; } = new ClientStick();
  2880. #endregion
  2881. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  2882. public List<StuStick> stuSticks { get; set; } = new List<StuStick>();
  2883. }
  2884. public class TchStick
  2885. {
  2886. public string school { get; set; }
  2887. /// <summary>
  2888. /// 名字
  2889. /// </summary>
  2890. public string name { get; set; }
  2891. public string picture { get; set; }
  2892. /// <summary>
  2893. /// 编码
  2894. /// </summary>
  2895. public string id { get; set; }
  2896. public string last { get; set; }
  2897. #region tmd
  2898. public ClientStick teacher { get; set; } = new ClientStick();
  2899. #endregion
  2900. #region hiteach
  2901. public ClientStick hiteach { get; set; } = new ClientStick();
  2902. public Indicator lesson { get; set; } = new Indicator();
  2903. #endregion
  2904. #region hita
  2905. public ClientStick hita { get; set; } = new ClientStick();
  2906. #endregion
  2907. #region ies5Teacher
  2908. public ClientStick ies5Tch { get; set; } = new ClientStick();
  2909. #endregion
  2910. #region otherTeacher
  2911. public ClientStick otherTch { get; set; } = new ClientStick();
  2912. #endregion
  2913. }
  2914. public class StuStick
  2915. {
  2916. public string school { get; set; }
  2917. /// <summary>
  2918. /// 名字
  2919. /// </summary>
  2920. public string name { get; set; }
  2921. public string picture { get; set; }
  2922. /// <summary>
  2923. /// 编码
  2924. /// </summary>
  2925. public string id { get; set; }
  2926. public string last { get; set; }
  2927. #region tmd
  2928. public ClientStick student { get; set; } = new ClientStick();
  2929. #endregion
  2930. #region ies5Student
  2931. public ClientStick ies5Stu { get; set; } = new ClientStick();
  2932. #endregion
  2933. #region otherStudent
  2934. public ClientStick otherStu { get; set; } = new ClientStick();
  2935. #endregion
  2936. }
  2937. public class ClientStick
  2938. {
  2939. public int userCount { get; set; }
  2940. public int userUpdown { get; set; }
  2941. public Indicator stick { get; set; } = new Indicator();
  2942. public Indicator duration { get; set; } = new Indicator();
  2943. public Indicator count { get; set; } = new Indicator();
  2944. }
  2945. public class Indicator
  2946. {
  2947. /// <summary>
  2948. /// 值
  2949. /// </summary>
  2950. public double value { get; set; } = 0;
  2951. /// <summary>
  2952. /// 值的增减浮动
  2953. /// </summary>
  2954. public double range { get; set; } = 0;
  2955. /// <summary>
  2956. /// 排名
  2957. /// </summary>
  2958. public double rank { get; set; } = 0;
  2959. /// <summary>
  2960. /// 排名的上升下降
  2961. /// </summary>
  2962. public double updown { get; set; } = 0;
  2963. }
  2964. public class Stick
  2965. {
  2966. public List<SchoolStick> schoolSticks { get; set; } = new List<SchoolStick>();
  2967. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  2968. }
  2969. public class Product
  2970. {
  2971. public string Name { get; set; }
  2972. public double VisitDuration { get; set; }
  2973. public double VisitCount { get; set; }
  2974. public double CalculateProductIndex(double timeWeight, double countWeight,double minVisitDuration, double maxVisitDuration, double minVisitCount, double maxVisitCount)
  2975. {
  2976. // 计算访问时长的Min-Max标准化值
  2977. double standardizedVisitDuration = (maxVisitDuration - minVisitDuration)!=0?(VisitDuration - minVisitDuration) / (maxVisitDuration - minVisitDuration):0;
  2978. // 计算访问次数的Min-Max标准化值
  2979. double standardizedVisitCount = (maxVisitCount - minVisitCount)!=0?(VisitCount - minVisitCount) / (maxVisitCount - minVisitCount):0;
  2980. // 计算加权综合指数
  2981. double comprehensiveIndex = timeWeight * standardizedVisitDuration + countWeight * standardizedVisitCount;
  2982. return Math.Round(comprehensiveIndex,4);
  2983. }
  2984. }
  2985. }
  2986. }