SystemService.cs 230 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172
  1. using Azure.Storage.Blobs.Models;
  2. using Microsoft.Extensions.Configuration;
  3. using Newtonsoft.Json.Linq;
  4. using StackExchange.Redis;
  5. using System;
  6. using System.Collections.Concurrent;
  7. using System.Collections.Generic;
  8. using System.IdentityModel.Tokens.Jwt;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Net.Http.Json;
  12. using System.Text;
  13. using System.Text.Json;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. using TEAMModelOS.SDK.DI;
  17. using TEAMModelOS.SDK.Extension;
  18. using TEAMModelOS.SDK.Models.Dtos;
  19. using static TEAMModelOS.SDK.CoreAPIHttpService;
  20. using Microsoft.Azure.Cosmos;
  21. using System.Collections;
  22. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  23. namespace TEAMModelOS.SDK.Models.Service
  24. {
  25. public static class SystemService
  26. {
  27. #region
  28. static string cn_wb = @"
  29. IES晚间报告:{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
  30. 以下是报告的具体详细信息。
  31. {cn_examTitle}{cn_examList}
  32. {cn_lessonTitle}{cn_lessonList}
  33. {cn_groupTitle}{cn_groupList}
  34. 如有布置作业任务,将于次日8点通过早报方式发送。
  35. ";
  36. static string cn_examList = "【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
  37. static string cn_lessonList = "【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}%。";
  38. static string cn_groupListJoin = "【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位加入。";
  39. static string cn_groupListLeave = "【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位离开。";
  40. static string cn_zb = @"
  41. IES早间报告:{tmdname}您好,以下是您发布过的作业任务汇总报告。
  42. 以下是报告的具体详细信息。
  43. {cn_homeworkTitle}{cn_homeworkList}
  44. ";
  45. static string cn_homeworkList = "【{homeworkName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
  46. static string cn_homeworkTitle = "作业任务提交详情:";
  47. static string cn_examTitle = "评测任务提交详情:";
  48. static string cn_lessonTitle = "课堂教学出席详情:";
  49. static string cn_groupTitle = "个人课程名单变化详情:";
  50. static string cn_lessonDetail = @"</br>课例名称:{name},开课时间:{time},时长:{duration}分钟</br>
  51. 1.本节课名单{count}人,分成{groupCount}组,出席人数:{attendCount}人,缺席:{absentCount}人,出席率{attendRate}%</br>
  52. 2.学习参与度指数平均:{engagementIndexAverge} </br>
  53. 分组参与度:{grpEngagement}</br>
  54. 参与较多者:{highRankEngagement}</br>
  55. 3.记分:总记分:{totalPoint}分 </br>
  56. 个人记分较多者:{highRankPerPoint}</br>
  57. 小组记分较多的:{highRankGrpPoint}</br>
  58. 4.互动:{interactionCount}题,总互动分:{totalInteractPoint}分</br>
  59. 5.任务:{pushCount}次,作品总数:{collateTaskCount}件</br>
  60. 6.测验:{examCount}次,题数:{examQuizCount}题,平均得分率:{examPointRate}% </br>
  61. 表现较好者:{highRankExam}</br>
  62. 表现较弱者:{lowRankExam}</br>
  63. 7.互评:{smartRatingCount}次,合计参与:{clientSmartRatingCount}次</br>
  64. 8.协作:{coworkTaskCount}次,作品总数:{coworkGroupCount}件,总操作量:{coworkGroupCount}</br>";
  65. #endregion
  66. #region
  67. static string tw_wb = @"
  68. IES晚間報告:{tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
  69. 以下是詳細資訊。
  70. {tw_examTitle}{tw_examList}
  71. {tw_lessonTitle}{tw_lessonList}
  72. {tw_groupTitle}{tw_groupList}
  73. 如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
  74. ";
  75. static string tw_examList = "【{examName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。";
  76. static string tw_lessonList = "【{lessonName}】課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}%。";
  77. static string tw_groupListJoin = "【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位加入。";
  78. static string tw_groupListLeave = "【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位離開。";
  79. static string tw_zb = @"
  80. IES晨間報告:{tmdname}您好,以下是您曾經發佈過的作業任務總結報告。
  81. 以下是具體詳細資訊。
  82. {tw_homeworkTitle}{tw_homeworkList}
  83. ";
  84. static string tw_homeworkList = "【{homeworkName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。";
  85. static string tw_homeworkTitle = "作業任務繳交詳情:";
  86. static string tw_examTitle = "測驗任務完成詳情:";
  87. static string tw_lessonTitle = "課堂教學出席詳情:";
  88. static string tw_groupTitle = "個人課程名單變動詳情:";
  89. static string tw_lessonDetail = @"</br>课例名称:{name},開課時間:{time},時長:{duration}分鐘</br>
  90. 1.本節課名單{count}人,分成{groupCount}組,出席人数:{attendCount}人,缺席:{absentCount}人,出席率{attendRate}%</br>
  91. 2.學習参與度指數平均:{engagementIndexAverge}</br>
  92. 分組参舆度:{grpEngagement}</br>
  93. 参與较多者:{highRankEngagement}</br>
  94. 3.記分:總記分:{totalPoint}分</br>
  95. 個人記分较多者:{highRankPerPoint}</br>
  96. 小組記分较多的:{highRankGrpPoint}</br>
  97. 4.互動:{interactionCount}题,總互動分:{totalInteractPoint}分</br>
  98. 5.任務:{pushCount}次,作品總数:{collateTaskCount}件</br>
  99. 6.測驗:{examCount}次,题數:{examQuizCount}题,平均得分率:{examPointRate}%</br>
  100. 表現较好者:{highRankExam}</br>
  101. 表現较弱者:{lowRankExam}</br>
  102. 7.互评:{smartRatingCount}次,合計参與:{clientSmartRatingCount}次</br>
  103. 8.協作:{coworkTaskCount}次,作品總數:{coworkGroupCount}件,總操作量:{coworkGroupCount}</br>";
  104. #endregion
  105. #region
  106. static string en_wb = @"
  107. IES Evening Report:Hello {tmdname}, here is your personal IES teaching summary report for today. As of {sendTime}, you have published {examCount} test tasks, {homeworkCount} homework tasks, and uploaded {lessonCount} HiTeach lesson activity records.
  108. The following are the specific details.
  109. {en_examTitle}{en_examList}
  110. {en_lessonTitle}{en_lessonList}
  111. {en_groupTitle}{en_groupList}
  112. If there are homework tasks assigned, they will be sent through the morning report at 8 am the next day.
  113. ";
  114. static string en_examList = "[ {examName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.";
  115. static string en_lessonList = "[ {lessonName} ] lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}%.";
  116. static string en_groupListJoin = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} joined.";
  117. static string en_groupListLeave = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} left.";
  118. static string en_zb = @"
  119. IES Morning Report:
  120. Hello {tmdname}, here is the summary report of the homework tasks you have posted.
  121. {en_homeworkTitle}{en_homeworkList}
  122. ";
  123. static string en_homeworkList = "[ {homeworkName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.";
  124. static string en_homeworkTitle = "Homework Submission Details:";
  125. static string en_examTitle = "Test task submission details:";
  126. static string en_lessonTitle = "Lesson attendance details:";
  127. static string en_groupTitle = "Personal course list change details:";
  128. static string en_lessonDetail = @"</br>Lesson Name: {name}, Start time: {time}, Duration: {duration} Minutes</br>
  129. 1. There are {count} people in this course, divided into {groupCount} groups, attendance: {attendCount} people, absences: 0 people, attendance rate {attendRate}%</br>
  130. 2. Learning Engagement : {engagementIndexAverge}</br>
  131. Engagement per group: {grpEngagement}</br>
  132. More engaged students: {highRankEngagement}</br>
  133. 3. Total Points: {totalPoint} points</br>
  134. Persons with more points: {highRankPerPoint}</br>
  135. Groups with more points: {highRankGrpPoint}</br>
  136. 4. IRS Interaction: {interactionCount} questions, total IRS interaction score: {totalInteractPoint} points</br>
  137. 5. Tasks: {pushCount} times, total number of collected works: {collateTaskCount} </br>
  138. 6. Test/Exam: {examCount} times, number of questions: {examQuizCount} questions, average scoring rate: {examPointRate}%</br>
  139. Better performers: {highRankExam}</br>
  140. Weaker performers: {lowRankExam}</br>
  141. 7. Smart Rating: {smartRatingCount} times, total participation: {clientSmartRatingCount} times</br>
  142. 8. Collaboration: {coworkTaskCount} times, total number of works: {coworkGroupCount}, total operation: {coworkGroupCount}</br>";
  143. #endregion
  144. // #region
  145. // static string cn_wb = @"
  146. //IES晚间报告:</br>{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
  147. //</br>&nbsp;&nbsp;&nbsp;以下是报告的具体详细信息。
  148. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_examTitle}</br>{cn_examList}
  149. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_lessonTitle}</br>{cn_lessonList}
  150. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_groupTitle}</br>{cn_groupList}
  151. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如有布置作业任务,将于次日8点通过早报方式发送。
  152. //";
  153. // static string cn_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。</br>";
  154. // static string cn_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}%。</br>";
  155. // static string cn_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位加入。</br>";
  156. // static string cn_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位离开。</br>";
  157. // static string cn_zb = @"
  158. //IES早间报告:</br>{tmdname}您好,以下是您发布过的作业任务汇总报告。
  159. //</br>&nbsp;&nbsp;&nbsp;以下是报告的具体详细信息。
  160. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_homeworkTitle}</br>{cn_homeworkList}
  161. //";
  162. // static string cn_homeworkList = "【{homeworkName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。</br>";
  163. // static string cn_homeworkTitle = "作业任务提交详情:";
  164. // static string cn_examTitle = "评测任务提交详情:";
  165. // static string cn_lessonTitle = "课堂教学出席详情:";
  166. // static string cn_groupTitle = "个人课程名单变化详情:";
  167. // #endregion
  168. // #region
  169. // static string tw_wb = @"
  170. //IES晚間報告:</br>{tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
  171. //</br>&nbsp;&nbsp;&nbsp;以下是詳細資訊。
  172. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_examTitle}</br>{tw_examList}
  173. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_lessonTitle}</br>{tw_lessonList}
  174. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_groupTitle}</br>{tw_groupList}
  175. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
  176. //";
  177. // static string tw_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{examName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。</br>";
  178. // static string tw_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{lessonName}】課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}%。</br>";
  179. // static string tw_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位加入。</br>";
  180. // static string tw_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位離開。</br>";
  181. // static string tw_zb = @"
  182. //IES晨間報告:</br>{tmdname}您好,以下是您曾經發佈過的作業任務總結報告。
  183. //</br>&nbsp;&nbsp;&nbsp;以下是具體詳細資訊。
  184. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_homeworkTitle}</br>{tw_homeworkList}
  185. //";
  186. // static string tw_homeworkList = "【{homeworkName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。</br>";
  187. // static string tw_homeworkTitle = "作業任務繳交詳情:";
  188. // static string tw_examTitle = "測驗任務完成詳情:";
  189. // static string tw_lessonTitle = "課堂教學出席詳情:";
  190. // static string tw_groupTitle = "個人課程名單變動詳情:";
  191. // #endregion
  192. // #region
  193. // static string en_wb = @"
  194. //IES Evening Report:</br>Hello {tmdname}, here is your personal IES teaching summary report for today. As of {sendTime}, you have published {examCount} test tasks, {homeworkCount} homework tasks, and uploaded {lessonCount} HiTeach lesson activity records.
  195. //</br>&nbsp;&nbsp;&nbsp;The following are the specific details.
  196. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_examTitle}</br>{en_examList}
  197. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_lessonTitle}</br>{en_lessonList}
  198. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_groupTitle}</br>{en_groupList}
  199. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If there are homework tasks assigned, they will be sent through the morning report at 8 am the next day.
  200. //";
  201. // static string en_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {examName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.</br>";
  202. // static string en_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {lessonName} ] lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}%.</br>";
  203. // static string en_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {grouplistName} ] has a total of {memberCount}, {joinCount} joined.</br>";
  204. // static string en_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {grouplistName} ] has a total of {memberCount}, {joinCount} left.</br>";
  205. // static string en_zb = @"
  206. //IES Morning Report:
  207. //</br>&nbsp;&nbsp;&nbsp;Hello {tmdname}, here is the summary report of the homework tasks you have posted.
  208. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_homeworkTitle}</br>{en_homeworkList}
  209. //";
  210. // static string en_homeworkList = "[ {homeworkName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.</br>";
  211. // static string en_homeworkTitle = "Homework Submission Details:";
  212. // static string en_examTitle = "Test task submission details:";
  213. // static string en_lessonTitle = "Lesson attendance details:";
  214. // static string en_groupTitle = "Personal course list change details:";
  215. // #endregion
  216. /// <summary>
  217. ///
  218. /// </summary>
  219. /// <param name="_azureRedis"></param>
  220. /// <param name="_azureCosmos"></param>
  221. /// <param name="coreAPIHttpService"></param>
  222. /// <param name="dingDing"></param>
  223. /// <param name="_httpClient"></param>
  224. /// <param name="_snowflakeId"></param>
  225. /// <param name="notifyUrl"></param>
  226. /// <param name="_mailFactory"></param>
  227. /// <param name="am"></param>
  228. /// <param name="pm"></param>
  229. /// <returns></returns>
  230. public static async Task<List<CodeValue> > AccumulateDaily(IConfiguration _configuration,AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos,AzureStorageFactory _azureStorage,
  231. CoreAPIHttpService coreAPIHttpService, DingDing dingDing,HttpClient _httpClient, SnowflakeId _snowflakeId,string notifyUrl, int am=0 ,int pm=0)
  232. {
  233. DateTimeOffset now = DateTimeOffset.Now;
  234. string day = now.ToString("yyyyMMdd");
  235. string homeworkYesterday = now.AddDays(-1).ToString("yyyyMMdd");
  236. HashSet<string> keys = new HashSet<string>();
  237. //当天评测发布的。
  238. //当天的个人评测提交数
  239. Dictionary<string, double?> exam_submit = new();
  240. SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:exam-going:{day}");
  241. // Dictionary<string, double?> exam_going = new();
  242. if (exam_goingScores != null)
  243. {
  244. foreach (var score in exam_goingScores)
  245. {
  246. double val = score.Score;
  247. string key = score.Element.ToString();
  248. // exam_going.Add(key, val);
  249. exam_submit.Add(key, val);
  250. keys.Add(key);
  251. }
  252. }
  253. ///需要再次获取 没有任何人提交的作业和评测任务。
  254. SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
  255. if (exam_submitScores != null)
  256. {
  257. foreach (var score in exam_submitScores)
  258. {
  259. double val = score.Score;
  260. string key = score.Element.ToString();
  261. exam_submit.TryAdd(key, val);
  262. keys.Add(key);
  263. }
  264. }
  265. //今天发布的作业
  266. SortedSetEntry[] homework_goingScores_today = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{day}");
  267. Dictionary<string, double?> homework_submit_today = new();
  268. //Dictionary<string, double?> homework_going = new();
  269. if (homework_goingScores_today != null)
  270. {
  271. foreach (var score in homework_goingScores_today)
  272. {
  273. double val = score.Score;
  274. string key = score.Element.ToString();
  275. //homework_going.Add(key, val);
  276. homework_submit_today.TryAdd(key, val);
  277. keys.Add(key);
  278. }
  279. }
  280. //昨天发布的作业
  281. SortedSetEntry[] homework_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{homeworkYesterday}");
  282. Dictionary<string, double?> homework_submit = new();
  283. //Dictionary<string, double?> homework_going = new();
  284. if (homework_goingScores != null)
  285. {
  286. foreach (var score in homework_goingScores)
  287. {
  288. double val = score.Score;
  289. string key = score.Element.ToString();
  290. //homework_going.Add(key, val);
  291. homework_submit.TryAdd(key, val);
  292. keys.Add(key);
  293. }
  294. }
  295. //昨天的个人作业提交数
  296. SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{homeworkYesterday}");
  297. if (homework_submitScores != null)
  298. {
  299. foreach (var score in homework_submitScores)
  300. {
  301. double val = score.Score;
  302. string key = score.Element.ToString();
  303. homework_submit.TryAdd(key, val);
  304. keys.Add(key);
  305. }
  306. }
  307. //当天的个人名单加入人数
  308. Dictionary<string, double?> grouplist = new();
  309. SortedSetEntry[] grouplistScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:grouplist:{day}");
  310. if (grouplistScores != null)
  311. {
  312. foreach (var score in grouplistScores)
  313. {
  314. double val = score.Score;
  315. string key = score.Element.ToString();
  316. grouplist.TryAdd(key, val);
  317. keys.Add(key);
  318. }
  319. }
  320. //当天教师的开课数量Accumulate:Daily:teacher:lesson-create:20240527
  321. Dictionary<string, double?> lessoncreate = new();
  322. SortedSetEntry[] llessoncreateScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:lesson-create:{day}");
  323. if (llessoncreateScores != null)
  324. {
  325. foreach (var score in llessoncreateScores)
  326. {
  327. double val = score.Score;
  328. string key = score.Element.ToString();
  329. lessoncreate.TryAdd(key, val);
  330. keys.Add(key);
  331. }
  332. }
  333. List<string> ids = new List<string>();
  334. keys.ToList().ForEach(x => {
  335. ids.Add(x.Split("::")[0]);
  336. });
  337. List<CoreUser> coreUsers = new List<CoreUser>();
  338. List<Teacher> teachers= new List<Teacher>();
  339. if (ids.IsNotEmpty())
  340. {
  341. string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
  342. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
  343. if (result.list.IsNotEmpty())
  344. {
  345. teachers.AddRange(result.list);
  346. }
  347. var content = new StringContent(ids.Distinct().ToJsonString(), Encoding.UTF8, "application/json");
  348. try
  349. {
  350. string json = await coreAPIHttpService.GetUserInfos(content);
  351. if (!string.IsNullOrWhiteSpace(json))
  352. {
  353. coreUsers = json.ToObject<List<CoreUser>>();
  354. }
  355. }
  356. catch (Exception ex)
  357. {
  358. await dingDing.SendBotMsg($"{coreAPIHttpService.options.location}用户转换失败:{coreAPIHttpService.options.coreUrl}", GroupNames.醍摩豆服務運維群組);
  359. }
  360. }
  361. List<CodeValue> notifys = new List<CodeValue>();
  362. foreach (var teacher in teachers)
  363. {
  364. //if (!(teacher.id.Equals("1535418750")))
  365. //{
  366. // continue;
  367. //}
  368. //if (!(teacher.id.Equals("1535418750")))
  369. //{
  370. // continue;
  371. //}
  372. StringBuilder notify = new StringBuilder();
  373. #if DEBUG
  374. int sendTime_pm = now.Hour;
  375. int sendTime_am = now.Hour;
  376. #else
  377. int sendTime_pm = 20;
  378. int sendTime_am =8;
  379. #endif
  380. if (am>0) {
  381. sendTime_am = am;
  382. }
  383. if (pm>0)
  384. {
  385. sendTime_pm = pm;
  386. }
  387. string lang = teacher.lang;
  388. var tzt = now.GetGMTTime((int)teacher.timezone);
  389. if (string.IsNullOrWhiteSpace(teacher.lang))
  390. {
  391. if (coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
  392. {
  393. lang= "zh-cn";
  394. }
  395. if (coreAPIHttpService.options.location.Contains("Global",StringComparison.OrdinalIgnoreCase))
  396. {
  397. lang= "en-us";
  398. }
  399. }
  400. int examCount = 0,homeworkCount=0,lessonCount=0;
  401. StringBuilder examSB= new StringBuilder();
  402. foreach (var exam in exam_submit)
  403. {
  404. string[] ks = exam.Key.Split("::");
  405. string tid = ks[0];
  406. string examId = ks[1];
  407. string examName = ks[3];
  408. if (tid.Equals(teacher.id)) {
  409. if (tzt.Hour==sendTime_pm)
  410. {
  411. string sql = $"select c.status from c where c.examId='{examId}' and c.pk='ExamClassResult'";
  412. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamClassResult>(sql, $"ExamClassResult-{tid}");
  413. if (result.list.IsNotEmpty()) {
  414. var unsubmit = result.list.SelectMany(x => x.status).Where(x => x==1);
  415. var submit = result.list.SelectMany(x => x.status).Where(x => x==0);
  416. examCount++;
  417. switch (lang)
  418. {
  419. case "zh-cn":
  420. examSB.Append(cn_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  421. break;
  422. case "zh-tw":
  423. examSB.Append(tw_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  424. break;
  425. case "en-us":
  426. examSB.Append(en_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  427. break;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. StringBuilder homeworkSB = new StringBuilder();
  434. foreach (var homeworksm in homework_submit_today)
  435. {
  436. string[] ks = homeworksm.Key.Split("::");
  437. string tid = ks[0];
  438. string homeworkId = ks[1];
  439. string homeworkName = ks[3];
  440. if (tid.Equals(teacher.id))
  441. {
  442. if (tzt.Hour==sendTime_pm)
  443. {
  444. homeworkCount++;
  445. }
  446. }
  447. }
  448. foreach (var homeworksm in homework_submit)
  449. {
  450. string[] ks = homeworksm.Key.Split("::");
  451. string tid = ks[0];
  452. string homeworkId = ks[1];
  453. string homeworkName = ks[3];
  454. if (tid.Equals(teacher.id))
  455. {
  456. if (tzt.Hour==sendTime_am)
  457. {
  458. var response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(homeworkId, new PartitionKey($"Homework-{tid}"));
  459. if (response.StatusCode == System.Net.HttpStatusCode.OK) {
  460. Homework homework= JsonDocument.Parse(response.Content).RootElement.ToObject<Homework>();
  461. List<string > classes= new List<string>();
  462. classes.AddRange(homework.stuLists);
  463. classes.AddRange(homework.classes);
  464. List<HomeworkUser> homeworkUsers= await HomeworkService.AnswerRecordAll(_azureCosmos.GetCosmosClient(), coreAPIHttpService, dingDing, homework, tid, "Student", classes, "student");
  465. // homeworkCount++;
  466. switch (lang)
  467. {
  468. case "zh-cn":
  469. homeworkSB.Append(cn_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  470. break;
  471. case "zh-tw":
  472. homeworkSB.Append(tw_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  473. break;
  474. case "en-us":
  475. homeworkSB.Append(en_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  476. break;
  477. }
  478. }
  479. }
  480. }
  481. }
  482. StringBuilder lessonSB = new StringBuilder();
  483. StringBuilder lessonDetailSB = new StringBuilder();
  484. foreach (var lesson in lessoncreate)
  485. {
  486. string[] ks = lesson.Key.Split("::");
  487. string tid = ks[0];
  488. if (tid.Equals(teacher.id))
  489. {
  490. if (tzt.Hour==sendTime_pm)
  491. {
  492. long stime = now.AddHours(-20).ToUnixTimeMilliseconds();
  493. string sql = $"select value c from c where c.tmdid='{teacher.id}' and c.pk='LessonRecord' and c.startTime> {stime} ";
  494. List<LessonRecord>lessons = new List<LessonRecord>();
  495. var schoolResult= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<LessonRecord>(sql);
  496. var teahcerResult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(sql, "LessonRecord");
  497. lessons.AddRange(schoolResult.list);
  498. lessons.AddRange(teahcerResult.list);
  499. foreach (var lessonRecord in lessons)
  500. {
  501. LessonBase lessonBase = null;
  502. try
  503. {
  504. string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
  505. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{lessonRecord.id}/IES/base.json").DownloadContentAsync();
  506. string basejson = baseblobDownload.Content.ToString().Replace("\"Uncall\"", "0").Replace("Uncall", "0");
  507. lessonBase = basejson.ToObject<LessonBase>();
  508. lessonCount++;
  509. var grpEngagement = string.Join(",", lessonBase.summary?.grpEngagement.Select((x, index) => $"G{index+1}({x})"));
  510. var highRankEngagement = string.Join(",", lessonBase.summary?.highRankEngagement?.Select((x, index) => $"S{index+1}({x})"));
  511. var highRankPerPoint = string.Join(",", lessonBase.summary?.highRankPerPoint?.Select((x, index) => $"S{index+1}({x})"));
  512. var highRankGrpPoint = string.Join(",", lessonBase.summary?.highRankGrpPoint?.Select((x, index) => $"S{index+1}({x})"));
  513. var highRankExam = string.Join(",", lessonBase.summary?.highRankExam?.Select((x, index) => $"S{index+1}({x})"));
  514. var lowRankExam = string.Join(",", lessonBase.summary?.lowRankExam?.Select((x, index) => $"S{index+1}({x})"));
  515. switch (lang)
  516. {
  517. case "zh-cn":
  518. if (lessonBase!=null)
  519. {
  520. lessonDetailSB.Append(cn_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}",$"{lessonBase.group.Count()}").Replace("{time}", DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyy-MM-dd HH:mm:ss"))
  521. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  522. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  523. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  524. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  525. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  526. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  527. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  528. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  529. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  530. }
  531. lessonSB.Append(cn_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  532. break;
  533. case "zh-tw":
  534. if (lessonBase!=null)
  535. {
  536. lessonDetailSB.Append(tw_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}", $"{lessonBase.group.Count()}").Replace("{time}", DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyy-MM-dd HH:mm:ss"))
  537. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  538. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  539. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  540. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  541. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  542. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  543. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  544. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  545. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  546. }
  547. lessonSB.Append(tw_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  548. break;
  549. case "en-us":
  550. if (lessonBase!=null)
  551. {
  552. lessonDetailSB.Append(en_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}", $"{lessonBase.group.Count()}").Replace("{time}", DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).ToString("yyyy-MM-dd HH:mm:ss"))
  553. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  554. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  555. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  556. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  557. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  558. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  559. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  560. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  561. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  562. }
  563. lessonSB.Append(en_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  564. break;
  565. }
  566. }
  567. catch (Exception ex)
  568. {
  569. }
  570. }
  571. }
  572. }
  573. }
  574. StringBuilder grouplistSB = new StringBuilder();
  575. List<string> grouplistIds=new List<string>();
  576. foreach (var group in grouplist)
  577. {
  578. string[] ks = group.Key.Split("::");
  579. grouplistIds.Add(ks[1]);
  580. }
  581. List<GroupListDto> groupListDtos= await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), dingDing, grouplistIds, null);
  582. foreach (var group in grouplist)
  583. {
  584. string[] ks = group.Key.Split("::");
  585. string tid = ks[0];
  586. string grouplistId = ks[1];
  587. string grouplistName = ks[3];
  588. var gpdto= groupListDtos.Find(x => x.id.Equals(grouplistId));
  589. if (gpdto!= null)
  590. {
  591. if (tid.Equals(teacher.id))
  592. {
  593. if (tzt.Hour==sendTime_pm)
  594. {
  595. switch (lang)
  596. {
  597. case "zh-cn":
  598. if (group.Value>=0)
  599. {
  600. grouplistSB.Append(cn_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  601. }
  602. else
  603. {
  604. grouplistSB.Append(cn_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  605. }
  606. break;
  607. case "zh-tw":
  608. if (group.Value>=0)
  609. {
  610. grouplistSB.Append(tw_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  611. }
  612. else
  613. {
  614. grouplistSB.Append(tw_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  615. }
  616. break;
  617. case "en-us":
  618. if (group.Value>=0)
  619. {
  620. grouplistSB.Append(en_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  621. }
  622. else
  623. {
  624. grouplistSB.Append(en_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  625. }
  626. break;
  627. }
  628. }
  629. }
  630. }
  631. }
  632. // await dingDing.SendBotMsg($"{teacher.name},{homework_submit_today.ToJsonString()},pm:{pm},am:{am},tztH:{tzt.Hour},sendPm:{sendTime_pm},sendAm:{sendTime_am},examCount:{examCount},lessonCount:{lessonCount},homeworkCount:{homeworkCount}", GroupNames.成都开发測試群組);
  633. if (tzt.Hour==sendTime_pm && (!string.IsNullOrWhiteSpace(lessonDetailSB.ToString()) || examCount>0 || lessonCount>0 || homeworkCount>0 || (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))))
  634. {
  635. string template=string.Empty;
  636. string title=string.Empty;
  637. switch (lang)
  638. {
  639. case "zh-cn":
  640. title="IES晚间报告";
  641. template=cn_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  642. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  643. .Replace("{cn_examList}", examSB.ToString()).Replace("{cn_lessonList}", lessonSB.ToString()).Replace("{cn_groupList}", grouplistSB.ToString());
  644. if (examCount>0)
  645. {
  646. template= template.Replace("{cn_examTitle}", cn_examTitle);
  647. }
  648. else {
  649. template= template.Replace("{cn_examTitle}", "");
  650. }
  651. if (homeworkCount>0)
  652. {
  653. template= template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
  654. }
  655. else
  656. {
  657. template= template.Replace("{cn_homeworkTitle}", "");
  658. }
  659. if (lessonCount>0)
  660. {
  661. template= template.Replace("{cn_lessonTitle}", cn_lessonTitle);
  662. }
  663. else
  664. {
  665. template= template.Replace("{cn_lessonTitle}", "");
  666. }
  667. if (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))
  668. {
  669. template=template.Replace("{cn_groupTitle}", cn_groupTitle);
  670. }
  671. else
  672. {
  673. template= template.Replace("{cn_groupTitle}", "");
  674. }
  675. break;
  676. case "zh-tw":
  677. title="IES晚間報告";
  678. template=tw_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  679. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  680. .Replace("{tw_examList}", examSB.ToString()).Replace("{tw_lessonList}", lessonSB.ToString()).Replace("{tw_groupList}", grouplistSB.ToString());
  681. if (examCount>0)
  682. {
  683. template= template.Replace("{tw_examTitle}", tw_examTitle);
  684. }
  685. else
  686. {
  687. template= template.Replace("{tw_examTitle}", "");
  688. }
  689. if (homeworkCount>0)
  690. {
  691. template= template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
  692. }
  693. else
  694. {
  695. template= template.Replace("{tw_homeworkTitle}", "");
  696. }
  697. if (lessonCount>0)
  698. {
  699. template= template.Replace("{tw_lessonTitle}", tw_lessonTitle);
  700. }
  701. else
  702. {
  703. template= template.Replace("{tw_lessonTitle}", "");
  704. }
  705. if (grouplist.Count>0)
  706. {
  707. template=template.Replace("{tw_groupTitle}", tw_groupTitle);
  708. }
  709. else
  710. {
  711. template= template.Replace("{tw_groupTitle}", "");
  712. }
  713. break;
  714. case "en-us":
  715. title ="IES Evening Report";
  716. template=en_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  717. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  718. .Replace("{en_examList}", examSB.ToString()).Replace("{en_lessonList}", lessonSB.ToString()).Replace("{en_groupList}", grouplistSB.ToString());
  719. if (examCount>0)
  720. {
  721. template= template.Replace("{en_examTitle}", en_examTitle);
  722. }
  723. else
  724. {
  725. template= template.Replace("{en_examTitle}", "");
  726. }
  727. if (homeworkCount>0)
  728. {
  729. template= template.Replace("{en_homeworkTitle}", en_homeworkTitle);
  730. }
  731. else
  732. {
  733. template= template.Replace("{en_homeworkTitle}", "");
  734. }
  735. if (lessonCount>0)
  736. {
  737. template= template.Replace("{en_lessonTitle}", en_lessonTitle);
  738. }
  739. else
  740. {
  741. template= template.Replace("{en_lessonTitle}", "");
  742. }
  743. if (grouplist.Count>0)
  744. {
  745. template=template.Replace("{en_groupTitle}", en_groupTitle);
  746. }
  747. else
  748. {
  749. template= template.Replace("{en_groupTitle}", "");
  750. }
  751. break;
  752. }
  753. template= template.Replace("\r\n", "");
  754. string eventId = $"Evening_Report-{_snowflakeId.NextId()}";
  755. NotifyData notifyData = new NotifyData
  756. {
  757. hubName = "hita5",
  758. sender = "IES",
  759. tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
  760. title = title,
  761. eventId =eventId,
  762. eventName =title,
  763. data = "{\"value\":{}}",
  764. body=template,
  765. };
  766. HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
  767. var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
  768. if (coreUser!=null)
  769. {
  770. // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name, sender: "TEAMModel");
  771. //var tid = lang.Equals("zh-cn") ? "d-136eddbd974046f1a721c8f4e210b9bf" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  772. var tid = string.Empty;
  773. if (coreAPIHttpService.options.location.Contains("China"))
  774. {
  775. tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
  776. }
  777. else
  778. {
  779. tid=lang.Equals("zh-cn") ? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  780. }
  781. await coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = $"{template}</br>{lessonDetailSB.ToString()}" } } }, coreAPIHttpService.options.location, _configuration);
  782. }
  783. notify.Append(template);
  784. }
  785. if (tzt.Hour==sendTime_am && !string.IsNullOrWhiteSpace(homeworkSB.ToString()))
  786. {
  787. string template = string.Empty;
  788. string title = string.Empty;
  789. switch (lang)
  790. {
  791. case "zh-cn":
  792. title ="IES早间报告";
  793. template= cn_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  794. .Replace("{cn_homeworkList}", homeworkSB.ToString());
  795. template=template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
  796. break;
  797. case "zh-tw":
  798. title ="IES晨間報告";
  799. template= tw_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  800. .Replace("{tw_homeworkList}", homeworkSB.ToString());
  801. template=template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
  802. break;
  803. case "en-us":
  804. title ="IES Morning Report";
  805. template=en_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  806. .Replace("{en_homeworkList}", homeworkSB.ToString());
  807. template=template.Replace("{en_homeworkTitle}", en_homeworkTitle);
  808. break;
  809. }
  810. template= template.Replace("\r\n", "");
  811. string eventId = $"Morning_Report-{_snowflakeId.NextId()}";
  812. NotifyData notifyData = new NotifyData
  813. {
  814. hubName = "hita5",
  815. sender = "IES",
  816. tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
  817. title = title,
  818. eventId = eventId,
  819. eventName =title,
  820. data = "{\"value\":{}}",
  821. body=template,
  822. };
  823. HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
  824. var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
  825. if (coreUser!=null)
  826. {
  827. // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name,sender:"TEAMModel");
  828. var tid = string.Empty ;
  829. if (coreAPIHttpService.options.location.Contains("China"))
  830. {
  831. tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
  832. }
  833. else {
  834. tid=lang.Equals("zh-cn")? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  835. }
  836. await coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = template } } }, coreAPIHttpService.options.location, _configuration);
  837. }
  838. notify.Append(template);
  839. }
  840. notifys.Add(new CodeValue { code=teacher.id, value= notify.ToString() });
  841. }
  842. return notifys;
  843. }
  844. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, DingDing dingDing, Accumulate accumulate)
  845. {
  846. if (!string.IsNullOrWhiteSpace(accumulate.key) && !string.IsNullOrWhiteSpace(accumulate.target) &&
  847. !string.IsNullOrWhiteSpace(accumulate.id) && !string.IsNullOrWhiteSpace(accumulate.name) &&
  848. !string.IsNullOrWhiteSpace(accumulate.scope) && !string.IsNullOrWhiteSpace(accumulate.client))
  849. {
  850. await RecordAccumulateData(azureRedis, accumulate.key, accumulate.target, accumulate.id, accumulate.name, accumulate.scope, accumulate.client, accumulate.count);
  851. }
  852. else
  853. {
  854. await dingDing.SendBotMsg($"IES累计数据变更统计参数异常,{accumulate.ToJsonString()}", GroupNames.成都开发測試群組);
  855. }
  856. }
  857. /// <summary>
  858. /// 记录累计数据
  859. /// </summary>
  860. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, string key, string target, string id, string name, string scope, string client, int count)
  861. {
  862. if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(target) &&
  863. !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) &&
  864. !string.IsNullOrWhiteSpace(scope)&& !string.IsNullOrWhiteSpace(client))
  865. {
  866. //处理UTC时差
  867. var nowTime = DateTimeOffset.UtcNow.GetGMTTime();
  868. int difference = (DayOfWeek.Sunday - nowTime.DayOfWeek + 7) % 7; //1-7的结果0-6
  869. var day = nowTime.ToString("yyyyMMdd");
  870. string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
  871. string member = $"{target}::{id}::{client}::{name}";
  872. await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
  873. await azureRedis.GetRedisClient(8).KeyExpireAsync(redisKey, new TimeSpan((difference+1)*24, 10, 0));
  874. //if (key.Equals("lesson") || key.StartsWith("login_"))
  875. //{
  876. // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
  877. // if (scope.Equals("school"))
  878. // {
  879. // member = $"ies::{id}::{name}";
  880. // }
  881. // else {
  882. // member = $"ies::ies::{name}";
  883. // }
  884. // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
  885. //}
  886. }
  887. }
  888. public const double timeWeight = 0.7;
  889. public const double countWeight = 0.3;
  890. static double GetUserDuration(List<long> times)
  891. {
  892. if (times.IsNotEmpty())
  893. {
  894. if (times.Count>=2)
  895. {
  896. double totalDuration = 0;
  897. // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
  898. long ltime = times[0];
  899. for (int i = 1; i < times.Count; i++)
  900. {
  901. long ctime = times[i];
  902. //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
  903. long timeDifference = ctime - ltime;
  904. ///如果一小时内连续操作,则按真实时间累计
  905. if (timeDifference < 3600000)
  906. {
  907. totalDuration += timeDifference;
  908. }
  909. else
  910. { ///如果一小时内没有连续操作,则按象征性加10秒,以确保数据有效性。 如果因为一小时没有操作,则表示没有新的接口再次请求,当即就已经退出系统。否则后续仍然会有接口进入,并且带有时间戳
  911. totalDuration += 10000;
  912. }
  913. ltime = ctime;
  914. }
  915. return totalDuration;
  916. }
  917. else { return 10000; }
  918. }
  919. else
  920. {
  921. return 0;
  922. }
  923. }
  924. public static List<SchoolStick> CountSchoolStickiness(IEnumerable<IGrouping<string, ApiVisit>> schoolApiVisits, IEnumerable<ApiVisit> apiVisits, List<SchoolStick> bygoneStickiness)
  925. {
  926. List<SchoolStick> schoolStickiness = new List<SchoolStick>();
  927. //用于做标准化值的最大最小度量值
  928. 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;
  929. 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;
  930. 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;
  931. 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;
  932. double max_tch_hita_c = 0, max_tch_hiteach_c = 0, max_tch_ies5Tch_c = 0, max_tch_otherTch_c = 0;
  933. double max_tch_hita_d = 0, max_tch_hiteach_d = 0, max_tch_ies5Tch_d = 0, max_tch_otherTch_d = 0;
  934. double min_tch_hita_c = 0, min_tch_hiteach_c = 0, min_tch_ies5Tch_c = 0, min_tch_otherTch_c = 0;
  935. double min_tch_hita_d = 0, min_tch_hiteach_d = 0, min_tch_ies5Tch_d = 0, min_tch_otherTch_d = 0;
  936. foreach (var chinaSchoolKey in schoolApiVisits)
  937. {
  938. SchoolStick stickiness = new SchoolStick()
  939. {
  940. id = chinaSchoolKey.Key
  941. };
  942. var teachers = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("teacher")).GroupBy(x => x.userId);
  943. double hitaTime = 0, hiteachTime = 0, ies5TchTime = 0, otherTchTime = 0, ies5StuTime = 0, otherStuTime = 0;
  944. int hitaTch = 0, hiteachTch = 0, ies5Tch = 0, otherTch = 0, ies5Stu = 0, otherStu = 0;
  945. double hitaCount = 0, hiteachCount = 0, ies5TchCount = 0, otherTchCount = 0, ies5StuCount = 0, otherStuCount = 0;
  946. double lessonCount = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson")).Count();
  947. int teacherCount = teachers.Count();
  948. double max_stu_ies5Stu_c = 0, max_stu_otherStu_c = 0;
  949. double max_stu_ies5Stu_d = 0, max_stu_otherStu_d = 0;
  950. double min_stu_ies5Stu_c = 0, min_stu_otherStu_c = 0;
  951. double min_stu_ies5Stu_d = 0, min_stu_otherStu_d = 0;
  952. foreach (var user in teachers)
  953. {
  954. TchStick tchStick = new TchStick()
  955. {
  956. id = user.Key,
  957. school= chinaSchoolKey.Key
  958. };
  959. //HiTA
  960. var teacherHitaVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hita"));
  961. var teacherHitaVisitCount = teacherHitaVisit.Count();
  962. if (teacherHitaVisitCount>0)
  963. { hitaTch+=1; }
  964. var teacherHitaVisitTime = GetUserDuration(teacherHitaVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  965. hitaCount+=teacherHitaVisitCount;
  966. hitaTime+=teacherHitaVisitTime;
  967. tchStick.hita.count.value=teacherHitaVisitCount;
  968. tchStick.hita.duration.value=teacherHitaVisitTime;
  969. //Other
  970. var teacherOtherVisit = user.Where(x => !x.client.Equals("hita")&&!x.client.Equals("hiteach")&&!x.client.Equals("ies5"));
  971. var teacherOtherVisitCount = teacherOtherVisit.Count();
  972. var teacherOtherVisitTime = GetUserDuration(teacherOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  973. if (teacherOtherVisitCount>0)
  974. { otherTch+=1; }
  975. otherTchCount+=teacherOtherVisitCount;
  976. otherTchTime+=teacherOtherVisitTime;
  977. tchStick.otherTch.count.value=teacherOtherVisitCount;
  978. tchStick.otherTch.duration.value=teacherOtherVisitTime;
  979. //HiTeach
  980. //教师访问hiteach 不带学校信息的
  981. var teacherHiteachVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hiteach") && string.IsNullOrWhiteSpace(x.school));
  982. //教师访问hiteach 包含学校信息的
  983. var teacherHiteachSchoolVisit = user.Where(x => x.client.Equals("hiteach"));
  984. //教师所有的Hiteach访问
  985. List<ApiVisit> teacherHiteachAllVisit = new List<ApiVisit>();
  986. teacherHiteachAllVisit.AddRange(teacherHiteachVisit);
  987. teacherHiteachAllVisit.AddRange(teacherHiteachSchoolVisit);
  988. var teacherHiteachAllVisitCount = teacherHiteachAllVisit.Count();
  989. if (teacherHiteachAllVisitCount>0)
  990. { hiteachTch+=1; }
  991. var teacherHiteachAllVisitTime = GetUserDuration(teacherHiteachAllVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  992. hiteachCount+=teacherHiteachAllVisitCount;
  993. hiteachTime+=teacherHiteachAllVisitTime;
  994. tchStick.hiteach.count.value=teacherHiteachAllVisitCount;
  995. tchStick.hiteach.duration.value=teacherHiteachAllVisitTime;
  996. //IES5
  997. var teacherIes5Visit = user.Where(x => x.client.Equals("ies5"));
  998. var teacherIes5VisitCount = teacherIes5Visit.Count();
  999. if (teacherIes5VisitCount>0)
  1000. { ies5Tch+=1; }
  1001. var teacherIes5VisitTime = GetUserDuration(teacherIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1002. ies5TchCount+=teacherIes5VisitCount;
  1003. ies5TchTime+=teacherIes5VisitTime;
  1004. tchStick.ies5Tch.count.value=teacherIes5VisitCount;
  1005. tchStick.ies5Tch.duration.value=teacherIes5VisitTime;
  1006. double lessonCountTch = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson") && x.userId.Equals(user.Key)).Count();
  1007. tchStick.lesson.value=lessonCountTch;
  1008. tchStick.teacher.count.value=tchStick.hita.count.value+tchStick.hiteach.count.value+tchStick.ies5Tch.count.value+tchStick.otherTch.count.value;
  1009. tchStick.teacher.duration.value=tchStick.hita.duration.value+tchStick.hiteach.duration.value+tchStick.ies5Tch.duration.value+tchStick.otherTch.duration.value;
  1010. tchStick.hita.userCount=1;
  1011. tchStick.hiteach.userCount=1;
  1012. tchStick.ies5Tch.userCount=1;
  1013. tchStick.otherTch.userCount=1;
  1014. tchStick.teacher.userCount=1;
  1015. //if (tchStick.hita.count.value>0 && tchStick.hita.duration.value>0)
  1016. //{
  1017. // tchStick.hita.stick.value= (tchStick.hita.duration.value/1000/tchStick.hita.count.value * tchStick.hita.count.value/tchStick.teacher.count.value);
  1018. //}
  1019. //if (tchStick.ies5Tch.count.value>0 && tchStick.ies5Tch.duration.value>0)
  1020. //{
  1021. // tchStick.ies5Tch.stick.value= (tchStick.ies5Tch.duration.value/1000/tchStick.ies5Tch.count.value * tchStick.ies5Tch.count.value/tchStick.teacher.count.value);
  1022. //}
  1023. //if (tchStick.otherTch.count.value>0 && tchStick.otherTch.duration.value>0)
  1024. //{
  1025. // tchStick.otherTch.stick.value= (tchStick.otherTch.duration.value/1000/tchStick.otherTch.count.value);
  1026. //}
  1027. //if (tchStick.hiteach.count.value>0 && tchStick.hiteach.duration.value>0)
  1028. //{
  1029. // tchStick.hiteach.stick.value= (tchStick.hiteach.duration.value/1000/tchStick.hiteach.count.value)+(tchStick.lesson.value*100);
  1030. //}
  1031. //if (tchStick.teacher.count.value>0 && tchStick.teacher.duration.value>0)
  1032. //{
  1033. // tchStick.teacher.stick.value= (tchStick.teacher.duration.value/1000/tchStick.teacher.count.value)+ (tchStick.lesson.value*100);
  1034. //}
  1035. #region
  1036. if (tchStick.hita.count.value>0)
  1037. {
  1038. if (min_tch_hita_c ==0)
  1039. {
  1040. min_tch_hita_c= tchStick.hita.count.value;
  1041. }
  1042. else if (min_tch_hita_c>tchStick.hita.count.value)
  1043. {
  1044. min_tch_hita_c=tchStick.hita.count.value;
  1045. }
  1046. if (tchStick.hita.count.value>max_tch_hita_c)
  1047. {
  1048. max_tch_hita_c= tchStick.hita.count.value;
  1049. }
  1050. }
  1051. if (tchStick.hiteach.count.value>0)
  1052. {
  1053. if (min_tch_hiteach_c ==0)
  1054. {
  1055. min_tch_hiteach_c= tchStick.hiteach.count.value;
  1056. }
  1057. else if (min_tch_hiteach_c>tchStick.hiteach.count.value)
  1058. {
  1059. min_tch_hiteach_c=tchStick.hiteach.count.value;
  1060. }
  1061. if (tchStick.hiteach.count.value>max_tch_hiteach_c)
  1062. {
  1063. max_tch_hiteach_c= tchStick.hiteach.count.value;
  1064. }
  1065. }
  1066. if (tchStick.ies5Tch.count.value>0)
  1067. {
  1068. if (min_tch_ies5Tch_c ==0)
  1069. {
  1070. min_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  1071. }
  1072. else if (min_tch_ies5Tch_c>tchStick.ies5Tch.count.value)
  1073. {
  1074. min_tch_ies5Tch_c=tchStick.ies5Tch.count.value;
  1075. }
  1076. if (tchStick.ies5Tch.count.value>max_tch_ies5Tch_c)
  1077. {
  1078. max_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  1079. }
  1080. }
  1081. if (tchStick.otherTch.count.value>0)
  1082. {
  1083. if (min_tch_otherTch_c ==0)
  1084. {
  1085. min_tch_otherTch_c= tchStick.otherTch.count.value;
  1086. }
  1087. else if (min_tch_otherTch_c>tchStick.otherTch.count.value)
  1088. {
  1089. min_tch_otherTch_c=tchStick.otherTch.count.value;
  1090. }
  1091. if (tchStick.otherTch.count.value>max_tch_otherTch_c)
  1092. {
  1093. max_tch_otherTch_c= tchStick.otherTch.count.value;
  1094. }
  1095. }
  1096. if (tchStick.hita.duration.value>0)
  1097. {
  1098. if (min_tch_hita_d ==0)
  1099. {
  1100. min_tch_hita_d= tchStick.hita.duration.value;
  1101. }
  1102. else if (min_tch_hita_d>tchStick.hita.duration.value)
  1103. {
  1104. min_tch_hita_d=tchStick.hita.duration.value;
  1105. }
  1106. if (tchStick.hita.duration.value>max_tch_hita_d)
  1107. {
  1108. max_tch_hita_d= tchStick.hita.duration.value;
  1109. }
  1110. }
  1111. if (tchStick.hiteach.duration.value>0)
  1112. {
  1113. if (min_tch_hiteach_d ==0)
  1114. {
  1115. min_tch_hiteach_d= tchStick.hiteach.duration.value;
  1116. }
  1117. else if (min_tch_hiteach_d>tchStick.hiteach.duration.value)
  1118. {
  1119. min_tch_hiteach_d=tchStick.hiteach.duration.value;
  1120. }
  1121. if (tchStick.hiteach.duration.value>max_tch_hiteach_d)
  1122. {
  1123. max_tch_hiteach_d= tchStick.hiteach.duration.value;
  1124. }
  1125. }
  1126. if (tchStick.ies5Tch.duration.value>0)
  1127. {
  1128. if (min_tch_ies5Tch_d ==0)
  1129. {
  1130. min_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  1131. }
  1132. else if (min_tch_ies5Tch_d>tchStick.ies5Tch.duration.value)
  1133. {
  1134. min_tch_ies5Tch_d=tchStick.ies5Tch.duration.value;
  1135. }
  1136. if (tchStick.ies5Tch.duration.value>max_tch_ies5Tch_d)
  1137. {
  1138. max_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  1139. }
  1140. }
  1141. if (tchStick.otherTch.duration.value>0)
  1142. {
  1143. if (min_tch_otherTch_d ==0)
  1144. {
  1145. min_tch_otherTch_d= tchStick.otherTch.duration.value;
  1146. }
  1147. else if (min_tch_otherTch_d>tchStick.otherTch.duration.value)
  1148. {
  1149. min_tch_otherTch_d=tchStick.otherTch.duration.value;
  1150. }
  1151. if (tchStick.otherTch.duration.value>max_tch_otherTch_d)
  1152. {
  1153. max_tch_otherTch_d= tchStick.otherTch.duration.value;
  1154. }
  1155. }
  1156. #endregion
  1157. stickiness.tchSticks.Add(tchStick);
  1158. }
  1159. 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);
  1160. var studentCount = student.Count();
  1161. foreach (var user in student)
  1162. {
  1163. StuStick stuStick = new StuStick
  1164. {
  1165. id=user.Key,
  1166. school=chinaSchoolKey.Key
  1167. };
  1168. var studentOtherVisit = user.Where(x => !x.client.Equals("ies5"));
  1169. var studentOtherVisitCount = studentOtherVisit.Count();
  1170. if (studentOtherVisitCount>0)
  1171. { otherStu+=1; }
  1172. double studentOtherVisitTime = GetUserDuration(studentOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1173. var studentIes5Visit = user.Where(x => x.client.Equals("ies5"));
  1174. var studentIes5VisitCount = studentIes5Visit.Count();
  1175. if (studentIes5VisitCount>0)
  1176. { ies5Stu+=1; }
  1177. double studentIes5VisitTime = GetUserDuration(studentIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1178. ies5StuCount+=studentIes5VisitCount;
  1179. ies5StuTime+=studentIes5VisitTime;
  1180. otherStuCount+=studentOtherVisitCount;
  1181. otherStuTime+=studentOtherVisitTime;
  1182. stuStick.ies5Stu.count.value=studentIes5VisitCount;
  1183. stuStick.ies5Stu.duration.value=studentIes5VisitTime;
  1184. stuStick.otherStu.count.value=studentOtherVisitCount;
  1185. stuStick.otherStu.duration.value=studentOtherVisitTime;
  1186. stuStick.student.count.value= stuStick.ies5Stu.count.value+stuStick.otherStu.count.value;
  1187. stuStick.student.duration.value= stuStick.ies5Stu.duration.value+stuStick.otherStu.duration.value;
  1188. stuStick.ies5Stu.userCount=1;
  1189. stuStick.otherStu.userCount=1;
  1190. stuStick.student.userCount=1;
  1191. //if (stuStick.ies5Stu.count.value>0 && stuStick.ies5Stu.duration.value>0)
  1192. //{
  1193. // stuStick.ies5Stu.stick.value= (stuStick.ies5Stu.duration.value/1000/stuStick.ies5Stu.count.value);
  1194. //}
  1195. //if (stuStick.otherStu.count.value>0 && stuStick.otherStu.duration.value>0)
  1196. //{
  1197. // stuStick.otherStu.stick.value=(stuStick.otherStu.duration.value/1000/stuStick.otherStu.count.value);
  1198. //}
  1199. //if (stuStick.student.count.value>0 && stuStick.student.duration.value>0)
  1200. //{
  1201. // stuStick.student.stick.value=(stuStick.student.duration.value/1000/stuStick.student.count.value);
  1202. //}
  1203. #region
  1204. if (stuStick.otherStu.count.value>0)
  1205. {
  1206. if (min_stu_otherStu_c ==0)
  1207. {
  1208. min_stu_otherStu_c= stuStick.otherStu.count.value;
  1209. }
  1210. else if (min_stu_otherStu_c>stuStick.otherStu.count.value)
  1211. {
  1212. min_stu_otherStu_c=stuStick.otherStu.count.value;
  1213. }
  1214. if (stuStick.otherStu.count.value>max_stu_otherStu_c)
  1215. {
  1216. max_stu_otherStu_c= stuStick.otherStu.count.value;
  1217. }
  1218. }
  1219. if (stuStick.ies5Stu.count.value>0)
  1220. {
  1221. if (min_stu_ies5Stu_c ==0)
  1222. {
  1223. min_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  1224. }
  1225. else if (min_stu_ies5Stu_c>stuStick.ies5Stu.count.value)
  1226. {
  1227. min_stu_ies5Stu_c=stuStick.ies5Stu.count.value;
  1228. }
  1229. if (stuStick.ies5Stu.count.value>max_stu_ies5Stu_c)
  1230. {
  1231. max_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  1232. }
  1233. }
  1234. if (stuStick.otherStu.duration.value>0)
  1235. {
  1236. if (min_stu_otherStu_d ==0)
  1237. {
  1238. min_stu_otherStu_d= stuStick.otherStu.duration.value;
  1239. }
  1240. else if (min_stu_otherStu_d>stuStick.otherStu.duration.value)
  1241. {
  1242. min_stu_otherStu_d=stuStick.otherStu.duration.value;
  1243. }
  1244. if (stuStick.otherStu.duration.value>max_stu_otherStu_d)
  1245. {
  1246. max_stu_otherStu_d= stuStick.otherStu.duration.value;
  1247. }
  1248. }
  1249. if (stuStick.ies5Stu.duration.value>0)
  1250. {
  1251. if (min_stu_ies5Stu_d ==0)
  1252. {
  1253. min_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  1254. }
  1255. else if (min_stu_ies5Stu_d>stuStick.ies5Stu.duration.value)
  1256. {
  1257. min_stu_ies5Stu_d=stuStick.ies5Stu.duration.value;
  1258. }
  1259. if (stuStick.ies5Stu.duration.value>max_stu_ies5Stu_d)
  1260. {
  1261. max_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  1262. }
  1263. }
  1264. #endregion
  1265. stickiness.stuSticks.Add(stuStick);
  1266. }
  1267. //时长
  1268. stickiness.hita.duration.value=hitaTime;
  1269. stickiness.hiteach.duration.value=hiteachTime;
  1270. stickiness.otherTch.duration.value=otherTchTime;
  1271. stickiness.ies5Tch.duration.value=ies5TchTime;
  1272. stickiness.ies5Stu.duration.value=ies5StuTime;
  1273. stickiness.otherStu.duration.value=otherStuTime;
  1274. stickiness.teacher.duration.value=hitaTime+hiteachTime+otherTchTime+ies5TchTime;
  1275. stickiness.student.duration.value=otherStuTime+ies5StuTime;
  1276. //用户数
  1277. stickiness.hita.userCount=hitaTch;
  1278. stickiness.hiteach.userCount=hiteachTch;
  1279. stickiness.ies5Tch.userCount=ies5Tch;
  1280. stickiness.otherTch.userCount=otherTch;
  1281. stickiness.ies5Stu.userCount=ies5Stu;
  1282. stickiness.otherStu.userCount=otherStu;
  1283. stickiness.teacher.userCount=teacherCount;
  1284. stickiness.student.userCount=studentCount;
  1285. //访问数
  1286. stickiness.hita.count.value=hitaCount;
  1287. stickiness.hiteach.count.value=hiteachCount;
  1288. stickiness.ies5Tch.count.value=ies5TchCount;
  1289. stickiness.otherTch.count.value=otherTchCount;
  1290. stickiness.ies5Stu.count.value=ies5StuCount;
  1291. stickiness.otherStu.count.value=otherStuCount;
  1292. stickiness.teacher.count.value=hitaCount+hiteachCount+ies5TchCount+otherTchCount;
  1293. stickiness.student.count.value=ies5StuCount+otherStuCount;
  1294. //开课数
  1295. stickiness.lesson.value=lessonCount;
  1296. //if (stickiness.hita.count.value>0 && stickiness.hita.duration.value>0)
  1297. //{
  1298. // stickiness.hita.stick.value=(stickiness.hita.userCount* stickiness.hita.count.value)/(stickiness.hita.duration.value/1000/stickiness.hita.count.value);
  1299. //}
  1300. //if (stickiness.ies5Stu.count.value>0 && stickiness.ies5Stu.duration.value>0)
  1301. //{
  1302. // stickiness.ies5Stu.stick.value=(stickiness.ies5Stu.userCount* stickiness.ies5Stu.count.value)/(stickiness.ies5Stu.duration.value/1000/stickiness.ies5Stu.count.value);
  1303. //}
  1304. //if (stickiness.ies5Tch.count.value>0 && stickiness.ies5Tch.duration.value>0)
  1305. //{
  1306. // stickiness.ies5Tch.stick.value=(stickiness.ies5Tch.userCount* stickiness.ies5Tch.count.value)/(stickiness.ies5Tch.duration.value/1000/stickiness.ies5Tch.count.value);
  1307. //}
  1308. //if (stickiness.otherStu.count.value>0 && stickiness.otherStu.duration.value>0)
  1309. //{
  1310. // stickiness.otherStu.stick.value=(stickiness.otherStu.userCount* stickiness.otherStu.count.value)/(stickiness.otherStu.duration.value/1000/stickiness.otherStu.count.value);
  1311. //}
  1312. //if (stickiness.otherTch.count.value>0 && stickiness.otherTch.duration.value>0)
  1313. //{
  1314. // stickiness.otherTch.stick.value=(stickiness.otherTch.userCount* stickiness.otherTch.count.value)/(stickiness.otherTch.duration.value/1000/stickiness.otherTch.count.value);
  1315. //}
  1316. //if (stickiness.hiteach.count.value>0 && stickiness.hiteach.duration.value>0)
  1317. //{
  1318. // stickiness.hiteach.stick.value=(stickiness.hiteach.userCount* stickiness.hiteach.count.value)/(stickiness.hiteach.duration.value/1000/stickiness.hiteach.count.value)+stickiness.lesson.value;
  1319. //}
  1320. //if (stickiness.teacher.count.value>0 && stickiness.teacher.duration.value>0)
  1321. //{
  1322. // stickiness.teacher.stick.value=(stickiness.teacher.userCount* stickiness.teacher.count.value)/(stickiness.teacher.duration.value/1000/stickiness.teacher.count.value)+ stickiness.lesson.value;
  1323. //}
  1324. //if (stickiness.student.count.value>0 && stickiness.student.duration.value>0)
  1325. //{
  1326. // stickiness.student.stick.value=(stickiness.student.userCount* stickiness.student.count.value)/(stickiness.student.duration.value/1000/stickiness.student.count.value)+ stickiness.lesson.value;
  1327. //}
  1328. #region
  1329. if (stickiness.hita.count.value>0)
  1330. {
  1331. if (min_sch_hita_c ==0)
  1332. {
  1333. min_sch_hita_c= stickiness.hita.count.value;
  1334. }
  1335. else if (min_sch_hita_c>stickiness.hita.count.value)
  1336. {
  1337. min_sch_hita_c=stickiness.hita.count.value;
  1338. }
  1339. if (stickiness.hita.count.value>max_sch_hita_c)
  1340. {
  1341. max_sch_hita_c= stickiness.hita.count.value;
  1342. }
  1343. }
  1344. if (stickiness.hiteach.count.value>0)
  1345. {
  1346. if (min_sch_hiteach_c ==0)
  1347. {
  1348. min_sch_hiteach_c= stickiness.hiteach.count.value;
  1349. }
  1350. else if (min_sch_hiteach_c>stickiness.hiteach.count.value)
  1351. {
  1352. min_sch_hiteach_c=stickiness.hiteach.count.value;
  1353. }
  1354. if (stickiness.hiteach.count.value>max_sch_hiteach_c)
  1355. {
  1356. max_sch_hiteach_c= stickiness.hiteach.count.value;
  1357. }
  1358. }
  1359. if (stickiness.ies5Tch.count.value>0)
  1360. {
  1361. if (min_sch_ies5Tch_c ==0)
  1362. {
  1363. min_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  1364. }
  1365. else if (min_sch_ies5Tch_c>stickiness.ies5Tch.count.value)
  1366. {
  1367. min_sch_ies5Tch_c=stickiness.ies5Tch.count.value;
  1368. }
  1369. if (stickiness.ies5Tch.count.value>max_sch_ies5Tch_c)
  1370. {
  1371. max_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  1372. }
  1373. }
  1374. if (stickiness.otherTch.count.value>0)
  1375. {
  1376. if (min_sch_otherTch_c ==0)
  1377. {
  1378. min_sch_otherTch_c= stickiness.otherTch.count.value;
  1379. }
  1380. else if (min_sch_otherTch_c>stickiness.otherTch.count.value)
  1381. {
  1382. min_sch_otherTch_c=stickiness.otherTch.count.value;
  1383. }
  1384. if (stickiness.otherTch.count.value>max_sch_otherTch_c)
  1385. {
  1386. max_sch_otherTch_c= stickiness.otherTch.count.value;
  1387. }
  1388. }
  1389. if (stickiness.otherStu.count.value>0)
  1390. {
  1391. if (min_sch_otherStu_c ==0)
  1392. {
  1393. min_sch_otherStu_c= stickiness.otherStu.count.value;
  1394. }
  1395. else if (min_sch_otherStu_c>stickiness.otherStu.count.value)
  1396. {
  1397. min_sch_otherStu_c=stickiness.otherStu.count.value;
  1398. }
  1399. if (stickiness.otherStu.count.value>max_sch_otherStu_c)
  1400. {
  1401. max_sch_otherStu_c= stickiness.otherStu.count.value;
  1402. }
  1403. }
  1404. if (stickiness.ies5Stu.count.value>0)
  1405. {
  1406. if (min_sch_ies5Stu_c ==0)
  1407. {
  1408. min_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  1409. }
  1410. else if (min_sch_ies5Stu_c>stickiness.ies5Stu.count.value)
  1411. {
  1412. min_sch_ies5Stu_c=stickiness.ies5Stu.count.value;
  1413. }
  1414. if (stickiness.ies5Stu.count.value>max_sch_ies5Stu_c)
  1415. {
  1416. max_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  1417. }
  1418. }
  1419. if (stickiness.hita.duration.value>0)
  1420. {
  1421. if (min_sch_hita_d ==0)
  1422. {
  1423. min_sch_hita_d= stickiness.hita.duration.value;
  1424. }
  1425. else if (min_sch_hita_d>stickiness.hita.duration.value)
  1426. {
  1427. min_sch_hita_d=stickiness.hita.duration.value;
  1428. }
  1429. if (stickiness.hita.duration.value>max_sch_hita_d)
  1430. {
  1431. max_sch_hita_d= stickiness.hita.duration.value;
  1432. }
  1433. }
  1434. if (stickiness.hiteach.duration.value>0)
  1435. {
  1436. if (min_sch_hiteach_d ==0)
  1437. {
  1438. min_sch_hiteach_d= stickiness.hiteach.duration.value;
  1439. }
  1440. else if (min_sch_hiteach_d>stickiness.hiteach.duration.value)
  1441. {
  1442. min_sch_hiteach_d=stickiness.hiteach.duration.value;
  1443. }
  1444. if (stickiness.hiteach.duration.value>max_sch_hiteach_d)
  1445. {
  1446. max_sch_hiteach_d= stickiness.hiteach.duration.value;
  1447. }
  1448. }
  1449. if (stickiness.ies5Tch.duration.value>0)
  1450. {
  1451. if (min_sch_ies5Tch_d ==0)
  1452. {
  1453. min_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  1454. }
  1455. else if (min_sch_ies5Tch_d>stickiness.ies5Tch.duration.value)
  1456. {
  1457. min_sch_ies5Tch_d=stickiness.ies5Tch.duration.value;
  1458. }
  1459. if (stickiness.ies5Tch.duration.value>max_sch_ies5Tch_d)
  1460. {
  1461. max_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  1462. }
  1463. }
  1464. if (stickiness.otherTch.duration.value>0)
  1465. {
  1466. if (min_sch_otherTch_d ==0)
  1467. {
  1468. min_sch_otherTch_d= stickiness.otherTch.duration.value;
  1469. }
  1470. else if (min_sch_otherTch_d>stickiness.otherTch.duration.value)
  1471. {
  1472. min_sch_otherTch_d=stickiness.otherTch.duration.value;
  1473. }
  1474. if (stickiness.otherTch.duration.value>max_sch_otherTch_d)
  1475. {
  1476. max_sch_otherTch_d= stickiness.otherTch.duration.value;
  1477. }
  1478. }
  1479. if (stickiness.otherStu.duration.value>0)
  1480. {
  1481. if (min_sch_otherStu_d ==0)
  1482. {
  1483. min_sch_otherStu_d= stickiness.otherStu.duration.value;
  1484. }
  1485. else if (min_sch_otherStu_d>stickiness.otherStu.duration.value)
  1486. {
  1487. min_sch_otherStu_d=stickiness.otherStu.duration.value;
  1488. }
  1489. if (stickiness.otherStu.duration.value>max_sch_otherStu_d)
  1490. {
  1491. max_sch_otherStu_d= stickiness.otherStu.duration.value;
  1492. }
  1493. }
  1494. if (stickiness.ies5Stu.duration.value>0)
  1495. {
  1496. if (min_sch_ies5Stu_d ==0)
  1497. {
  1498. min_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  1499. }
  1500. else if (min_sch_ies5Stu_d>stickiness.ies5Stu.duration.value)
  1501. {
  1502. min_sch_ies5Stu_d=stickiness.ies5Stu.duration.value;
  1503. }
  1504. if (stickiness.ies5Stu.duration.value>max_sch_ies5Stu_d)
  1505. {
  1506. max_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  1507. }
  1508. }
  1509. #endregion
  1510. var bygoneStickinessSchool = bygoneStickiness?.Find(x => x.id.Equals(chinaSchoolKey.Key));
  1511. stickiness.tchSticks= OrderByTchStick(stickiness.tchSticks, bygoneStickinessSchool?.tchSticks);
  1512. stickiness.stuSticks= OrderByStuStick(stickiness.stuSticks, bygoneStickinessSchool?.stuSticks);
  1513. schoolStickiness.Add(stickiness);
  1514. }
  1515. return OrderBySchoolStick(schoolStickiness, bygoneStickiness);
  1516. }
  1517. private static List<StuStick> OrderByStuStick(List<StuStick> currentStickiness, List<StuStick>? bygoneStickiness)
  1518. {
  1519. // 假设visit已经填充了数据
  1520. #region
  1521. var rank_tmd_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  1522. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1523. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1524. #endregion
  1525. #region
  1526. var rank_tmd_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1527. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1528. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1529. #endregion
  1530. #region
  1531. var rank_tmd_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1532. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1533. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1534. #endregion
  1535. currentStickiness.ForEach(x =>
  1536. {
  1537. #region
  1538. if (x.student.count.value>0)
  1539. {
  1540. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.student.count.value);
  1541. if (index_tmd_count!=-1)
  1542. {
  1543. x.student.count.rank = index_tmd_count + 1;
  1544. }
  1545. }
  1546. if (x.ies5Stu.count.value>0)
  1547. {
  1548. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  1549. if (index_ies5Stu_count!=-1)
  1550. {
  1551. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  1552. }
  1553. }
  1554. if (x.otherStu.count.value>0)
  1555. {
  1556. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  1557. if (index_otherStu_count!=-1)
  1558. {
  1559. x.otherStu.count.rank = index_otherStu_count + 1;
  1560. }
  1561. }
  1562. #endregion
  1563. #region
  1564. if (x.student.duration.value> 0)
  1565. {
  1566. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.student.duration.value);
  1567. if (index_tmd_duration!=-1)
  1568. {
  1569. x.student.duration.rank = index_tmd_duration + 1;
  1570. }
  1571. }
  1572. if (x.ies5Stu.duration.value>0)
  1573. {
  1574. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  1575. if (index_ies5Stu_duration!=-1)
  1576. {
  1577. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  1578. }
  1579. }
  1580. if (x.otherStu.duration.value>0)
  1581. {
  1582. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  1583. if (index_otherStu_duration!=-1)
  1584. {
  1585. x.otherStu.duration.rank = index_otherStu_duration + 1;
  1586. }
  1587. }
  1588. #endregion
  1589. #region
  1590. if (x.student.stick.value>0)
  1591. {
  1592. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.student.stick.value);
  1593. if (index_tmd_stick!=-1)
  1594. {
  1595. x.student.stick.rank = index_tmd_stick + 1;
  1596. }
  1597. }
  1598. if (x.ies5Stu.stick.value>0)
  1599. {
  1600. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  1601. if (index_ies5Stu_stick!=-1)
  1602. {
  1603. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  1604. }
  1605. }
  1606. if (x.otherStu.stick.value>0)
  1607. {
  1608. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  1609. if (index_otherStu_stick!=-1)
  1610. {
  1611. x.otherStu.stick.rank = index_otherStu_stick + 1;
  1612. }
  1613. }
  1614. #endregion
  1615. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  1616. if (bygone!=null)
  1617. {
  1618. #region tmd
  1619. //人数上升下降
  1620. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  1621. //访问数量上升下降
  1622. x.student.count.range= x.student.count.value-bygone.student.count.value;
  1623. //访问数量排名上升下降
  1624. x.student.count.updown= -(x.student.count.rank-bygone.student.count.rank);
  1625. //停留时长上升下降
  1626. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  1627. //停留时长排名上升下降
  1628. x.student.duration.updown=-(x.student.duration.rank-bygone.student.duration.rank);
  1629. //访问指数上升下降
  1630. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  1631. //访问指数排名上升下降
  1632. x.student.stick.updown=-(x.student.stick.rank-bygone.student.stick.rank);
  1633. #endregion
  1634. #region otherStu
  1635. //人数上升下降
  1636. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  1637. //访问数量上升下降
  1638. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  1639. //访问数量排名上升下降
  1640. x.otherStu.count.updown= -(x.otherStu.count.rank-bygone.otherStu.count.rank);
  1641. //停留时长上升下降
  1642. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  1643. //停留时长排名上升下降
  1644. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  1645. //访问指数上升下降
  1646. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  1647. //访问指数排名上升下降
  1648. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  1649. #endregion
  1650. #region ies5Stu
  1651. //人数上升下降
  1652. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  1653. //访问数量上升下降
  1654. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  1655. //访问数量排名上升下降
  1656. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  1657. //停留时长上升下降
  1658. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  1659. //停留时长排名上升下降
  1660. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  1661. //访问指数上升下降
  1662. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  1663. //访问指数排名上升下降
  1664. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  1665. #endregion
  1666. }
  1667. else
  1668. {
  1669. #region tmd
  1670. //人数上升下降
  1671. x.student.userUpdown= x.student.userCount;
  1672. //访问数量上升下降
  1673. x.student.count.range= x.student.count.value;
  1674. //访问数量排名上升下降
  1675. x.student.count.updown= x.student.count.rank;
  1676. //停留时长上升下降
  1677. x.student.duration.range=x.student.duration.value;
  1678. //停留时长排名上升下降
  1679. x.student.duration.updown=x.student.duration.rank;
  1680. //访问指数上升下降
  1681. x.student.stick.range=x.student.stick.value;
  1682. //访问指数排名上升下降
  1683. x.student.stick.updown=x.student.stick.rank;
  1684. #endregion
  1685. #region otherStu
  1686. //人数上升下降
  1687. x.otherStu.userUpdown= x.otherStu.userCount;
  1688. //访问数量上升下降
  1689. x.otherStu.count.range= x.otherStu.count.value;
  1690. //访问数量排名上升下降
  1691. x.otherStu.count.updown= x.otherStu.count.rank;
  1692. //停留时长上升下降
  1693. x.otherStu.duration.range=x.otherStu.duration.value;
  1694. //停留时长排名上升下降
  1695. x.otherStu.duration.updown=x.otherStu.duration.rank;
  1696. //访问指数上升下降
  1697. x.otherStu.stick.range=x.otherStu.stick.value;
  1698. //访问指数排名上升下降
  1699. x.otherStu.stick.updown=x.otherStu.stick.rank;
  1700. #endregion
  1701. #region ies5Stu
  1702. //人数上升下降
  1703. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  1704. //访问数量上升下降
  1705. x.ies5Stu.count.range= x.ies5Stu.count.value;
  1706. //访问数量排名上升下降
  1707. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  1708. //停留时长上升下降
  1709. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  1710. //停留时长排名上升下降
  1711. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  1712. //访问指数上升下降
  1713. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  1714. //访问指数排名上升下降
  1715. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  1716. #endregion
  1717. }
  1718. });
  1719. //当前时间没有的
  1720. var disappears = bygoneStickiness?.Where(x => x.student.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  1721. if (disappears!=null && disappears.Count()>0)
  1722. {
  1723. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  1724. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  1725. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  1726. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  1727. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  1728. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  1729. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  1730. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  1731. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  1732. foreach (var disappear in disappears)
  1733. {
  1734. //下降
  1735. // y 5 t0
  1736. disappear.student.stick.updown= -disappear.student.stick.rank;
  1737. disappear.student.stick.range= -disappear.student.stick.value;
  1738. disappear.student.stick.value=0;
  1739. disappear.student.stick.rank=rank_tmd_stick_Max+1;
  1740. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  1741. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  1742. disappear.ies5Stu.stick.value=0;
  1743. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  1744. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  1745. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  1746. disappear.otherStu.stick.value=0;
  1747. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  1748. disappear.student.count.updown= -disappear.student.count.rank;
  1749. disappear.student.count.range= -disappear.student.count.value;
  1750. disappear.student.count.value=0;
  1751. disappear.student.count.rank=rank_tmd_count_Max+1;
  1752. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  1753. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  1754. disappear.ies5Stu.count.value=0;
  1755. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  1756. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  1757. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  1758. disappear.otherStu.count.value=0;
  1759. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  1760. disappear.student.duration.updown= -disappear.student.duration.rank;
  1761. disappear.student.duration.range= -disappear.student.duration.value;
  1762. disappear.student.duration.value=0;
  1763. disappear.student.duration.rank=rank_tmd_duration_Max+1;
  1764. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  1765. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  1766. disappear.ies5Stu.duration.value=0;
  1767. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  1768. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  1769. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  1770. disappear.otherStu.duration.value=0;
  1771. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  1772. currentStickiness.Add(disappear);
  1773. }
  1774. }
  1775. currentStickiness= currentStickiness.OrderByDescending(x => x.student.stick.value).ToList();
  1776. return currentStickiness;
  1777. }
  1778. private static List<TchStick> OrderByTchStick(List<TchStick> currentStickiness, List<TchStick>? bygoneStickiness)
  1779. {
  1780. // 假设visit已经填充了数据
  1781. #region
  1782. var rank_tmd_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  1783. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  1784. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  1785. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  1786. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  1787. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  1788. #endregion
  1789. #region
  1790. var rank_tmd_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1791. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1792. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1793. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1794. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1795. #endregion
  1796. #region
  1797. var rank_tmd_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1798. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1799. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1800. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1801. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1802. #endregion
  1803. currentStickiness.ForEach(x =>
  1804. {
  1805. #region
  1806. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.teacher.count.value);
  1807. if (index_tmd_count!=-1)
  1808. {
  1809. x.teacher.count.rank = index_tmd_count + 1;
  1810. }
  1811. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  1812. if (index_hita_count!=-1)
  1813. {
  1814. x.hita.count.rank = index_hita_count + 1;
  1815. }
  1816. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  1817. if (index_hiteach_count!=-1)
  1818. {
  1819. x.hiteach.count.rank = index_hiteach_count + 1;
  1820. }
  1821. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  1822. if (index_ies5Tch_count!=-1)
  1823. {
  1824. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  1825. }
  1826. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  1827. if (index_otherTch_count!=-1)
  1828. {
  1829. x.otherTch.count.rank = index_otherTch_count + 1;
  1830. }
  1831. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  1832. if (index_lesson_count!=-1)
  1833. {
  1834. x.lesson.rank = index_lesson_count + 1;
  1835. }
  1836. #endregion
  1837. #region
  1838. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.teacher.duration.value);
  1839. if (index_tmd_duration!=-1)
  1840. {
  1841. x.teacher.duration.rank = index_tmd_duration + 1;
  1842. }
  1843. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  1844. if (index_hita_duration!=-1)
  1845. {
  1846. x.hita.duration.rank = index_hita_duration + 1;
  1847. }
  1848. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  1849. if (index_hiteach_duration!=-1)
  1850. {
  1851. x.hiteach.duration.rank = index_hiteach_duration + 1;
  1852. }
  1853. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  1854. if (index_ies5Tch_duration!=-1)
  1855. {
  1856. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  1857. }
  1858. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  1859. if (index_otherTch_duration!=-1)
  1860. {
  1861. x.otherTch.duration.rank = index_otherTch_duration + 1;
  1862. }
  1863. #endregion
  1864. #region
  1865. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.teacher.stick.value);
  1866. if (index_tmd_stick!=-1)
  1867. {
  1868. x.teacher.stick.rank = index_tmd_stick + 1;
  1869. }
  1870. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  1871. if (index_hita_stick!=-1)
  1872. {
  1873. x.hita.stick.rank = index_hita_stick + 1;
  1874. }
  1875. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  1876. if (index_hiteach_stick!=-1)
  1877. {
  1878. x.hiteach.stick.rank = index_hiteach_stick + 1;
  1879. }
  1880. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  1881. if (index_ies5Tch_stick!=-1)
  1882. {
  1883. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  1884. }
  1885. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  1886. if (index_otherTch_stick!=-1)
  1887. {
  1888. x.otherTch.stick.rank = index_otherTch_stick + 1;
  1889. }
  1890. #endregion
  1891. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  1892. if (bygone!=null)
  1893. {
  1894. #region
  1895. x.lesson.range=x.lesson.value-bygone.lesson.value;
  1896. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  1897. #endregion
  1898. #region tmd
  1899. //人数上升下降
  1900. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  1901. //访问数量上升下降
  1902. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  1903. //访问数量排名上升下降
  1904. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  1905. //停留时长上升下降
  1906. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  1907. //停留时长排名上升下降
  1908. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  1909. //访问指数上升下降
  1910. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  1911. //访问指数排名上升下降
  1912. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  1913. #endregion
  1914. #region hita
  1915. //人数上升下降
  1916. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  1917. //访问数量上升下降
  1918. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  1919. //访问数量排名上升下降
  1920. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  1921. //停留时长上升下降
  1922. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  1923. //停留时长排名上升下降
  1924. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  1925. //访问指数上升下降
  1926. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  1927. //访问指数排名上升下降
  1928. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  1929. #endregion
  1930. #region hiteach
  1931. //人数上升下降
  1932. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  1933. //访问数量上升下降
  1934. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  1935. //访问数量排名上升下降
  1936. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  1937. //停留时长上升下降
  1938. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  1939. //停留时长排名上升下降
  1940. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  1941. //访问指数上升下降
  1942. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  1943. //访问指数排名上升下降
  1944. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  1945. #endregion
  1946. #region otherTch
  1947. //人数上升下降
  1948. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  1949. //访问数量上升下降
  1950. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  1951. //访问数量排名上升下降
  1952. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  1953. //停留时长上升下降
  1954. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  1955. //停留时长排名上升下降
  1956. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  1957. //访问指数上升下降
  1958. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  1959. //访问指数排名上升下降
  1960. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  1961. #endregion
  1962. #region ies5Tch
  1963. //人数上升下降
  1964. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  1965. //访问数量上升下降
  1966. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  1967. //访问数量排名上升下降
  1968. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  1969. //停留时长上升下降
  1970. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  1971. //停留时长排名上升下降
  1972. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  1973. //访问指数上升下降
  1974. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  1975. //访问指数排名上升下降
  1976. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  1977. #endregion
  1978. }
  1979. else
  1980. {
  1981. #region
  1982. x.lesson.range=x.lesson.value;
  1983. x.lesson.updown=x.lesson.rank;
  1984. #endregion
  1985. #region tmd
  1986. //人数上升下降
  1987. x.teacher.userUpdown= x.teacher.userCount;
  1988. //访问数量上升下降
  1989. x.teacher.count.range= x.teacher.count.value;
  1990. //访问数量排名上升下降
  1991. x.teacher.count.updown= x.teacher.count.rank;
  1992. //停留时长上升下降
  1993. x.teacher.duration.range=x.teacher.duration.value;
  1994. //停留时长排名上升下降
  1995. x.teacher.duration.updown=x.teacher.duration.rank;
  1996. //访问指数上升下降
  1997. x.teacher.stick.range=x.teacher.stick.value;
  1998. //访问指数排名上升下降
  1999. x.teacher.stick.updown=x.teacher.stick.rank;
  2000. #endregion
  2001. #region hita
  2002. //人数上升下降
  2003. x.hita.userUpdown= x.hita.userCount;
  2004. //访问数量上升下降
  2005. x.hita.count.range= x.hita.count.value;
  2006. //访问数量排名上升下降
  2007. x.hita.count.updown= x.hita.count.rank;
  2008. //停留时长上升下降
  2009. x.hita.duration.range=x.hita.duration.value;
  2010. //停留时长排名上升下降
  2011. x.hita.duration.updown=x.hita.duration.rank;
  2012. //访问指数上升下降
  2013. x.hita.stick.range=x.hita.stick.value;
  2014. //访问指数排名上升下降
  2015. x.hita.stick.updown=x.hita.stick.rank;
  2016. #endregion
  2017. #region hiteach
  2018. //人数上升下降
  2019. x.hiteach.userUpdown= x.hiteach.userCount;
  2020. //访问数量上升下降
  2021. x.hiteach.count.range= x.hiteach.count.value;
  2022. //访问数量排名上升下降
  2023. x.hiteach.count.updown= x.hiteach.count.rank;
  2024. //停留时长上升下降
  2025. x.hiteach.duration.range=x.hiteach.duration.value;
  2026. //停留时长排名上升下降
  2027. x.hiteach.duration.updown=x.hiteach.duration.rank;
  2028. //访问指数上升下降
  2029. x.hiteach.stick.range=x.hiteach.stick.value;
  2030. //访问指数排名上升下降
  2031. x.hiteach.stick.updown=x.hiteach.stick.rank;
  2032. #endregion
  2033. #region otherTch
  2034. //人数上升下降
  2035. x.otherTch.userUpdown= x.otherTch.userCount;
  2036. //访问数量上升下降
  2037. x.otherTch.count.range= x.otherTch.count.value;
  2038. //访问数量排名上升下降
  2039. x.otherTch.count.updown= x.otherTch.count.rank;
  2040. //停留时长上升下降
  2041. x.otherTch.duration.range=x.otherTch.duration.value;
  2042. //停留时长排名上升下降
  2043. x.otherTch.duration.updown=x.otherTch.duration.rank;
  2044. //访问指数上升下降
  2045. x.otherTch.stick.range=x.otherTch.stick.value;
  2046. //访问指数排名上升下降
  2047. x.otherTch.stick.updown=x.otherTch.stick.rank;
  2048. #endregion
  2049. #region ies5Tch
  2050. //人数上升下降
  2051. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  2052. //访问数量上升下降
  2053. x.ies5Tch.count.range= x.ies5Tch.count.value;
  2054. //访问数量排名上升下降
  2055. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  2056. //停留时长上升下降
  2057. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  2058. //停留时长排名上升下降
  2059. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  2060. //访问指数上升下降
  2061. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  2062. //访问指数排名上升下降
  2063. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  2064. #endregion
  2065. }
  2066. });
  2067. //当前时间没有的
  2068. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  2069. if (disappears!=null && disappears.Count()>0)
  2070. {
  2071. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  2072. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  2073. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  2074. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  2075. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  2076. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  2077. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  2078. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  2079. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  2080. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  2081. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  2082. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  2083. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  2084. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  2085. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  2086. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  2087. foreach (var disappear in disappears)
  2088. {
  2089. disappear.lesson.updown=-disappear.lesson.rank;
  2090. disappear.lesson.range=-disappear.lesson.value;
  2091. disappear.lesson.value=0;
  2092. disappear.lesson.rank=rank_lesson_Max+1;
  2093. //下降
  2094. // y 5 t0
  2095. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  2096. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  2097. disappear.teacher.stick.value=0;
  2098. disappear.teacher.stick.rank=rank_tmd_stick_Max+1;
  2099. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  2100. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  2101. disappear.hiteach.stick.value=0;
  2102. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  2103. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  2104. disappear.hita.stick.range= -disappear.hita.stick.value;
  2105. disappear.hita.stick.value=0;
  2106. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  2107. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  2108. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  2109. disappear.ies5Tch.stick.value=0;
  2110. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  2111. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  2112. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  2113. disappear.otherTch.stick.value=0;
  2114. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  2115. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  2116. disappear.teacher.count.range= -disappear.teacher.count.value;
  2117. disappear.teacher.count.value=0;
  2118. disappear.teacher.count.rank=rank_tmd_count_Max+1;
  2119. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  2120. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  2121. disappear.hiteach.count.value=0;
  2122. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  2123. disappear.hita.count.updown= -disappear.hita.count.rank;
  2124. disappear.hita.count.range= -disappear.hita.count.value;
  2125. disappear.hita.count.value=0;
  2126. disappear.hita.count.rank=rank_hita_count_Max+1;
  2127. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  2128. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  2129. disappear.ies5Tch.count.value=0;
  2130. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  2131. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  2132. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  2133. disappear.otherTch.count.value=0;
  2134. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  2135. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  2136. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  2137. disappear.teacher.duration.value=0;
  2138. disappear.teacher.duration.rank=rank_tmd_duration_Max+1;
  2139. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  2140. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  2141. disappear.hiteach.duration.value=0;
  2142. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  2143. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  2144. disappear.hita.duration.range= -disappear.hita.duration.value;
  2145. disappear.hita.duration.value=0;
  2146. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  2147. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  2148. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  2149. disappear.ies5Tch.duration.value=0;
  2150. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  2151. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  2152. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  2153. disappear.otherTch.duration.value=0;
  2154. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  2155. currentStickiness.Add(disappear);
  2156. }
  2157. }
  2158. currentStickiness= currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  2159. return currentStickiness;
  2160. }
  2161. /// <summary>
  2162. ///
  2163. /// </summary>
  2164. /// <param name="currentStickiness">现在的</param>
  2165. /// <param name="bygoneStickiness">过去的</param>
  2166. /// <returns></returns>
  2167. private static List<SchoolStick> OrderBySchoolStick(List<SchoolStick> currentStickiness, List<SchoolStick>? bygoneStickiness)
  2168. {
  2169. // 假设visit已经填充了数据
  2170. #region
  2171. var rank_teacher_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  2172. var rank_student_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  2173. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  2174. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  2175. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2176. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2177. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  2178. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  2179. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  2180. #endregion
  2181. #region
  2182. var rank_teacher_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2183. var rank_student_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2184. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2185. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2186. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2187. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2188. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2189. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2190. #endregion
  2191. #region
  2192. var rank_teacher_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2193. var rank_student_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2194. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2195. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2196. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2197. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2198. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2199. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2200. #endregion
  2201. currentStickiness.ForEach(x =>
  2202. {
  2203. #region
  2204. if (x.teacher.count.value>0)
  2205. {
  2206. int index_teacher_count = rank_teacher_count.FindIndex(i => i==x.teacher.count.value);
  2207. if (index_teacher_count!=-1)
  2208. {
  2209. x.teacher.count.rank = index_teacher_count + 1;
  2210. }
  2211. }
  2212. if (x.student.count.value>0)
  2213. {
  2214. int index_student_count = rank_student_count.FindIndex(i => i==x.student.count.value);
  2215. if (index_student_count!=-1)
  2216. {
  2217. x.student.count.rank = index_student_count + 1;
  2218. }
  2219. }
  2220. if (x.hita.count.value>0)
  2221. {
  2222. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  2223. if (index_hita_count!=-1)
  2224. {
  2225. x.hita.count.rank = index_hita_count + 1;
  2226. }
  2227. }
  2228. if (x.hiteach.count.value>0)
  2229. {
  2230. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  2231. if (index_hiteach_count!=-1)
  2232. {
  2233. x.hiteach.count.rank = index_hiteach_count + 1;
  2234. }
  2235. }
  2236. if (x.ies5Tch.count.value>0)
  2237. {
  2238. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  2239. if (index_ies5Tch_count!=-1)
  2240. {
  2241. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  2242. }
  2243. }
  2244. if (x.otherTch.count.value>0)
  2245. {
  2246. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  2247. if (index_otherTch_count!=-1)
  2248. {
  2249. x.otherTch.count.rank = index_otherTch_count + 1;
  2250. }
  2251. }
  2252. if (x.ies5Stu.count.value>0)
  2253. {
  2254. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  2255. if (index_ies5Stu_count!=-1)
  2256. {
  2257. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  2258. }
  2259. }
  2260. if (x.otherStu.count.value>0)
  2261. {
  2262. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  2263. if (index_otherStu_count!=-1)
  2264. {
  2265. x.otherStu.count.rank = index_otherStu_count + 1;
  2266. }
  2267. }
  2268. if (x.lesson.value>0)
  2269. {
  2270. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  2271. if (index_lesson_count!=-1)
  2272. {
  2273. x.lesson.rank = index_lesson_count + 1;
  2274. }
  2275. }
  2276. #endregion
  2277. #region
  2278. if (x.teacher.duration.value>0)
  2279. {
  2280. int index_teacher_duration = rank_teacher_duration.FindIndex(i => i==x.teacher.duration.value);
  2281. if (index_teacher_duration!=-1)
  2282. {
  2283. x.teacher.duration.rank = index_teacher_duration + 1;
  2284. }
  2285. }
  2286. if (x.student.duration.value>0)
  2287. {
  2288. int index_student_duration = rank_student_duration.FindIndex(i => i==x.student.duration.value);
  2289. if (index_student_duration!=-1)
  2290. {
  2291. x.student.duration.rank = index_student_duration + 1;
  2292. }
  2293. }
  2294. if (x.hita.duration.value>0)
  2295. {
  2296. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  2297. if (index_hita_duration!=-1)
  2298. {
  2299. x.hita.duration.rank = index_hita_duration + 1;
  2300. }
  2301. }
  2302. if (x.hiteach.duration.value>0)
  2303. {
  2304. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  2305. if (index_hiteach_duration!=-1)
  2306. {
  2307. x.hiteach.duration.rank = index_hiteach_duration + 1;
  2308. }
  2309. }
  2310. if (x.ies5Tch.duration.value>0)
  2311. {
  2312. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  2313. if (index_ies5Tch_duration!=-1)
  2314. {
  2315. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  2316. }
  2317. }
  2318. if (x.otherTch.duration.value>0)
  2319. {
  2320. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  2321. if (index_otherTch_duration!=-1)
  2322. {
  2323. x.otherTch.duration.rank = index_otherTch_duration + 1;
  2324. }
  2325. }
  2326. if (x.ies5Stu.duration.value>0)
  2327. {
  2328. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  2329. if (index_ies5Stu_duration!=-1)
  2330. {
  2331. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  2332. }
  2333. }
  2334. if (x.otherStu.duration.value>0)
  2335. {
  2336. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  2337. if (index_otherStu_duration!=-1)
  2338. {
  2339. x.otherStu.duration.rank = index_otherStu_duration + 1;
  2340. }
  2341. }
  2342. #endregion
  2343. #region
  2344. if (x.teacher.stick.value>0)
  2345. {
  2346. int index_teacher_stick = rank_teacher_stick.FindIndex(i => i==x.teacher.stick.value);
  2347. if (index_teacher_stick!=-1)
  2348. {
  2349. x.teacher.stick.rank = index_teacher_stick + 1;
  2350. }
  2351. }
  2352. if (x.student.stick.value>0)
  2353. {
  2354. int index_student_stick = rank_student_stick.FindIndex(i => i==x.student.stick.value);
  2355. if (index_student_stick!=-1)
  2356. {
  2357. x.student.stick.rank = index_student_stick + 1;
  2358. }
  2359. }
  2360. if (x.hita.stick.value>0)
  2361. {
  2362. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  2363. if (index_hita_stick!=-1)
  2364. {
  2365. x.hita.stick.rank = index_hita_stick + 1;
  2366. }
  2367. }
  2368. if (x.hiteach.stick.value>0)
  2369. {
  2370. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  2371. if (index_hiteach_stick!=-1)
  2372. {
  2373. x.hiteach.stick.rank = index_hiteach_stick + 1;
  2374. }
  2375. }
  2376. if (x.ies5Tch.stick.value>0)
  2377. {
  2378. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  2379. if (index_ies5Tch_stick!=-1)
  2380. {
  2381. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  2382. }
  2383. }
  2384. if (x.otherTch.stick.value>0)
  2385. {
  2386. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  2387. if (index_otherTch_stick!=-1)
  2388. {
  2389. x.otherTch.stick.rank = index_otherTch_stick + 1;
  2390. }
  2391. }
  2392. if (x.ies5Stu.stick.value>0)
  2393. {
  2394. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  2395. if (index_ies5Stu_stick!=-1)
  2396. {
  2397. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  2398. }
  2399. }
  2400. if (x.otherStu.stick.value>0)
  2401. {
  2402. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  2403. if (index_otherStu_stick!=-1)
  2404. {
  2405. x.otherStu.stick.rank = index_otherStu_stick + 1;
  2406. }
  2407. }
  2408. #endregion
  2409. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  2410. if (bygone!=null)
  2411. {
  2412. #region
  2413. x.lesson.range=x.lesson.value-bygone.lesson.value;
  2414. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  2415. #endregion
  2416. #region student
  2417. //人数上升下降
  2418. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  2419. //访问数量上升下降
  2420. x.student.count.range= x.student.count.value-bygone.student.count.value;
  2421. //访问数量排名上升下降
  2422. x.student.count.updown= -(x.student.count.rank - bygone.student.count.rank);
  2423. //停留时长上升下降
  2424. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  2425. //停留时长排名上升下降
  2426. x.student.duration.updown=-(x.student.duration.rank - bygone.student.duration.rank);
  2427. //访问指数上升下降
  2428. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  2429. //访问指数排名上升下降
  2430. x.student.stick.updown=-(x.student.stick.rank - bygone.student.stick.rank);
  2431. #endregion
  2432. #region teacher
  2433. //人数上升下降
  2434. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  2435. //访问数量上升下降
  2436. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  2437. //访问数量排名上升下降
  2438. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  2439. //停留时长上升下降
  2440. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  2441. //停留时长排名上升下降
  2442. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  2443. //访问指数上升下降
  2444. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  2445. //访问指数排名上升下降
  2446. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  2447. #endregion
  2448. #region hita
  2449. //人数上升下降
  2450. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  2451. //访问数量上升下降
  2452. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  2453. //访问数量排名上升下降
  2454. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  2455. //停留时长上升下降
  2456. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  2457. //停留时长排名上升下降
  2458. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  2459. //访问指数上升下降
  2460. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  2461. //访问指数排名上升下降
  2462. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  2463. #endregion
  2464. #region hiteach
  2465. //人数上升下降
  2466. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  2467. //访问数量上升下降
  2468. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  2469. //访问数量排名上升下降
  2470. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  2471. //停留时长上升下降
  2472. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  2473. //停留时长排名上升下降
  2474. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  2475. //访问指数上升下降
  2476. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  2477. //访问指数排名上升下降
  2478. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  2479. #endregion
  2480. #region otherTch
  2481. //人数上升下降
  2482. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  2483. //访问数量上升下降
  2484. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  2485. //访问数量排名上升下降
  2486. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  2487. //停留时长上升下降
  2488. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  2489. //停留时长排名上升下降
  2490. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  2491. //访问指数上升下降
  2492. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  2493. //访问指数排名上升下降
  2494. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  2495. #endregion
  2496. #region otherStu
  2497. //人数上升下降
  2498. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  2499. //访问数量上升下降
  2500. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  2501. //访问数量排名上升下降
  2502. x.otherStu.count.updown= -(x.otherStu.count.rank - bygone.otherStu.count.rank);
  2503. //停留时长上升下降
  2504. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  2505. //停留时长排名上升下降
  2506. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  2507. //访问指数上升下降
  2508. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  2509. //访问指数排名上升下降
  2510. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  2511. #endregion
  2512. #region ies5Stu
  2513. //人数上升下降
  2514. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  2515. //访问数量上升下降
  2516. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  2517. //访问数量排名上升下降
  2518. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  2519. //停留时长上升下降
  2520. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  2521. //停留时长排名上升下降
  2522. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  2523. //访问指数上升下降
  2524. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  2525. //访问指数排名上升下降
  2526. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  2527. #endregion
  2528. #region ies5Tch
  2529. //人数上升下降
  2530. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  2531. //访问数量上升下降
  2532. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  2533. //访问数量排名上升下降
  2534. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  2535. //停留时长上升下降
  2536. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  2537. //停留时长排名上升下降
  2538. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  2539. //访问指数上升下降
  2540. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  2541. //访问指数排名上升下降
  2542. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  2543. #endregion
  2544. }
  2545. else
  2546. {
  2547. #region
  2548. x.lesson.range=x.lesson.value;
  2549. x.lesson.updown=x.lesson.rank;
  2550. #endregion
  2551. #region teacher
  2552. //人数上升下降
  2553. x.teacher.userUpdown= x.teacher.userCount;
  2554. //访问数量上升下降
  2555. x.teacher.count.range= x.teacher.count.value;
  2556. //访问数量排名上升下降
  2557. x.teacher.count.updown= x.teacher.count.rank;
  2558. //停留时长上升下降
  2559. x.teacher.duration.range=x.teacher.duration.value;
  2560. //停留时长排名上升下降
  2561. x.teacher.duration.updown=x.teacher.duration.rank;
  2562. //访问指数上升下降
  2563. x.teacher.stick.range=x.teacher.stick.value;
  2564. //访问指数排名上升下降
  2565. x.teacher.stick.updown=x.teacher.stick.rank;
  2566. #endregion
  2567. #region student
  2568. //人数上升下降
  2569. x.student.userUpdown= x.student.userCount;
  2570. //访问数量上升下降
  2571. x.student.count.range= x.student.count.value;
  2572. //访问数量排名上升下降
  2573. x.student.count.updown= x.student.count.rank;
  2574. //停留时长上升下降
  2575. x.student.duration.range=x.student.duration.value;
  2576. //停留时长排名上升下降
  2577. x.student.duration.updown=x.student.duration.rank;
  2578. //访问指数上升下降
  2579. x.student.stick.range=x.student.stick.value;
  2580. //访问指数排名上升下降
  2581. x.student.stick.updown=x.student.stick.rank;
  2582. #endregion
  2583. #region hita
  2584. //人数上升下降
  2585. x.hita.userUpdown= x.hita.userCount;
  2586. //访问数量上升下降
  2587. x.hita.count.range= x.hita.count.value;
  2588. //访问数量排名上升下降
  2589. x.hita.count.updown= x.hita.count.rank;
  2590. //停留时长上升下降
  2591. x.hita.duration.range=x.hita.duration.value;
  2592. //停留时长排名上升下降
  2593. x.hita.duration.updown=x.hita.duration.rank;
  2594. //访问指数上升下降
  2595. x.hita.stick.range=x.hita.stick.value;
  2596. //访问指数排名上升下降
  2597. x.hita.stick.updown=x.hita.stick.rank;
  2598. #endregion
  2599. #region hiteach
  2600. //人数上升下降
  2601. x.hiteach.userUpdown= x.hiteach.userCount;
  2602. //访问数量上升下降
  2603. x.hiteach.count.range= x.hiteach.count.value;
  2604. //访问数量排名上升下降
  2605. x.hiteach.count.updown= x.hiteach.count.rank;
  2606. //停留时长上升下降
  2607. x.hiteach.duration.range=x.hiteach.duration.value;
  2608. //停留时长排名上升下降
  2609. x.hiteach.duration.updown=x.hiteach.duration.rank;
  2610. //访问指数上升下降
  2611. x.hiteach.stick.range=x.hiteach.stick.value;
  2612. //访问指数排名上升下降
  2613. x.hiteach.stick.updown=x.hiteach.stick.rank;
  2614. #endregion
  2615. #region otherTch
  2616. //人数上升下降
  2617. x.otherTch.userUpdown= x.otherTch.userCount;
  2618. //访问数量上升下降
  2619. x.otherTch.count.range= x.otherTch.count.value;
  2620. //访问数量排名上升下降
  2621. x.otherTch.count.updown= x.otherTch.count.rank;
  2622. //停留时长上升下降
  2623. x.otherTch.duration.range=x.otherTch.duration.value;
  2624. //停留时长排名上升下降
  2625. x.otherTch.duration.updown=x.otherTch.duration.rank;
  2626. //访问指数上升下降
  2627. x.otherTch.stick.range=x.otherTch.stick.value;
  2628. //访问指数排名上升下降
  2629. x.otherTch.stick.updown=x.otherTch.stick.rank;
  2630. #endregion
  2631. #region otherStu
  2632. //人数上升下降
  2633. x.otherStu.userUpdown= x.otherStu.userCount;
  2634. //访问数量上升下降
  2635. x.otherStu.count.range= x.otherStu.count.value;
  2636. //访问数量排名上升下降
  2637. x.otherStu.count.updown= x.otherStu.count.rank;
  2638. //停留时长上升下降
  2639. x.otherStu.duration.range=x.otherStu.duration.value;
  2640. //停留时长排名上升下降
  2641. x.otherStu.duration.updown=x.otherStu.duration.rank;
  2642. //访问指数上升下降
  2643. x.otherStu.stick.range=x.otherStu.stick.value;
  2644. //访问指数排名上升下降
  2645. x.otherStu.stick.updown=x.otherStu.stick.rank;
  2646. #endregion
  2647. #region ies5Stu
  2648. //人数上升下降
  2649. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  2650. //访问数量上升下降
  2651. x.ies5Stu.count.range= x.ies5Stu.count.value;
  2652. //访问数量排名上升下降
  2653. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  2654. //停留时长上升下降
  2655. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  2656. //停留时长排名上升下降
  2657. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  2658. //访问指数上升下降
  2659. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  2660. //访问指数排名上升下降
  2661. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  2662. #endregion
  2663. #region ies5Tch
  2664. //人数上升下降
  2665. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  2666. //访问数量上升下降
  2667. x.ies5Tch.count.range= x.ies5Tch.count.value;
  2668. //访问数量排名上升下降
  2669. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  2670. //停留时长上升下降
  2671. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  2672. //停留时长排名上升下降
  2673. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  2674. //访问指数上升下降
  2675. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  2676. //访问指数排名上升下降
  2677. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  2678. #endregion
  2679. }
  2680. });
  2681. //当前时间没有的
  2682. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  2683. if (disappears!=null && disappears.Count()>0)
  2684. {
  2685. double rank_student_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  2686. double rank_student_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  2687. double rank_student_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  2688. double rank_teacher_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  2689. double rank_teacher_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  2690. double rank_teacher_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  2691. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  2692. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  2693. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  2694. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  2695. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  2696. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  2697. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  2698. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  2699. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  2700. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  2701. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  2702. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  2703. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  2704. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  2705. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  2706. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  2707. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  2708. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  2709. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  2710. foreach (var disappear in disappears)
  2711. {
  2712. disappear.lesson.updown=-disappear.lesson.rank;
  2713. disappear.lesson.range=-disappear.lesson.value;
  2714. disappear.lesson.value=0;
  2715. disappear.lesson.rank=rank_lesson_Max+1;
  2716. //下降
  2717. // y 5 t0
  2718. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  2719. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  2720. disappear.teacher.stick.value=0;
  2721. disappear.teacher.stick.rank=rank_teacher_stick_Max+1;
  2722. disappear.student.stick.updown= -disappear.student.stick.rank;
  2723. disappear.student.stick.range= -disappear.student.stick.value;
  2724. disappear.student.stick.value=0;
  2725. disappear.student.stick.rank=rank_student_stick_Max+1;
  2726. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  2727. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  2728. disappear.hiteach.stick.value=0;
  2729. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  2730. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  2731. disappear.hita.stick.range= -disappear.hita.stick.value;
  2732. disappear.hita.stick.value=0;
  2733. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  2734. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  2735. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  2736. disappear.ies5Stu.stick.value=0;
  2737. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  2738. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  2739. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  2740. disappear.ies5Tch.stick.value=0;
  2741. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  2742. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  2743. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  2744. disappear.otherStu.stick.value=0;
  2745. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  2746. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  2747. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  2748. disappear.otherTch.stick.value=0;
  2749. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  2750. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  2751. disappear.teacher.count.range= -disappear.teacher.count.value;
  2752. disappear.teacher.count.value=0;
  2753. disappear.teacher.count.rank=rank_teacher_count_Max+1;
  2754. disappear.student.count.updown= -disappear.student.count.rank;
  2755. disappear.student.count.range= -disappear.student.count.value;
  2756. disappear.student.count.value=0;
  2757. disappear.student.count.rank=rank_student_count_Max+1;
  2758. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  2759. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  2760. disappear.hiteach.count.value=0;
  2761. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  2762. disappear.hita.count.updown= -disappear.hita.count.rank;
  2763. disappear.hita.count.range= -disappear.hita.count.value;
  2764. disappear.hita.count.value=0;
  2765. disappear.hita.count.rank=rank_hita_count_Max+1;
  2766. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  2767. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  2768. disappear.ies5Stu.count.value=0;
  2769. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  2770. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  2771. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  2772. disappear.ies5Tch.count.value=0;
  2773. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  2774. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  2775. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  2776. disappear.otherStu.count.value=0;
  2777. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  2778. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  2779. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  2780. disappear.otherTch.count.value=0;
  2781. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  2782. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  2783. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  2784. disappear.teacher.duration.value=0;
  2785. disappear.teacher.duration.rank=rank_teacher_duration_Max+1;
  2786. disappear.student.duration.updown= -disappear.student.duration.rank;
  2787. disappear.student.duration.range= -disappear.student.duration.value;
  2788. disappear.student.duration.value=0;
  2789. disappear.student.duration.rank=rank_student_duration_Max+1;
  2790. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  2791. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  2792. disappear.hiteach.duration.value=0;
  2793. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  2794. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  2795. disappear.hita.duration.range= -disappear.hita.duration.value;
  2796. disappear.hita.duration.value=0;
  2797. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  2798. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  2799. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  2800. disappear.ies5Stu.duration.value=0;
  2801. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  2802. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  2803. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  2804. disappear.ies5Tch.duration.value=0;
  2805. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  2806. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  2807. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  2808. disappear.otherStu.duration.value=0;
  2809. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  2810. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  2811. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  2812. disappear.otherTch.duration.value=0;
  2813. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  2814. currentStickiness.Add(disappear);
  2815. }
  2816. }
  2817. currentStickiness = currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  2818. return currentStickiness;
  2819. }
  2820. /// <summary>
  2821. /// 结算访问日志
  2822. /// </summary>
  2823. public static async Task
  2824. VisitSettle(List<string> times, AzureStorageFactory _azureStorage, AzureRedisFactory _azureRedis, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, IPSearcher _ipSearcher, string force)
  2825. {
  2826. foreach (var timeDate in times)
  2827. {
  2828. List<Stick> chinaSticks = new List<Stick>();
  2829. List<Stick> globalSticks = new List<Stick>();
  2830. if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date))
  2831. {
  2832. var blobClientChina = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json");
  2833. var blobClientGlobal = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json");
  2834. bool g = true, c = true;
  2835. if (blobClientChina.Exists() && force.Equals("0"))
  2836. {
  2837. c=false;
  2838. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json").DownloadContentAsync();
  2839. var contentBygone = result.Content.ToString();
  2840. var chinaStick = contentBygone.ToObject<Stick>();
  2841. chinaSticks.Add(chinaStick);
  2842. }
  2843. if (blobClientGlobal.Exists()&& force.Equals("0"))
  2844. {
  2845. g=false;
  2846. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json").DownloadContentAsync();
  2847. var contentBygone = result.Content.ToString();
  2848. var globalStick = contentBygone.ToObject<Stick>();
  2849. globalSticks.Add(globalStick);
  2850. }
  2851. if (g||c)
  2852. {
  2853. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
  2854. var content = result.Content.ToString();
  2855. content= content.Substring(0, content.Length-2);
  2856. if (content.EndsWith("}"))
  2857. {
  2858. content=$"[{content}]";
  2859. }
  2860. else
  2861. {
  2862. content=$"[{content}}}]";
  2863. }
  2864. List<ApiVisit> apiVisits = new List<ApiVisit>();
  2865. apiVisits.AddRange(content.ToObject<List<ApiVisit>>());
  2866. var dateNow = DateTimeOffset.Now.GetGMTTime(8);
  2867. if ($"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  2868. { //当前小时一致的
  2869. BlobDownloadResult resultHour = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}.log").DownloadContentAsync();
  2870. var contentHour = resultHour.Content.ToString();
  2871. contentHour= contentHour.Substring(0, contentHour.Length-2);
  2872. if (contentHour.EndsWith("}"))
  2873. {
  2874. contentHour=$"[{contentHour}]";
  2875. }
  2876. else
  2877. {
  2878. contentHour=$"[{contentHour}}}]";
  2879. }
  2880. var httpLog = contentHour.ToObject<List<HttpLog>>();
  2881. (ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) = await SystemService.ConvertHttpLog(httpLog, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, dateNow, false);
  2882. apiVisits.AddRange(visits);
  2883. }
  2884. if (c)
  2885. {
  2886. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "China");
  2887. //大陆学校
  2888. var chinaApiVisits = apiVisits.Where(x => x.hostName.Equals("大陆站"));
  2889. var chinaSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("大陆站")).GroupBy(x => x.school);
  2890. List<SchoolStick> chinaStickiness = CountSchoolStickiness(chinaSchoolVisits, chinaApiVisits, apiVisitsBygone.schoolSticks);
  2891. Stick stickc = new Stick();
  2892. stickc.schoolSticks=chinaStickiness;
  2893. chinaSticks.Add(stickc);
  2894. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  2895. {
  2896. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickc.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/cday.json", true);
  2897. }
  2898. }
  2899. if (g)
  2900. {
  2901. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "Global");
  2902. //国际学校
  2903. var globalApiVisits = apiVisits.Where(x => x.hostName.Equals("国际站"));
  2904. var globalSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("国际站")).GroupBy(x => x.school);
  2905. List<SchoolStick> globalStickiness = CountSchoolStickiness(globalSchoolVisits, globalApiVisits, apiVisitsBygone.schoolSticks);
  2906. Stick stickg = new Stick();
  2907. stickg.schoolSticks=globalStickiness;
  2908. globalSticks.Add(stickg);
  2909. //如果是当天的 ,则不能保存
  2910. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  2911. {
  2912. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickg.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/gday.json", true);
  2913. }
  2914. }
  2915. }
  2916. else
  2917. {
  2918. continue;
  2919. }
  2920. }
  2921. }
  2922. }
  2923. public static async Task<Stick> GetBygoneSettleData(AzureStorageFactory _azureStorage, DateTimeOffset date, string cg)
  2924. {
  2925. //过去一天的数据
  2926. var bygone = date.AddDays(-1);
  2927. Stick apiVisitsBygone = new Stick();
  2928. try
  2929. {
  2930. cg=cg.Contains("China", StringComparison.OrdinalIgnoreCase) ? "cday.json" : "gday.json";
  2931. BlobDownloadResult chinaResultBygone = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{bygone:yyyy}/{bygone:MM}/{bygone:dd}/{cg}").DownloadContentAsync();
  2932. var contentBygone = chinaResultBygone.Content.ToString();
  2933. apiVisitsBygone= contentBygone.ToObject<Stick>();
  2934. }
  2935. catch
  2936. { //可能出现异常,因为文件不存在。第一次初始化,前一天的数据没有 }
  2937. }
  2938. return apiVisitsBygone;
  2939. }
  2940. public static async Task<(ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)>
  2941. ConvertHttpLog(List<HttpLog> logs, AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, DateTimeOffset gmt8Time, bool test = false)
  2942. {
  2943. ConcurrentBag<ApiVisit> visits = new ConcurrentBag<ApiVisit>();
  2944. ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
  2945. object lockObj = new object();
  2946. await Parallel.ForEachAsync(logs, async (log, _) =>
  2947. {
  2948. if (!log.path.Contains("."))
  2949. {
  2950. string uuid = Guid.NewGuid().ToString();
  2951. List<string> schoolMatch = new List<string>();
  2952. List<string> useridMatch = new List<string>();
  2953. var vist = new ApiVisit()
  2954. {
  2955. id=uuid,
  2956. ip=log.ip,
  2957. tid=log.tid,
  2958. time= log.time,
  2959. userId= log.id,
  2960. picture=log.picture,
  2961. school= log.school,
  2962. tname= log.name,
  2963. path = log.path,
  2964. client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
  2965. scope=log.scope,
  2966. host= log.host,
  2967. hostName=log.hostName,
  2968. l=log.l,
  2969. year = $"{gmt8Time:yyyy}",
  2970. month = $"{gmt8Time:MM}",
  2971. day = $"{gmt8Time:dd}",
  2972. hour =$"{gmt8Time:HH}"
  2973. };
  2974. if (test)
  2975. {
  2976. var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
  2977. //本地调试时间
  2978. if (vist.ip.Equals("0.0.0.1"))
  2979. {
  2980. time= time.AddHours(8);
  2981. }
  2982. vist.year = $"{time:yyyy}";
  2983. vist.month = $"{time:MM}";
  2984. vist.day = $"{time:dd}";
  2985. vist.hour =$"{time:HH}";
  2986. }
  2987. if (string.IsNullOrWhiteSpace(vist.userId))
  2988. {
  2989. //var jsonPathContext = new JsonPathContext();
  2990. //jsonPathContext.ValueSystem= new JsonTextValueSystem();
  2991. string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','creatorId','creator','code','studentId','student','studentid']";
  2992. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  2993. {
  2994. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  2995. //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
  2996. var nodes_path = jsonObject.SelectTokens(path);
  2997. foreach (var node in nodes_path)
  2998. {
  2999. // 只获取是字符串的
  3000. if (node.Type.Equals(JTokenType.String))
  3001. {
  3002. switch (true)
  3003. {
  3004. case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
  3005. {
  3006. try
  3007. {
  3008. var jwt = new JwtSecurityToken($"{node}");
  3009. string id = jwt.Payload.Sub;
  3010. var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
  3011. var picture = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("picture"))?.Value;
  3012. if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
  3013. {
  3014. vist.userId=id;
  3015. vist.scope="teacher";
  3016. vist.tname=name;
  3017. vist.picture=picture;
  3018. useridMatch.Add(id);
  3019. }
  3020. }
  3021. catch (Exception ex) { }
  3022. break;
  3023. }
  3024. case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
  3025. ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
  3026. ||node.Path.Contains("userId"):
  3027. {
  3028. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  3029. {
  3030. vist.userId=$"{node}";
  3031. vist.scope="teacher";
  3032. useridMatch.Add($"{node}");
  3033. }
  3034. break;
  3035. }
  3036. case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
  3037. {
  3038. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  3039. {
  3040. vist.userId=$"{node}";
  3041. vist.scope="student";
  3042. useridMatch.Add($"{node}");
  3043. }
  3044. break;
  3045. }
  3046. case bool when node.Path.Contains("code"):
  3047. {
  3048. if (!string.IsNullOrWhiteSpace($"{node}"))
  3049. {
  3050. if (long.TryParse($"{node}", out long _id))
  3051. {
  3052. vist.userId=$"{node}";
  3053. useridMatch.Add($"{node}");
  3054. }
  3055. else
  3056. {
  3057. string[] codes = $"{node}".Split("-");
  3058. foreach (var _code in codes)
  3059. {
  3060. if (long.TryParse(_code, out long _codeid))
  3061. {
  3062. vist.userId=$"{node}";
  3063. useridMatch.Add($"{_code}");
  3064. break;
  3065. }
  3066. }
  3067. }
  3068. }
  3069. break;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  3075. {
  3076. string s = log.param.ToJsonString().Replace("\\", "");
  3077. Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
  3078. Match matchtmdid = regextmdid.Match(s);
  3079. if (matchtmdid.Success)
  3080. {
  3081. var t = matchtmdid.Groups[1].Value;
  3082. if (!string.IsNullOrWhiteSpace(t))
  3083. {
  3084. vist.userId=t;
  3085. vist.scope="teacher";
  3086. useridMatch.Add(t);
  3087. }
  3088. }
  3089. Regex regexname = new Regex("\"tmdname\":\"(.+?)\"");
  3090. Match matchname = regexname.Match(s);
  3091. if (matchname.Success)
  3092. {
  3093. var t = matchname.Groups[1].Value;
  3094. if (!string.IsNullOrWhiteSpace(t))
  3095. {
  3096. vist.tname=t;
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. else
  3103. {
  3104. if (string.IsNullOrWhiteSpace($"{vist.scope}"))
  3105. {
  3106. vist.scope="teacher";
  3107. uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
  3108. }
  3109. }
  3110. if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false"))
  3111. {
  3112. vist.school="";
  3113. string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
  3114. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  3115. {
  3116. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  3117. var nodes_path = jsonObject.SelectTokens(path);
  3118. foreach (var node in nodes_path)
  3119. {
  3120. // 只获取是字符串的
  3121. if (node.Type.Equals(JTokenType.String))
  3122. {
  3123. switch (true)
  3124. {
  3125. case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
  3126. ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
  3127. {
  3128. if (!$"{node}".Contains("-")&& $"{node}".Length<=8 && $"{node}".Length>=1)
  3129. {
  3130. vist.school=$"{node}";
  3131. schoolMatch.Add($"{node}");
  3132. }
  3133. break;
  3134. }
  3135. case bool when node.Path.Contains("code"):
  3136. {
  3137. if (!$"{node}".Contains("-")&& $"{node}".Length<=8&& $"{node}".Length>=1)
  3138. {
  3139. vist.school=$"{node}";
  3140. schoolMatch.Add($"{node}");
  3141. }
  3142. else
  3143. {
  3144. string[] codes = $"{node}".Split("-");
  3145. foreach (var _code in codes)
  3146. {
  3147. if ($"{_code}".Length<=8 && $"{_code}".Length>=1)
  3148. {
  3149. vist.school=$"{_code}";
  3150. schoolMatch.Add($"{_code}");
  3151. break;
  3152. }
  3153. }
  3154. }
  3155. break;
  3156. }
  3157. }
  3158. }
  3159. }
  3160. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  3161. {
  3162. string s = log.param.ToJsonString().Replace("\\", "");
  3163. Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
  3164. Match matchname = regexname.Match(s);
  3165. if (matchname.Success)
  3166. {
  3167. var t = matchname.Groups[1].Value;
  3168. if (!string.IsNullOrWhiteSpace(t))
  3169. {
  3170. vist.school=t;
  3171. }
  3172. }
  3173. }
  3174. }
  3175. }
  3176. //处理 client
  3177. {
  3178. if (!string.IsNullOrWhiteSpace(log.client))
  3179. {
  3180. if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
  3181. {
  3182. vist.client="ies5";
  3183. }
  3184. if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
  3185. {
  3186. vist.client="aclassone";
  3187. }
  3188. if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
  3189. {
  3190. vist.client="habb";
  3191. }
  3192. if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
  3193. {
  3194. vist.client="hiscan";
  3195. }
  3196. if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
  3197. {
  3198. vist.client="hita";
  3199. vist.scope="teacher";
  3200. }
  3201. if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
  3202. {
  3203. vist.client="hiteachcc";
  3204. }
  3205. if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
  3206. {
  3207. vist.scope="teacher";
  3208. vist.client="hiteach";
  3209. }
  3210. if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
  3211. {
  3212. vist.client="open";
  3213. }
  3214. }
  3215. }
  3216. //补全站点
  3217. {
  3218. if (
  3219. (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
  3220. {
  3221. vist.hostName="国际站";
  3222. vist.host="www.teammodel.net";
  3223. vist.client="ies5";
  3224. vist.l="Global";
  3225. }
  3226. else if (
  3227. log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
  3228. ||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"))
  3229. {
  3230. vist.hostName="大陆站";
  3231. vist.host="www.teammodel.cn";
  3232. vist.client="ies5"; vist.l="China";
  3233. }
  3234. else if ((log.host.Contains("localhost") && log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
  3235. {
  3236. vist.hostName="测试站";
  3237. vist.host="test.teammodel.cn";
  3238. vist.client="ies5";
  3239. vist.l="China";
  3240. }
  3241. else if (
  3242. (log.host.Equals("scyx.teammodel.cn") ||log.host.Equals("jinniu.teammodel.cn")))
  3243. {
  3244. vist.hostName="研修2.0";
  3245. vist.host="scyx.teammodel.cn";
  3246. vist.client="ability"; vist.l="China";
  3247. }
  3248. else if (
  3249. log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn") ||log.host.Equals("zhiyin-test.teammodel.cn"))
  3250. {
  3251. vist.hostName="开放平台";
  3252. vist.host="open.teammodel.cn";
  3253. vist.client="open";
  3254. vist.l="China";
  3255. }
  3256. else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
  3257. {
  3258. vist.hostName="国际站";
  3259. vist.host="bi.teammodel.net";
  3260. vist.client="bi";
  3261. vist.scope="admin";
  3262. vist.l="Global";
  3263. }
  3264. else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
  3265. {
  3266. vist.hostName="大陆站";
  3267. vist.host="bi.teammodel.cn";
  3268. vist.client="bi";
  3269. vist.scope="admin";
  3270. vist.l="China";
  3271. }
  3272. else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost") && (log.p.Equals("bi"))))
  3273. {
  3274. vist.hostName="测试站";
  3275. vist.host="testbi.teammodel.cn";
  3276. vist.client="bi";
  3277. vist.scope="admin";
  3278. vist.l="China";
  3279. }
  3280. else if (
  3281. log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
  3282. {
  3283. vist.hostName="大陆站";
  3284. vist.host="contest.teammodel.cn";
  3285. vist.client="contest"; vist.l="China";
  3286. }
  3287. else if (
  3288. log.host.Equals("hiteachcc.chinacloudsites.cn"))
  3289. {
  3290. vist.hostName="正式站";
  3291. vist.host="hiteachcc.teammodel.cn";
  3292. vist.client="hiteachcc";
  3293. vist.l="China";
  3294. }
  3295. else if (log.host.Equals("appraisal.chinacloudsites.cn"))
  3296. {
  3297. vist.hostName="大陆站";
  3298. vist.host="appraisal.teammodel.cn";
  3299. vist.client="appraisal";
  3300. vist.l="China";
  3301. }
  3302. else if ((log.host.Contains("localhost") && log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn") ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
  3303. {
  3304. vist.hostName="测试站";
  3305. vist.host="appraisal-test.teammodel.cn";
  3306. vist.client="appraisal";
  3307. vist.l="China";
  3308. }
  3309. else
  3310. {
  3311. if (!string.IsNullOrWhiteSpace(log.p))
  3312. {
  3313. vist.client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p;
  3314. }
  3315. else
  3316. {
  3317. vist.client="other";
  3318. }
  3319. if (log.host.EndsWith(".cn"))
  3320. {
  3321. vist.hostName="大陆站";
  3322. vist.l="China";
  3323. }
  3324. else if (log.host.EndsWith(".net"))
  3325. {
  3326. vist.hostName="国际站";
  3327. vist.l="Global";
  3328. }
  3329. else
  3330. {
  3331. vist.hostName="其他";
  3332. vist.l="其他";
  3333. }
  3334. }
  3335. }
  3336. //补全产品端
  3337. {
  3338. //研修2.0
  3339. if (log.path.Contains("research") || log.path.Contains("study") || log.path.Contains("standard-file"))
  3340. {
  3341. vist.client="ability";
  3342. }
  3343. if (log.path.Contains("teacher"))
  3344. {
  3345. vist.scope="teacher";
  3346. }
  3347. if (log.path.Contains("tmduser"))
  3348. {
  3349. vist.scope="tmduser";
  3350. }
  3351. if (log.path.Contains("student/login"))
  3352. {
  3353. vist.scope="student";
  3354. }
  3355. if (log.path.StartsWith("/activity"))
  3356. {
  3357. vist.client="contest";
  3358. }
  3359. //小程序
  3360. if (log.path.Contains("aclassone"))
  3361. {
  3362. vist.client="aclassone";
  3363. }
  3364. // /// <summary>
  3365. /// ExamInfo qamode 書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
  3366. /// </summary>
  3367. //艺术评测
  3368. 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"))
  3369. {
  3370. vist.client="art";
  3371. }
  3372. if (log.path.Contains("common/exam/upsert-record"))
  3373. {
  3374. JObject jobject = JObject.Parse(log.param.GetRawText());
  3375. var jtokens = jobject.SelectTokens("$..artId");
  3376. if (jtokens!=null && jtokens.Count()>0)
  3377. {
  3378. vist.client="art";
  3379. vist.scope="student";
  3380. }
  3381. }
  3382. if (log.path.Contains("habb"))
  3383. {
  3384. vist.client="habb";
  3385. }
  3386. //阅卷客户端
  3387. if (log.path.Contains("hiscan"))
  3388. {
  3389. vist.client="hiscan";
  3390. }
  3391. if (log.path.Contains("hita"))
  3392. {
  3393. vist.client="hita";
  3394. }
  3395. if (log.path.Contains("hiteachcc"))
  3396. {
  3397. vist.client="hiteachcc";
  3398. }
  3399. if (log.path.Contains("sokrate"))
  3400. {
  3401. vist.client="sokrate";
  3402. }
  3403. if (log.path.Contains("sokrate") || log.path.Contains("score"))
  3404. {
  3405. vist.client="sokrate";
  3406. }
  3407. if (log.path.Contains("hiteach"))
  3408. {
  3409. vist.client="hiteach";
  3410. }
  3411. ///IES开放平台
  3412. if (log.path.Contains("business") || log.path.Contains("biz") || log.path.Contains("openapi-config") || log.path.Contains("open-api"))
  3413. {
  3414. vist.client="open";
  3415. }
  3416. //从token的role 能否获取 开放平台
  3417. //单点登录及第三方接口
  3418. 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")
  3419. || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding") || log.path.Contains("wechat")
  3420. )
  3421. {
  3422. vist.client="sso-third";
  3423. }
  3424. }
  3425. //处理IP转地区
  3426. var region = await _ipSearcher.SearchIpAsync(vist.ip);
  3427. if (string.IsNullOrWhiteSpace(region))
  3428. {
  3429. region="未知IP·未知IP·未知IP";
  3430. }
  3431. if (!string.IsNullOrWhiteSpace(region))
  3432. {
  3433. region= region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
  3434. var regions = region.Split("·");
  3435. if (regions.Length==4)
  3436. {
  3437. vist.area= regions[0];
  3438. vist.province = regions[1];
  3439. vist.city = regions[2];
  3440. }
  3441. if (regions.Length==3)
  3442. {
  3443. vist.area= regions[0];
  3444. vist.province = regions[1];
  3445. }
  3446. if (regions.Length==2)
  3447. {
  3448. vist.area= regions[0];
  3449. vist.province = regions[1];
  3450. }
  3451. if (regions.Length==1)
  3452. {
  3453. vist.area= regions[0];
  3454. }
  3455. }
  3456. //处理地区转经纬度
  3457. {
  3458. IEnumerable<JToken> tokens = default;
  3459. if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  3460. {
  3461. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
  3462. if (!(tokens.Any() && tokens.Count()>0))
  3463. {
  3464. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
  3465. if (!(tokens.Any() && tokens.Count()>0))
  3466. {
  3467. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
  3468. }
  3469. if (!(tokens.Any() && tokens.Count()>0))
  3470. {
  3471. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
  3472. }
  3473. }
  3474. }
  3475. else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  3476. {
  3477. if (vist.area.Equals("中国"))
  3478. {
  3479. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
  3480. if (!(tokens.Any() && tokens.Count()>0))
  3481. {
  3482. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  3483. }
  3484. }
  3485. else
  3486. {
  3487. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
  3488. }
  3489. }
  3490. else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  3491. {
  3492. if (vist.area.Equals("中国"))
  3493. {
  3494. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
  3495. if (!(tokens.Any() && tokens.Count()>0))
  3496. {
  3497. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  3498. }
  3499. }
  3500. else
  3501. {
  3502. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
  3503. }
  3504. }
  3505. else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  3506. {
  3507. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
  3508. }
  3509. if (tokens!=null && tokens.Any())
  3510. {
  3511. List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
  3512. foreach (JToken token in tokens)
  3513. {
  3514. regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
  3515. }
  3516. var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
  3517. if (!points.IsNotEmpty())
  3518. {
  3519. points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
  3520. }
  3521. if (string.IsNullOrWhiteSpace(vist.city))
  3522. {
  3523. vist.city=points?.FirstOrDefault()?.city;
  3524. if (!string.IsNullOrWhiteSpace(vist.city) && vist.city.EndsWith("市"))
  3525. {
  3526. vist.city=vist.city.Replace("市", "");
  3527. }
  3528. }
  3529. vist.lat=points?.FirstOrDefault()?.lat;
  3530. vist.lng=points?.FirstOrDefault()?.lng;
  3531. }
  3532. else
  3533. {
  3534. if (vist.area.Equals("内网IP"))
  3535. {
  3536. if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
  3537. {
  3538. vist.lat="30.655821878416408";
  3539. vist.lng="104.08153351042463";
  3540. vist.area="中国";
  3541. vist.province="四川";
  3542. vist.city="成都";
  3543. }
  3544. else
  3545. {
  3546. vist.lat="25.044332";
  3547. vist.lng="121.509062";
  3548. vist.area="中国";
  3549. vist.province="台湾";
  3550. vist.city="台湾";
  3551. }
  3552. }
  3553. else
  3554. {
  3555. vist.lat="30.655821878416408";
  3556. vist.lng="104.08153351042463";
  3557. vist.area="中国";
  3558. vist.province="四川";
  3559. vist.city="成都";
  3560. }
  3561. }
  3562. }
  3563. uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
  3564. visits.Add(vist);
  3565. }
  3566. }
  3567. );
  3568. List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
  3569. List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
  3570. var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
  3571. if (tmds.Any())
  3572. {
  3573. foreach (var tmd in tmds)
  3574. {
  3575. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{tmd}");
  3576. if (exists)
  3577. {
  3578. tmdexists.Add((tmd, exists, "teacher"));
  3579. }
  3580. else
  3581. {
  3582. exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
  3583. tmdexists.Add((tmd, exists, "student"));
  3584. }
  3585. }
  3586. }
  3587. var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
  3588. if (schs.Any())
  3589. {
  3590. foreach (var sch in schs)
  3591. {
  3592. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{sch}");
  3593. schexists.Add((sch, exists));
  3594. }
  3595. }
  3596. foreach (var item in uuidInfo)
  3597. {
  3598. foreach (var tmd in item.tmdid)
  3599. {
  3600. var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
  3601. if (tmdext.tmd!= null && tmdext.exists)
  3602. {
  3603. var vist = visits.Where(x => x.id.Equals(item.uuid));
  3604. foreach (var vi in vist)
  3605. {
  3606. vi.userId=tmd;
  3607. if (string.IsNullOrWhiteSpace(vi.scope))
  3608. {
  3609. vi.scope=tmdext.scope;
  3610. }
  3611. }
  3612. break;
  3613. }
  3614. }
  3615. foreach (var sch in item.school)
  3616. {
  3617. var schext = schexists.Find(x => x.sch.Equals(sch));
  3618. if (schext.sch!= null && schext.exists)
  3619. {
  3620. var vist = visits.Where(x => x.id.Equals(item.uuid));
  3621. foreach (var vi in vist)
  3622. {
  3623. vi.school=sch;
  3624. }
  3625. break;
  3626. }
  3627. }
  3628. }
  3629. return (visits, uuidInfo);
  3630. }
  3631. public class ApiVisit
  3632. {
  3633. public string id { get; set; }
  3634. public string path { get; set; }
  3635. /// <summary>
  3636. /// 细分
  3637. /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
  3638. /// 产品端
  3639. /// </summary>
  3640. public string client { get; set; }
  3641. /// <summary>
  3642. /// 具体功能
  3643. /// </summary>
  3644. // public string func { get; set; }
  3645. public string userId { get; set; }
  3646. public string picture { get; set; }
  3647. public string scope { get; set; }
  3648. public string tname { get; set; }
  3649. public string school { get; set; }
  3650. public string ip { get; set; }
  3651. //public string region { get; set; }
  3652. public string area { get; set; }
  3653. public string province { get; set; }
  3654. public string city { get; set; } = "";
  3655. public long time { get; set; }
  3656. /// <summary>
  3657. ///
  3658. /// </summary>
  3659. public string host { get; set; }
  3660. public string hostName { get; set; } = "其他";
  3661. /// <summary>
  3662. /// tokenid
  3663. /// </summary>
  3664. public string tid { get; set; }
  3665. public string year { get; set; }
  3666. public string month { get; set; }
  3667. public string day { get; set; }
  3668. public string hour { get; set; }
  3669. //public RegionLngLat point { get; set; }
  3670. public string lat { get; set; }
  3671. public string lng { get; set; }
  3672. public string l { get; set; }
  3673. }
  3674. public class HttpLog
  3675. {
  3676. public string ip { get; set; }
  3677. public long time { get; set; }
  3678. public string host { get; set; }
  3679. public string hostName = "其他";
  3680. public string tid { get; set; }
  3681. public string path { get; set; }
  3682. public string client { get; set; }
  3683. public JsonElement param { get; set; }
  3684. public string id { get; set; }
  3685. public string name { get; set; }
  3686. public string picture { get; set; }
  3687. public string school { get; set; }
  3688. public string p { get; set; }
  3689. // public string ua { get; set; }
  3690. // public string referer { get; set; }
  3691. public string scope { get; set; }
  3692. public string year { get; set; }
  3693. public string month { get; set; }
  3694. public string day { get; set; }
  3695. public string hour { get; set; }
  3696. public string l { get; set; }
  3697. }
  3698. public record RegionLngLat
  3699. {
  3700. public string country { get; set; }
  3701. public string province { get; set; }
  3702. public string city { get; set; }
  3703. public string lat { get; set; }
  3704. public string lng { get; set; }
  3705. public string area { get; set; }
  3706. public string m { get; set; } = "0";
  3707. }
  3708. public class CountData
  3709. {
  3710. public string pk { get; set; } = "";
  3711. public string sk { get; set; } = "";
  3712. public string sp { get; set; } = "";
  3713. public int count { get; set; }
  3714. }
  3715. public class SchoolStick
  3716. {
  3717. /// <summary>
  3718. /// 名字
  3719. /// </summary>
  3720. public string name { get; set; }
  3721. public string picture { get; set; }
  3722. /// <summary>
  3723. /// 编码
  3724. /// </summary>
  3725. public string id { get; set; }
  3726. public string last { get; set; }
  3727. #region teacher
  3728. public ClientStick teacher { get; set; } = new ClientStick();
  3729. #endregion
  3730. #region student
  3731. public ClientStick student { get; set; } = new ClientStick();
  3732. #endregion
  3733. #region hiteach
  3734. public ClientStick hiteach { get; set; } = new ClientStick();
  3735. public Indicator lesson { get; set; } = new Indicator();
  3736. #endregion
  3737. #region hita
  3738. public ClientStick hita { get; set; } = new ClientStick();
  3739. #endregion
  3740. #region ies5Teacher
  3741. public ClientStick ies5Tch { get; set; } = new ClientStick();
  3742. #endregion
  3743. #region otherTeacher
  3744. public ClientStick otherTch { get; set; } = new ClientStick();
  3745. #endregion
  3746. #region ies5Student
  3747. public ClientStick ies5Stu { get; set; } = new ClientStick();
  3748. #endregion
  3749. #region otherStudent
  3750. public ClientStick otherStu { get; set; } = new ClientStick();
  3751. #endregion
  3752. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  3753. public List<StuStick> stuSticks { get; set; } = new List<StuStick>();
  3754. }
  3755. public class TchStick
  3756. {
  3757. public string school { get; set; }
  3758. /// <summary>
  3759. /// 名字
  3760. /// </summary>
  3761. public string name { get; set; }
  3762. public string picture { get; set; }
  3763. /// <summary>
  3764. /// 编码
  3765. /// </summary>
  3766. public string id { get; set; }
  3767. public string last { get; set; }
  3768. #region tmd
  3769. public ClientStick teacher { get; set; } = new ClientStick();
  3770. #endregion
  3771. #region hiteach
  3772. public ClientStick hiteach { get; set; } = new ClientStick();
  3773. public Indicator lesson { get; set; } = new Indicator();
  3774. #endregion
  3775. #region hita
  3776. public ClientStick hita { get; set; } = new ClientStick();
  3777. #endregion
  3778. #region ies5Teacher
  3779. public ClientStick ies5Tch { get; set; } = new ClientStick();
  3780. #endregion
  3781. #region otherTeacher
  3782. public ClientStick otherTch { get; set; } = new ClientStick();
  3783. #endregion
  3784. }
  3785. public class StuStick
  3786. {
  3787. public string school { get; set; }
  3788. /// <summary>
  3789. /// 名字
  3790. /// </summary>
  3791. public string name { get; set; }
  3792. public string picture { get; set; }
  3793. /// <summary>
  3794. /// 编码
  3795. /// </summary>
  3796. public string id { get; set; }
  3797. public string last { get; set; }
  3798. #region tmd
  3799. public ClientStick student { get; set; } = new ClientStick();
  3800. #endregion
  3801. #region ies5Student
  3802. public ClientStick ies5Stu { get; set; } = new ClientStick();
  3803. #endregion
  3804. #region otherStudent
  3805. public ClientStick otherStu { get; set; } = new ClientStick();
  3806. #endregion
  3807. }
  3808. public class ClientStick
  3809. {
  3810. public int userCount { get; set; }
  3811. public int userUpdown { get; set; }
  3812. public Indicator stick { get; set; } = new Indicator();
  3813. public Indicator duration { get; set; } = new Indicator();
  3814. public Indicator count { get; set; } = new Indicator();
  3815. }
  3816. public class Indicator
  3817. {
  3818. /// <summary>
  3819. /// 值
  3820. /// </summary>
  3821. public double value { get; set; } = 0;
  3822. /// <summary>
  3823. /// 值的增减浮动
  3824. /// </summary>
  3825. public double range { get; set; } = 0;
  3826. /// <summary>
  3827. /// 排名
  3828. /// </summary>
  3829. public double rank { get; set; } = 0;
  3830. /// <summary>
  3831. /// 排名的上升下降
  3832. /// </summary>
  3833. public double updown { get; set; } = 0;
  3834. }
  3835. public class Stick
  3836. {
  3837. public List<SchoolStick> schoolSticks { get; set; } = new List<SchoolStick>();
  3838. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  3839. }
  3840. public class Product
  3841. {
  3842. public string Name { get; set; }
  3843. public double VisitDuration { get; set; }
  3844. public double VisitCount { get; set; }
  3845. public double CalculateProductIndex(double timeWeight, double countWeight, double minVisitDuration, double maxVisitDuration, double minVisitCount, double maxVisitCount)
  3846. {
  3847. // 计算访问时长的Min-Max标准化值
  3848. double standardizedVisitDuration = (maxVisitDuration - minVisitDuration)!=0 ? (VisitDuration - minVisitDuration) / (maxVisitDuration - minVisitDuration) : 0;
  3849. // 计算访问次数的Min-Max标准化值
  3850. double standardizedVisitCount = (maxVisitCount - minVisitCount)!=0 ? (VisitCount - minVisitCount) / (maxVisitCount - minVisitCount) : 0;
  3851. // 计算加权综合指数
  3852. double comprehensiveIndex = timeWeight * standardizedVisitDuration + countWeight * standardizedVisitCount;
  3853. return Math.Round(comprehensiveIndex, 4);
  3854. }
  3855. }
  3856. }
  3857. }