123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730 |
- package com.ruoyi.web.controller;
- import cn.hutool.core.collection.CollUtil;
- 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.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 {
- @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 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:8017/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();
- // double v2 = v > 0 ? v : 0;
- double v2 = v;
- switch ((int) collectZt.get(i).getValue()) {
- //计划检修损失:
- case 6:
- //检修
- jxss += v2;
- break;
- case 1:
- //手动停机
- sdtj += v2;
- break;
- //非计划检修损失:
- case 4:
- //故障
- gzss += v2;
- break;
- case 0:
- //待机
- djss += v2;
- break;
- //性能损失:
- case 2:
- //性能
- xnss += v2;
- break;
- case 3:
- //发电降出力
- fdjcl += v2;
- break;
- //限电损失:
- case 8:
- //限电降出力
- xdjcl += v2;
- break;
- case 9:
- //限电停机
- xdtj += v2;
- 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(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(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(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();
- 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 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 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));
- 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);
- if (czxd) {
- //叶轮转速给定
- List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
- getLatestByEntity(entityYlzsgd);
- Map<String, List<PointData>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
- ztMap.forEach((wtId, ztInfo) -> {
- List<PointData> fss = fsMap.get(wtId).getPointDatas();
- List<PointData> gls = glMap.get(wtId);
- //叶轮转速给定
- List<PointData> ylzsgds = collectYlzsgd.get(wtId);
- calcRealtimeTurbineXd(ztInfo, gls.get(0), fss.get(fss.size() - 1), ylzsgds.get(0));
- });
- }
- });
- Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
- Map<String, String> entityQfzt = getEntityMap("SSQFZT", "turbine");
- //Map<String, String> entityKygl = getEntityMap("KYGL", "turbine");
- List<PointInfo> fsEntity = entityFs.stream().peek(fs -> {
- PointData data = fs.getPointDatas().get(fs.getPointDatas().size() - 1);
- if (data != null) {
- fs.setPointDatas(Collections.singletonList(data));
- } else {
- fs.setPointDatas(Collections.singletonList(new PointData()));
- }
- }).collect(Collectors.toList());
- List<PointData> qfztDataList = fsEntity.stream().map(fs -> {
- String wtId = fs.getTurbineId();
- PointData data = fs.getPointDatas().get(0);
- 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) {
- 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 static void main(String[] args) {
- Double b = 2.0;
- double c = 2.0;
- System.out.println(b == c);
- Double d = Double.valueOf(c);
- System.out.println(Objects.equals(b, c));
- System.out.println(Objects.equals(d, b));
- System.out.println(Objects.equals(null, null));
- List<PointData> points = new ArrayList<>();
- points.add(new PointData(1000, 1));
- points.add(new PointData(1500, 2));
- points.add(new PointData(2000, 1));
- points.add(new PointData(2500, 3));
- // Map<Integer, Long> durations = calculateStateDurations(points);
- // for (Map.Entry<Integer, Long> entry : durations.entrySet()) {
- // System.out.println("State " + entry.getKey() + ": " + entry.getValue() + "ms");
- // }
- }
- 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 void getLatestByEntity(List<PointInfo> entity) {
- 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())));
- });
- }
- 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(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(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(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) {
- 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);
- }
- }
- }
- //此处加公式
- 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 date, int granularity) {
- date = DateUtil.beginOfMinute(date);
- DateTime start = DateUtil.offsetMinute(date, -granularity);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- Map<String, PointInfo> rawMapFs = getRawDataByEntity(entityFs, goldenUri(), start, date, PointInfo::getTurbineId);
- //功率
- List<PointInfo> entityGl = getEntity("AI114", "turbine");
- Map<String, PointInfo> rawMapGl = getRawDataByEntity(entityGl, goldenUri(), start, date, PointInfo::getTurbineId);
- List<PointInfo> entityZt = getEntity("MXZT", "turbine");
- Map<String, PointInfo> rawMapZt = getRawDataByEntity(entityZt, goldenUri(), start, date, PointInfo::getTurbineId);
- 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(), 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 : pd.getValue() < 0 ? 0 : NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
- for (PointData fsData : fsDatas) {
- if (fsData.getValue() > 3 && CalcCache.llgl.get(tbId).get(fsData.getValue()) == null) {
- System.out.println();
- }
- }
- double llgl = fsDatas.stream().mapToDouble(pd -> pd.getValue() <= 3 ? 0d : CalcCache.llgl.get(tbId).get(pd.getValue())).average().orElse(0.0);
- double kygl = fsDatas.stream().filter(pd -> ztMap.get(pd.getTs()) != 4 || ztMap.get(pd.getTs()) != 6)
- .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);
- double v = llgl * 0.9;
- if (kygl > v) kygl = v;
- 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 date, int granularity) {
- date = DateUtil.beginOfMinute(date);
- DateTime start = DateUtil.offsetMinute(date, -granularity);
- //AGC
- List<PointInfo> entityAgc = getEntity("AGC002", "booster");
- Map<String, PointInfo> statMapAgc = getStatDataByEntity(entityAgc, goldenUri(), start, date, PointInfo::getStationId);
- //出线
- List<PointInfo> entityCx = getEntity("AGC001", "booster");
- Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, date, 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);
- day.setLlgl(min.getLlgl());
- day.setKygl(min.getKygl());
- day.setAgc(agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef());
- day.setPjgl(cxInfo.getPointDatas().get(0).getValue() * cxInfo.getCoef());
- 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) {
- 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 = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
- //风速
- List<PointInfo> entityFs = getEntity("AI066", "turbine");
- getRawDataByEntity(entityFs, goldenUri(), begin, end);
- Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
- //环境温度
- List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
- 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())).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);
- 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);
- 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) {
- 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);
- 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) {
- 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));
- 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;
- }
- }
- }
|