SystemService.cs 251 KB

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