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