12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140 |
- package com.ruoyi.web.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.collection.ListUtil;
- import cn.hutool.core.date.DateField;
- import cn.hutool.core.date.DateRange;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.text.StrBuilder;
- import cn.hutool.core.thread.ThreadUtil;
- import cn.hutool.core.util.NumberUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson2.JSON;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.ruoyi.quartz.handler.IJobHandler;
- import com.ruoyi.ucp.entity.*;
- import com.ruoyi.ucp.feign.AdapterApi;
- import com.ruoyi.ucp.service.*;
- import com.ruoyi.ucp.util.CalcCache;
- import org.apache.commons.math3.fitting.PolynomialCurveFitter;
- import org.apache.commons.math3.fitting.WeightedObservedPoints;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.net.URI;
- import java.util.*;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.atomic.AtomicReference;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @Service
- public class JavaFunctionJobHandler extends IJobHandler {
- private static Logger logger = LoggerFactory.getLogger(JavaFunctionJobHandler.class);
- @Resource
- private AdapterApi adapter;
- @Resource
- private IPointInfoService pointService;
- @Resource
- private IStationInfoHourService stationInfoHourService;
- @Resource
- private IStationInfoDayService stationInfoDayService;
- @Resource
- private ILineInfoDayService lineInfoDayService;
- @Resource
- private IStateAiService stateAiService;
- @Resource
- private StringRedisTemplate stringRedisTemplate;
- @Resource
- private IEquipmentModelService equipmentModelService;
- @Resource
- private ITurbineInfoDayService turbineInfoDayService;
- @Resource
- private IProEconReportIndicatorPoolService reportIndicatorPoolService;
- @Resource
- private ITurbineInfoMinService turbineInfoMinService;
- @Resource
- private IStationInfoMinService stationInfoMinService;
- @Resource
- private IProBasicProjectPlanService proBasicProjectPlanService;
- @Resource
- private IHistoryPredictService historyPredictService;
- @Resource
- private IPredictExaminService predictExaminService;
- @Resource
- private IPredictExamin2Service predictExamin2Service;
- @Resource
- private IStationInfoMin2Service stationInfoMin2Service;
- @Resource
- private IProjectInfoMin2Service projectInfoMin2Service;
- @Resource
- private IRealtimePredictService realtimePredictService;
- @Override
- public void execute() throws Exception {
- }
- @Override
- public IJobHandler getFunctionHandler() {
- return null;
- }
- @Override
- public void setFunctionHandler(IJobHandler jobHandler) {
- }
- public URI taosGoldenUriTest() {
- return URI.create("http://127.0.0.1:8011/ts");
- }
- public String pointInfos2Keys(List<PointInfo> entity) {
- return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- }
- public List<StationInfoHour> getStationinfoByHour(Date hour) {
- QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", hour);
- return stationInfoHourService.list(wrapper);
- }
- public List<StationInfoHour> getStationinfoByHour(Date hour, List<PointInfo> entity) {
- List<StationInfoHour> byDate = getStationinfoByHour(hour);
- if (CollUtil.isEmpty(byDate)) {
- entity.forEach(pi -> {
- StationInfoHour day = new StationInfoHour();
- day.setStationId(pi.getStationId());
- day.setRecordDate(hour);
- byDate.add(day);
- });
- }
- return byDate;
- }
- public List<StationInfoDay> getStationinfoByDate(Date date) {
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- return stationInfoDayService.list(wrapper);
- }
- public List<StationInfoMin> getStationinfoByMin(Date date) {
- QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- return stationInfoMinService.list(wrapper);
- }
- public List<StationInfoMin> getStationinfoByMin(Date date, List<PointInfo> entity) {
- List<StationInfoMin> byDate = getStationinfoByMin(date);
- if (CollUtil.isEmpty(byDate)) {
- entity.forEach(pi -> {
- StationInfoMin day = new StationInfoMin();
- day.setStationId(pi.getStationId());
- day.setRecordDate(date);
- byDate.add(day);
- });
- }
- return byDate;
- }
- public List<StationInfoMin> getStationinfoByMin(Date date, String stId) {
- QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date).eq("station_id", stId);
- List<StationInfoMin> list = stationInfoMinService.list(wrapper);
- if (CollUtil.isEmpty(list)) {
- StationInfoMin day = new StationInfoMin();
- day.setStationId(stId);
- day.setRecordDate(date);
- list.add(day);
- }
- return list;
- }
- public StationInfoMin2 getStationinfoByMin2(Date date, String stId) {
- QueryWrapper<StationInfoMin2> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date).eq("station_id", stId);
- StationInfoMin2 list = stationInfoMin2Service.getOne(wrapper, false);
- if (list == null) {
- list = new StationInfoMin2();
- list.setStationId(stId);
- list.setRecordDate(date);
- }
- return list;
- }
- public StationInfoMin getStationinfoByMinOne(Date date, String stId) {
- QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date).eq("station_id", stId);
- return stationInfoMinService.getOne(wrapper, false);
- }
- public StationInfoDay getStationinfoByDate(Date date, String stId) {
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date).eq("station_id", stId);
- List<StationInfoDay> list = stationInfoDayService.list(wrapper);
- StationInfoDay day;
- if (CollUtil.isEmpty(list)) {
- day = new StationInfoDay();
- day.setStationId(stId);
- day.setRecordDate(date);
- } else {
- day = list.get(0);
- }
- return day;
- }
- public List<StationInfoDay> getStationinfoByDate(Date date, List<PointInfo> entity) {
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- List<StationInfoDay> list = stationInfoDayService.list(wrapper);
- if (CollUtil.isEmpty(list)) {
- entity.forEach(pi -> {
- StationInfoDay day = new StationInfoDay();
- day.setStationId(pi.getStationId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list;
- }
- public List<StationInfoDay> getStationinfoByDate2(Date date, List<PointInfo> entity) {
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- List<String> sts = entity.stream().map(PointInfo::getStationId).collect(Collectors.toList());
- wrapper.eq("record_date", date).in("station_id", sts);
- List<StationInfoDay> list = stationInfoDayService.list(wrapper);
- if (CollUtil.isEmpty(list)) {
- entity.forEach(pi -> {
- StationInfoDay day = new StationInfoDay();
- day.setStationId(pi.getStationId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list;
- }
- public List<LineInfoDay> getLineinfoByDate(Date date) {
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- return lineInfoDayService.list(wrapper);
- }
- public List<LineInfoDay> getLineinfoByDate(Date date, String stId) {
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date).eq("station_id", stId);
- return lineInfoDayService.list(wrapper);
- }
- public List<LineInfoDay> getLineinfoByDate(Date date, List<PointInfo> entity) {
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- if (CollUtil.isEmpty(list)) {
- entity.forEach(pi -> {
- LineInfoDay day = new LineInfoDay();
- day.setStationId(pi.getStationId());
- day.setProjectId(pi.getProjectId());
- day.setLineId(pi.getLineId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list;
- }
- public List<LineInfoDay> getLineinfoByDate2(Date date, List<PointInfo> entity) {
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- List<String> lines = entity.stream().map(PointInfo::getLineId).collect(Collectors.toList());
- wrapper.eq("record_date", date).in("line_id", lines);
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- if (CollUtil.isEmpty(list)) {
- entity.forEach(pi -> {
- LineInfoDay day = new LineInfoDay();
- day.setStationId(pi.getStationId());
- day.setProjectId(pi.getProjectId());
- day.setLineId(pi.getLineId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list;
- }
- public URI taosUri() {
- return URI.create("http://172.16.12.101:8012/ts");
- }
- public URI goldenUri() {
- return URI.create("http://172.16.12.103:8011/ts");
- }
- public Map<String, String> getEntityMap(String uniformCode, String institutionType) {
- PointInfo pi = new PointInfo();
- pi.setUniformCode(uniformCode);
- pi.setInstitutionType(institutionType);
- List<PointInfo> entity = pointService.getByEntity(pi);
- switch (institutionType) {
- case "turbine":
- case "state":
- return entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
- case "station":
- return entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
- }
- return new HashMap<>();
- }
- public Map<String, TurbineInfoDay> getTurbineinfoMap(Date date, List<PointInfo> entity) {
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
- if (list.isEmpty()) {
- entity.forEach(pi -> {
- TurbineInfoDay day = new TurbineInfoDay();
- day.setStationId(pi.getStationId());
- day.setProjectId(pi.getProjectId());
- day.setLineId(pi.getLineId());
- day.setTurbineId(pi.getTurbineId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list.stream().collect(Collectors.toMap(TurbineInfoDay::getTurbineId, Function.identity()));
- }
- public List<PointInfo> getEntity(String uniformCode, String institutionType) {
- PointInfo pi = new PointInfo();
- pi.setUniformCode(uniformCode);
- pi.setInstitutionType(institutionType);
- return pointService.getByEntity(pi);
- }
- public List<PointInfo> getEntityByUis(String uniformCode, String institutionType, String stId) {
- PointInfo pi = new PointInfo();
- pi.setUniformCode(uniformCode);
- pi.setInstitutionType(institutionType);
- pi.setStationId(stId);
- return pointService.getByEntity(pi);
- }
- public Map<String, Double> getTurbinePowerLoss(Double rfdl, PointInfo piZt, List<PointData> fsList, List<PointData> glList) {
- if (rfdl == null) rfdl = 0.0;
- String tbId = piZt.getTurbineId();
- // Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
- double sumfs = fsList.stream().mapToDouble(PointData::getValue).sum();
- // double xs = 1;
- // if (rfdl > 0 && sum1 > 0) {
- // xs = rfdl / (sum1 / 240);
- // }
- // double sum2 = fsList.stream().mapToDouble(pd -> {
- // Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
- // if (v == null) v = 0.0;
- // return v;
- // }).sum();
- // sum2=sum2/240;
- List<PointData> collectZt = piZt.getPointDatas();
- double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
- Map<String, Double> map = new HashMap<>();
- if (Math.abs(collectZt.size() - fsList.size()) < 9 && Math.abs(fsList.size() - glList.size()) < 9) {
- int min = Math.min(collectZt.size(), Math.min(fsList.size(), glList.size()));
- for (int i = 0; i < min; i++) {
- Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
- if (v == null) v = 0.0;
- v = v - glList.get(i).getValue();
- switch ((int) collectZt.get(i).getValue()) {
- //计划检修损失:
- case 6:
- //检修
- jxss += v;
- break;
- case 1:
- //手动停机
- sdtj += v;
- break;
- //非计划检修损失:
- case 4:
- //故障
- gzss += v;
- break;
- case 0:
- //待机
- djss += v;
- break;
- //性能损失:
- case 2:
- //性能
- xnss += v;
- break;
- case 3:
- //发电降出力
- fdjcl += v;
- break;
- //限电损失:
- case 8:
- //限电降出力
- xdjcl += v;
- break;
- case 9:
- //限电停机
- xdtj += v;
- break;
- }
- }
- }
- if (jxss > 3600000) jxss = 3600000;
- if (sdtj > 3600000) sdtj = 3600000;
- if (gzss > 3600000) gzss = 3600000;
- if (djss > 3600000) djss = 3600000;
- if (xnss > 3600000) xnss = 3600000;
- if (fdjcl > 3600000) fdjcl = 3600000;
- if (xdjcl > 3600000) xdjcl = 3600000;
- if (xdtj > 3600000) xdtj = 3600000;
- //15秒*60分钟
- map.put("jxss", jxss > 0 ? jxss / 240 : 0);
- map.put("sdtj", sdtj > 0 ? sdtj / 240 : 0);
- map.put("gzss", gzss > 0 ? gzss / 240 : 0);
- map.put("djss", djss > 0 ? djss / 240 : 0);
- map.put("xnss", xnss > 0 ? xnss / 240 : 0);
- map.put("fdjcl", fdjcl > 0 ? fdjcl / 240 : 0);
- map.put("xdjcl", xdjcl > 0 ? xdjcl / 240 : 0);
- map.put("xdtj", xdtj > 0 ? xdtj / 240 : 0);
- double v = map.get("jxss") + map.get("sdtj") + map.get("gzss") + map.get("djss") + map.get("xnss") + map.get("fdjcl") + map.get("xdjcl") + map.get("xdtj");
- System.out.println(piZt.getTurbineId() + ",日发" + rfdl + ",损失" + v + ",风速和" + sumfs / 240);
- return map;
- }
- public void calcAQTS(Date date) {
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("min(record_date) record_date");
- StationInfoDay one = stationInfoDayService.getOne(wrapper);
- wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", one.getRecordDate());
- //最早时间的列表
- List<StationInfoDay> list = stationInfoDayService.list(wrapper);
- List<StationInfoDay> today = getStationinfoByDate(date);
- if (today.isEmpty()) {
- for (StationInfoDay infoDay : list) {
- StationInfoDay day = new StationInfoDay();
- day.setStationId(infoDay.getStationId());
- day.setRecordDate(date);
- day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
- today.add(day);
- }
- } else {
- Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- for (StationInfoDay day : today) {
- StationInfoDay day1 = collect.get(day.getStationId());
- day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
- }
- }
- stationInfoDayService.saveOrUpdateBatch(today);
- }
- public void calcLineSwGWCyDl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
- Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
- StationInfoDay stationInfo;
- for (LineInfoDay lineInfo : lineInfos) {
- stationInfo = stationMap.get(lineInfo.getStationId());
- double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
- lineInfo.setSwdl(xs * stationInfo.getSwdl());
- lineInfo.setGwdl(xs * stationInfo.getGwdl());
- lineInfo.setCydl(xs * stationInfo.getCydl());
- lineInfo.setZyb(xs * stationInfo.getZyb());
- }
- lineInfoDayService.saveOrUpdateBatch(lineInfos);
- }
- public void calcLineSwGWCyDlSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
- Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
- StationInfoDay stationInfo;
- for (LineInfoDay lineInfo : lineInfos) {
- stationInfo = stationMap.get(lineInfo.getStationId());
- double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
- lineInfo.setSwdl(xs * stationInfo.getSwdl());
- lineInfo.setGwdl(xs * stationInfo.getGwdl());
- lineInfo.setCydl(xs * stationInfo.getCydl());
- lineInfo.setZyb(xs * stationInfo.getZyb());
- }
- lineInfoDayService.saveOrUpdateBatch(lineInfos);
- }
- public void calcLineSwGWCyDl(Date date, String stId) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- StationInfoDay sti = getStationinfoByDate(time0, stId);
- List<LineInfoDay> lineInfos = getLineinfoByDate(time0, stId);
- for (LineInfoDay lineInfo : lineInfos) {
- double xs = (double) lineInfo.getRfdl() / sti.getRfdl();
- lineInfo.setSwdl(xs * sti.getSwdl());
- lineInfo.setGwdl(xs * sti.getGwdl());
- lineInfo.setCydl(xs * sti.getCydl());
- lineInfo.setZyb(xs * sti.getZyb());
- }
- lineInfoDayService.saveOrUpdateBatch(lineInfos);
- }
- public void calcStationZhcyRfDl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
- List<StationInfoDay> byDate = getStationinfoByDate(time0);
- for (StationInfoDay day : byDate) {
- day.setRfdl(rfdlMap.get(day.getStationId()));
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcStationRjhfdl(Date date) {
- List<DateTime> months = DateUtil.rangeToList(date, DateUtil.endOfYear(date), DateField.MONTH);
- for (DateTime month : months) {
- DateTime begin = DateUtil.beginOfMonth(month);
- DateTime end = DateUtil.endOfMonth(month);
- DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
- DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
- List<StationInfoDay> days = stationInfoDayService.list(wrapper);
- Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
- if (CollUtil.isNotEmpty(days)) {
- dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
- Collectors.toMap(sid -> DateUtil.formatDate(sid.getRecordDate()), Function.identity())));
- }
- wrapper.clear();
- wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
- List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
- Map<String, List<StationInfoDay>> sidMap;
- if (CollUtil.isNotEmpty(sids)) {
- sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
- } else {
- sidMap = null;
- }
- QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
- wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
- .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
- List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
- for (ProBasicProjectPlan plan : plantList) {
- String stId = plan.getWindpowerstationId();
- Map<String, StationInfoDay> daym = dayMap.get(stId);
- if (daym == null) daym = new HashMap<>();
- if (sidMap == null) {
- for (StationInfoDay day : daym.values()) {
- day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
- }
- } else {
- //去年月发电量
- List<StationInfoDay> sidList = sidMap.get(stId);
- double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
- double v = plan.getGeneratingCapacity() / rfdlSum;
- for (StationInfoDay sid : sidList) {
- DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
- StationInfoDay day = daym.get(DateUtil.formatDate(time));
- if (day == null) {
- day = new StationInfoDay();
- day.setStationId(stId);
- day.setRecordDate(time);
- days.add(day);
- }
- day.setJhfdl(v * sid.getRfdl());
- }
- }
- }
- stationInfoDayService.saveOrUpdateBatch(days);
- }
- }
- public void calcStationRjhfdl2(Date month) {
- DateTime begin = DateUtil.beginOfMonth(month);
- DateRange range = DateUtil.range(begin, DateUtil.endOfYear(begin), DateField.MONTH);
- QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
- wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
- .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
- List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
- for (DateTime date : range) {
- }
- DateTime end = DateUtil.endOfMonth(month);
- DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
- DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
- List<StationInfoDay> days = stationInfoDayService.list(wrapper);
- Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
- if (CollUtil.isNotEmpty(days)) {
- dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
- Collectors.toMap(sid -> DateUtil.date(sid.getRecordDate()).toString(), Function.identity())));
- }
- wrapper.clear();
- wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
- List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
- Map<String, List<StationInfoDay>> sidMap;
- if (CollUtil.isNotEmpty(sids)) {
- sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
- } else {
- sidMap = null;
- }
- for (ProBasicProjectPlan plan : plantList) {
- String stId = plan.getWindpowerstationId();
- Map<String, StationInfoDay> daym = dayMap.get(stId);
- if (daym == null) daym = new HashMap<>();
- if (sidMap == null) {
- for (StationInfoDay day : daym.values()) {
- day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
- }
- } else {
- //去年月发电量
- List<StationInfoDay> sidList = sidMap.get(stId);
- double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
- double v = plan.getGeneratingCapacity() / rfdlSum;
- for (StationInfoDay sid : sidList) {
- DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
- StationInfoDay day = daym.get(time.toString());
- if (day == null) {
- day = new StationInfoDay();
- day.setStationId(stId);
- day.setRecordDate(time);
- days.add(day);
- }
- day.setJhfdl(v * sid.getRfdl());
- }
- }
- }
- stationInfoDayService.saveOrUpdateBatch(days);
- }
- public void calcStationZhcyRfDlSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
- List<StationInfoDay> byDate = getStationinfoByDate(time0);
- for (StationInfoDay day : byDate) {
- day.setRfdl(rfdlMap.get(day.getStationId()));
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcStationZhcyRfDl(Date date, String stId) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0)
- .eq("station_id", stId).groupBy("station_id");
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
- StationInfoDay day = getStationinfoByDate(time0, stId);
- day.setRfdl(rfdlMap.get(day.getStationId()));
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- stationInfoDayService.saveOrUpdateBatch(Collections.singleton(day));
- }
- public void calcStationSwGwCyRdl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
- List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
- List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
- getZeroNextData(swdlEt, time0, time);
- getZeroNextData(gwdlEt, time0, time);
- getZeroNextData(cydlEt, time0, time);
- Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
- String stId;
- PointInfo swdlPi, gwdlPi, cydlPi;
- for (StationInfoDay info : byDate) {
- stId = info.getStationId();
- swdlPi = swdlMap.get(stId);
- gwdlPi = gwdlMap.get(stId);
- cydlPi = cydlMap.get(stId);
- int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
- int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
- if (swdl < 0 || swdl > 6000000) swdl = 0;
- if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
- if (cydl < 0 || cydl > 6000000) cydl = 0;
- info.setSwdl(swdl);
- info.setGwdl(gwdl);
- info.setZyb(cydl);
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcStationSwGwCyDlSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
- List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
- List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
- getZeroNextData(swdlEt, time0);
- getZeroNextData(gwdlEt, time0);
- getZeroNextData(cydlEt, time0);
- Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
- String stId;
- PointInfo swdlPi, gwdlPi, cydlPi;
- for (StationInfoDay info : byDate) {
- stId = info.getStationId();
- swdlPi = swdlMap.get(stId);
- gwdlPi = gwdlMap.get(stId);
- cydlPi = cydlMap.get(stId);
- int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
- int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
- if (swdl < 0 || swdl > 6000000) swdl = 0;
- if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
- if (cydl < 0 || cydl > 6000000) cydl = 0;
- info.setSwdl(swdl);
- info.setGwdl(gwdl);
- info.setZyb(cydl);
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcStationSwGwCyRdl(Date date, String stId) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> swdlEt = getEntityByUis("Z-ZXYG-CX", "meter", stId);
- List<PointInfo> gwdlEt = getEntityByUis("Z-FXYG-CX", "meter", stId);
- List<PointInfo> cydlEt = getEntityByUis("Z-ZXYG-ZYB", "meter", stId);
- getZeroNextData(swdlEt, time0, time);
- getZeroNextData(gwdlEt, time0, time);
- getZeroNextData(cydlEt, time0, time);
- List<StationInfoDay> byDate = getStationinfoByDate2(time0, swdlEt);
- StationInfoDay info = byDate.get(0);
- PointInfo swdlPi = swdlEt.get(0);
- PointInfo gwdlPi = gwdlEt.get(0);
- PointInfo cydlPi = cydlEt.get(0);
- int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
- int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
- if (stId.equals("GJNY_SXGS_JSL_FDC_STA") && time0.before(DateUtil.parse("2024-07-08"))) {
- swdl = swdl * 100;
- gwdl = gwdl * 100;
- }
- if (swdl < 0 || swdl > 6000000) swdl = 0;
- if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
- if (cydl < 0 || cydl > 6000000) cydl = 0;
- info.setSwdl(swdl);
- info.setGwdl(gwdl);
- info.setZyb(cydl);
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void SwdlRepair(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
- Map<String, PointInfo> map = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- List<StationInfoDay> list = getStationinfoByDate(time0);
- Map<String, StationInfoDay> dayMap = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- CalcCache.swdlTime.forEach((key, ts) -> {
- int swdl = 0;
- PointData data1, data0;
- double ll = (double) (time.getTime() - ts) / 23 * 60 * 60 * 1000;
- if (ts > 0 && (ll > 23 && ll < 25)) {
- StationInfoDay day = dayMap.get(key);
- PointInfo info = map.get(key);
- List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), key, time.getTime(), DateUtil.offsetMinute(time, 6).getTime());
- if (CollUtil.isEmpty(raw1)) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, time.getTime() + 1000);
- data1 = section.get(key);
- } else {
- data1 = raw1.get(0);
- }
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, ts + 1000);
- data0 = section.get(key);
- swdl = (int) ((data1.getValue() - data0.getValue()) * info.getCoef());
- if (swdl > day.getRfdl()) {
- List<PointData> rawl1 = adapter.getHistoryRaw(goldenUri(), key, DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
- for (int i = rawl1.size() - 1; i >= 0; i--) {
- swdl = (int) ((rawl1.get(i).getValue() - data0.getValue()) * info.getCoef());
- if (swdl <= day.getRfdl()) {
- day.setSwdl(swdl);
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- CalcCache.swdlTime.put(info.getPointKey(), rawl1.get(i).getTs());
- break;
- }
- }
- } else {
- day.setSwdl(swdl);
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- }
- }
- });
- for (StationInfoDay day : list) {
- int swdl = 0;
- if (day.getSwdl() > day.getRfdl()) {
- PointInfo info = map.get(day.getStationId());
- Long l = CalcCache.swdlTime.get(info.getPointKey());
- PointData data0;
- if (l == null || l == 0) {
- List<PointData> raw0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), time0.getTime(), DateUtil.offsetMinute(time0, 6).getTime());
- if (CollUtil.isEmpty(raw0)) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), time0.getTime() + 1000);
- data0 = section.get(info.getPointKey());
- } else {
- data0 = raw0.get(0);
- }
- } else {
- double ll = (double) (time.getTime() - l) / 23 * 60 * 60 * 1000;
- if (ll > 23 && ll < 25) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), l + 1000);
- data0 = section.get(info.getPointKey());
- } else {
- continue;
- }
- }
- List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
- for (int i = raw1.size() - 1; i >= 0; i--) {
- swdl = (int) ((raw1.get(i).getValue() - data0.getValue()) * info.getCoef());
- if (swdl <= day.getRfdl()) {
- day.setSwdl(swdl);
- day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
- day.setCydl(day.getZhcydl() - day.getZyb());
- CalcCache.swdlTime.put(info.getPointKey(), raw1.get(i).getTs());
- break;
- }
- }
- }
- }
- stationInfoDayService.saveOrUpdateBatch(list);
- stringRedisTemplate.opsForValue().set("swdlTime", JSON.toJSONString(CalcCache.swdlTime));
- }
- public void getZeroNextData(List<PointInfo> entity, Date start0, Date start) {
- List<PointData> snap0, snap;
- for (PointInfo info : entity) {
- PointData data0, data;
- List<PointData> datas = new ArrayList<>();
- snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 6).getTime());
- if (CollUtil.isEmpty(snap0)) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
- snap0 = new ArrayList<>(section.values());
- }
- snap = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start.getTime(), DateUtil.offsetMinute(start, 6).getTime());
- if (CollUtil.isEmpty(snap)) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start.getTime());
- snap = new ArrayList<>(section.values());
- }
- if (CollUtil.isEmpty(snap0) || CollUtil.isEmpty(snap)) {
- data0 = new PointData();
- data = new PointData();
- } else {
- data0 = snap0.get(0);
- data = snap.get(0);
- }
- datas.add(data0);
- datas.add(data);
- info.setPointDatas(datas);
- }
- }
- public void getZeroNextData(List<PointInfo> entity, Date start0) {
- String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
- List<PointData> snap0;
- for (PointInfo info : entity) {
- PointData data0, data;
- List<PointData> datas = new ArrayList<>();
- snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 90).getTime());
- if (CollUtil.isEmpty(snap0)) {
- Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
- snap0 = new ArrayList<>(section.values());
- }
- data = latest.get(info.getPointKey());
- if (CollUtil.isEmpty(snap0) || data == null) {
- data0 = new PointData();
- data = new PointData();
- } else {
- data0 = snap0.get(0);
- }
- datas.add(data0);
- datas.add(data);
- info.setPointDatas(datas);
- }
- }
- public void calcStationHourRFDL(Date hour) {
- PointInfo pointInfo = new PointInfo();
- pointInfo.setInstitutionType("station");
- pointInfo.setUniformCode("RFDLSYZ");
- List<PointInfo> entity = pointService.getByEntity(pointInfo);
- Map<String, PointData> section = adapter.getHistorySection(taosUri(), pointInfos2Keys(entity), hour.getTime());
- List<StationInfoHour> byHours = getStationinfoByHour(hour);
- if (byHours.isEmpty()) {
- for (PointInfo point : entity) {
- StationInfoHour info = new StationInfoHour();
- info.setStationId(point.getStationId());
- info.setRecordDate(DateUtil.beginOfHour(hour));
- info.setRfdl(section.get(point.getPointKey()).getValue());
- byHours.add(info);
- }
- } else {
- Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
- for (StationInfoHour byHour : byHours) {
- byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getValue());
- }
- }
- stationInfoHourService.saveOrUpdateBatch(byHours);
- }
- public void calcLineRfdl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- getZeroNextData(entity, time0, time);
- Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
- List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
- String lineId;
- PointInfo swdlPi;
- int v = 0;
- for (LineInfoDay day : byDate) {
- lineId = day.getLineId();
- swdlPi = swdlMap.get(lineId);
- v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- if (v < 0 || v > 30000000) v = 0;
- day.setRfdl(v);
- }
- lineInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcTurbineRFDLSameDay() {
- DateTime time = DateUtil.date();
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(time);
- List<PointInfo> entity = getEntity("AI121", "turbine");
- getZeroNextData(entity, time0, time);
- Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, String> fsMap = getEntityMap("AI066", "turbine");
- Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
- TurbineInfoDay infoDay;
- PointInfo rfdlPi;
- String turbineId;
- List<TurbineInfoDay> infoDays = new ArrayList<>();
- DoubleStatData stat;
- for (PointInfo info : entity) {
- turbineId = info.getTurbineId();
- infoDay = byDate.get(turbineId);
- rfdlPi = turMap.get(turbineId);
- double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
- if (v < 0 || v > 1000000) {
- v = 0;
- } else if (v > 30000) {
- v = v / (v % 30000 + 3);
- }
- infoDay.setRfdl(v);
- stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
- if (stat == null) {
- infoDay.setPjfs(0.0);
- } else {
- infoDay.setPjfs(stat.getAvg().getValue());
- }
- infoDays.add(infoDay);
- }
- turbineInfoDayService.saveOrUpdateBatch(infoDays);
- }
- public void calcTurbine5s2SameDay() {
- DateTime time = DateUtil.date();
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(time);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- //状态
- List<PointInfo> entityZT = getEntity("MXZT", "turbine");
- Map<String, Map<String, PointInfo>> ztMapMapInfos = entityZT.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
- List<TurbineInfoDay> infoDays = new ArrayList<>();
- Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- Map<String, Map<String, PointInfo>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
- //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
- // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
- TurbineInfoDay infoDay = dayMap.get(wtId);
- PointInfo fspi = fsMapMap.get(stId).get(wtId);
- PointInfo glpi = glMapMap.get(stId).get(wtId);
- getSnapDataByEntity(fspi, time0, time, 15);
- getSnapDataByEntity(glpi, time0, time, 15);
- getSnapDataByEntity(ztInfo, taosUri(), time0, time, 15);
- List<PointData> fsData = fspi.getPointDatas();
- fsData = fsData.stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztInfo, fsData, glpi.getPointDatas());
- infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
- infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
- infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
- infoDay.setSlss(0.0);
- infoDay.setDjss(loss.get("djss"));
- infoDay.setGzss(loss.get("gzss"));
- //if (infoDay.getRfdl() == 0) {
- // infoDay.setXnss(0.0);
- //} else {
- // infoDay.setXnss(loss.get("xnss"));
- //}
- infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() + infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
- infoDays.add(infoDay);
- }));
- turbineInfoDayService.saveOrUpdateBatch(infoDays);
- }
- public void calcLineRfdlSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- getZeroNextData(entity, time0);
- Map<String, PointInfo> rfdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
- List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
- PointInfo rfdlPi;
- int v;
- for (LineInfoDay day : byDate) {
- rfdlPi = rfdlMap.get(day.getLineId());
- v = (int) ((rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef());
- if (v < 0 || v > 30000000) v = 0;
- day.setRfdl(v);
- }
- lineInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcLineRfdl(Date date, String stId) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> StrUtil.isNotEmpty(e.getProjectId()) && Objects.equals(stId, e.getStationId())).collect(Collectors.toList());
- getZeroNextData(entity, time0, time);
- Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
- List<LineInfoDay> byDate = getLineinfoByDate2(time0, entity);
- String lineId;
- PointInfo swdlPi;
- int v = 0;
- for (LineInfoDay day : byDate) {
- lineId = day.getLineId();
- swdlPi = swdlMap.get(lineId);
- v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- if (v < 0 || v > 30000000) v = 0;
- day.setRfdl(v);
- }
- lineInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcLineDjlRfdl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- //date当天零点加三分钟
- DateTime time2 = DateUtil.offsetMinute(time, 3);
- //date昨天零点加三分钟
- DateTime time1 = DateUtil.offsetMinute(time0, 3);
- PointInfo pi = new PointInfo();
- pi.setUniformCode("Z-ZXYG-JX");
- pi.setLineId("all");
- List<PointInfo> entity = pointService.getByEntity(pi);
- // entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
- String keys = pointInfos2Keys(entity);
- Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
- Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
- List<LineInfoDay> byDate = getLineinfoByDate(time0);
- Map<String, LineInfoDay> collect = new HashMap<>();
- if (!byDate.isEmpty()) {
- collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
- }
- List<LineInfoDay> list = new ArrayList<>();
- for (PointInfo info : entity) {
- LineInfoDay day;
- if (byDate.isEmpty()) {
- day = new LineInfoDay();
- day.setStationId(info.getStationId());
- day.setProjectId(info.getProjectId());
- day.setLineId(info.getLineId());
- day.setRecordDate(time0);
- } else {
- day = collect.get(info.getLineId());
- }
- day.setRfdl((int) ((latest2.get(info.getPointKey()).getValue() - latest1.get(info.getPointKey()).getValue()) * info.getCoef()));
- if (day.getRfdl() <= 0 || day.getRfdl() > 30000000) {
- day.setRfdl(0);
- }
- list.add(day);
- }
- lineInfoDayService.saveOrUpdateBatch(list);
- }
- public int test(Date date, String key, int coef) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- PointInfo info = new PointInfo();
- info.setPointKey(key);
- getZeroNextData(Collections.singletonList(info), time0, time);
- int swdl = (int) ((info.getPointDatas().get(1).getValue() - info.getPointDatas().get(0).getValue()) * coef);
- return swdl;
- }
- public void calcStationZhcydl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
- List<LineInfoDay> list = lineInfoDayService.list(wrapper);
- List<StationInfoDay> byDate = getStationinfoByDate(time0);
- // list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
- Map<String, StationInfoDay> collect = new HashMap<>();
- if (!byDate.isEmpty()) {
- collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- }
- StationInfoDay infoDay;
- List<StationInfoDay> infoDays = new ArrayList<>();
- for (LineInfoDay day : list) {
- if (byDate.isEmpty()) {
- infoDay = new StationInfoDay();
- infoDay.setStationId(day.getStationId());
- infoDay.setRecordDate(time0);
- } else {
- infoDay = collect.get(day.getStationId());
- }
- infoDay.setRfdl(day.getRfdl());
- infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
- infoDays.add(infoDay);
- }
- stationInfoDayService.saveOrUpdateBatch(infoDays);
- }
- public void calcStationHourPjglRfdl(Date hour) {
- //hour整点
- DateTime time = DateUtil.beginOfHour(hour);
- //1小时前
- DateTime time0 = DateUtil.offsetHour(time, -1);
- //当天零点
- DateTime rft = DateUtil.beginOfDay(time);
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), time0, time, PointInfo::getStationId);
- List<StationInfoHour> byHours = getStationinfoByHour(time, entityCx);
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- if (time.getHours() == 0) {
- getSectionDataByEntity(entity, goldenUri(), DateUtil.offsetDay(rft, -1), time);
- } else {
- getSectionDataByEntity(entity, goldenUri(), rft, time);
- }
- Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- for (StationInfoHour byHour : byHours) {
- List<PointInfo> pis = stMap.get(byHour.getStationId());
- double dl = 0, v = 0;
- List<PointData> pds;
- for (PointInfo pi : pis) {
- pds = pi.getPointDatas();
- if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
- dl += (v < 0 || v > 30000000) ? 0 : v;
- }
- byHour.setRfdl(dl);
- PointInfo info = statMapCx.get(byHour.getStationId());
- double v1 = info.getPointDatas().get(0).getValue();
- byHour.setPjgl(v1 <= 0 ? 0 : v1 * info.getCoef());
- }
- stationInfoHourService.saveOrUpdateBatch(byHours);
- }
- public void calcStationMinRfdl(Date hour) {
- //hour整分钟
- DateTime time = DateUtil.beginOfMinute(hour);
- //当天零点
- DateTime rft = DateUtil.beginOfDay(time);
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- List<StationInfoMin> byHours = getStationinfoByMin(time, entity);
- getSectionDataByEntity(entity, goldenUri(), rft, time);
- Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- for (StationInfoMin byHour : byHours) {
- List<PointInfo> pis = stMap.get(byHour.getStationId());
- double dl = 0, v = 0;
- List<PointData> pds;
- for (PointInfo pi : pis) {
- pds = pi.getPointDatas();
- if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
- dl += (v < 0 || v > 30000000) ? 0 : v;
- }
- byHour.setRfdl(dl);
- }
- stationInfoMinService.saveOrUpdateBatch(byHours);
- }
- public void calcStationHourPJGL(Date hour) {
- hour = DateUtil.beginOfHour(hour);
- DateTime start = DateUtil.offsetHour(hour, -1);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, hour, PointInfo::getStationId);
- List<StationInfoHour> byHours = getStationinfoByHour(hour, entityCx);
- for (StationInfoHour byHour : byHours) {
- PointInfo info = statMapCx.get(byHour.getStationId());
- double v = info.getPointDatas().get(0).getValue();
- if (v < 0) {
- v = 0;
- } else {
- v = v * info.getCoef();
- }
- byHour.setPjgl(v);
- }
- stationInfoHourService.saveOrUpdateBatch(byHours);
- }
- public void calcStationRfdlFj(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
- List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> dayMap = list.stream().collect(Collectors.toMap(TurbineInfoDay::getStationId, Function.identity()));
- List<StationInfoDay> byDate = getStationinfoByDate(time0);
- TurbineInfoDay tDay;
- for (StationInfoDay day : byDate) {
- tDay = dayMap.get(day.getStationId());
- day.setRfdlFj(tDay.getRfdl());
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }
- public void calcTurbineRFDL(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> entity = getEntity("AI121", "turbine");
- getZeroNextData(entity, time0, time);
- Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, String> fsMap = getEntityMap("AI066", "turbine");
- Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
- TurbineInfoDay infoDay;
- PointInfo rfdlPi;
- String turbineId;
- List<TurbineInfoDay> infoDays = new ArrayList<>();
- DoubleStatData stat;
- for (PointInfo info : entity) {
- turbineId = info.getTurbineId();
- infoDay = byDate.get(turbineId);
- rfdlPi = turMap.get(turbineId);
- double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
- if (v < 0 || v > 1000000) {
- v = 0;
- } else if (v > 30000) {
- v = v / (v % 30000 + 3);
- }
- infoDay.setRfdl(v);
- stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
- if (stat == null) {
- infoDay.setPjfs(0.0);
- } else {
- infoDay.setPjfs(stat.getAvg().getValue());
- }
- infoDays.add(infoDay);
- }
- turbineInfoDayService.saveOrUpdateBatch(infoDays);
- }
- /*public void calcTurbine5s(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- //状态
- List<PointInfo> entityZt = getEntity("MXZT", "turbine");
- //功率
- Map<String, String> collectGl = getEntityMap("AI114", "turbine");
- //风速
- Map<String, String> collectFs = getEntityMap("AI066", "turbine");
- Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityZt);
- String tbId;
- TurbineInfoDay infoDay;
- List<TurbineInfoDay> infoDays = new ArrayList<>();
- for (PointInfo info : entityZt) {
- tbId = info.getTurbineId();
- List<PointData> snapZt = adapter.getHistorySnap(taosUri(), info.getPointKey(), time0.getTime(), time.getTime(), 60);
- //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
- // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
- List<DoubleStatData> statGl = adapter.getHistoryStat2(goldenUri(), collectGl.get(tbId), time0.getTime(), time.getTime(), 60);
- List<DoubleStatData> statFs = adapter.getHistoryStat2(goldenUri(), collectFs.get(tbId), time0.getTime(), time.getTime(), 60);
- List<PointData> glList = statGl.stream().map(DoubleStatData::getAvg).collect(Collectors.toList());
- List<PointData> fsList = statFs.stream().map(DoubleStatData::getAvg)
- .peek(fs -> {
- if (fs.getValue() < 25) {
- fs.setDoubleValue(NumberUtil.round(fs.getValue(), 2).doubleValue());
- } else {
- fs.setDoubleValue(25.0);
- }
- }).collect(Collectors.toList());
- // Map<String, Double> loss = getTurbinePowerLoss(snapZt, fsList, tbId, glList);
- Map<String, Double> loss = new HashMap<>();
- infoDay = dayMap.get(tbId);
- infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
- infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
- infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
- infoDay.setSlss(0.0);
- if (infoDay.getRfdl() == 0) {
- infoDay.setXnss(0.0);
- } else {
- infoDay.setXnss(loss.get("xnss") * 0.1);
- }
- infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
- infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
- infoDays.add(infoDay);
- }
- turbineInfoDayService.saveOrUpdateBatch(infoDays);
- }*/
- //此处加公式
- public void calcStationSspjfs() {
- List<PointInfo> fsEntity = getEntity("AI066", "turbine");
- String keys = pointInfos2Keys(fsEntity);
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
- Map<String, List<String>> listMap = fsEntity.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.mapping(PointInfo::getPointKey, Collectors.toList())));
- Map<String, String> entityMap = getEntityMap("SSPJFS", "station");
- List<PointData> tsData = new ArrayList<>();
- listMap.forEach((stId, keyList) -> {
- double v = keyList.stream().mapToDouble(key -> latest.get(key).getValue()).average().orElse(0.0);
- PointData data = new PointData();
- data.setTs(System.currentTimeMillis());
- data.setTagName(entityMap.get(stId));
- data.setDoubleValue(v);
- tsData.add(data);
- });
- adapter.writeHistoryBatch(taosUri(), tsData);
- }
- public void calcTurbine5s2(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- getSnapDataByEntity(entityFs, time0, time, 15);
- getSnapDataByEntity(entityGl, time0, time, 15);
- List<PointInfo> ztMapMap = calcTurbineZt(time0, time, entityFs, entityGl);
- Map<String, Map<String, PointInfo>> ztMapMapInfos = ztMapMap.stream().collect(
- Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
- List<TurbineInfoDay> infoDays = new ArrayList<>();
- Map<String, Map<String, List<PointData>>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
- Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
- ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
- //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
- // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
- TurbineInfoDay infoDay = dayMap.get(wtId);
- Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztMapMapInfos.get(stId).get(wtId), fsMapMap.get(stId).get(wtId), glMapMap.get(stId).get(wtId));
- infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
- infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
- infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
- infoDay.setSlss(0.0);
- infoDay.setDjss(loss.get("djss"));
- infoDay.setGzss(loss.get("gzss"));
- //if (infoDay.getRfdl() == 0) {
- // infoDay.setXnss(0.0);
- //} else {
- // infoDay.setXnss(loss.get("xnss"));
- //}
- infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
- infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
- infoDays.add(infoDay);
- }));
- turbineInfoDayService.saveOrUpdateBatch(infoDays);
- }
- public List<PointInfo> calcTurbineZt(Date start, Date end, List<PointInfo> fsInfos, List<PointInfo> glInfos) {
- List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
- List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
- turbineZt.addAll(turbineAizt);
- Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- getSnapDataByEntity(entityAgc, start, end, 15);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- getSnapDataByEntity(entityCx, start, end, 15);
- //叶轮转速给定
- List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
- getSnapDataByEntity(entityYlzsgd, start, end, 15);
- Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, Map<String, List<PointData>>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
- Map<String, Map<String, PointInfo>> fsMapMap = fsInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- Map<String, Map<String, List<PointData>>> glMapMap = glInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
- Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
- ztMapMap.forEach((stId, ztMap) -> {
- PointInfo agcInfo = collectAgc.get(stId);
- PointInfo cxInfo = collectCx.get(stId);
- Map<String, PointInfo> fsMap = fsMapMap.get(stId);
- Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
- ztMap.forEach((wtId, zt) -> {
- List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0
- : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- fsMap.get(wtId).setPointDatas(peek);
- List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
- Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
- return new PointData(pd.getTs(), v == null ? 0 : v);
- }).collect(Collectors.toList());
- pdsZsglMap.put(wtId, zsglSnap);
- });
- List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
- agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
- agc.setLongValue(0L);
- }).collect(Collectors.toList());
- agcInfo.setPointDatas(agcc);
- List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
- cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
- cx.setLongValue(0L);
- }).collect(Collectors.toList());
- cxInfo.setPointDatas(cxc);
- //风机风速、功率->场站风速、功率
- // List<PointData> firstFs = new ArrayList<>();
- // List<PointData> firstGl = new ArrayList<>();
- List<PointData> firstZsgl = new ArrayList<>();
- double v1, v2, v3;
- for (int i = 0; i < agcInfo.getPointDatas().size(); i++) {
- int finalI = i;
- long ts = start.getTime() + i * 15000L;
- // v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
- // v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
- v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
- // firstFs.add(new PointData(ts, v1));
- // firstGl.add(new PointData(ts, v2));
- firstZsgl.add(new PointData(ts, v3));
- }
- List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
- String ybj = "GJNY_SXGS_XZ_F_WT_0013_EQ,GJNY_SXGS_XZ_F_WT_0023_EQ,GJNY_SXGS_XZ_F_WT_0027_EQ,GJNY_SXGS_XZ_F_WT_0034_EQ,GJNY_SXGS_XZ_F_WT_0044_EQ,GJNY_SXGS_XZ_F_WT_0060_EQ,GJNY_SXGS_XZ_F_WT_0062_EQ,GJNY_SXGS_FSG_F_WT_0005_EQ,GJNY_SXGS_FSG_F_WT_0006_EQ,GJNY_SXGS_FSG_F_WT_0038_EQ,GJNY_SXGS_FSG_F_WT_0039_EQ,GJNY_SXGS_ZZ_F_WT_0008_EQ,GJNY_SXGS_ZZ_F_WT_0015_EQ,GJNY_SXGS_ZZ_F_WT_0022_EQ,GJNY_SXGS_ZZ_F_WT_0046_EQ,GJNY_SXGS_ZZ_F_WT_0049_EQ,GJNY_SXGS_CSL_F_WT_0003_EQ,GJNY_SXGS_CSL_F_WT_0012_EQ,GJNY_SXGS_CSL_F_WT_0023_EQ,GJNY_SXGS_JSL_F_WT_0002_EQ,GJNY_SXGS_JSL_F_WT_0003_EQ,GJNY_SXGS_JSL_F_WT_0028_EQ,GJNY_SXGS_JSL_F_WT_0047_EQ,GJNY_SXGS_JSL_F_WT_0070_EQ,GJNY_SXGS_JSL_F_WT_0094_EQ,GJNY_SXGS_LJS_F_WT_0002_EQ,GJNY_SXGS_LJS_F_WT_0011_EQ,GJNY_SXGS_LJS_F_WT_0030_EQ,GJNY_SXGS_LJS_F_WT_0033_EQ";
- ztMap.forEach((wtId, ztInfo) -> {
- if (ybj.contains(wtId)) return;
- List<PointData> fss = fsMap.get(wtId).getPointDatas();
- List<PointData> gls = glMapMap.get(stId).get(wtId);
- //叶轮转速给定
- List<PointData> ylzsgds = collectYlzsgd.get(stId).get(wtId);
- calcTurbineXd(ztInfo, gls, fss, ylzsgds, czxd);
- });
- });
- return turbineZt;
- }
- public List<PointData> calcTurbineSimpleZt(Date start, Date end, Integer interval, String tbId) {
- List<PointInfo> turbineZt = calcTurbineDizt(start, end, interval, tbId);
- List<PointInfo> turbineAizt = calcTurbineAizt(start, end, interval, tbId);
- turbineZt.addAll(turbineAizt);
- Map<String, List<PointData>> collect = turbineZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
- return collect.get(tbId);//.stream().map(PointData::getValue).collect(Collectors.toList());
- }
- public void calcTurbineXd(PointInfo ztInfo, List<PointData> gls, List<PointData> fss, List<PointData> ylzsgds, List<PointData> czxd) {
- Map<String, EquipmentModel> map = equipmentModelService.map();
- Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
- List<PointData> zts = ztInfo.getPointDatas();
- for (int i = 0; i < fss.size(); i++) {
- double ssgl = gls.get(i).getValue();
- double ssfs = fss.get(i).getValue();
- double ylzsgd = ylzsgds.get(i).getValue();
- if (czxd.get(i).isBooleanValue() && ssgl < capacity * 0.9) {
- if (ssfs >= 12) {
- zts.get(i).setDoubleValue(8.0);
- }
- if (ylzsgd != 0 && ylzsgd < 17.3) {//降出力
- zts.get(i).setDoubleValue(8.0);
- }
- }
- }
- }
- //此处加公式
- public List<PointData> calcStationXd2(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
- String stId = agcInfo.getStationId();
- List<PointData> agcSnap = agcInfo.getPointDatas();
- List<PointData> zsgl5s = get5Avg(zsglSnap);
- List<PointData> agc5s = get5Avg(agcSnap);
- List<PointData> cx5s = get5Avg(cxSnap);
- //场站限电
- List<PointData> czxd = zsglSnap.stream().map(s -> new PointData(s.getTs(), 0.0)).collect(Collectors.toList());
- //之前是否限电
- boolean iszqxd = false;
- for (int i = 0; i < zsglSnap.size(); i++) {
- boolean isxd = false;
- double zsgl = zsglSnap.get(i).getValue();
- double zsgl5 = zsgl5s.get(i).getValue();
- double agc = agcSnap.get(i).getValue();
- double agc5 = agc5s.get(i).getValue();
- double cxgl = cxSnap.get(i).getValue();
- double cxgl5 = cx5s.get(i).getValue();
- boolean k; //agc一直不变
- //第一次初始化复制实时数据到缓存
- if (CalcCache.powerCache.get(stId) == null || CalcCache.powerCache.get(stId) != agc) {
- CalcCache.powerCache.put(stId, agc);
- k = false;
- } else {
- k = true;
- }
- if (agc != 0) {
- //如果场站限电状态为不限电
- if (zsgl5 >= agcInfo.getSpare2() * 40) {
- if (agc5 <= cxgl5) {
- isxd = true;
- } else if (iszqxd) {
- if (zsgl / agc > 1.15) {
- isxd = true;
- } else if (zsgl > agc && agc5 - cxgl5 < 400) {
- isxd = true;
- }
- } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
- isxd = true;
- }
- } else if (k) {
- if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
- isxd = true;
- }
- }
- }
- czxd.get(i).setBooleanValue(isxd);
- iszqxd = isxd;
- }
- return czxd;
- }
- private List<PointData> get5Avg(List<PointData> pointData) {
- List<PointData> result = new ArrayList<>();
- for (int i = 0; i < pointData.size(); i++) {
- PointData data = new PointData();
- data.setTs(pointData.get(i).getTs());
- double v;
- if (i > 4) {
- v = (pointData.get(i).getValue() + pointData.get(i - 1).getValue() + pointData.get(i - 2).getValue() + pointData.get(i - 3).getValue() + pointData.get(i - 4).getValue()) / 5;
- } else {
- v = pointData.get(i).getValue();
- }
- data.setDoubleValue(v);
- result.add(data);
- }
- return result;
- }
- public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval) {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- List<StateAi> list = stateAiService.list();
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- getSnapDataByEntity(entityAiZt, start, end, interval);
- for (PointInfo info : entityAiZt) {
- List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
- Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
- if (m == null) m = 2;
- pd.setDoubleValue(Double.valueOf(m));
- }).collect(Collectors.toList());
- info.setPointDatas(peek);
- }
- return entityAiZt;
- }
- public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval, String tbId) {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- entityAiZt = entityAiZt.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- List<StateAi> list = stateAiService.list();
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- getSnapDataByEntity(entityAiZt, start, end, interval);
- for (PointInfo info : entityAiZt) {
- List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
- Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
- if (m == null) m = 2;
- pd.setDoubleValue(Double.valueOf(m));
- }).collect(Collectors.toList());
- info.setPointDatas(peek);
- }
- return entityAiZt;
- }
- public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval) {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- map.forEach((uc, pi) -> {
- List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
- List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
- pi.setPointDatas(ds);
- ThreadUtil.sleep(5);
- });
- List<PointData> mx000 = map.get("MX000").getPointDatas();
- PointData data0;
- for (int i = 0; i < mx000.size(); i++) {
- data0 = mx000.get(i);
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(1.0);
- } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(2.0);
- } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(4.0);
- } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(6.0);
- } else {
- // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
- data0.setDoubleValue(2.0);
- }
- }
- map.get("MX001").setPointDatas(null);
- map.get("MX002").setPointDatas(null);
- map.get("MX004").setPointDatas(null);
- map.get("MX006").setPointDatas(null);
- });
- return entity0;
- }
- public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval, String tbId) {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity0 = entity0.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- entity1 = entity1.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- entity2 = entity2.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- entity4 = entity4.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- entity6 = entity6.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- map.forEach((uc, pi) -> {
- List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
- List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
- pi.setPointDatas(ds);
- ThreadUtil.sleep(5);
- });
- List<PointData> mx000 = map.get("MX000").getPointDatas();
- PointData data0;
- for (int i = 0; i < mx000.size(); i++) {
- data0 = mx000.get(i);
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(1.0);
- } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(2.0);
- } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(4.0);
- } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(6.0);
- } else {
- // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
- data0.setDoubleValue(2.0);
- }
- }
- map.get("MX001").setPointDatas(null);
- map.get("MX002").setPointDatas(null);
- map.get("MX004").setPointDatas(null);
- map.get("MX006").setPointDatas(null);
- });
- return entity0;
- }
- public PointInfo calcTurbineAizt2(PointInfo entityAiZt, Map<String, Map<Integer, Integer>> collectAi, Date start, Date end, int interval) {
- if (entityAiZt == null) return null;
- getSnapDataByEntity(entityAiZt, start, end, interval);
- Map<Integer, Integer> integerMap = collectAi.get(entityAiZt.getSpare());
- List<PointData> data = entityAiZt.getPointDatas().stream().peek(pd -> {
- Integer m = integerMap.get((int) pd.getValue());
- if (m == null) m = 2;
- pd.setDoubleValue(Double.valueOf(m));
- }).collect(Collectors.toList());
- entityAiZt.setPointDatas(data);
- return entityAiZt;
- }
- public PointInfo calcTurbineDizt2(Map<String, PointInfo> wtucpi, Map<String, PointData> latest, Date start, Date end, int interval) {
- if (wtucpi == null) return null;
- wtucpi.forEach((uc, pi) -> {
- List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
- List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
- pi.setPointDatas(ds);
- ThreadUtil.sleep(5);
- });
- PointInfo mx000 = wtucpi.get("MX000");
- PointData data0;
- for (int i = 0; i < mx000.getPointDatas().size(); i++) {
- data0 = mx000.getPointDatas().get(i);
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- } else if (wtucpi.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(1.0);
- } else if (wtucpi.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(2.0);
- } else if (wtucpi.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(4.0);
- } else if (wtucpi.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
- data0.setDoubleValue(6.0);
- } else {
- System.out.println(mx000.getTurbineId() + data0.getTs() + ":di无对应状态!");
- data0.setDoubleValue(2.0);
- }
- }
- wtucpi.get("MX001").setPointDatas(null);
- wtucpi.get("MX002").setPointDatas(null);
- wtucpi.get("MX004").setPointDatas(null);
- wtucpi.get("MX006").setPointDatas(null);
- return mx000;
- }
- public List<PointData> boolPointDatasFull(boolean v, List<PointData> data, long startTime, long endTime, int interval) {
- int j = 0, m = 0;
- List<PointData> data2 = new ArrayList<>();
- for (long i = startTime; i <= endTime; i += interval * 1000L) {
- PointData dt = new PointData();
- dt.setTs(i);
- data2.add(dt);
- //超出范围
- if (j >= data.size() - 1) continue;
- if (i < data.get(j).getTs()) {
- if (m == 0) {
- dt.setBooleanValue(v);
- } else {
- dt.setBooleanValue(data.get(j - 1).isBooleanValue());
- }
- } else {
- dt.setBooleanValue(data.get(j).isBooleanValue());
- j++;
- m++;
- }
- }
- return data2;
- }
- public List<PointData> doublePointDatasFull(double v, List<PointData> data, long startTime, long endTime, int interval) {
- int j = 0, m = 0;
- List<PointData> data2 = new ArrayList<>();
- for (long i = startTime; i <= endTime; i += interval * 1000L) {
- PointData dt = new PointData();
- dt.setTs(i);
- data2.add(dt);
- //超出范围
- if (j >= data.size() - 1) continue;
- if (i < data.get(j).getTs()) {
- if (m == 0) {
- dt.setDoubleValue(v);
- } else {
- dt.setDoubleValue(data.get(j - 1).getValue());
- }
- } else {
- dt.setDoubleValue(data.get(j).getValue());
- j++;
- m++;
- }
- }
- return data2;
- }
- public void calcGlqxnh(Date start, Date end) {
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, EquipmentModel> map = equipmentModelService.map();
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- List<StateAi> list = stateAiService.list();
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
- // entityFs = entityFs.stream().filter(ef -> !CalcCache.keys.contains(ef.getTurbineId())).collect(Collectors.toList());
- for (PointInfo ef : entityFs) {
- String wtId = ef.getTurbineId();
- PointInfo glInfo = glMap.get(wtId);
- getSnapDataByEntity(ef, start, end, 60);
- getSnapDataByEntity(glInfo, start, end, 60);
- List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- ef.setPointDatas(peek);
- PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
- PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
- Map<Double, Double> fit = new TreeMap<>();
- if (turbineZt != null) {
- double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineZt.setPointDatas(null);
- }
- if (turbineAizt != null) {
- double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineAizt.setPointDatas(null);
- }
- ef.setPointDatas(null);
- glInfo.setPointDatas(null);
- String key = "glqxnh:" + (end.getMonth() + 1) + ":" + wtId;
- stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
- CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
- }
- System.out.println("苹果天涯");
- // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
- }
- public void calcGlqxnhSurplus(Date start, Date end) {
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, EquipmentModel> map = equipmentModelService.map();
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- List<StateAi> list = stateAiService.list();
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
- entityFs = entityFs.stream().filter(ef -> !CalcCache.already.contains(ef.getTurbineId())).collect(Collectors.toList());
- for (PointInfo ef : entityFs) {
- String wtId = ef.getTurbineId();
- PointInfo glInfo = glMap.get(wtId);
- getSnapDataByEntity(ef, start, end, 60);
- getSnapDataByEntity(glInfo, start, end, 60);
- List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- ef.setPointDatas(peek);
- PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
- PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
- Map<Double, Double> fit = new TreeMap<>();
- if (turbineZt != null) {
- double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineZt.setPointDatas(null);
- }
- if (turbineAizt != null) {
- double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineAizt.setPointDatas(null);
- }
- ef.setPointDatas(null);
- glInfo.setPointDatas(null);
- String key = "glqxnh:" + end.getMonth() + ":" + wtId;
- stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
- CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
- }
- System.out.println("苹果天涯");
- // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
- }
- public Map<Double, Double> dataProcessAndFit(PointInfo fsPI, PointInfo glPI, PointInfo ztPI, Map<Double, Double> modelPowerMap, double capacity) {
- System.out.println("开始拟合");
- List<PointData> fsPds = fsPI.getPointDatas();
- List<PointData> glPds = glPI.getPointDatas();
- glPds = glPds.stream().peek(gl -> gl.setDoubleValue(gl.getValue() * glPI.getCoef())).collect(Collectors.toList());
- List<PointData> ztPds = ztPI.getPointDatas();
- WeightedObservedPoints points = new WeightedObservedPoints();
- if (ztPds.size() - glPds.size() == 1) ztPds.remove(glPds.size());
- //数据过滤 0正常,1过滤掉
- if (fsPds.size() != glPds.size() || glPds.size() != ztPds.size()) return new HashMap<>();
- Double bzv;
- for (int i = 0; i < ztPds.size(); i++) {
- double fs = fsPds.get(i).getValue();
- double gl = glPds.get(i).getValue();
- // 过滤非并网值 风机状态不等于2
- if (ztPds.get(i).getValue() != 2.0) {
- //
- } else if (fs < 0 || fs > 25 || gl < 0 || gl > capacity * 1.05) {// 按给定风速功率过滤
- //
- } else {
- bzv = modelPowerMap.get(fs);
- if (bzv == null || bzv == 0.0) {
- points.add(fs, gl);
- continue;
- }
- double k = gl / bzv; //功率曲线偏差: 保证功率/实际功率 k:偏差百分比
- if (k < 0.61 || k > 1.25) {
- //
- } else {
- points.add(fs, gl);
- }
- }
- }
- Map<Double, Double> glyc = new TreeMap<>();
- PolynomialCurveFitter fitter = PolynomialCurveFitter.create(4);
- try {
- double[] result = fitter.fit(points.toList());
- double min = calcMin(result);
- System.out.println(ztPI.getTurbineId());
- System.out.println(ztPI.getSpare());
- System.out.println(min);
- double[] max = calcMax(result);
- if (min == 0 || max[0] == 0 || max[1] == 0) {
- System.out.println();
- }
- System.out.println(max[0] + "," + max[1]);
- double ru;
- for (double i = 0; i < 25; i += 0.01) {
- i = NumberUtil.round(i, 2).doubleValue();
- if (i < 3) {
- ru = 0.0;
- } else if (i < min) {
- ru = modelPowerMap.get(i);
- } else if (i < max[0]) {
- ru = calcPoly(i, result);
- } else {
- ru = max[1];
- }
- glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
- }
- } catch (Exception e) {
- System.out.println(ztPI.getTurbineId());
- System.out.println(ztPI.getSpare());
- System.out.println(e.getMessage());
- }
- System.out.println("拟合完成" + glyc);
- return glyc;
- }
- public double calcMin(double[] coef) {
- double minX = 0, minY = 9000;
- for (double x = 0; x < 8; x += 0.01) {
- double y = calcPoly(x, coef);
- if (y < minY) {
- minY = y;
- minX = x;
- }
- }
- return minX;
- }
- public double[] calcMax(double[] coef) {
- double[] a = new double[2];
- for (double x = 8; x < 16; x += 0.01) {
- double y = calcPoly(x, coef);
- if (y > a[1]) {
- a[0] = x;
- a[1] = y;
- }
- }
- return a;
- }
- public void printResult(double[] r, double accuracy) {
- for (double index = 0; index < 25; index += accuracy) {
- System.out.println("[" + index + "," + calcPoly(index, r) + "],");
- }
- }
- public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end) {
- String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> section0 = adapter.getHistorySection(uri, collect, start.getTime());
- Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
- for (PointInfo entity : entitys) {
- List<PointData> list = new ArrayList<>();
- PointData p0 = section0.get(entity.getPointKey());
- PointData p1 = section1.get(entity.getPointKey());
- if (p0 != null && p1 != null) {
- list.add(p0);
- list.add(p1);
- }
- entity.setPointDatas(list);
- }
- }
- public Map<String, PointInfo> getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end, Function<PointInfo, String> function) {
- getSectionDataByEntity(entitys, uri, start, end);
- return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
- }
- public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date end) {
- String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
- for (PointInfo entity : entitys) {
- entity.setPointDatas(new ArrayList<>());
- entity.getPointDatas().add(section1.get(entity.getPointKey()));
- }
- }
- public Map<String, PointInfo> getSnapDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end, int interval, Function<PointInfo, String> function) {
- getSnapDataByEntity(entitys, uri, start, end, interval);
- return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
- }
- private Map<String, PointInfo> getLatestByEntity(List<PointInfo> entitys, URI uri, Function<PointInfo, String> function) {
- getLatestByEntity(entitys, uri);
- return entitys.stream().collect(Collectors.toMap(function, Function.identity()));
- }
- public void getLatestByEntity(List<PointInfo> entity, URI uri) {
- String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getLatest(uri, collect);
- entity.forEach(e -> {
- e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
- });
- }
- public void getLatestByEntity(List<PointInfo> entity) {
- getLatestByEntity(entity, goldenUri());
- }
- public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
- for (PointInfo info : entity) {
- getSnapDataByEntity(info, uri, start, end, interval);
- ThreadUtil.sleep(5);
- }
- }
- public void getSnapDataByEntity(PointInfo entity, URI uri, Date start, Date end, int interval) {
- List<PointData> snap = adapter.getHistorySnap(uri, entity.getPointKey(), start.getTime(), end.getTime(), interval);
- entity.setPointDatas(snap);
- }
- public void getSnapDataByEntity(List<PointInfo> entity, Date start, Date end, int interval) {
- getSnapDataByEntity(entity, goldenUri(), start, end, interval);
- }
- public void getSnapDataByEntity(PointInfo entity, Date start, Date end, int interval) {
- getSnapDataByEntity(entity, goldenUri(), start, end, interval);
- }
- public double calcPoly(String wtId, double value) {
- return CalcCache.fitcoef.get(wtId).get(value);
- }
- public double calcPoly(double x, double[] factor) {
- double y = 0;
- for (int deg = 0; deg < factor.length; deg++) {
- y += Math.pow(x, deg) * factor[deg];
- }
- return y;
- }
- //切入切出风速
- public void cutInWindSpeed() {
- //date当天零点
- DateTime timeNow00 = DateUtil.beginOfDay(new Date());
- //date昨天零点
- DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
- //上个月
- DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
- //上个月第一天
- DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
- //上个月最后一天
- DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
- //上个月天数
- int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
- //遍历天数
- for (int i = 1; i <= days; i++) {
- DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
- DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
- List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
- List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
- turbineZt.addAll(turbineZtDI);
- //所有风机的风速测点
- QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("uniform_code", "AI066");
- List<PointInfo> pointInfos = getEntity("AI066", "turbine");
- // List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
- //定义切入风速map集合
- ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
- //定义切出风速集合
- ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
- //插入集合
- List<TurbineInfoDay> interest = new ArrayList<>();
- //更新集合
- List<TurbineInfoDay> update = new ArrayList<>();
- //遍历每台风机,取出每台风机的pointDatas
- for (PointInfo turbine : turbineZt) {
- mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
- mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
- List<PointData> pointDatas = turbine.getPointDatas();
- //风速测点key
- String windSpeedKey = null;
- //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
- for (PointInfo info : pointInfos) {
- if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
- windSpeedKey = info.getPointKey();
- }
- }
- //遍历pointDatas,取出当前状态和后一个状态
- for (int k = 1; k < pointDatas.size(); k++) {
- PointData pointData1 = pointDatas.get(k - 1);
- PointData pointData2 = pointDatas.get(k);
- double value1 = pointData1.getValue();
- double value2 = pointData2.getValue();
- //切入时间
- long ts1;
- //切出时间
- long ts2;
- //如果1的值为0,2的值为2,则为切入状态
- if (value1 == 0 && value2 == 2) {
- ts1 = pointData2.getTs();
- // String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
- // System.out.println(turbine.getTurbineId() + "切入" + stringDate);
- //切入时间前5分钟
- long ts11 = ts1 - 300000;
- //根据风速key,从适配器取切入前5分钟的所有风速
- List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
- //平均所有风速即为平均切入风速
- double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
- // System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
- //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
- mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
- }
- //切出
- if (value1 == 2 && value2 != 2) {
- ts2 = pointData2.getTs();
- String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
- // System.out.println(turbine.getTurbineId() + "切出" + stringDate);
- //切出时间前5分钟
- long ts22 = ts2 - 300000;
- List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
- double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
- // System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
- //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
- mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
- }
- }
- //遍历map集合,取出每个风机的所有切入风速,算一个平均值
- ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
- //平均切入风速
- double avgCutInWindSpeed = 0;
- if (mapTurbineValues != null) {
- AtomicReference<Double> sum = new AtomicReference<>(0.0);
- //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
- for (String key : mapTurbineValues.keySet()) {
- if (mapTurbineValues.get(key) > 5) {
- mapTurbineValues.remove(key);
- }
- }
- mapTurbineValues.forEach((k1, v) -> {
- sum.updateAndGet(v1 -> v1 + v);
- });
- //如果值为空则置0
- if (sum.get() == 0) {
- avgCutInWindSpeed = 0;
- } else {
- avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
- }
- System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
- }
- //遍历map集合,取出每个风机的所有切出风速,算一个平均值
- ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
- double avgCutOutWindSpeed;
- if (mapTurbineValues2 != null) {
- AtomicReference<Double> sum = new AtomicReference<>(0.0);
- for (String key : mapTurbineValues2.keySet()) {
- if (mapTurbineValues2.get(key) > 5) {
- mapTurbineValues2.remove(key);
- }
- }
- mapTurbineValues2.forEach((k2, v) -> {
- sum.updateAndGet(v1 -> v1 + v);
- });
- if (sum.get() == 0) {
- avgCutOutWindSpeed = 0;
- } else {
- avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
- }
- System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
- }
- //存入数据库
- String turbineId = turbine.getTurbineId();
- Date jdkDate = timeBegin;
- System.out.println(turbineId + " " + jdkDate);
- QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
- turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
- turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
- TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
- System.out.println(one);
- if (one == null) {
- TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
- turbineInfoDay.setTurbineId(turbine.getTurbineId());
- turbineInfoDay.setRecordDate(timeBegin);
- turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
- System.out.println(turbineInfoDay);
- interest.add(turbineInfoDay);
- // turbineInfoDayService.save(turbineInfoDay);
- } else {
- one.setXfqrfs(avgCutInWindSpeed);
- System.out.println(one);
- // turbineInfoDayService.updateById(one);
- update.add(one);
- }
- }
- // //批量插入
- // turbineInfoDayService.saveBatch(interest);
- // //批量更新
- // turbineInfoDayService.updateBatchById(update);
- // //批量插入或更新
- turbineInfoDayService.saveOrUpdateBatch(interest);
- turbineInfoDayService.saveOrUpdateBatch(update);
- }
- }
- //算额定风速
- public void calcGlqxnh_edfs() {
- //date当天零点
- DateTime timeNow00 = DateUtil.beginOfDay(new Date());
- //date昨天零点
- DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
- //上个月
- DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
- //上个月第一天
- DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
- //上个月最后一天
- DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
- //上个月天数
- int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
- //遍历天数
- for (int i = 1; i <= days; i++) {
- DateTime end = DateUtil.offsetDay(timeBegin1, i);
- DateTime start = DateUtil.offsetDay(timeBegin1, i - 1);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, EquipmentModel> map = equipmentModelService.map();
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- List<StateAi> list = stateAiService.list();
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
- //插入集合
- List<TurbineInfoDay> interest = new ArrayList<>();
- //更新集合
- List<TurbineInfoDay> update = new ArrayList<>();
- for (PointInfo ef : entityFs) {
- String wtId = ef.getTurbineId();
- PointInfo glInfo = glMap.get(wtId);
- getSnapDataByEntity(ef, start, end, 60);
- getSnapDataByEntity(glInfo, start, end, 60);
- List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- ef.setPointDatas(peek);
- try {
- PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
- PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
- Map<Double, Double> fit = new TreeMap<>();
- double capacity = 2000;
- if (turbineZt != null) {
- System.out.println("数据处理拟合");
- capacity = map.get(turbineZt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineZt.setPointDatas(null);
- }
- if (turbineAizt != null) {
- System.out.println("数据处理拟合");
- capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
- fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
- // fitMap.put(wtId, fit);
- turbineAizt.setPointDatas(null);
- }
- ef.setPointDatas(null);
- glInfo.setPointDatas(null);
- //存redis
- // stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
- System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
- //符合条件的风速和
- List<Double> listDouble = new ArrayList<>();
- //遍历fit集合,取出值与capacity相等的key
- if (!fit.isEmpty()) {
- for (double key : fit.keySet()) {
- Double v = fit.get(key);
- //如果v-capacity的值小于10大于-10,则把key加入listDouble
- if ((Math.abs(v - capacity) <= 10) && Math.abs(v - capacity) >= -10) {
- listDouble.add(key);
- }
- }
- }
- //取出listDouble的值求平均值
- double agValue = 0;
- if (!listDouble.isEmpty()) {
- for (Double aDouble : listDouble) {
- agValue += aDouble;
- }
- agValue = agValue / listDouble.size();
- }
- System.out.println("wtId:" + wtId + "agValue平均额定风速:" + agValue);
- //存入数据库
- System.out.println(wtId + " " + start);
- QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
- turbineInfoDayQueryWrapper.eq("turbine_id", wtId);
- turbineInfoDayQueryWrapper.eq("record_date", start);
- TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
- System.out.println(one);
- if (one == null) {
- TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
- turbineInfoDay.setTurbineId(wtId);
- turbineInfoDay.setRecordDate(start);
- turbineInfoDay.setEdfs(agValue);
- System.out.println(turbineInfoDay);
- // turbineInfoDayService.save(turbineInfoDay);
- interest.add(turbineInfoDay);
- } else {
- one.setEdfs(agValue);
- System.out.println(one);
- // turbineInfoDayService.updateById(one);
- update.add(one);
- }
- } catch (Exception e) {
- System.out.println(wtId + " " + start);
- }
- }
- // //批量插入
- // turbineInfoDayService.saveBatch(interest);
- // //批量更新
- // turbineInfoDayService.updateBatchById(update);
- // //批量插入或更新
- turbineInfoDayService.saveOrUpdateBatch(interest);
- turbineInfoDayService.saveOrUpdateBatch(update);
- }
- // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
- }
- //环境温度
- public void ambientTemperature() {
- //date当天零点
- DateTime timeNow = DateUtil.beginOfDay(new Date());
- //date昨天零点
- DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
- //所有风机的温度
- QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("uniform_code", "AI072");
- List<PointInfo> pointInfos = getEntity("AI072", "turbine");
- //插入集合
- List<TurbineInfoDay> interest = new ArrayList<>();
- //更新集合
- List<TurbineInfoDay> update = new ArrayList<>();
- //遍历pointInfos
- for (PointInfo turbine : pointInfos) {
- List<PointData> pointDatas = adapter.getHistorySnap(goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
- //遍历pointDatas,取出数据算平均值
- double avgCutInWindSpeed = 0;
- for (PointData pointData : pointDatas) {
- avgCutInWindSpeed += pointData.getValue();
- }
- avgCutInWindSpeed /= pointDatas.size();
- //存入数据库
- String turbineId = turbine.getTurbineId();
- Date jdkDate = timeBegin;
- System.out.println(turbineId + " " + jdkDate);
- QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
- turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
- turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
- TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
- System.out.println(one);
- if (one == null) {
- TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
- turbineInfoDay.setTurbineId(turbine.getTurbineId());
- turbineInfoDay.setRecordDate(timeBegin);
- turbineInfoDay.setHjwd(avgCutInWindSpeed);
- System.out.println(turbineInfoDay);
- interest.add(turbineInfoDay);
- // turbineInfoDayService.save(turbineInfoDay);
- } else {
- one.setHjwd(avgCutInWindSpeed);
- System.out.println(one);
- update.add(one);
- // turbineInfoDayService.updateById(one);
- }
- }
- // //批量插入
- // turbineInfoDayService.saveBatch(interest);
- // //批量更新
- // turbineInfoDayService.updateBatchById(update);
- // //批量插入或更新
- turbineInfoDayService.saveOrUpdateBatch(interest);
- turbineInfoDayService.saveOrUpdateBatch(update);
- }
- public void writeReportPool(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", time0);
- List<StationInfoDay> days = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfMonth, time0).groupBy("station_id");
- List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfYear, time0).groupBy("station_id");
- List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- // wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
- // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(StationInfoDay::getStationId).collect(Collectors.toList()));
- List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
- if (!pools.isEmpty()) {
- StationInfoDay day, month, year;
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- for (ProEconReportIndicatorPool pool : pools) {
- String stationId = pool.getForeignKeyId();
- day = dayMap.get(stationId);
- pool.setRfdldb(day.getRfdl().doubleValue());
- pool.setRswdldb(day.getSwdl().doubleValue());
- pool.setRgwgwdldb(day.getGwdl().doubleValue());
- pool.setRfdcydldb(day.getCydl().doubleValue());
- pool.setRzhcydldb(day.getZhcydl().doubleValue());
- month = monthMap.get(stationId);
- pool.setYfdldb(month.getRfdl().doubleValue());
- pool.setYswdldb(month.getSwdl().doubleValue());
- pool.setYgwgwdldb(month.getGwdl().doubleValue());
- pool.setYfdcydldb(month.getCydl().doubleValue());
- pool.setYzhcydldb(month.getZhcydl().doubleValue());
- year = yearMap.get(stationId);
- pool.setNfdldb(year.getRfdl().doubleValue());
- pool.setNswdldb(year.getSwdl().doubleValue());
- pool.setNgwgwdldb(year.getGwdl().doubleValue());
- pool.setNfdcydldb(year.getCydl().doubleValue());
- pool.setNzhcydldb(year.getZhcydl().doubleValue());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- } else {
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- for (StationInfoDay day : days) {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(day.getStationId());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- }
- }
- public void writeReportPoolSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", time0);
- List<StationInfoDay> days = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfMonth, time0).groupBy("station_id");
- List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfYear, time0).groupBy("station_id");
- List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
- Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
- QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
- List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
- wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
- StationInfoDay day, month, year;
- if (pools.isEmpty()) {
- pools = new ArrayList<>();
- for (StationInfoDay infoDay : days) {
- String stationId = infoDay.getStationId();
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(stationId);
- pool.setWindpowerstationId(stationId);
- month = monthMap.get(stationId);
- year = yearMap.get(stationId);
- poolSetValueDl1(pool, infoDay, month, year);
- pools.add(pool);
- }
- } else {
- for (ProEconReportIndicatorPool pool : pools) {
- String stationId = pool.getWindpowerstationId();
- day = dayMap.get(stationId);
- month = monthMap.get(stationId);
- year = yearMap.get(stationId);
- poolSetValueDl1(pool, day, month, year);
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(pools);
- if (poolsCompany == null) {
- poolsCompany = new ProEconReportIndicatorPool();
- poolsCompany.setRecordDate(time0);
- poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
- poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
- poolSetValueDl(poolsCompany, pools);
- } else {
- poolSetValueDl(poolsCompany, pools);
- }
- reportIndicatorPoolService.saveOrUpdate(poolsCompany);
- }
- public void poolSetValueDl1(ProEconReportIndicatorPool pool, StationInfoDay day, StationInfoDay month, StationInfoDay year) {
- pool.setRfdldb(day.getRfdl().doubleValue());
- pool.setRswdldb(day.getSwdl().doubleValue());
- pool.setRgwgwdldb(day.getGwdl().doubleValue());
- pool.setRfdcydldb(day.getCydl().doubleValue());
- pool.setRzhcydldb(day.getZhcydl().doubleValue());
- pool.setYfdldb(month.getRfdl().doubleValue());
- pool.setYswdldb(month.getSwdl().doubleValue());
- pool.setYgwgwdldb(month.getGwdl().doubleValue());
- pool.setYfdcydldb(month.getCydl().doubleValue());
- pool.setYzhcydldb(month.getZhcydl().doubleValue());
- pool.setNfdldb(year.getRfdl().doubleValue());
- pool.setNswdldb(year.getSwdl().doubleValue());
- pool.setNgwgwdldb(year.getGwdl().doubleValue());
- pool.setNfdcydldb(year.getCydl().doubleValue());
- pool.setNzhcydldb(year.getZhcydl().doubleValue());
- }
- public void poolSetValueDl(ProEconReportIndicatorPool pool, LineInfoDay day, LineInfoDay month, LineInfoDay year) {
- pool.setRfdldb(day.getRfdl().doubleValue());
- pool.setRswdldb(day.getSwdl());
- pool.setRgwgwdldb(day.getGwdl());
- pool.setRfdcydldb(day.getCydl());
- pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
- pool.setYfdldb(month.getRfdl().doubleValue());
- pool.setYswdldb(month.getSwdl());
- pool.setYgwgwdldb(month.getGwdl());
- pool.setYfdcydldb(month.getCydl());
- pool.setYzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
- pool.setNfdldb(year.getRfdl().doubleValue());
- pool.setNswdldb(year.getSwdl());
- pool.setNgwgwdldb(year.getGwdl());
- pool.setNfdcydldb(year.getCydl());
- pool.setNzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
- }
- public void poolSetValueDl(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
- ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
- pool.setRfdldb(p.getRfdldb());
- pool.setRswdldb(p.getRswdldb());
- pool.setRgwgwdldb(p.getRgwgwdldb());
- pool.setRfdcydldb(p.getRfdcydldb());
- pool.setRzhcydldb(p.getRzhcydldb());
- pool.setYfdldb(p.getYfdldb());
- pool.setYswdldb(p.getYswdldb());
- pool.setYgwgwdldb(p.getYgwgwdldb());
- pool.setYfdcydldb(p.getYfdcydldb());
- pool.setYzhcydldb(p.getYzhcydldb());
- pool.setNfdldb(p.getNfdldb());
- pool.setNswdldb(p.getNswdldb());
- pool.setNgwgwdldb(p.getNgwgwdldb());
- pool.setNfdcydldb(p.getNfdcydldb());
- pool.setNzhcydldb(p.getNzhcydldb());
- }
- public void writeReportPoolProject(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").eq("record_date", time0).groupBy("project_id");
- List<LineInfoDay> days = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
- List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
- List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
- // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
- wrapperrp2.eq("record_date", time0).in("foreign_key_id", days.stream().map(LineInfoDay::getProjectId).collect(Collectors.toList()));
- List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp2);
- if (!pools2.isEmpty()) {
- LineInfoDay day, month, year;
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- String projectId;
- for (ProEconReportIndicatorPool pool : pools2) {
- projectId = pool.getForeignKeyId();
- day = dayMap.get(projectId);
- pool.setRfdldb(day.getRfdl().doubleValue());
- pool.setRswdldb(day.getSwdl());
- pool.setRgwgwdldb(day.getGwdl());
- pool.setRfdcydldb(day.getCydl());
- pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
- month = monthMap.get(projectId);
- pool.setYfdldb(month.getRfdl().doubleValue());
- pool.setYswdldb(month.getSwdl());
- pool.setYgwgwdldb(month.getGwdl());
- pool.setYfdcydldb(month.getCydl());
- pool.setRzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
- year = yearMap.get(projectId);
- pool.setNfdldb(year.getRfdl().doubleValue());
- pool.setNswdldb(year.getSwdl());
- pool.setNgwgwdldb(year.getGwdl());
- pool.setNfdcydldb(year.getCydl());
- pool.setRzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- } else {
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- for (LineInfoDay day : days) {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(day.getProjectId());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- }
- }
- public void writeReportPoolProjectSameDay() {
- //date当天零点
- DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").eq("record_date", time0).groupBy("project_id,station_id");
- List<LineInfoDay> days = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
- List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
- List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
- Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
- QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
- List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
- LineInfoDay day, month, year;
- if (pools.isEmpty()) {
- pools = new ArrayList<>();
- for (LineInfoDay infoDay : days) {
- String projectId = infoDay.getProjectId();
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(projectId);
- pool.setWindpowerstationId(infoDay.getStationId());
- pool.setProjectId(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- poolSetValueDl(pool, infoDay, month, year);
- pools.add(pool);
- }
- } else {
- for (ProEconReportIndicatorPool pool : pools) {
- String projectId = pool.getProjectId();
- day = dayMap.get(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- poolSetValueDl(pool, day, month, year);
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(pools);
- }
- public void writeReportPoolPjfs(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id").eq("record_date", time0).groupBy("project_id");
- List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
- List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
- List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
- List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
- wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
- if (pools2 == null) {
- ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
- GSPJFS.setRecordDate(time0);
- GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
- GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
- reportIndicatorPoolService.saveOrUpdate(GSPJFS);
- }
- TurbineInfoDay day, month, year;
- String projectId;
- if (!pools.isEmpty()) {
- for (ProEconReportIndicatorPool pool : pools) {
- projectId = pool.getForeignKeyId();
- day = dayMap.get(projectId);
- pool.setRpjfs(day.getPjfs());
- month = monthMap.get(projectId);
- pool.setYpjfs(month.getPjfs());
- year = yearMap.get(projectId);
- pool.setNpjfs(year.getPjfs());
- }
- double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
- double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
- double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
- if (!(pools2 == null)) {
- pools2.setRpjfs(v1);
- pools2.setYpjfs(v2);
- pools2.setNpjfs(v3);
- reportIndicatorPoolService.saveOrUpdate(pools2);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(pools);
- } else {
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- for (TurbineInfoDay day2 : days) {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(day2.getProjectId());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- }
- }
- public void gongsizhibiao(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<ProEconReportIndicatorPool> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", time0)
- //包含"STA"
- .like("foreign_key_id", "_STA");
- List<ProEconReportIndicatorPool> list = reportIndicatorPoolService.list(wrapper);
- //遍历list,累加指标RFDL
- //公司指标,日发电量
- double rfdl = 0;
- //公司指标,日上网电量
- double swdl = 0;
- //公司指标,日购网电量
- double gwdl = 0;
- //公司指标,日综合厂用电量
- double zhcydl = 0;
- //公司指标,月发电量
- double yfdl = 0;
- //公司指标,月上网电量
- double yswdl = 0;
- //公司指标,月购网电量
- double ygwdl = 0;
- //公司指标,月综合厂用电量
- double yzhcydl = 0;
- //公司指标,年发电量
- double nfdl = 0;
- //公司指标,年上网电量
- double nswdl = 0;
- //公司指标,年购网电量
- double ngwdl = 0;
- //公司指标,年综合厂用电量
- double nzhcydl = 0;
- for (ProEconReportIndicatorPool pool : list) {
- rfdl += pool.getRfdldb();
- swdl += pool.getRswdldb();
- gwdl += pool.getRgwgwdldb();
- zhcydl += pool.getRzhcydldb();
- yfdl += pool.getYfdldb();
- yswdl += pool.getYswdldb();
- ygwdl += pool.getYgwgwdldb();
- yzhcydl += pool.getYzhcydldb();
- nfdl += pool.getNfdldb();
- nswdl += pool.getNswdldb();
- ngwdl += pool.getNgwgwdldb();
- nzhcydl += pool.getNzhcydldb();
- }
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
- wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool GSZB = reportIndicatorPoolService.getOne(wrapperrp2);
- //公司指标集合
- GSZB.setRfdldb(rfdl);
- GSZB.setRswdldb(swdl);
- GSZB.setRgwgwdldb(gwdl);
- GSZB.setRzhcydldb(zhcydl);
- GSZB.setYfdldb(yfdl);
- GSZB.setYswdldb(yswdl);
- GSZB.setYgwgwdldb(ygwdl);
- GSZB.setYzhcydldb(yzhcydl);
- GSZB.setNfdldb(nfdl);
- GSZB.setNswdldb(nswdl);
- GSZB.setNgwgwdldb(ngwdl);
- GSZB.setNzhcydldb(nzhcydl);
- reportIndicatorPoolService.saveOrUpdate(GSZB);
- }
- //公司指标,累加风机理论发电量
- public void writeReportPoolLLFDL(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("avg(llfdl) llfdl,project_id").eq("record_date", time0).groupBy("project_id");
- List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
- List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
- List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
- wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
- List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
- QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
- wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
- if (pools2 == null) {
- ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
- GSPJFS.setRecordDate(time0);
- GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
- GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
- reportIndicatorPoolService.saveOrUpdate(GSPJFS);
- }
- TurbineInfoDay day, month, year;
- String projectId;
- if (!pools.isEmpty()) {
- for (ProEconReportIndicatorPool pool : pools) {
- projectId = pool.getForeignKeyId();
- day = dayMap.get(projectId);
- pool.setRllfdl(day.getLlfdl());
- month = monthMap.get(projectId);
- pool.setYllfdl(month.getLlfdl());
- year = yearMap.get(projectId);
- pool.setNllfdl(year.getLlfdl());
- }
- double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl).sum();
- double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYllfdl).sum();
- double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNllfdl).sum();
- //pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl),求和
- if (pools2 != null) {
- pools2.setRllfdl(v1);
- pools2.setYllfdl(v2);
- pools2.setNllfdl(v3);
- reportIndicatorPoolService.saveOrUpdate(pools2);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(pools);
- } else {
- List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
- for (TurbineInfoDay day2 : days) {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(day2.getProjectId());
- poolList.add(pool);
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolList);
- }
- }
- public void calcRealtimeTurbineZt() {
- DateTime date0 = DateUtil.date();
- boolean isOnMin = false;
- //分钟变化
- if (CalcCache.minuteNow.minute() != date0.minute()) {
- date0 = DateUtil.beginOfMinute(date0);
- CalcCache.minuteNow = date0;
- isOnMin = true;
- }
- DateTime date = date0;
- List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
- List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
- turbineZt.addAll(turbineAizt);
- turbineZt = turbineZt.stream().peek(t -> {
- if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= date.getTime()) {
- t.getPointDatas().get(0).setDoubleValue(12.0);
- }
- }).collect(Collectors.toList());
- Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- getSnapDataByEntity(entityAgc, DateUtil.offsetMinute(date, -5), date, 15);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- getSnapDataByEntity(entityCx, DateUtil.offsetMinute(date, -5), date, 15);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- getSnapDataByEntity(entityFs, DateUtil.offsetMinute(date, -5), date, 15);
- Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- getLatestByEntity(entityGl);
- Map<String, List<PointData>> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
- List<PointInfo> entityCzxd = getEntity("AGC009", "booster");
- Map<String, PointData> xdPdMap = new HashMap<>();
- for (PointInfo info : entityCzxd) {
- PointData pd = new PointData();
- pd.setTagName(info.getPointKey());
- xdPdMap.put(info.getStationId(), pd);
- }
- ztMapMap.forEach((stId, ztMap) -> {
- PointInfo agcInfo = collectAgc.get(stId);
- PointInfo cxInfo = collectCx.get(stId);
- Map<String, PointInfo> fsMap = fsMapMap.get(stId);
- Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
- ztMap.forEach((wtId, zt) -> {
- List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- fsMap.get(wtId).setPointDatas(peek);
- List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
- Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
- return new PointData(pd.getTs(), v == null ? 0 : v);
- }).collect(Collectors.toList());
- pdsZsglMap.put(wtId, zsglSnap);
- });
- List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
- agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
- agc.setLongValue(0L);
- }).collect(Collectors.toList());
- agcInfo.setPointDatas(agcc);
- List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
- cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
- cx.setLongValue(0L);
- }).collect(Collectors.toList());
- cxInfo.setPointDatas(cxc);
- //风机风速、功率->场站风速、功率
- List<PointData> firstZsgl = new ArrayList<>();
- double v3;
- for (int i = 0; i < 20; i++) {
- int finalI = i;
- long ts = date.getTime() + i * 15000;
- v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
- firstZsgl.add(new PointData(ts, v3));
- }
- boolean czxd = calcRealtimeStationXd(agcInfo, cxInfo.getPointDatas(), firstZsgl);
- xdPdMap.get(stId).setBooleanValue(czxd);
- if (czxd) {
- //叶轮转速给定
- List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
- getLatestByEntity(entityYlzsgd);
- Map<String, List<PointData>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
- String ybj = "GJNY_SXGS_XZ_F_WT_0013_EQ,GJNY_SXGS_XZ_F_WT_0023_EQ,GJNY_SXGS_XZ_F_WT_0027_EQ,GJNY_SXGS_XZ_F_WT_0034_EQ,GJNY_SXGS_XZ_F_WT_0044_EQ,GJNY_SXGS_XZ_F_WT_0060_EQ,GJNY_SXGS_XZ_F_WT_0062_EQ,GJNY_SXGS_FSG_F_WT_0005_EQ,GJNY_SXGS_FSG_F_WT_0006_EQ,GJNY_SXGS_FSG_F_WT_0038_EQ,GJNY_SXGS_FSG_F_WT_0039_EQ,GJNY_SXGS_ZZ_F_WT_0008_EQ,GJNY_SXGS_ZZ_F_WT_0015_EQ,GJNY_SXGS_ZZ_F_WT_0022_EQ,GJNY_SXGS_ZZ_F_WT_0046_EQ,GJNY_SXGS_ZZ_F_WT_0049_EQ,GJNY_SXGS_CSL_F_WT_0003_EQ,GJNY_SXGS_CSL_F_WT_0012_EQ,GJNY_SXGS_CSL_F_WT_0023_EQ,GJNY_SXGS_JSL_F_WT_0002_EQ,GJNY_SXGS_JSL_F_WT_0003_EQ,GJNY_SXGS_JSL_F_WT_0028_EQ,GJNY_SXGS_JSL_F_WT_0047_EQ,GJNY_SXGS_JSL_F_WT_0070_EQ,GJNY_SXGS_JSL_F_WT_0094_EQ,GJNY_SXGS_LJS_F_WT_0002_EQ,GJNY_SXGS_LJS_F_WT_0011_EQ,GJNY_SXGS_LJS_F_WT_0030_EQ,GJNY_SXGS_LJS_F_WT_0033_EQ";
- ztMap.forEach((wtId, ztInfo) -> {
- if (ybj.contains(wtId)) return;
- List<PointData> fss = fsMap.get(wtId).getPointDatas();
- List<PointData> gls = glMap.get(wtId);
- List<PointData> zsgls = pdsZsglMap.get(wtId);
- //叶轮转速给定
- List<PointData> ylzsgds = collectYlzsgd.get(wtId);
- calcRealtimeTurbineXd(ztInfo, gls.get(0), fss.get(fss.size() - 1), ylzsgds.get(0), zsgls.get(zsgls.size() - 1));
- });
- }
- });
- Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
- Map<String, String> entityQfzt = getEntityMap("SSQFZT", "turbine");
- List<PointData> qfztDataList = entityFs.stream().map(qfzt -> {
- String wtId = qfzt.getTurbineId();
- PointData data = qfzt.getPointDatas().get(qfzt.getPointDatas().size() - 1);
- data.setTs(date.getTime());
- data.setTagName(entityQfzt.get(wtId));
- data.setDoubleValue(calcQfzt(glMap.get(wtId).get(0).getValue(), CalcCache.fitcoef.get(wtId).get(data.getValue())));
- return data;
- }).collect(Collectors.toList());
- //风机状态转换为写适配器的测点与值
- List<PointData> dataList = turbineZt.stream().map(zt -> {
- PointData data = zt.getPointDatas().get(0);
- data.setTs(date.getTime());
- data.setTagName(entityMxzt.get(zt.getTurbineId()));
- return data;
- }).collect(Collectors.toList());
- if (isOnMin) {
- List<PointData> czztDatas = xdPdMap.values().stream().peek(pd -> pd.setTs(date.getTime())).collect(Collectors.toList());
- adapter.writeHistoryBatch(taosUri(), czztDatas);
- adapter.writeHistoryBatch(taosUri(), dataList);
- adapter.writeHistoryBatch(taosUri(), qfztDataList);
- } else {
- List<PointData> collect = dataList.stream().filter(d -> {
- if (Objects.equals(CalcCache.statusCache.get(d.getTagName()), d.getValue())) {
- return false;
- } else {
- CalcCache.statusCache.put(d.getTagName(), d.getValue());
- return true;
- }
- }).collect(Collectors.toList());
- List<PointData> qfztDatas = qfztDataList.stream().filter(d -> {
- if (Objects.equals(CalcCache.qfztCache.get(d.getTagName()), d.getValue())) {
- return false;
- } else {
- CalcCache.qfztCache.put(d.getTagName(), d.getValue());
- return true;
- }
- }).collect(Collectors.toList());
- adapter.writeHistoryBatch(taosUri(), collect);
- adapter.writeHistoryBatch(taosUri(), qfztDatas);
- }
- }
- //此处加公式
- public Map<String, Double> calcRealtimeTurbineZt(String stId) {
- List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
- List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
- turbineZt.addAll(turbineAizt);
- Map<String, Double> collect = turbineZt.stream().filter(zt -> zt.getStationId().equals(stId)).peek(t -> {
- if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= DateUtil.date().getTime()) {
- t.getPointDatas().get(0).setDoubleValue(12.0);
- }
- }).collect(Collectors.toMap(PointInfo::getTurbineId, pi -> pi.getPointDatas().get(0).getValue()));
- return collect;
- }
- public void calcStationMinZtts(Date time, String stId) {
- Map<Double, Long> map = calcSectionStationZtts(time, stId);
- StationInfoMin byMin = getStationinfoByMinOne(time, stId);
- //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
- byMin.setDjts(map.get(0.0));
- byMin.setYxts(map.get(2.0));
- byMin.setGzts(map.get(4.0));
- byMin.setJxts(map.get(6.0));
- stationInfoMinService.saveOrUpdate(byMin);
- }
- public Map<Double, Long> calcSectionZtts(Date time, String stId, Function<PointInfo, String> fun) {
- Map<Double, Long> diztTs = calcSectionDiztTs(time, stId, fun);
- Map<Double, Long> aiztTs = calcSectionAiztTs(time, stId, fun);
- if (diztTs.isEmpty()) {
- return aiztTs;
- } else if (aiztTs.isEmpty()) {
- return diztTs;
- } else if (diztTs.size() > aiztTs.size()) {
- diztTs.forEach((k, v) -> {
- long l = aiztTs.getOrDefault(k, 0L);
- if (v == null) v = 0L;
- v = v + l;
- });
- return diztTs;
- } else {
- aiztTs.forEach((k, v) -> {
- long l = diztTs.getOrDefault(k, 0L);
- if (v == null) v = 0L;
- v = v + l;
- });
- return aiztTs;
- }
- }
- public Map<Double, Long> calcSectionStationZtts(Date time, String stId) {
- Map<Double, Long> diztTs = calcSectionStationDiztTs(time, stId);
- Map<Double, Long> aiztTs = calcSectionStationAiztTs(time, stId);
- if (diztTs.isEmpty()) {
- return aiztTs;
- } else if (aiztTs.isEmpty()) {
- return diztTs;
- } else if (diztTs.size() > aiztTs.size()) {
- diztTs.forEach((k, v) -> {
- long l = aiztTs.getOrDefault(k, 0L);
- if (v == null) v = 0L;
- v = v + l;
- });
- return diztTs;
- } else {
- aiztTs.forEach((k, v) -> {
- long l = diztTs.getOrDefault(k, 0L);
- if (v == null) v = 0L;
- v = v + l;
- });
- return aiztTs;
- }
- }
- // 计算每种状态的总持续时间
- public void calcTurbineStateMin(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> entityMxzt = getEntity("MXZT", "turbine");
- getRawDataByEntity(entityMxzt, taosUri(), time0, time);
- Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entityMxzt);
- for (PointInfo info : entityMxzt) {
- TurbineInfoDay infoDay = byDate.get(info.getTurbineId());
- Map<String, Map<Double, Long>> dlmm = calcStateDurationFrequency(info.getPointDatas());
- Map<Double, Long> durations = dlmm.get("duration");
- Map<Double, Long> frequency = dlmm.get("frequency");
- infoDay.setDjMin(durations.getOrDefault(0.0, 0L) / 60000.0);
- infoDay.setTjMin(durations.getOrDefault(1.0, 0L) / 60000.0);
- infoDay.setYxMin(durations.getOrDefault(2.0, 0L) / 60000.0);
- infoDay.setGzMin(durations.getOrDefault(4.0, 0L) / 60000.0);
- infoDay.setJxMin(durations.getOrDefault(6.0, 0L) / 60000.0);
- infoDay.setXdMin(durations.getOrDefault(8.0, 0L) / 60000.0);
- infoDay.setLxMin(durations.getOrDefault(12.0, 0L) / 60000.0);
- }
- turbineInfoDayService.saveOrUpdateBatch(byDate.values());
- }
- public Map<String, Map<Double, Long>> calcStateDurationFrequency(List<PointData> datas) {
- if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
- Map<Double, Long> durations = new HashMap<>();
- Map<Double, Long> frequency = new HashMap<>();
- Map<String, Map<Double, Long>> dlmm = new HashMap<>();
- double prevState = datas.get(0).getValue(); // 初始状态
- long prevTs = datas.get(0).getTs(); // 初始时间戳
- PointData current;
- double currentState;
- long currentTs;
- for (int i = 1; i < datas.size(); i++) {
- current = datas.get(i);
- currentState = current.getValue();
- currentTs = current.getTs();
- if (currentState != prevState) {
- // 当状态变化时,计算前一个状态的持续时间并更新map
- durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
- frequency.put(prevState, frequency.getOrDefault(prevState, 0L) + 1);
- prevState = currentState;
- prevTs = currentTs;
- }
- }
- // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
- durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
- dlmm.put("duration", durations);
- dlmm.put("frequency", frequency);
- return dlmm;
- }
- public Map<Double, Long> calculateStateDurations(List<PointData> datas) {
- if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
- Map<Double, Long> durations = new HashMap<>();
- double prevState = datas.get(0).getValue(); // 初始状态
- long prevTs = datas.get(0).getTs(); // 初始时间戳
- PointData current;
- double currentState;
- long currentTs;
- for (int i = 1; i < datas.size(); i++) {
- current = datas.get(i);
- currentState = current.getValue();
- currentTs = current.getTs();
- if (currentState != prevState) {
- // 当状态变化时,计算前一个状态的持续时间并更新map
- durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
- prevState = currentState;
- prevTs = currentTs;
- }
- }
- // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
- durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
- return durations;
- }
- public void getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
- for (PointInfo info : entity) {
- List<PointData> snap = adapter.getHistoryRaw(uri, info.getPointKey(), start.getTime(), end.getTime());
- // ThreadUtil.sleep(5);
- info.setPointDatas(snap);
- }
- }
- public void getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
- for (PointInfo info : entity) {
- DoubleStatData stat = adapter.getHistoryStat(uri, info.getPointKey(), start.getTime(), end.getTime());
- ThreadUtil.sleep(5);
- info.setPointDatas(new ArrayList<>(3));
- if (stat != null) {
- info.getPointDatas().add(stat.getAvg());
- info.getPointDatas().add(stat.getMax());
- info.getPointDatas().add(stat.getMin());
- } else {
- info.getPointDatas().add(new PointData());
- info.getPointDatas().add(new PointData());
- info.getPointDatas().add(new PointData());
- }
- }
- }
- public Map<String, PointInfo> getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
- getStatDataByEntity(entity, uri, start, end);
- return entity.stream().collect(Collectors.toMap(function, Function.identity()));
- }
- public List<PointInfo> getLatest(String uniformCode, String institutionType) {
- List<PointInfo> entity = getEntity(uniformCode, institutionType);
- String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
- entity.forEach(e -> {
- e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
- });
- return entity;
- }
- public List<PointInfo> calcRealtimeTurbineDizt() {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> result = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- String collect = map.values().stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- PointInfo info2 = map.get("MX002");
- PointData data2 = latest.get(info2.getPointKey());
- if (data2.getValue() == 1.0) {
- data2.setDoubleValue(2.0);
- data2.setBooleanValue(false);
- info2.setPointDatas(Collections.singletonList(data2));
- result.add(info2);
- } else {
- PointInfo info0 = map.get("MX000");
- PointData data0 = latest.get(info0.getPointKey());
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- info0.setPointDatas(Collections.singletonList(data0));
- result.add(info0);
- } else {
- PointInfo info6 = map.get("MX006");
- PointData data6 = latest.get(info6.getPointKey());
- if (data6.getValue() == 1.0) {
- data6.setDoubleValue(6.0);
- data6.setBooleanValue(false);
- info6.setPointDatas(Collections.singletonList(data6));
- result.add(info6);
- } else {
- PointInfo info4 = map.get("MX004");
- PointData data4 = latest.get(info4.getPointKey());
- if (data4.getValue() == 1.0) {
- data4.setDoubleValue(4.0);
- data4.setBooleanValue(false);
- info4.setPointDatas(Collections.singletonList(data4));
- result.add(info4);
- } else {
- PointInfo info1 = map.get("MX001");
- PointData data1 = latest.get(info1.getPointKey());
- if (data1.getValue() == 1.0) {
- data1.setDoubleValue(1.0);
- data1.setBooleanValue(false);
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- } else {
- // Map<String, PointData> latest2 = adapter.getLatest(goldenUri(), collect);
- data1.setDoubleValue(2.0);
- System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- }
- }
- }
- }
- }
- });
- return result;
- }
- public Map<Double, Long> calcSectionStationDiztTs(Date time, String stId) {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> result = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- entity = entity.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
- if (CollUtil.isEmpty(entity)) return new HashMap<>();
- String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- PointInfo info2 = map.get("MX002");
- PointData data2 = latest.get(info2.getPointKey());
- if (data2.getValue() == 1.0) {
- data2.setDoubleValue(2.0);
- data2.setBooleanValue(false);
- info2.setPointDatas(Collections.singletonList(data2));
- result.add(info2);
- } else {
- PointInfo info0 = map.get("MX000");
- PointData data0 = latest.get(info0.getPointKey());
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- info0.setPointDatas(Collections.singletonList(data0));
- result.add(info0);
- } else {
- PointInfo info6 = map.get("MX006");
- PointData data6 = latest.get(info6.getPointKey());
- if (data6.getValue() == 1.0) {
- data6.setDoubleValue(6.0);
- data6.setBooleanValue(false);
- info6.setPointDatas(Collections.singletonList(data6));
- result.add(info6);
- } else {
- PointInfo info4 = map.get("MX004");
- PointData data4 = latest.get(info4.getPointKey());
- if (data4.getValue() == 1.0) {
- data4.setDoubleValue(4.0);
- data4.setBooleanValue(false);
- info4.setPointDatas(Collections.singletonList(data4));
- result.add(info4);
- } else {
- PointInfo info1 = map.get("MX001");
- PointData data1 = latest.get(info1.getPointKey());
- if (data1.getValue() == 1.0) {
- data1.setDoubleValue(1.0);
- data1.setBooleanValue(false);
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- } else {
- data1.setDoubleValue(2.0);
- System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- }
- }
- }
- }
- }
- });
- Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- return longMap;
- }
- public Map<Double, Long> calcSectionStationAiztTs(Date time, String stId) {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- entityAiZt = entityAiZt.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
- if (CollUtil.isEmpty(entityAiZt)) return new HashMap<>();
- List<StateAi> list = stateAiService.list();
- //机型,源状态,目标状态
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
- for (PointInfo info : entityAiZt) {
- PointData data = latest.get(info.getPointKey());
- Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
- if (m == null) {
- m = 2;
- System.out.println("ai状态未配对:" + data.getValue());
- }
- data.setDoubleValue(Double.valueOf(m));
- info.setPointDatas(Collections.singletonList(data));
- }
- Map<Double, Long> longMap = entityAiZt.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- return longMap;
- }
- public List<PointInfo> calcRealtimeTurbineAizt() {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- List<StateAi> list = stateAiService.list();
- //机型,源状态,目标状态
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
- for (PointInfo info : entityAiZt) {
- PointData data = latest.get(info.getPointKey());
- Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
- if (m == null) m = 2;
- data.setDoubleValue(Double.valueOf(m));
- info.setPointDatas(Collections.singletonList(data));
- }
- return entityAiZt;
- }
- public Map<Double, Long> calcSectionDiztTs(Date time, String id, Function<PointInfo, String> fun) {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> result = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- entity = entity.stream().filter(pi -> id.equals(fun.apply(pi))).collect(Collectors.toList());
- if (CollUtil.isEmpty(entity)) return new HashMap<>();
- String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- PointInfo info2 = map.get("MX002");
- PointData data2 = latest.get(info2.getPointKey());
- if (data2.getValue() == 1.0) {
- data2.setDoubleValue(2.0);
- data2.setBooleanValue(false);
- info2.setPointDatas(Collections.singletonList(data2));
- result.add(info2);
- } else {
- PointInfo info0 = map.get("MX000");
- PointData data0 = latest.get(info0.getPointKey());
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- info0.setPointDatas(Collections.singletonList(data0));
- result.add(info0);
- } else {
- PointInfo info6 = map.get("MX006");
- PointData data6 = latest.get(info6.getPointKey());
- if (data6.getValue() == 1.0) {
- data6.setDoubleValue(6.0);
- data6.setBooleanValue(false);
- info6.setPointDatas(Collections.singletonList(data6));
- result.add(info6);
- } else {
- PointInfo info4 = map.get("MX004");
- PointData data4 = latest.get(info4.getPointKey());
- if (data4.getValue() == 1.0) {
- data4.setDoubleValue(4.0);
- data4.setBooleanValue(false);
- info4.setPointDatas(Collections.singletonList(data4));
- result.add(info4);
- } else {
- PointInfo info1 = map.get("MX001");
- PointData data1 = latest.get(info1.getPointKey());
- if (data1.getValue() == 1.0) {
- data1.setDoubleValue(1.0);
- data1.setBooleanValue(false);
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- } else {
- System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
- data1.setDoubleValue(2.0);
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- }
- }
- }
- }
- }
- });
- Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- return longMap;
- }
- public Map<Double, Long> calcSectionAiztTs(Date time, String id, Function<PointInfo, String> fun) {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- entityAiZt = entityAiZt.stream().filter(pi -> id.equals(fun.apply(pi))).collect(Collectors.toList());
- if (CollUtil.isEmpty(entityAiZt)) return new HashMap<>();
- List<StateAi> list = stateAiService.list();
- //机型,源状态,目标状态
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
- for (PointInfo info : entityAiZt) {
- PointData data = latest.get(info.getPointKey());
- Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
- if (m == null) {
- m = 2;
- System.out.println("ai状态未配对:" + data.getValue());
- }
- data.setDoubleValue(Double.valueOf(m));
- info.setPointDatas(Collections.singletonList(data));
- }
- Map<Double, Long> longMap = entityAiZt.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- return longMap;
- }
- public void getAgoAvg(List<PointInfo> entity, Date start, Date end) {
- for (PointInfo info : entity) {
- DoubleStatData snap = adapter.getHistoryStat(goldenUri(), info.getPointKey(), start.getTime(), end.getTime());
- ThreadUtil.sleep(5);
- info.setPointDatas(Collections.singletonList(snap.getAvg()));
- }
- }
- public void calcRealtimeTurbineXd(PointInfo ztInfo, PointData gl, PointData fs, PointData ylzsgd, PointData zsgl) {
- Map<String, EquipmentModel> map = equipmentModelService.map();
- Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
- PointData zt = ztInfo.getPointDatas().get(0);
- if (gl.getValue() < capacity * 0.9) {
- if (fs.getValue() >= 12) {
- zt.setDoubleValue(8.0);
- }
- if (ylzsgd.getValue() != 0 && ylzsgd.getValue() < 17.3) {//降出力
- zt.setDoubleValue(8.0);
- }
- if (calcQfzt(gl.getValue(), zsgl.getValue()) >= 3) {
- zt.setDoubleValue(8.0);
- }
- }
- }
- //此处加公式
- public boolean calcRealtimeStationXd(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
- String stId = agcInfo.getStationId();
- List<PointData> agcSnap = agcInfo.getPointDatas();
- List<PointData> zsgl5s = get5Avg(zsglSnap);
- List<PointData> agc5s = get5Avg(agcSnap);
- List<PointData> cx5s = get5Avg(cxSnap);
- //之前是否限电
- boolean iszqxd = false;
- for (int i = 0; i < zsglSnap.size(); i++) {
- boolean isxd = false;
- double zsgl = zsglSnap.get(i).getValue();
- double zsgl5 = zsgl5s.get(i).getValue();
- double agc = agcSnap.get(i).getValue();
- double agc5 = agc5s.get(i).getValue();
- double cxgl = cxSnap.get(i).getValue();
- double cxgl5 = cx5s.get(i).getValue();
- boolean k; //agc一直不变
- //第一次初始化复制实时数据到缓存
- if (CalcCache.powerCacheRt.get(stId) == null || CalcCache.powerCacheRt.get(stId) != agc) {
- CalcCache.powerCacheRt.put(stId, agc);
- k = false;
- } else {
- k = true;
- }
- if (agc != 0) {
- //如果场站限电状态为不限电
- if (zsgl5 >= agcInfo.getSpare2() * 40) {
- if (agc5 <= cxgl5) {
- isxd = true;
- } else if (iszqxd) {
- if (zsgl / agc > 1.15) {
- isxd = true;
- } else if (zsgl > agc && agc5 - cxgl5 < 400) {
- isxd = true;
- }
- } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
- isxd = true;
- }
- } else if (k) {
- if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
- isxd = true;
- }
- }
- }
- iszqxd = isxd;
- }
- return iszqxd;
- }
- /*public void calcStationSwGwCyRdl(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
- List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
- List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
- getZeroNextData(swdlEt, time0, time);
- getZeroNextData(gwdlEt, time0, time);
- getZeroNextData(cydlEt, time0, time);
- Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
- String stId;
- PointInfo swdlPi, gwdlPi, cydlPi;
- for (StationInfoDay info : byDate) {
- stId = info.getStationId();
- swdlPi = swdlMap.get(stId);
- gwdlPi = gwdlMap.get(stId);
- cydlPi = cydlMap.get(stId);
- int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
- int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
- int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
- if (swdl < 0 || swdl > 1000000) swdl = 0;
- if (gwdl < 0 || gwdl > 1000000) gwdl = 0;
- if (cydl < 0 || cydl > 1000000) cydl = 0;
- info.setSwdl(swdl);
- info.setGwdl(gwdl);
- info.setCydl(cydl);
- }
- stationInfoDayService.saveOrUpdateBatch(byDate);
- }*/
- public void writeReportPool5SPjfsLlfdlZtsj(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
- "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
- "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
- .eq("record_date", time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
- "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
- "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
- .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
- "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
- "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
- .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
- List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
- wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
- List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
- wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
- TurbineInfoDay day, month, year;
- String projectId;
- if (poolsProject.isEmpty()) {
- for (TurbineInfoDay infoDay : days) {
- projectId = infoDay.getProjectId();
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(projectId);
- pool.setWindpowerstationId(infoDay.getStationId());
- pool.setProjectId(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- poolSetValue1(pool, infoDay, month, year);
- poolsProject.add(pool);
- }
- } else {
- for (ProEconReportIndicatorPool pool : poolsProject) {
- projectId = pool.getProjectId();
- day = dayMap.get(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- poolSetValue1(pool, day, month, year);
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
- Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
- if (poolsStation.isEmpty()) {
- projectMap.forEach((StId, pis) -> {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(StId);
- pool.setWindpowerstationId(StId);
- poolSetValue(pool, pis);
- poolsStation.add(pool);
- });
- } else {
- for (ProEconReportIndicatorPool pool : poolsStation) {
- List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
- poolSetValue(pool, pools);
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
- if (poolsCompany == null) {
- poolsCompany = new ProEconReportIndicatorPool();
- poolsCompany.setRecordDate(time0);
- poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
- poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
- poolSetValue(poolsCompany, poolsStation);
- } else {
- poolSetValue(poolsCompany, poolsStation);
- }
- reportIndicatorPoolService.saveOrUpdate(poolsCompany);
- }
- public void writeReportPoolPjfs2(Date date) {
- //date当天零点
- DateTime time = DateUtil.beginOfDay(date);
- //date昨天零点
- DateTime time0 = DateUtil.offsetDay(time, -1);
- DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
- DateTime beginOfYear = DateUtil.beginOfYear(time0);
- QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id,station_id")
- .eq("record_date", time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id,station_id")
- .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- wrapper = new QueryWrapper<>();
- wrapper.select("avg(pjfs) pjfs,project_id,station_id")
- .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
- List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
- Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
- QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
- List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
- wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
- List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
- wrapperRp = new QueryWrapper<>();
- wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
- ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
- TurbineInfoDay day, month, year;
- String projectId;
- if (poolsProject.isEmpty()) {
- for (TurbineInfoDay infoDay : days) {
- projectId = infoDay.getProjectId();
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(projectId);
- pool.setWindpowerstationId(infoDay.getStationId());
- pool.setProjectId(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- pool.setRpjfs(infoDay.getPjfs());
- pool.setYpjfs(month.getPjfs());
- pool.setNpjfs(year.getPjfs());
- poolsProject.add(pool);
- }
- } else {
- for (ProEconReportIndicatorPool pool : poolsProject) {
- projectId = pool.getProjectId();
- day = dayMap.get(projectId);
- month = monthMap.get(projectId);
- year = yearMap.get(projectId);
- pool.setRpjfs(day.getPjfs());
- pool.setYpjfs(month.getPjfs());
- pool.setNpjfs(year.getPjfs());
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
- Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
- if (poolsStation.isEmpty()) {
- projectMap.forEach((StId, pis) -> {
- ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
- pool.setRecordDate(time0);
- pool.setForeignKeyId(StId);
- pool.setWindpowerstationId(StId);
- ProEconReportIndicatorPool p = sumProperties(pis, ProEconReportIndicatorPool.class);
- pool.setRpjfs(p.getRpjfs() / pis.size());
- pool.setYpjfs(p.getYpjfs() / pis.size());
- pool.setNpjfs(p.getNpjfs() / pis.size());
- poolsStation.add(pool);
- });
- } else {
- for (ProEconReportIndicatorPool pool : poolsStation) {
- List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
- ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
- pool.setRpjfs(p.getRpjfs() / pools.size());
- pool.setYpjfs(p.getYpjfs() / pools.size());
- pool.setNpjfs(p.getNpjfs() / pools.size());
- }
- }
- reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
- if (poolsCompany == null) {
- poolsCompany = new ProEconReportIndicatorPool();
- poolsCompany.setRecordDate(time0);
- poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
- poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
- ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
- poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
- poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
- poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
- } else {
- ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
- poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
- poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
- poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
- }
- reportIndicatorPoolService.saveOrUpdate(poolsCompany);
- }
- public void poolSetValue1(ProEconReportIndicatorPool pool, TurbineInfoDay day, TurbineInfoDay month, TurbineInfoDay year) {
- pool.setRpjfs(day.getPjfs());
- pool.setRgzssdl(day.getGzss() == null ? day.getFjhjxss() * 0.11 : day.getGzss());
- pool.setRjxssdl(day.getJhjxss());
- pool.setRdjssdl(day.getDjss() == null ? day.getFjhjxss() * 0.89 : day.getDjss());
- pool.setRxnssdl(day.getXnss());
- pool.setRxdjclssdl(day.getXdss());
- pool.setRllfdl(day.getLlfdl());
- pool.setRhjdjxs(day.getDjMin() / 60);
- pool.setRhjgztjxs(day.getGzMin() / 60);
- pool.setRhjtxzdxs(day.getLxMin() / 60);
- pool.setRhjjxtjxs(day.getJxMin() / 60);
- pool.setRhjxdxs(day.getXdMin() / 60);
- pool.setRhjyxxs(day.getYxMin() / 60);
- pool.setRhjslxs(0.0);
- pool.setYpjfs(month.getPjfs());
- pool.setYgzssdl(month.getGzss() == null ? month.getFjhjxss() * 0.11 : month.getGzss());
- pool.setYjxssdl(month.getJhjxss());
- pool.setYdjssdl(month.getDjss() == null ? month.getFjhjxss() * 0.89 : month.getDjss());
- pool.setYxnssdl(month.getXnss());
- pool.setYxdjclssdl(month.getXdss());
- pool.setYllfdl(month.getLlfdl());
- pool.setYhjdjxs(month.getDjMin() / 60);
- pool.setYhjgztjxs(month.getGzMin() / 60);
- pool.setYhjtxzdxs(month.getLxMin() / 60);
- pool.setYhjjxtjxs(month.getJxMin() / 60);
- pool.setYhjxdxs(month.getXdMin() / 60);
- pool.setYhjyxxs(month.getYxMin() / 60);
- pool.setYhjslxs(0.0);
- pool.setNpjfs(year.getPjfs());
- pool.setNgzssdl(year.getGzss() == null ? year.getFjhjxss() * 0.11 : year.getGzss());
- pool.setNjxssdl(year.getJhjxss());
- pool.setNdjssdl(year.getDjss() == null ? year.getFjhjxss() * 0.89 : year.getDjss());
- pool.setNxnssdl(year.getXnss());
- pool.setNxdjclssdl(year.getXdss());
- pool.setNllfdl(year.getLlfdl());
- pool.setNhjdjxs(year.getDjMin() / 60);
- pool.setNhjgztjxs(year.getGzMin() / 60);
- pool.setNhjtxzdxs(year.getLxMin() / 60);
- pool.setNhjjxtjxs(year.getJxMin() / 60);
- pool.setNhjxdxs(year.getXdMin() / 60);
- pool.setNhjyxxs(year.getYxMin() / 60);
- pool.setNhjslxs(0.0);
- }
- public void poolSetValue(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
- ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
- pool.setRpjfs(p.getRpjfs() / pools.size());
- pool.setRgzssdl(p.getRgzssdl());
- pool.setRjxssdl(p.getRjxssdl());
- pool.setRdjssdl(p.getRdjssdl());
- pool.setRxnssdl(p.getRxnssdl());
- pool.setRxdjclssdl(p.getRxdjclssdl());
- pool.setRllfdl(p.getRllfdl());
- pool.setRhjdjxs(p.getRhjdjxs());
- pool.setRhjgztjxs(p.getRhjgztjxs());
- pool.setRhjtxzdxs(p.getRhjtxzdxs());
- pool.setRhjjxtjxs(p.getRhjjxtjxs());
- pool.setRhjxdxs(p.getRhjxdxs());
- pool.setRhjyxxs(p.getRhjyxxs());
- pool.setRhjslxs(0.0);
- pool.setYpjfs(p.getYpjfs() / pools.size());
- pool.setYgzssdl(p.getYgzssdl());
- pool.setYjxssdl(p.getYjxssdl());
- pool.setYdjssdl(p.getYdjssdl());
- pool.setYxnssdl(p.getYxnssdl());
- pool.setYxdjclssdl(p.getYxdjclssdl());
- pool.setYllfdl(p.getYllfdl());
- pool.setYhjdjxs(p.getYhjdjxs());
- pool.setYhjgztjxs(p.getYhjgztjxs());
- pool.setYhjtxzdxs(p.getYhjtxzdxs());
- pool.setYhjjxtjxs(p.getYhjjxtjxs());
- pool.setYhjxdxs(p.getYhjxdxs());
- pool.setYhjyxxs(p.getYhjyxxs());
- pool.setYhjslxs(0.0);
- pool.setNpjfs(p.getNpjfs() / pools.size());
- pool.setNgzssdl(p.getNgzssdl());
- pool.setNjxssdl(p.getNjxssdl());
- pool.setNdjssdl(p.getNdjssdl());
- pool.setNxnssdl(p.getNxnssdl());
- pool.setNxdjclssdl(p.getNxdjclssdl());
- pool.setNllfdl(p.getNllfdl());
- pool.setNhjdjxs(p.getNhjdjxs());
- pool.setNhjgztjxs(p.getNhjgztjxs());
- pool.setNhjtxzdxs(p.getNhjtxzdxs());
- pool.setNhjjxtjxs(p.getNhjjxtjxs());
- pool.setNhjxdxs(p.getNhjxdxs());
- pool.setNhjyxxs(p.getNhjyxxs());
- pool.setNhjslxs(0.0);
- }
- public <T> T sumProperties(List<T> list, Class<T> clazz) {
- T result;
- try {
- result = clazz.getDeclaredConstructor().newInstance();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- if (list == null || list.isEmpty()) return result;
- // 获取所有字段
- Field[] fields = clazz.getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true); // 确保私有字段也可以被访问
- // 检查字段类型是否为Double
- Class<?> type = field.getType();
- if (type.equals(Double.class) || type.equals(Integer.class) || type.equals(Long.class) || type.equals(Float.class)) {
- double sum = 0.0;
- // 遍历列表中的每个对象并累加数值字段
- try {
- for (T item : list) {
- Field itemField = clazz.getDeclaredField(field.getName());
- itemField.setAccessible(true);
- // 尝试获取当前对象的字段值
- Double value = (Double) itemField.get(item); // 注意类型转换
- if (value != null) sum += value;
- }
- // 设置累加后的值到结果对象中
- if (type.equals(Double.class)) {
- field.set(result, sum);
- } else if (type.equals(Integer.class)) {
- field.set(result, (int) sum);
- } else if (type.equals(Long.class)) {
- field.set(result, (long) sum);
- } else {
- field.set(result, (float) sum);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return result;
- }
- }
- }
- return result;
- }
- private ProEconReportIndicatorPool getPoolSum(List<ProEconReportIndicatorPool> pools) {
- ProEconReportIndicatorPool pool0 = new ProEconReportIndicatorPool();
- for (ProEconReportIndicatorPool pool : pools) {
- pool0.setRfdldb(nullSum(pool0.getRfdldb(), pool.getRfdldb()));
- pool0.setRswdldb(nullSum(pool0.getRswdldb(), pool.getRswdldb()));
- pool0.setRgwgwdldb(nullSum(pool0.getRgwgwdldb(), pool.getRgwgwdldb()));
- pool0.setRnwgwdldb(nullSum(pool0.getRnwgwdldb(), pool.getRnwgwdldb()));
- }
- return pool0;
- }
- public double nullSum(Double a, Double b) {
- if (a == null) a = 0.0;
- if (b == null) b = 0.0;
- return a + b;
- }
- public double calcQfzt(Double ssgl, Double zsgl) {
- if (ssgl == null || ssgl < 0) ssgl = 0.0;
- double qfzt, ratioll;
- ratioll = (zsgl == null || zsgl <= 0) ? 0 : (zsgl - ssgl) / zsgl;
- if (ratioll < 0.05) {
- qfzt = 0;
- } else if (ratioll < 0.1) {
- qfzt = 1;
- } else if (ratioll < 0.2) {
- qfzt = 2;
- } else if (ratioll < 0.4) {
- qfzt = 3;
- } else {
- qfzt = 4;
- }
- return qfzt;
- }
- public List<TurbineInfoMin> getTurbineinfoByMin(Date date) {
- QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
- wrapper.eq("record_date", date);
- return turbineInfoMinService.list(wrapper);
- }
- public List<TurbineInfoMin> getTurbineinfoByMin(Date date, List<PointInfo> entity) {
- List<TurbineInfoMin> list = getTurbineinfoByMin(date);
- if (list.isEmpty()) {
- entity.forEach(pi -> {
- TurbineInfoMin day = new TurbineInfoMin();
- day.setStationId(pi.getStationId());
- day.setProjectId(pi.getProjectId());
- day.setLineId(pi.getLineId());
- day.setTurbineId(pi.getTurbineId());
- day.setRecordDate(date);
- list.add(day);
- });
- }
- return list;
- }
- public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date) {
- List<TurbineInfoMin> tims = getTurbineinfoByMin(date);
- return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
- }
- public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date, List<PointInfo> entity) {
- List<TurbineInfoMin> tims = getTurbineinfoByMin(date, entity);
- return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
- }
- public Map<String, PointInfo> getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
- getRawDataByEntity(entity, uri, start, end);
- return entity.stream().collect(Collectors.toMap(function, Function.identity()));
- }
- public void calcTurbinePjfsPjglKyglLlglMin(Date time) {
- DateTime date = DateUtil.beginOfMinute(time);
- int i = Math.floorDiv(date.minute(), 15) * 15;
- date.setMinutes(i);
- DateTime start = DateUtil.offsetMinute(date, -15);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- Map<String, PointInfo> rawMapFs = getSnapDataByEntity(entityFs, goldenUri(), start, date, 15, PointInfo::getTurbineId);
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- Map<String, PointInfo> rawMapGl = getSnapDataByEntity(entityGl, goldenUri(), start, date, 15, PointInfo::getTurbineId);
- //状态
- List<PointInfo> entityZt = getEntity("MXZT", "turbine");
- Map<String, PointInfo> rawMapZt = getRawDataByEntity(entityZt, taosUri(), start, date, PointInfo::getTurbineId);
- //发电量
- List<PointInfo> entityFdl = getEntity("AI121", "turbine");
- getSectionDataByEntity(entityFdl, goldenUri(), start, date);
- List<TurbineInfoMin> mins = getTurbineinfoByMin(date, entityFs);
- for (TurbineInfoMin min : mins) {
- String tbId = min.getTurbineId();
- List<PointData> fsDatas = rawMapFs.get(tbId).getPointDatas();
- List<PointData> ztDatas = rawMapZt.get(tbId).getPointDatas();
- ztDatas = doublePointDatasFull(2, ztDatas, start.getTime() - 1000, date.getTime(), 1);
- Map<Long, Double> ztMap = ztDatas.stream().collect(Collectors.toMap(PointData::getTs, PointData::getValue));
- double pjfs = fsDatas.stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- fsDatas = fsDatas.stream().peek(pd -> pd.setDoubleValue(pd.getValue() >= 23 ? 23.0 : pd.getValue() < 0 ? 0 :
- NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- double llgl = fsDatas.stream().mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
- List<PointData> kyFsDatas = fsDatas.stream().filter(pd -> {
- if (ztMap.get(pd.getTs()) == null) System.out.println(pd.getTs());
- return ztMap.get(pd.getTs()) != 4 || ztMap.get(pd.getTs()) != 6;
- }).collect(Collectors.toList());
- double kygl = kyFsDatas.stream().mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
- double sjgl = rawMapGl.get(tbId).getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- if (kygl < sjgl) kygl = sjgl;
- if (llgl < sjgl) llgl = sjgl * 1.0005;
- min.setPjfs(pjfs);
- min.setPjgl(sjgl);
- min.setLlgl(llgl);
- min.setKygl(kygl);
- }
- turbineInfoMinService.saveOrUpdateBatch(mins);
- }
- public void calcStationRealtimeLLgl() {
- DateTime end = DateUtil.date();
- DateTime date = DateUtil.offsetMinute(end, -5);
- Map<String, String> sszllglMap = getEntityMap("SSZLLGL", "station");
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- getLatestByEntity(entityCx);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- getRawDataByEntity(entityFs, goldenUri(), date, end);
- for (PointInfo fsPi : entityFs) {
- List<PointData> pds = fsPi.getPointDatas();
- Double pd = pds.stream().mapToDouble(PointData::getValue).average().orElse(0);
- double fs = pd > 25 ? 24.99 : pd < 0 ? 0 : NumberUtil.round(pd, 2).doubleValue();
- double llgl = fs < 3 ? 0d : CalcCache.llgl.get(fsPi.getTurbineId()).get(fs);
- fsPi.setSpare2(llgl);
- }
- Map<String, List<PointInfo>> stPisMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- List<PointData> pds = new ArrayList<>();
- for (PointInfo cx : entityCx) {
- PointData pdCx = cx.getPointDatas().get(0);
- double sjgl = pdCx.getValue() * cx.getCoef();
- double llgl = stPisMap.get(cx.getStationId()).stream().mapToDouble(pi -> pi.getSpare2()).sum();
- if (pdCx.getTs() + 10 * 60 * 1000 > end.getTime()) {
- if (llgl < sjgl) llgl = sjgl * 1.0005;
- if (llgl > sjgl * 1.5) llgl = sjgl * 1.5;
- } else {
- System.out.println("实际功率测点离线");
- }
- PointData data = new PointData();
- data.setTs(System.currentTimeMillis());
- data.setTagName(sszllglMap.get(cx.getStationId()));
- data.setDoubleValue(llgl);
- pds.add(data);
- }
- adapter.writeHistoryBatch(taosUri(), pds);
- }
- public void calcTurbineSsfsQx(Date date) {
- DateTime date0 = DateUtil.beginOfDay(date);
- DateTime date1 = DateUtil.endOfDay(date);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- List<String> fjs = Arrays.asList("GJNY_SXGS_FSG_F_WT_0040_EQ", "GJNY_SXGS_FSG_F_WT_0047_EQ");
- entityFs = entityFs.stream().filter(e -> fjs.contains(e.getTurbineId())).collect(Collectors.toList());
- getSnapDataByEntity(entityFs, date0, date1, 60);
- int i = 0;
- for (PointInfo et : entityFs) {
- StrBuilder sb = new StrBuilder();
- StrBuilder sb1 = new StrBuilder();
- for (PointData v : et.getPointDatas()) {
- sb.append(v.getValue()).append(",");
- sb1.append(i).append(",");
- i++;
- }
- System.out.println(sb1);
- System.out.println(sb);
- }
- }
- public void calcStationLlglKyglSjglAgcMin(Date time) {
- DateTime date = DateUtil.beginOfMinute(time);
- int i = Math.floorDiv(date.minute(), 15) * 15;
- date.setMinutes(i);
- DateTime start = DateUtil.offsetMinute(date, -15);
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- Map<String, PointInfo> statMapAgc = getLatestByEntity(entityAgc, goldenUri(), PointInfo::getStationId);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- Map<String, PointInfo> statMapCx = getSnapDataByEntity(entityCx, goldenUri(), start, date, 15, PointInfo::getStationId);
- QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
- wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", date).groupBy("station_id");
- List<TurbineInfoMin> list = turbineInfoMinService.list(wrapper);
- Map<String, TurbineInfoMin> minMap = list.stream().collect(Collectors.toMap(TurbineInfoMin::getStationId, Function.identity()));
- List<StationInfoMin> byDate = getStationinfoByMin(date, entityAgc);
- for (StationInfoMin day : byDate) {
- String stId = day.getStationId();
- TurbineInfoMin min = minMap.get(stId);
- PointInfo agcInfo = statMapAgc.get(stId);
- PointInfo cxInfo = statMapCx.get(stId);
- double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0);
- double pjgl = cxgl * cxInfo.getCoef();
- day.setKygl(Math.max(min.getKygl(), pjgl));
- double llgl = min.getLlgl();
- if (llgl < pjgl) llgl = pjgl * 1.0005;
- day.setLlgl(llgl);
- day.setAgc(agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef());
- day.setPjgl(pjgl);
- day.setPjfs(min.getPjfs());
- }
- stationInfoMinService.saveOrUpdateBatch(byDate);
- }
- public Map<String, Map<Double, Long>> calcSectionStationZtts(Date time) {
- List<PointInfo> diztTs = calcSectionStationDiztTs(time);
- List<PointInfo> aiztTs = calcSectionStationAiztTs(time);
- diztTs.addAll(aiztTs);
- Map<String, Map<Double, Long>> sdlMap = new HashMap<>();
- //Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- Map<String, List<PointInfo>> collect = diztTs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- for (Map.Entry<String, List<PointInfo>> entry : collect.entrySet()) {
- Map<Double, Long> map = entry.getValue().stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
- sdlMap.put(entry.getKey(), map);
- }
- return sdlMap;
- }
- public List<PointInfo> calcSectionStationDiztTs(Date time) {
- List<PointInfo> entity = new ArrayList<>();
- List<PointInfo> result = new ArrayList<>();
- List<PointInfo> entity0 = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("MX001", "state");
- List<PointInfo> entity2 = getEntity("MX002", "state");
- List<PointInfo> entity4 = getEntity("MX004", "state");
- List<PointInfo> entity6 = getEntity("MX006", "state");
- entity.addAll(entity0);
- entity.addAll(entity1);
- entity.addAll(entity2);
- entity.addAll(entity4);
- entity.addAll(entity6);
- String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
- Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
- wtUcPis.forEach((wtId, map) -> {
- PointInfo info2 = map.get("MX002");
- PointData data2 = latest.get(info2.getPointKey());
- if (data2.getValue() == 1.0) {
- data2.setDoubleValue(2.0);
- data2.setBooleanValue(false);
- info2.setPointDatas(Collections.singletonList(data2));
- result.add(info2);
- } else {
- PointInfo info0 = map.get("MX000");
- PointData data0 = latest.get(info0.getPointKey());
- if (data0.getValue() == 1.0) {
- data0.setDoubleValue(0.0);
- data0.setBooleanValue(false);
- info0.setPointDatas(Collections.singletonList(data0));
- result.add(info0);
- } else {
- PointInfo info6 = map.get("MX006");
- PointData data6 = latest.get(info6.getPointKey());
- if (data6.getValue() == 1.0) {
- data6.setDoubleValue(6.0);
- data6.setBooleanValue(false);
- info6.setPointDatas(Collections.singletonList(data6));
- result.add(info6);
- } else {
- PointInfo info4 = map.get("MX004");
- PointData data4 = latest.get(info4.getPointKey());
- if (data4.getValue() == 1.0) {
- data4.setDoubleValue(4.0);
- data4.setBooleanValue(false);
- info4.setPointDatas(Collections.singletonList(data4));
- result.add(info4);
- } else {
- PointInfo info1 = map.get("MX001");
- PointData data1 = latest.get(info1.getPointKey());
- if (data1.getValue() == 1.0) {
- data1.setDoubleValue(1.0);
- data1.setBooleanValue(false);
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- } else {
- data1.setDoubleValue(2.0);
- System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
- info1.setPointDatas(Collections.singletonList(data1));
- result.add(info1);
- }
- }
- }
- }
- }
- });
- return result;
- }
- public List<PointInfo> calcSectionStationAiztTs(Date time) {
- List<PointInfo> entityAiZt = getEntity("AI422", "state");
- List<StateAi> list = stateAiService.list();
- //机型,源状态,目标状态
- Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
- String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
- Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
- for (PointInfo info : entityAiZt) {
- PointData data = latest.get(info.getPointKey());
- Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
- if (m == null) {
- m = 2;
- System.out.println("ai状态未配对:" + data.getValue());
- }
- data.setDoubleValue(m);
- info.setPointDatas(Collections.singletonList(data));
- }
- return entityAiZt;
- }
- public void calcStationSjglAgcPjfsHjwdDlMin(Date time,Map<String, Double> fjhjwd) {
- DateTime end = DateUtil.beginOfMinute(time);
- int i = Math.floorDiv(end.minute(), 15) * 15;
- end.setMinutes(i);
- DateTime begin = DateUtil.offsetMinute(end, -15);
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- getSectionDataByEntity(entityAgc, goldenUri(), end);
- Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- Map<String, PointInfo> statMapCx = getSnapDataByEntity(entityCx, goldenUri(), begin, end,15, PointInfo::getStationId);
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- getSnapDataByEntity(entityHjwd, goldenUri(), begin, end,15);
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- getSectionDataByEntity(entity, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
- wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", end).groupBy("station_id");
- List<TurbineInfoMin> list = turbineInfoMinService.list(wrapper);
- Map<String, TurbineInfoMin> minMap = list.stream().collect(Collectors.toMap(TurbineInfoMin::getStationId, Function.identity()));
- List<StationInfoMin> byDate = getStationinfoByMin(end, entityAgc);
- Map<String, Map<Double, Long>> zttsMap = calcSectionStationZtts(end);
- for (StationInfoMin day : byDate) {
- String id = day.getStationId();
- TurbineInfoMin min = minMap.get(id);
- Map<Double, Long> map = zttsMap.get(id);
- day.setPjfs(min.getPjfs());
- PointInfo cxInfo = statMapCx.get(id);
- double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- cxgl = cxgl * cxInfo.getCoef();
- if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
- if (cxgl > 169600) cxgl = 169600;
- day.setPjgl(cxgl);
- PointInfo agcInfo = mapAgc.get(id);
- double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
- if (agc < day.getPjgl()) agc = day.getPjgl();
- day.setAgc(agc);
- List<PointInfo> fdlInfos = fdlsMap.get(id);
- double rfdl = fdlInfos.stream().mapToDouble(pi -> {
- double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- if (v < 0) v = 0;
- return v;
- }).sum();
- if (rfdl >= 42400.0) rfdl = day.getPjgl() / 4.0;
- day.setRfdl(rfdl);
- if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
- day.setPjgl(rfdl * 4);
- day.setAgc(day.getPjgl());
- }
- if (day.getPjgl() == 0.0 && rfdl != 0.0) {
- day.setPjgl(rfdl * 4);
- }
- if (day.getAgc() == 170000 && rfdl != 42400.0) {
- day.setAgc(rfdl * 4);
- }
- List<PointInfo> hjwdInfos = hjwdsMap.get(id);
- List<Double> hjwds = new ArrayList<>();
- for (PointInfo wd : hjwdInfos) {
- double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
- if (v > 83) v = 0;
- if (v == 0) {
- v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
- } else {
- fjhjwd.put(wd.getTurbineId(), v);
- }
- hjwds.add(v);
- }
- day.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
- //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
- day.setDjts(map.get(0.0));
- day.setYxts(map.get(2.0));
- day.setGzts(map.get(4.0));
- day.setJxts(map.get(6.0));
- day.setLlgl(min.getLlgl());
- day.setKygl(min.getKygl());
- }
- stationInfoMinService.saveOrUpdateBatch(byDate);
- }
- public void calcStationSjglAgcPjfsHjwdDlMin(Date begin, Date end, String stId) {
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- entityAgc = entityAgc.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getSectionDataByEntity(entityAgc, goldenUri(), end);
- Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
- getSectionDataByEntity(entity, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- List<StationInfoMin> byDate = getStationinfoByMin(end, stId);
- byDate = byDate.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- Map<Double, Long> map = calcSectionStationZtts(end, stId);
- for (StationInfoMin day : byDate) {
- String id = day.getStationId();
- // if (day.getPjfs() == null || day.getPjfs() == 0) {
- List<PointInfo> fsInfos = fssMap.get(id);
- double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
- day.setPjfs(pjfs);
- // }
- // if (day.getPjgl() == null || day.getPjgl() == 0) {
- PointInfo cxInfo = statMapCx.get(id);
- double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- cxgl = cxgl * cxInfo.getCoef();
- if (cxgl <= 0 && day.getPjfs() > 3) cxgl = nihe(day.getPjfs());
- if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
- if (cxgl > 169600 && day.getPjfs() > 3) cxgl = nihe(day.getPjfs());
- day.setPjgl(cxgl);
- // }
- // if (day.getAgc() == null || day.getAgc() == 0) {
- PointInfo agcInfo = mapAgc.get(id);
- double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
- if (agc < day.getPjgl()) agc = day.getPjgl();
- day.setAgc(agc);
- // }
- // if (day.getRfdl() == null || day.getRfdl() == 0) {
- List<PointInfo> fdlInfos = fdlsMap.get(id);
- double rfdl = fdlInfos.stream().mapToDouble(pi -> {
- double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- if (v < 0) v = 0;
- // if (v > 10500) v = 10500.0;
- return v;
- }).sum();
- if ((rfdl < 660 && day.getPjgl() > 0) || rfdl >= 45500) rfdl = day.getPjgl() / 4.0;
- day.setRfdl(rfdl);
- if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
- day.setPjgl(rfdl * 4);
- day.setAgc(day.getPjgl());
- }
- if (day.getAgc() == 170000 && rfdl != 42400.0) {
- day.setAgc(rfdl * 4);
- }
- // }
- // if (day.getHjwd() == null || day.getHjwd() == 0) {
- List<PointInfo> hjwdInfos = hjwdsMap.get(id);
- double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
- day.setHjwd(hjwd);
- // }
- //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
- day.setDjts(map.get(0.0));
- day.setYxts(map.get(2.0));
- day.setGzts(map.get(4.0));
- day.setJxts(map.get(6.0));
- }
- stationInfoMinService.saveOrUpdateBatch(byDate);
- }
- public StationInfoMin calcStationSjglAgcPjfsHjwdDlMin2(Date begin, Date end, String stId) {
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- entityAgc = entityAgc.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getSectionDataByEntity(entityAgc, goldenUri(), end);
- Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
- getSectionDataByEntity(entity, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- List<StationInfoMin> byDate = getStationinfoByMin(end, stId);
- byDate = byDate.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- Map<Double, Long> map = calcSectionStationZtts(end, stId);
- for (StationInfoMin day : byDate) {
- String id = day.getStationId();
- List<PointInfo> fsInfos = fssMap.get(id);
- double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
- day.setPjfs(pjfs);
- PointInfo cxInfo = statMapCx.get(id);
- double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- cxgl = cxgl * cxInfo.getCoef();
- if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
- day.setPjgl(cxgl);
- PointInfo agcInfo = mapAgc.get(id);
- double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
- if (agc < day.getPjgl()) agc = day.getPjgl();
- day.setAgc(agc);
- List<PointInfo> fdlInfos = fdlsMap.get(id);
- double rfdl = fdlInfos.stream().mapToDouble(pi -> {
- double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- if (v < 0) v = 0;
- return v;
- }).sum();
- if ((rfdl < 660 && day.getPjgl() > 0) || rfdl > 45500) rfdl = day.getPjgl() / 4.0;
- day.setRfdl(rfdl);
- if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
- day.setPjgl(rfdl * 4);
- day.setAgc(day.getPjgl());
- }
- if (day.getPjgl() == 0.0 && rfdl != 0.0) {
- day.setPjgl(rfdl * 4);
- }
- if (day.getAgc() == 170000 && rfdl != 42400.0) {
- day.setAgc(rfdl * 4);
- }
- List<PointInfo> hjwdInfos = hjwdsMap.get(id);
- double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
- day.setHjwd(hjwd);
- //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
- day.setDjts(map.get(0.0));
- day.setYxts(map.get(2.0));
- day.setGzts(map.get(4.0));
- day.setJxts(map.get(6.0));
- }
- return byDate.get(0);
- }
- private double nihe(double pjfs) {
- //LJS
- // if (pjfs > 13) return 94251.0;
- // return -90.4382 * Math.pow(pjfs, 3) + 1661.275 * Math.pow(pjfs, 2) + 2245.86 * pjfs - 17011.14;
- //FSG
- if (pjfs > 8.62) return 35880.0;
- return -286.3119 * Math.pow(pjfs, 3) + 4837.637 * Math.pow(pjfs, 2) - 19121.73 * pjfs + 24636.96;
- }
- public void getPoint() {
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
- Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- System.out.println();
- }
- public void calcPredictExaminFj(Date date) {
- DateTime end = DateUtil.beginOfDay(date);
- DateTime begin = DateUtil.offsetDay(end, -1);
- List<PointInfo> entity = getEntity("MX000", "state");
- List<PointInfo> entity1 = getEntity("AI422", "state");
- entity.addAll(entity1);
- Map<String, EquipmentModel> map = equipmentModelService.map();
- //风机id,风机装机容量
- Map<String, Double> tbPowerMap = entity.stream().collect(Collectors.toMap(pi -> pi.getTurbineId(), pi -> map.get(pi.getSpare()).getPowerProduction()));
- //实际功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- getSnapDataByEntity(entityGl, begin, end, 15 * 60);
- Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- //短期 predictType + "_" + modelId + "_" + sstId + t
- QueryWrapper<HistoryPredict> dqWrapper = new QueryWrapper<>();
- dqWrapper.eq("device_type", "station").eq("predict_type", "DQ").eq("data_time", begin)
- .between("predict_time", begin, end).orderByAsc("data_time");
- List<HistoryPredict> dqList = historyPredictService.list(dqWrapper);
- Map<String, List<HistoryPredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- //超短期
- QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
- cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
- List<HistoryPredict> cdqList = historyPredictService.list(cdqWrapper);
- Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- List<PredictExamin> peList = new ArrayList<>();
- dqMap.forEach((stId, hps) -> {
- //短期
- List<Double> predictPower = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- List<Double> actualPower = glpisMap.get(stId).getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
- Double installCapacity = tbPowerMap.get(stId);
- HistoryPredict predict = hps.get(0);
- PredictExamin examin = new PredictExamin();
- examin.setModelId(predict.getModelId());
- examin.setPredictType("DQ");
- examin.setDeviceType(predict.getDeviceType());
- examin.setTime(begin);
- examin.setSiteId(predict.getSiteId());
- examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
- examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
- peList.add(examin);
- //超短期
- List<Double> predictPowerCdq = cdqMap.get(stId).stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- PredictExamin e = new PredictExamin();
- e.setModelId(predict.getModelId());
- e.setPredictType("CDQ");
- e.setDeviceType(predict.getDeviceType());
- e.setTime(begin);
- e.setSiteId(predict.getSiteId());
- e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
- e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
- peList.add(e);
- });
- predictExaminService.saveBatch(peList);
- }
- public void predictExaminBc(List<String> stIds, Date date) {
- List<RealtimePredict> peList = new ArrayList<>();
- for (String stId : stIds) {
- RealtimePredict examin = new RealtimePredict();
- examin.setModelId("1");
- examin.setPredictType("ZCQ");
- examin.setDeviceType("project");
- examin.setTime(date);
- examin.setSiteId(stId);
- examin.setPredictEnergy(0.0);
- examin.setId("ZCQ_1_" + stId + date.toString());
- peList.add(examin);
- }
- realtimePredictService.saveBatch(peList);
- }
- public void predictcdqBc(Date date) {
- List<RealtimePredict> peList = new ArrayList<>();
- RealtimePredict examin = new RealtimePredict();
- examin.setModelId("1");
- examin.setPredictType("ZCQ");
- examin.setDeviceType("project");
- examin.setTime(date);
- // examin.setSiteId(stId);
- examin.setPredictEnergy(0.0);
- // examin.setId("ZCQ_1_"+stId+date.toString());
- peList.add(examin);
- realtimePredictService.saveBatch(peList);
- }
- public void zcqycbc(List<String> stIds, Date date) {
- List<PredictExamin> peList = new ArrayList<>();
- for (String stId : stIds) {
- //短期
- PredictExamin examin = new PredictExamin();
- examin.setModelId("1");
- examin.setPredictType("DQ");
- examin.setDeviceType("station");
- examin.setTime(date);
- examin.setSiteId(stId);
- examin.setExaminScore(30.0);
- examin.setAccuracyRate(91.0);
- peList.add(examin);
- //超短期
- PredictExamin e = new PredictExamin();
- e.setModelId("1");
- e.setPredictType("CDQ");
- e.setDeviceType("station");
- e.setTime(date);
- e.setSiteId(stId);
- e.setExaminScore(30.0);
- e.setAccuracyRate(91.0);
- peList.add(e);
- }
- predictExaminService.saveBatch(peList);
- }
- public void calcPredictExamin(Date date) {
- DateTime end = DateUtil.beginOfDay(date);
- DateTime begin = DateUtil.offsetDay(end, -1);
- //实际功率
- List<PointInfo> entityGl = getEntity("AGC001", "booster");
- getSnapDataByEntity(entityGl, begin, end, 15 * 60);
- Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //短期 predictType + "_" + modelId + "_" + sstId + t
- QueryWrapper<HistoryPredict> dqWrapper = new QueryWrapper<>();
- dqWrapper.eq("device_type", "station").eq("predict_type", "DQ").eq("data_time", begin)
- .between("predict_time", begin, end).orderByAsc("data_time");
- List<HistoryPredict> dqList = historyPredictService.list(dqWrapper);
- Map<String, List<HistoryPredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- //超短期
- List<HistoryPredict> cdqList = new ArrayList<>();
- for (int i = 0; i < 6; i++) {
- DateTime hour = DateUtil.offsetHour(begin, 4 * i);
- DateTime hour2 = DateUtil.offsetHour(hour, 4);
- QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
- wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
- .between("predict_time", hour, hour2).orderByAsc("data_time");
- List<HistoryPredict> predicts = historyPredictService.list(wrapper);
- cdqList.addAll(predicts);
- }
- QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
- cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
- Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- List<PredictExamin> peList = new ArrayList<>();
- dqMap.forEach((stId, hps) -> {
- //短期
- List<Double> predictPower = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- PointInfo glinfo = glpisMap.get(stId);
- List<Double> actualPower = glinfo.getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
- Double installCapacity = glinfo.getSpare2() * 1000;
- HistoryPredict predict = hps.get(0);
- PredictExamin examin = new PredictExamin();
- examin.setModelId(predict.getModelId());
- examin.setPredictType("DQ");
- examin.setDeviceType(predict.getDeviceType());
- examin.setTime(begin);
- examin.setSiteId(predict.getSiteId());
- examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
- examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
- peList.add(examin);
- //超短期
- List<HistoryPredict> cdqhps = cdqMap.get(stId);
- if (CollUtil.isEmpty(cdqhps)) return;
- List<Double> predictPowerCdq = cdqhps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- PredictExamin e = new PredictExamin();
- e.setModelId(predict.getModelId());
- e.setPredictType("CDQ");
- e.setDeviceType(predict.getDeviceType());
- e.setTime(begin);
- e.setSiteId(predict.getSiteId());
- e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
- e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
- peList.add(e);
- });
- predictExaminService.saveBatch(peList);
- }
- public void calcPredictExamin2(Date date) {
- DateTime end = DateUtil.beginOfDay(date);
- DateTime begin = DateUtil.offsetDay(end, -1);
- //实际功率
- List<PointInfo> entityGl = getEntity("AGC001", "booster");
- getSnapDataByEntity(entityGl, begin, end, 15 * 60);
- Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- //短期 predictType + "_" + modelId + "_" + sstId + t
- QueryWrapper<RealtimePredict> dqWrapper = new QueryWrapper<>();
- dqWrapper.eq("device_type", "station").eq("predict_type", "DQ")
- .gt("time", begin).le("time", end).orderByAsc("time");
- List<RealtimePredict> dqList = realtimePredictService.list(dqWrapper);
- Map<String, List<RealtimePredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(RealtimePredict::getSiteId));
- //超短期
- List<HistoryPredict> cdqList = new ArrayList<>();
- for (int i = 0; i < 6; i++) {
- DateTime hour = DateUtil.offsetHour(begin, 4 * i);
- DateTime hour2 = DateUtil.offsetHour(hour, 4);
- QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
- wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
- .between("predict_time", hour, hour2).orderByAsc("data_time");
- List<HistoryPredict> predicts = historyPredictService.list(wrapper);
- cdqList.addAll(predicts);
- }
- QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
- cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
- Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- List<PredictExamin> peList = new ArrayList<>();
- dqMap.forEach((stId, hps) -> {
- //短期
- List<Double> predictPower = hps.stream().map(RealtimePredict::getPredictPower).collect(Collectors.toList());
- PointInfo glinfo = glpisMap.get(stId);
- List<Double> actualPower = glinfo.getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
- Double installCapacity = glinfo.getSpare2() * 1000;
- RealtimePredict predict = hps.get(0);
- PredictExamin examin = new PredictExamin();
- examin.setModelId(predict.getModelId());
- examin.setPredictType("DQ");
- examin.setDeviceType(predict.getDeviceType());
- examin.setTime(begin);
- examin.setSiteId(predict.getSiteId());
- examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
- examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
- peList.add(examin);
- //超短期
- List<HistoryPredict> cdqhps = cdqMap.get(stId);
- if (CollUtil.isEmpty(cdqhps)) return;
- List<Double> predictPowerCdq = cdqhps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- PredictExamin e = new PredictExamin();
- e.setModelId(predict.getModelId());
- e.setPredictType("CDQ");
- e.setDeviceType(predict.getDeviceType());
- e.setTime(begin);
- e.setSiteId(predict.getSiteId());
- e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
- e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
- peList.add(e);
- });
- predictExaminService.saveBatch(peList);
- }
- /**
- * 计算功率日预测曲线最大误差值
- *
- * @param predictPower 96个点的预测功率值
- * @param actualPower 96个点的实际功率值
- * @param installCapacity 装机容量
- * @return 结果
- */
- public double calcExaminScore(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
- if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
- int n = predictPower.size();
- if (actualPower.size() < n) return 0;
- double maxErrorPercentage = 0.0;
- for (int i = 0; i < n; i++) {
- double errorPercentage = 0.0;
- if (predictPower.get(i) == 0) {
- if (Math.abs(actualPower.get(i)) <= 0.03 * installCapacity) {
- continue; // 不考核
- } else {
- errorPercentage = 100.0;
- }
- } else {
- errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / installCapacity * 100;
- }
- if (errorPercentage > maxErrorPercentage) {
- maxErrorPercentage = errorPercentage;
- }
- }
- return maxErrorPercentage;
- }
- /**
- * 计算功率超短期预测曲线准确率
- *
- * @param predictPower 96个点的预测功率值
- * @param actualPower 96个点的实际功率值
- * @param installCapacity 装机容量
- * @return 结果
- */
- public double calcAccuracyRate(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
- if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
- int n = predictPower.size();
- if (actualPower.size() < n) return 0;
- double totalError = 0.0;
- int validPoints = 0;
- for (int i = 0; i < n; i++) {
- double errorPercentage = 0.0;
- if (Math.abs(predictPower.get(i) - actualPower.get(i)) <= 0.03 * installCapacity) {
- // 该点不计入误差计算
- continue;
- }
- errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / installCapacity * 100;
- totalError += errorPercentage;
- validPoints++;
- }
- if (validPoints == 0) {
- return 100.0; // 所有点均在3%以内,准确率为100%
- } else {
- return 100 - totalError / validPoints;
- }
- }
- private Map<String, Double> fjhjwd = new HashMap<>();
- private Map<String, Double> fjfs = new HashMap<>();
- public void calcStationPjfsHjwdMin(Date begin, Date end, String stId, StationInfoMin min) {
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- // StationInfoMin2 min2 = getStationinfoByMin2(end, stId);
- StationInfoMin2 min2 = new StationInfoMin2();
- min2.setStationId(stId);
- min2.setRecordDate(end);
- min2.setPjgl(min.getPjgl());
- min2.setRfdl(min.getRfdl());
- min2.setYxts(min.getYxts());
- List<PointInfo> fsInfos = fssMap.get(stId);
- fsInfos = fsInfos.stream().sorted(Comparator.comparing(PointInfo::getTurbineId)).collect(Collectors.toList());
- for (int i = 0; i < fsInfos.size(); i++) {
- setpjfs(min2, fsInfos.get(i), i + 1);
- }
- List<PointInfo> hjwdInfos = hjwdsMap.get(stId);
- List<Double> hjwds = new ArrayList<>();
- for (PointInfo wd : hjwdInfos) {
- double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
- if (v > 83 || v < -60) v = 0;
- if (v == 0) {
- v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
- } else {
- fjhjwd.put(wd.getTurbineId(), v);
- }
- hjwds.add(v);
- }
- min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
- // stationInfoMin2Service.saveOrUpdate(min2);
- stationInfoMin2Service.save(min2);
- }
- public List<PointInfo> filterPointInfo(List<PointInfo> entity, String id, Function<PointInfo, String> fun) {
- return entity.stream().filter(e -> id.equals(fun.apply(e))).collect(Collectors.toList());
- }
- public List<PointInfo> sortPointInfo(List<PointInfo> entity, Function<PointInfo, String> fun) {
- return entity.stream().sorted(Comparator.comparing(fun)).collect(Collectors.toList());
- }
- public void calcProjectPjfsHjwdMin2(Date begin, Date end, String stId, StationInfoMin2 min) {
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = filterPointInfo(entityFs, stId, PointInfo::getStationId);
- Map<String, List<PointInfo>> pisMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getProjectId));
- List<ProjectInfoMin2> min2s = new ArrayList<>();
- pisMap.forEach((pjId, pis) -> {
- List<PointInfo> infos = sortPointInfo(pis, PointInfo::getTurbineId);
- List<Integer> fjidns = infos.stream().map(pi -> Integer.parseInt(pi.getTurbineId().replaceFirst("GJNY_SXGS_.+_F_WT_", "")
- .replaceFirst("_EQ", ""))).collect(Collectors.toList());
- // Map<Double, Long> zttsMap = calcSectionZtts(end,pjId,PointInfo::getProjectId);
- // Long l = zttsMap.get(2.0);
- // if (l == null) l = 0L;
- //日发电量
- // List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- // entity=filterPointInfo(entity,pjId,PointInfo::getProjectId);
- // getSectionDataByEntity(entity, goldenUri(), begin, end);
- // double rfdl = entity.stream().mapToDouble(pi -> {
- // double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- // if (v < 0) v = 0;
- // return v;
- // }).sum();
- // if (rfdl >= 32500) rfdl = 32500.0;
- ProjectInfoMin2 min2 = new ProjectInfoMin2();
- min2.setStationId(stId);
- min2.setProjectId(pjId);
- min2.setRecordDate(end);
- // min2.setRfdl(rfdl);
- min2.setRfdl(min.getRfdl());
- min2.setHjwd(min.getHjwd());
- // min2.setYxts(l);
- min2.setYxts(min.getYxts());
- sm2fs2pm2(fjidns, min2, min);
- min2s.add(min2);
- });
- projectInfoMin2Service.saveBatch(min2s);
- }
- public ProjectInfoMin2 calcProjectPjfsHjwdMin2(Date end, String pjId, boolean b) {
- DateTime begin = DateUtil.offsetMinute(end, -15);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = filterPointInfo(entityFs, pjId, PointInfo::getProjectId);
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- entityFs = sortPointInfo(entityFs, PointInfo::getTurbineId);
- List<Double> fss = new ArrayList<>();
- for (PointInfo ef : entityFs) {
- double v = 0;
- if (ef.getPointDatas() == null || ef.getPointDatas().isEmpty()) {
- Map<String, PointData> latest = adapter.getLatest(goldenUri(), ef.getPointKey());
- PointData data = latest.get(ef.getPointKey());
- if (data != null) v = data.getValue();
- } else {
- v = ef.getPointDatas().stream().mapToDouble(p -> p.getValue() > 23 ? 23.0 : p.getValue() < 0 ? 0.0 : p.getValue()).average().orElse(0.0);
- }
- fss.add(v);
- }
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = filterPointInfo(entity, pjId, PointInfo::getProjectId);
- getSectionDataByEntity(entity, goldenUri(), begin, end);
- double rfdl = entity.stream().mapToDouble(pi -> {
- double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- if (v < 0) v = 0;
- return v;
- }).sum();
- if (rfdl >= 32500) rfdl = 32500.0;
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- entityHjwd = filterPointInfo(entityHjwd, pjId, PointInfo::getProjectId);
- getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
- List<Double> hjwds = new ArrayList<>();
- for (PointInfo wd : entityHjwd) {
- double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
- if (v > 83 || v < -60) v = 0;
- if (v == 0) {
- v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
- } else {
- fjhjwd.put(wd.getTurbineId(), v);
- }
- hjwds.add(v);
- }
- ProjectInfoMin2 min2 = new ProjectInfoMin2();
- min2.setProjectId(pjId);
- min2.setRecordDate(end);
- min2.setRfdl(rfdl);
- min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
- sm2fs2pm2(fss, min2);
- if (b) projectInfoMin2Service.save(min2);
- return min2;
- }
- private void sm2fs2pm2(List<Integer> is, ProjectInfoMin2 pjMin2, StationInfoMin2 stMin2) {
- List<Double> r = new ArrayList<>();
- String prefix1 = "getPjfs";
- try {
- for (Integer i : is) {
- // 构造方法名
- String methodName = prefix1 + i;
- // 获取方法对象
- Method method = stMin2.getClass().getMethod(methodName);
- // 调用方法并获取返回值
- Double result = (Double) method.invoke(stMin2);
- // 将结果添加到列表中
- r.add(result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- //setPjfs44(Double pjfs44)
- String prefix2 = "setPjfs";
- try {
- for (int i = 0; i < r.size(); i++) {
- // 构造方法名
- String methodName = prefix2 + (i + 1);
- // 获取方法对象
- Method method = pjMin2.getClass().getMethod(methodName, Double.class);
- // 调用方法并获取返回值
- method.invoke(pjMin2, r.get(i));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sm2fs2pm2(List<Double> fs, ProjectInfoMin2 pjMin2) {
- String prefix2 = "setPjfs";
- try {
- for (int i = 0; i < fs.size(); i++) {
- // 构造方法名
- String methodName = prefix2 + (i + 1);
- // 获取方法对象
- Method method = pjMin2.getClass().getMethod(methodName, Double.class);
- // 调用方法并获取返回值
- method.invoke(pjMin2, fs.get(i));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public StationInfoMin2 calcStationPjfsHjwdMin2(Date end, String stId, boolean b) {
- DateTime begin = DateUtil.offsetMinute(end, -15);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
- //日发电量
- List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
- entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
- getSectionDataByEntity(entity, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
- getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
- Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- Map<Double, Long> zttsMap = calcSectionStationZtts(end, stId);
- PointInfo cxInfo = statMapCx.get(stId);
- double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
- cxgl = cxgl * cxInfo.getCoef();
- List<PointInfo> fdlInfos = fdlsMap.get(stId);
- double rfdl = fdlInfos.stream().mapToDouble(pi -> {
- double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
- if (v < 0) v = 0;
- return v;
- }).sum();
- if ((rfdl < 660 && cxgl > 0) || rfdl >= 42400.0) rfdl = cxgl / 4.0;
- if (cxgl > 169600.0 && rfdl < 42400.0) {
- cxgl = rfdl * 4;
- }
- if (cxgl == 0.0 && rfdl != 0.0) {
- cxgl = rfdl * 4;
- }
- StationInfoMin2 min2 = new StationInfoMin2();
- min2.setStationId(stId);
- min2.setRecordDate(end);
- min2.setPjgl(cxgl);
- min2.setRfdl(rfdl);
- Long l = zttsMap.get(2.0);
- if (l == null) l = 0L;
- min2.setYxts(l);
- List<PointInfo> fsInfos = fssMap.get(stId);
- fsInfos = fsInfos.stream().sorted(Comparator.comparing(PointInfo::getTurbineId)).collect(Collectors.toList());
- for (int i = 0; i < fsInfos.size(); i++) {
- setpjfs(min2, fsInfos.get(i), i + 1);
- }
- List<PointInfo> hjwdInfos = hjwdsMap.get(stId);
- List<Double> hjwds = new ArrayList<>();
- for (PointInfo wd : hjwdInfos) {
- double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
- if (v > 83) v = 0;
- if (v == 0) {
- v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
- } else {
- fjhjwd.put(wd.getTurbineId(), v);
- }
- hjwds.add(v);
- }
- min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
- if (b) stationInfoMin2Service.save(min2);
- return min2;
- }
- private void setpjfs(StationInfoMin2 min2, PointInfo pi, int i) {
- double v = 0;
- if (pi == null || pi.getPointDatas().isEmpty()) {
- v = fjfs.getOrDefault(pi.getTurbineId(), 0.0);
- } else {
- v = pi.getPointDatas().stream().mapToDouble(p -> p.getValue() > 23 ? 23.0 : p.getValue() < 0 ? 0.0 : p.getValue()).average().orElse(0.0);
- fjfs.put(pi.getTurbineId(), v);
- }
- switch (i) {
- case 1:
- min2.setPjfs1(v);
- break;
- case 2:
- min2.setPjfs2(v);
- break;
- case 3:
- min2.setPjfs3(v);
- break;
- case 4:
- min2.setPjfs4(v);
- break;
- case 5:
- min2.setPjfs5(v);
- break;
- case 6:
- min2.setPjfs6(v);
- break;
- case 7:
- min2.setPjfs7(v);
- break;
- case 8:
- min2.setPjfs8(v);
- break;
- case 9:
- min2.setPjfs9(v);
- break;
- case 10:
- min2.setPjfs10(v);
- break;
- case 11:
- min2.setPjfs11(v);
- break;
- case 12:
- min2.setPjfs12(v);
- break;
- case 13:
- min2.setPjfs13(v);
- break;
- case 14:
- min2.setPjfs14(v);
- break;
- case 15:
- min2.setPjfs15(v);
- break;
- case 16:
- min2.setPjfs16(v);
- break;
- case 17:
- min2.setPjfs17(v);
- break;
- case 18:
- min2.setPjfs18(v);
- break;
- case 19:
- min2.setPjfs19(v);
- break;
- case 20:
- min2.setPjfs20(v);
- break;
- case 21:
- min2.setPjfs21(v);
- break;
- case 22:
- min2.setPjfs22(v);
- break;
- case 23:
- min2.setPjfs23(v);
- break;
- case 24:
- min2.setPjfs24(v);
- break;
- case 25:
- min2.setPjfs25(v);
- break;
- case 26:
- min2.setPjfs26(v);
- break;
- case 27:
- min2.setPjfs27(v);
- break;
- case 28:
- min2.setPjfs28(v);
- break;
- case 29:
- min2.setPjfs29(v);
- break;
- case 30:
- min2.setPjfs30(v);
- break;
- case 31:
- min2.setPjfs31(v);
- break;
- case 32:
- min2.setPjfs32(v);
- break;
- case 33:
- min2.setPjfs33(v);
- break;
- case 34:
- min2.setPjfs34(v);
- break;
- case 35:
- min2.setPjfs35(v);
- break;
- case 36:
- min2.setPjfs36(v);
- break;
- case 37:
- min2.setPjfs37(v);
- break;
- case 38:
- min2.setPjfs38(v);
- break;
- case 39:
- min2.setPjfs39(v);
- break;
- case 40:
- min2.setPjfs40(v);
- break;
- case 41:
- min2.setPjfs41(v);
- break;
- case 42:
- min2.setPjfs42(v);
- break;
- case 43:
- min2.setPjfs43(v);
- break;
- case 44:
- min2.setPjfs44(v);
- break;
- case 45:
- min2.setPjfs45(v);
- break;
- case 46:
- min2.setPjfs46(v);
- break;
- case 47:
- min2.setPjfs47(v);
- break;
- case 48:
- min2.setPjfs48(v);
- break;
- case 49:
- min2.setPjfs49(v);
- break;
- case 50:
- min2.setPjfs50(v);
- break;
- case 51:
- min2.setPjfs51(v);
- break;
- case 52:
- min2.setPjfs52(v);
- break;
- case 53:
- min2.setPjfs53(v);
- break;
- case 54:
- min2.setPjfs54(v);
- break;
- case 55:
- min2.setPjfs55(v);
- break;
- case 56:
- min2.setPjfs56(v);
- break;
- case 57:
- min2.setPjfs57(v);
- break;
- case 58:
- min2.setPjfs58(v);
- break;
- case 59:
- min2.setPjfs59(v);
- break;
- case 60:
- min2.setPjfs60(v);
- break;
- case 61:
- min2.setPjfs61(v);
- break;
- case 62:
- min2.setPjfs62(v);
- break;
- case 63:
- min2.setPjfs63(v);
- break;
- case 64:
- min2.setPjfs64(v);
- break;
- case 65:
- min2.setPjfs65(v);
- break;
- case 66:
- min2.setPjfs66(v);
- break;
- case 67:
- min2.setPjfs67(v);
- break;
- case 68:
- min2.setPjfs68(v);
- break;
- case 69:
- min2.setPjfs69(v);
- break;
- case 70:
- min2.setPjfs70(v);
- break;
- case 71:
- min2.setPjfs71(v);
- break;
- case 72:
- min2.setPjfs72(v);
- break;
- case 73:
- min2.setPjfs73(v);
- break;
- case 74:
- min2.setPjfs74(v);
- break;
- case 75:
- min2.setPjfs75(v);
- break;
- case 76:
- min2.setPjfs76(v);
- break;
- case 77:
- min2.setPjfs77(v);
- break;
- case 78:
- min2.setPjfs78(v);
- break;
- case 79:
- min2.setPjfs79(v);
- break;
- case 80:
- min2.setPjfs80(v);
- break;
- case 81:
- min2.setPjfs81(v);
- break;
- case 82:
- min2.setPjfs82(v);
- break;
- case 83:
- min2.setPjfs83(v);
- break;
- case 84:
- min2.setPjfs84(v);
- break;
- case 85:
- min2.setPjfs85(v);
- break;
- case 86:
- min2.setPjfs86(v);
- break;
- case 87:
- min2.setPjfs87(v);
- break;
- case 88:
- min2.setPjfs88(v);
- break;
- case 89:
- min2.setPjfs89(v);
- break;
- case 90:
- min2.setPjfs90(v);
- break;
- case 91:
- min2.setPjfs91(v);
- break;
- case 92:
- min2.setPjfs92(v);
- break;
- case 93:
- min2.setPjfs93(v);
- break;
- case 94:
- min2.setPjfs94(v);
- break;
- case 95:
- min2.setPjfs95(v);
- break;
- case 96:
- min2.setPjfs96(v);
- break;
- case 97:
- min2.setPjfs97(v);
- break;
- case 98:
- min2.setPjfs98(v);
- break;
- case 99:
- min2.setPjfs99(v);
- break;
- }
- }
- public void calcCdqKhfs(Date date) {
- DateTime begin = DateUtil.offsetDay(DateUtil.beginOfDay(date), -1);
- DateTime end = DateUtil.offsetDay(DateUtil.endOfDay(date), -1);
- DateTime beginDq = DateUtil.offsetDay(begin, -2);
- List<PointInfo> entityCzzt = getEntity("AGC009", "booster");
- getRawDataByEntity(entityCzzt, taosUri(), beginDq, end);
- Map<String, PointInfo> czztMap = entityCzzt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
- Map<String, Map<DateTime, List<Double>>> czztMapMap = new HashMap<>();
- czztMap.forEach((stId, pi) -> {
- Map<DateTime, List<Double>> ztMap = new HashMap<>();
- long b = beginDq.getTime();
- long e = end.getTime();
- long b0 = b;
- long e0 = b + 15 * 60 * 1000;
- while (e0 < e) {
- for (PointData pd : pi.getPointDatas()) {
- long ts = pd.getTs();
- if (ts >= b0 && ts < e0) {
- List<Double> doubles = ztMap.computeIfAbsent(DateUtil.date(b0), k -> new ArrayList<>());
- doubles.add(pd.getValue());
- } else if (ts >= e0 && ts < e0 + 15 * 60 * 1000) {
- List<Double> doubles = ztMap.computeIfAbsent(DateUtil.date(e0), k -> new ArrayList<>());
- doubles.add(pd.getValue());
- b0 = e0;
- e0 += 15 * 60 * 1000;
- } else {
- b0 = e0;
- e0 += 15 * 60 * 1000;
- }
- }
- if (pi.getPointDatas().size() == 0) {
- b0 = e0;
- e0 += 15 * 60 * 1000;
- }
- }
- czztMapMap.put(stId, ztMap);
- });
- //实际功率
- List<PointInfo> entityGl = getEntity("AGC001", "booster");
- Map<String, Double> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getSpare2));
- //实际功率
- QueryWrapper<StationInfoMin> minWrapper = new QueryWrapper<>();
- minWrapper.between("record_date", begin, end).orderByAsc("record_date");
- List<StationInfoMin> mins = stationInfoMinService.list(minWrapper);
- Map<String, List<StationInfoMin>> minMap = mins.stream().collect(Collectors.groupingBy(StationInfoMin::getStationId));
- //实际功率短期
- QueryWrapper<StationInfoMin> minWrapperDq = new QueryWrapper<>();
- minWrapperDq.between("record_date", beginDq, end).orderByAsc("record_date");
- List<StationInfoMin> minsDq = stationInfoMinService.list(minWrapperDq);
- Map<String, List<StationInfoMin>> minMapDq = minsDq.stream().collect(Collectors.groupingBy(StationInfoMin::getStationId));
- //短期预测功率
- QueryWrapper<RealtimePredict> dqWrapper = new QueryWrapper<>();
- dqWrapper.eq("device_type", "station").eq("predict_type", "DQ")
- .between("time", beginDq, end).orderByAsc("time");
- List<RealtimePredict> dqList = realtimePredictService.list(dqWrapper);
- Map<String, List<RealtimePredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(RealtimePredict::getSiteId));
- //短期预测功率准确率
- QueryWrapper<RealtimePredict> dqWrapperZcl = new QueryWrapper<>();
- dqWrapperZcl.eq("device_type", "station").eq("predict_type", "DQ")
- .between("time", begin, end).orderByAsc("time");
- List<RealtimePredict> dqListZcl = realtimePredictService.list(dqWrapperZcl);
- Map<String, List<RealtimePredict>> dqMapZcl = dqListZcl.stream().collect(Collectors.groupingBy(RealtimePredict::getSiteId));
- //超短期
- // 标准准确率
- final List<Double> WIND_STANDARD = Arrays.asList(0.80, 0.75, 0.70, 0.65);
- List<PredictExamin2> peList = new ArrayList<>();
- DateTime hpBegin = DateUtil.offsetMinute(begin, -15);
- for (int i = 0; i < 6; i++) {
- DateTime hour = DateUtil.offsetHour(hpBegin, 4 * i);
- DateTime hour2 = DateUtil.offsetHour(hour, 4);
- QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
- wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
- .between("predict_time", hour, hour2).orderByAsc("data_time");
- List<HistoryPredict> predicts = historyPredictService.list(wrapper);
- Map<String, List<HistoryPredict>> cdqMap = predicts.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
- int finalI = i;
- cdqMap.forEach((stId, hps) -> {
- List<StationInfoMin> minGl = minMap.get(stId);
- PredictExamin2 examin2 = new PredictExamin2();
- Double capacity = glpisMap.get(stId) * 1000;
- Date pdtHour = hps.get(0).getPredictTime();
- examin2.setModelId("1");
- examin2.setPredictType("CDQ");
- examin2.setDeviceType("station");
- examin2.setTime(pdtHour);
- examin2.setSiteId(stId);
- List<Double> ycgls = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
- List<StationInfoMin> sub = ListUtil.sub(minGl, 16 * finalI, 16 * (finalI + 1));
- List<Double> sjgls = sub.stream().map(StationInfoMin::getPjgl).collect(Collectors.toList());
- List<List<Double>> ycglss = ListUtil.split(ycgls, 4);
- List<List<Double>> sjglss = ListUtil.split(sjgls, 4);
- calculateForecastScore(examin2, ycglss, sjglss, WIND_STANDARD, capacity, pdtHour.getHours());
- peList.add(examin2);
- });
- }
- QueryWrapper<PredictExamin2> examin2Wrapper = new QueryWrapper<>();
- examin2Wrapper.eq("predict_type", "DQ").eq("device_type", "station")
- .eq("time", dqList.get(0).getTime());
- List<PredictExamin2> khfss = predictExamin2Service.list(examin2Wrapper);
- Map<String, PredictExamin2> khfsMap = khfss.stream().collect(Collectors.toMap(PredictExamin2::getSiteId, Function.identity()));
- //短期考核分数
- dqMap.forEach((stId, hps) -> {
- List<StationInfoMin> minDqList = minMapDq.get(stId);
- Map<DateTime, List<Double>> dtlMap = czztMapMap.get(stId);
- PredictExamin2 examin2 = khfsMap.get(stId);
- if (examin2 == null) return;
- Double capacity = glpisMap.get(stId) * 1000;
- examin2.setModelId("1");
- examin2.setPredictType("DQ");
- examin2.setDeviceType("station");
- examin2.setTime(hps.get(0).getTime());
- examin2.setSiteId(stId);
- examin2.setExaminScore(calcQAll(minDqList, hps, capacity, dtlMap));
- peList.add(examin2);
- });
- //短期准确率
- dqMapZcl.forEach((stId, hps) -> {
- List<StationInfoMin> minGl = minMap.get(stId);
- Double capacity = glpisMap.get(stId) * 1000;
- PredictExamin2 examin2 = new PredictExamin2();
- examin2.setModelId("1");
- examin2.setPredictType("DQ");
- examin2.setDeviceType("station");
- examin2.setTime(hps.get(0).getTime());
- examin2.setSiteId(stId);
- Map<Boolean, List<Double>> actualPowers = minGl.stream().collect(Collectors.groupingBy(m ->
- "qt".equals(getIsImportance(m.getRecordDate().getHours())),
- Collectors.mapping(StationInfoMin::getPjgl, Collectors.toList())));
- Map<Boolean, List<Double>> forecastPowers = hps.stream().collect(Collectors.groupingBy(m ->
- "qt".equals(getIsImportance(m.getTime().getHours())),
- Collectors.mapping(RealtimePredict::getPredictPower, Collectors.toList())));
- examin2.setAccuracyRate1(calcHarmonicMeanAccuracy(actualPowers.get(false), forecastPowers.get(false), capacity));
- examin2.setAccuracyRate4(calcHarmonicMeanAccuracy(actualPowers.get(true), forecastPowers.get(true), capacity));
- peList.add(examin2);
- });
- //可用电量
- minMap.forEach((stId, minsKy) -> {
- Double capacity = glpisMap.get(stId) * 1000;
- Map<DateTime, List<Double>> dtlMap = czztMapMap.get(stId);
- PredictExamin2 examin2 = new PredictExamin2();
- examin2.setModelId("1");
- examin2.setPredictType("KYDL");
- examin2.setDeviceType("station");
- examin2.setTime(minsKy.get(0).getRecordDate());
- examin2.setSiteId(stId);
- calcKydlFilter(examin2, minsKy, capacity, dtlMap);
- peList.add(examin2);
- });
- predictExamin2Service.saveOrUpdateBatch(peList);
- }
- public double calcQAll(List<StationInfoMin> actualPower, List<RealtimePredict> forecastPower, double capacity, Map<DateTime, List<Double>> dtlMap) {
- List<List<StationInfoMin>> splitActual = ListUtil.split(actualPower, 96);
- List<List<RealtimePredict>> splitForecast = ListUtil.split(forecastPower, 96);
- List<Double> Pi_rs0 = splitActual.get(0).stream().map(StationInfoMin::getPjgl).collect(Collectors.toList());
- double Q_D1 = calculatePenalty(splitForecast.get(0), Pi_rs0, capacity, dtlMap);
- List<Double> Pi_rs1 = splitActual.get(1).stream().map(StationInfoMin::getPjgl).collect(Collectors.toList());
- double Q_D2 = calculatePenalty(splitForecast.get(1), Pi_rs1, capacity, dtlMap);
- List<Double> Pi_rs2 = splitActual.get(2).stream().map(StationInfoMin::getPjgl).collect(Collectors.toList());
- double Q_D3 = calculatePenalty(splitForecast.get(2), Pi_rs2, capacity, dtlMap);
- double[] weights = {0.6, 0.3, 0.1};
- return Q_D1 * weights[0] + Q_D2 * weights[1] + Q_D3 * weights[2];
- }
- /**
- * 根据偏差计算积分电量
- * Pi_n 预测功率
- * Pi_r 实际功率
- */
- public double calculatePenalty(List<RealtimePredict> rps, List<Double> Pi_rs, double capacity, Map<DateTime, List<Double>> dtlMap) {
- int n = rps.size();
- double Q = 0;
- if (Pi_rs.size() != n) return Q;
- for (int i = 0; i < n; i++) {
- RealtimePredict predict = rps.get(i);
- List<Double> doubles = dtlMap.get(predict.getTime());
- //限电免考核
- if (calcXdRate(doubles) > 0.5) continue;
- double Pi_n = predict.getPredictPower();
- double Pi_r = Pi_rs.get(i);
- //免考核
- if (Pi_n <= 0.03 * capacity && Pi_r <= 0.03 * capacity) continue;
- //预测偏差
- double Ei = (Pi_r - Pi_n) / Pi_r;
- //免考核
- if (Math.abs(Ei) < 0.25) continue;
- double D = getD(Pi_n, Pi_r);
- double K = getK(predict.getTime().getHours(), Ei);
- Q += D * K;
- }
- //万kWh
- return Q / 10000;
- }
- public double getD(double Pi_n, double Pi_r) {
- double v;
- if (Pi_n > 1.25 * Pi_r) {
- v = 0.25 * (Pi_n - 1.25 * Pi_r);
- } else if (Pi_n > 0.75 * Pi_r) {
- v = 0;
- } else {
- v = 0.25 * (0.75 * Pi_r - Pi_n);
- }
- return v;
- }
- public double getK(int hour, double Ei) {
- double K = 0;
- String importance = getIsImportance(hour);
- if ("df".equals(importance)) {
- if (Ei < -0.25) {
- K = 0.05;
- } else if (Ei > 0.25) {
- K = 0.1;
- }
- } else if ("gf".equals(importance)) {
- if (Ei < -0.25) {
- K = 0.15;
- } else if (Ei > 0.25) {
- K = 0.05;
- }
- } else {
- K = 0.05;
- }
- return K;
- }
- // private double calculateWeightedSum(double[] integralDifferences, double weight) {
- // double sum = 0;
- // for (double diff : integralDifferences) {
- // sum += diff;
- // }
- // return sum * weight;
- // }
- /**
- * 计算超短期预测考核总分
- */
- public void calculateForecastScore(PredictExamin2 examin, List<List<Double>> predict, List<List<Double>> actual, List<Double> standards, double capacity, int hour) {
- double totalScore = 0.0;
- for (int i = 0; i < 4; i++) {
- Double standard = standards.get(i);
- double accuracy = calcHarmonicMeanAccuracy(actual.get(i), predict.get(i), capacity);
- if (i == 0) {
- examin.setAccuracyRate1(accuracy);
- } else if (i == 1) {
- examin.setAccuracyRate2(accuracy);
- } else if (i == 2) {
- examin.setAccuracyRate3(accuracy);
- } else {
- examin.setAccuracyRate4(accuracy);
- }
- // 预测准确率小于标准准确率
- double v = standard - accuracy;
- if (v > 0) {
- // 是否重点时段
- String importance = getIsImportance(hour + i);
- if ("qt".equals(importance)) {
- totalScore += capacity * 0.0003 * v * 100;
- } else {
- totalScore += capacity * 0.0015 * v * 100;
- }
- }
- }
- //MW转万kWh
- examin.setExaminScore(totalScore / 10000);
- }
- /**
- * 计算是否是重点时间段
- */
- public String getIsImportance(int hour) {
- if (hour >= 10 && hour < 16) {
- //大发
- return "df";
- } else if ((hour >= 6 && hour < 9) || (hour >= 17 && hour < 22)) {
- //高峰
- return "gf";
- }
- //其他
- return "qt";
- }
- /**
- * 计算某一小时段的调和平均数准确率
- */
- public double calcHarmonicMeanAccuracy(List<Double> actualPower, List<Double> forecastPower, double capacity) {
- int n = actualPower.size();
- double sum = 0;
- double sumrn = 0;
- for (int i = 0; i < n; i++) {
- double Pi_r = actualPower.get(i);
- double Pi_n = forecastPower.get(i);
- double abs = Math.abs(Pi_r - Pi_n);
- if (Pi_n <= 0.03 * capacity && Pi_r <= 0.03 * capacity) continue; // 免考核条件
- sumrn += abs;
- sum += Math.abs(Pi_r / (Pi_r + Pi_n) - 0.5) * abs;
- }
- return sumrn == 0 ? 0.99 : (1 - 2 * sum / sumrn);
- }
- /**
- * 可用电量计算过滤
- */
- public void calcKydlFilter(PredictExamin2 examin2, List<StationInfoMin> mins, double capacity, Map<DateTime, List<Double>> dtlMap) {
- double actualPower = 0, availablePower = 0, pjgl = 0;
- for (StationInfoMin min : mins) {
- List<Double> doubles = dtlMap.get(min.getRecordDate());
- //限电
- if (calcXdRate(doubles) > 0.6) continue;
- actualPower += min.getRfdl();
- availablePower += min.getKygl() / 4;
- pjgl += min.getPjgl() / 4;
- }
- double accuracy = calcKydlAccuracy(actualPower, availablePower, capacity);
- double penalty = calcKydlPenalty(accuracy, capacity);
- examin2.setAccuracyRate1(accuracy);
- double sum = mins.stream().mapToDouble(StationInfoMin::getRfdl).sum();
- double sum1 = mins.stream().mapToDouble(StationInfoMin::getKygl).sum();
- examin2.setAccuracyRate2(sum);
- examin2.setAccuracyRate3(sum1 / 4);
- examin2.setAccuracyRate4(calcKydlAccuracy(actualPower, pjgl, capacity));
- examin2.setExaminScore(penalty);
- }
- public double calcXdRate(List<Double> doubles) {
- if (CollUtil.isEmpty(doubles)) return 0; // 计算1.0的数量
- long countOfOnes = doubles.stream().filter(number -> number == 1.0).count();
- // 计算1.0在列表中的占比
- return (double) countOfOnes / doubles.size();
- }
- /**
- * 计算可用电量准确率
- */
- public double calcKydlAccuracy(double actualPower, double availablePower, double capacity) {
- if (actualPower == 0) return 0.97;
- double v = capacity * 24 * 0.03;
- if (actualPower < v && availablePower < v) return 0.97;
- return 1 - Math.abs(actualPower - availablePower) / actualPower;
- }
- /**
- * 计算考核扣分
- */
- public double calcKydlPenalty(double accuracy, double capacity) {
- if (accuracy >= 0.97) return 0.0;
- double v = capacity * 0.02 * (0.97 - accuracy) * 100;
- //万kWh
- return v / 10000;
- }
- public void calcStationXdTest(Date date, String stId) {
- DateTime end = DateUtil.beginOfDay(date);
- DateTime start = DateUtil.offsetDay(end, -1);
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- entityAgc = filterPointInfo(entityAgc, stId, PointInfo::getStationId);
- getSnapDataByEntity(entityAgc, start, end, 15);
- PointInfo agcInfo = entityAgc.get(0);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- entityCx = filterPointInfo(entityCx, stId, PointInfo::getStationId);
- getSnapDataByEntity(entityCx, start, end, 15);
- PointInfo cxInfo = entityCx.get(0);
- //状态
- List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
- turbineZt = filterPointInfo(turbineZt, stId, PointInfo::getStationId);
- List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
- turbineAizt = filterPointInfo(turbineAizt, stId, PointInfo::getStationId);
- turbineZt.addAll(turbineAizt);
- Map<String, PointInfo> ztMap = turbineZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- entityFs = filterPointInfo(entityFs, stId, PointInfo::getStationId);
- getSnapDataByEntity(entityFs, start, end, 15);
- Map<String, PointInfo> fsMap = entityFs.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
- Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
- ztMap.forEach((wtId, zt) -> {
- List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(
- pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- fsMap.get(wtId).setPointDatas(peek);
- List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
- Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
- return new PointData(pd.getTs(), v == null ? 0 : v);
- }).collect(Collectors.toList());
- pdsZsglMap.put(wtId, zsglSnap);
- });
- //风机风速、功率->场站风速、功率
- List<PointData> firstZsgl = new ArrayList<>();
- for (int i = 0; i < agcInfo.getPointDatas().size(); i++) {
- int finalI = i;
- long ts = start.getTime() + finalI * 15000L;
- double v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
- firstZsgl.add(new PointData(ts, v3));
- }
- List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
- for (PointData pd : czxd) {
- System.out.println(DateUtil.formatDateTime(new Date(pd.getTs())) + "," + pd.getValue());
- }
- }
- }
|