123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982 |
- package com.gyee.power.fitting.service.impl;
- import com.gyee.power.fitting.common.alg.CurrentVoltageCalc;
- import com.gyee.power.fitting.common.alg.PolynomialCurveFitting;
- import com.gyee.power.fitting.common.config.GyeeConfig;
- import com.gyee.power.fitting.common.constants.Constants;
- import com.gyee.power.fitting.common.feign.IAdapterService;
- import com.gyee.power.fitting.common.feign.RemoteServiceBuilder;
- import com.gyee.power.fitting.common.spring.InitialRunner;
- import com.gyee.power.fitting.common.util.DateUtils;
- import com.gyee.power.fitting.common.util.FileUtil;
- import com.gyee.power.fitting.common.util.PowerFittingUtil;
- import com.gyee.power.fitting.model.*;
- import com.gyee.power.fitting.model.anno.AnnotationTool;
- import com.gyee.power.fitting.model.anno.FixedVo;
- import com.gyee.power.fitting.model.custom.FjjxbVo;
- import com.gyee.power.fitting.model.custom.PhotovoltaicInfo;
- import com.gyee.power.fitting.model.custom.TableTitle;
- import com.gyee.power.fitting.model.custom.TsDoubleData;
- import com.gyee.power.fitting.service.ProBasicEquipmentPointService;
- import com.gyee.power.fitting.service.ProBasicPowerstationPointService;
- import com.gyee.power.fitting.service.custom.curve.DataScangfService;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.commons.math3.fitting.WeightedObservedPoints;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @Service
- public class NewIvPvCurveFittingService {
- @Resource
- private ProBasicWeatherStationServiceImpl weatherStationService;
- @Resource
- private ProBasicEquipmentPointService proBasicEquipmentPointService;
- @Resource
- private ProBasicPowerstationPointService proBasicPowerstationPointService;
- @Resource
- private IAdapterService adpClient;
- @Autowired
- private RemoteServiceBuilder remoteService;
- @Resource
- private GyeeConfig config;
- @Resource
- private PolynomialCurveFitting pncf;
- private List<FixedVo> fixedVos;
- private Map<String, String> uniforcodes;
- @Resource
- private DataScangfService dataScangfService;
- public void getDatas2File(String stationid, long start, long end, int interval) {
- int daym = 24 * 60 * 60 * 1000;
- //按天
- for (long i = start; i < end; i += daym) {
- List<List<PhotovoltaicInfo>> datas = getDatas(stationid, i, i + daym, interval);
- infos2File(datas);
- }
- }
- public Map<String, List<PhotovoltaicInfo>> getDatas2File1(String stationid,List<String> inverters, long start, long end, int interval) {
- int daym = 24 * 60 * 60 * 1000;
- Map<String, List<PhotovoltaicInfo>> wj = new HashMap<>();
- //按天
- for (long i = start; i < end; i += daym) {
- List<List<PhotovoltaicInfo>> datas = getDatasnotfile(stationid,inverters, i, i + daym, interval);
- for (List<PhotovoltaicInfo> data : datas) {
- List<PhotovoltaicInfo> infos = wj.get(data.get(0).getInverter());
- if (infos == null) {
- wj.put(data.get(0).getInverter(), data);
- } else {
- infos.addAll(data);
- }
- }
- }
- return wj;
- }
- private void infos2File(List<List<PhotovoltaicInfo>> datas) {
- //文件第一行
- List<FixedVo> fixedVos = AnnotationTool.getFixedVoList(PhotovoltaicInfo.class);
- String columnName = fixedVos.stream().map(FixedVo::getDes).collect(Collectors.joining(","));
- //遍历逆变器
- for (List<PhotovoltaicInfo> data : datas) {
- PhotovoltaicInfo info = data.get(0);
- String station = info.getStation();
- String fileName = config.getFilePathPrepare() + "gf" + File.separator + "一秒" + File.separator + station + "-" + info.getInverter() + "-" + DateUtils.date2StringS(new Date(info.getTime())) + ".csv";
- File file = new File(fileName);
- if (file.exists()) continue;
- StringBuilder sb = new StringBuilder();
- sb.append(columnName).append("\n");
- for (PhotovoltaicInfo datum : data) {
- sb.append(datum.getStation()).append(",").append(datum.getInverter()).append(",").append(DateUtils.date2StringL(new Date(datum.getTime())))
- .append(",").append(datum.getT()).append(",").append(datum.getS()).append(",").append(datum.getI()).append(",").append(datum.getV())
- .append(",").append(datum.getActualP()).append(",").append(datum.getAI()).append(",").append(datum.getAV()).append(",")
- .append(datum.getBI()).append(",").append(datum.getBV()).append(",").append(datum.getCI()).append(",").append(datum.getCV())
- .append("\n");
- }
- FileUtil.writeFile(fileName, sb.toString());
- }
- }
- public List<String> getFileList(String station, List<String> nbq, long startdate, int interval, long enddate, boolean isOffline) {
- List<String> fileList = new ArrayList<>();
- File file = null;
- //获取文件位置
- if (interval == 1) {
- file = new File(config.getFilePathPrepare() + "gf" + File.separator + "一秒" + File.separator);
- } else if (interval == 1) {
- file = new File(config.getFilePathPrepare() + "gf" + File.separator + "一秒" + File.separator);
- }
- //获取文件列表
- File[] files = file.listFiles();
- //如果文件不够,返回null
- for (long i = startdate; i < enddate; i += 24 * 60 * 60 * 1000) {
- int size = fileList.size();
- String s = DateUtils.date2StringS(new Date(i));
- for (File f : files) {
- if (f.getName().contains(station) && f.getName().contains(s) && jiancha(f.getName(), nbq))
- fileList.add(f.getName());
- }
- if (fileList.size() == size && !isOffline) return null;
- }
- return fileList;
- }
- private boolean jiancha(String name, List<String> nbq) {
- for (String s : nbq) {
- if (name.contains(s)) return true;
- }
- return false;
- }
- public Map<String, Object> getTable(String s) {
- List<FixedVo> fixedVos = AnnotationTool.getFixedVoList(PhotovoltaicInfo.class);
- List<TableTitle> collect = fixedVos.stream().map(d -> new TableTitle(d.getName(), d.getDes())).collect(Collectors.toList());
- Map<String, Object> tableMap = new HashMap<>();
- String fs = config.getFilePathPrepare() + "gf" + File.separator + s;
- List<PhotovoltaicInfo> infos = file2Info(fs, false);
- tableMap.put("data", infos);
- tableMap.put("title", collect);
- return tableMap;
- }
- private List<PhotovoltaicInfo> file2Info(String path, boolean isAll) {
- List<String> strings = FileUtil.readFile(path, isAll);
- List<PhotovoltaicInfo> infos = new ArrayList<>();
- for (int i = 1; i < strings.size(); i++) {
- String[] split = strings.get(i).split(",");
- PhotovoltaicInfo info = new PhotovoltaicInfo();
- try {
- info.setStation(split[0]);
- info.setInverter(split[1]);
- if (!"".equals(split[2])) {
- info.setTime(DateUtils.string2DateL(split[2]).getTime());
- info.setDatetime(split[2]);
- }
- info.setT(StringUtils.isBlank(split[3]) ? 0 : Double.parseDouble(split[3]));
- info.setS(StringUtils.isBlank(split[4]) ? 0 : Double.parseDouble(split[4]));
- info.setI(StringUtils.isBlank(split[5]) ? 0 : Double.parseDouble(split[5]));
- info.setV(StringUtils.isBlank(split[6]) ? 0 : Double.parseDouble(split[6]));
- info.setActualP(StringUtils.isBlank(split[7]) ? 0 : Double.parseDouble(split[7]));
- info.setAI(StringUtils.isBlank(split[8]) ? 0 : Double.parseDouble(split[8]));
- info.setAV(StringUtils.isBlank(split[9]) ? 0 : Double.parseDouble(split[9]));
- info.setBI(StringUtils.isBlank(split[10]) ? 0 : Double.parseDouble(split[10]));
- info.setBV(StringUtils.isBlank(split[11]) ? 0 : Double.parseDouble(split[11]));
- info.setCI(StringUtils.isBlank(split[12]) ? 0 : Double.parseDouble(split[12]));
- info.setCV(StringUtils.isBlank(split[13]) ? 0 : Double.parseDouble(split[13]));
- } catch (Exception e) {
- System.out.println();
- }
- infos.add(info);
- }
- return infos;
- }
- /**
- * 计算理论功率加入原列表
- *
- * @return
- */
- public Map<String, List<PhotovoltaicInfo>> calculatAnalysis(List<String> fileList) {
- String bzcldPath = config.getFilePathPrepare() + "bzd" + File.separator + "标准点.csv";
- List<PhotovoltaicInfo> bzclds = file2Info(bzcldPath, true);
- Map<String, PhotovoltaicInfo> bzcldMap = bzclds.stream().collect(Collectors.toMap(PhotovoltaicInfo::getInverter, Function.identity()));
- String fs = config.getFilePathPrepare() + "gf" + File.separator;
- Map<String, List<PhotovoltaicInfo>> stringListMap = new HashMap<>();
- for (String s : fileList) {
- //读取一个文件
- List<PhotovoltaicInfo> infos = file2Info(fs + s, true);
- List<PhotovoltaicInfo> theoryInfos;
- if (s.contains("HZJ_GDC") || s.contains("AK_GDC")) {
- theoryInfos = CurrentVoltageCalc.CalcTheoryPowerHZJ(infos, bzcldMap);
- } else {
- theoryInfos = CurrentVoltageCalc.CalcTheoryPower(infos, bzcldMap);
- }
- //按逆变器聚合数据
- if (stringListMap.containsKey(theoryInfos.get(0).getInverter())) {
- stringListMap.get(theoryInfos.get(0).getInverter()).addAll(theoryInfos);
- } else {
- stringListMap.put(theoryInfos.get(0).getInverter(), theoryInfos);
- }
- }
- return stringListMap;
- }
- /**
- * 计算理论功率加入原列表
- *
- * @return
- */
- public Map<String, List<PhotovoltaicInfo>> calculatAnalysis1(List<PhotovoltaicInfo> bzdList, Map<String, List<PhotovoltaicInfo>> datasInfos) {
- Map<String, PhotovoltaicInfo> bzcldMap = bzdList.stream().collect(Collectors.toMap(PhotovoltaicInfo::getInverter, Function.identity()));
- Map<String, List<PhotovoltaicInfo>> stringListMap = new HashMap<>();
- String s;
- for (Map.Entry<String, List<PhotovoltaicInfo>> entry : datasInfos.entrySet()) {
- s = entry.getKey();
- List<PhotovoltaicInfo> theoryInfos;
- if (s.contains("HZJ_GDC") || s.contains("AK_GDC")) {
- theoryInfos = CurrentVoltageCalc.CalcTheoryPowerHZJ(entry.getValue(), bzcldMap);
- } else {
- theoryInfos = CurrentVoltageCalc.CalcTheoryPower(entry.getValue(), bzcldMap);
- }
- stringListMap.put(s, theoryInfos);
- }
- return stringListMap;
- }
- // public Map<String, List<PhotovoltaicInfo>> calculatAnalysis1(List<List<List<PhotovoltaicInfo>>> feill) {
- //
- // String bzcldPath = config.getFilePathPrepare() + "bzd"+File.separator + "标准点.csv";
- // List<PhotovoltaicInfo> bzclds = file2Info(bzcldPath, true);
- // Map<String, PhotovoltaicInfo> bzcldMap = bzclds.stream().collect(Collectors.toMap(PhotovoltaicInfo::getInverter, Function.identity()));
- //
- // String fs = config.getFilePathPrepare() + "gf" +File.separator;
- // Map<String, List<PhotovoltaicInfo>> stringListMap = new HashMap<>();
- // for (String s : fileList) {
- // //读取一个文件
- // List<PhotovoltaicInfo> infos = file2Info(fs + s, true);
- // List<PhotovoltaicInfo> theoryInfos;
- // if (s.contains("HZJ_GDC") || s.contains("AK_GDC")) {
- // theoryInfos = CurrentVoltageCalc.CalcTheoryPowerHZJ(infos, bzcldMap);
- // } else {
- // theoryInfos = CurrentVoltageCalc.CalcTheoryPower(infos, bzcldMap);
- // }
- // //按逆变器聚合数据
- // if (stringListMap.containsKey(theoryInfos.get(0).getInverter())) {
- // stringListMap.get(theoryInfos.get(0).getInverter()).addAll(theoryInfos);
- //
- // } else {
- // stringListMap.put(theoryInfos.get(0).getInverter(), theoryInfos);
- // }
- // }
- // return stringListMap;
- // }
- /**
- * 合并同逆变器文件
- *
- * @param fileList
- * @return
- */
- public Map<String, List<PhotovoltaicInfo>> mergeCalculat(List<String> fileList) {
- String fs = config.getFilePathPrepare() + "gf" + File.separator;
- Map<String, List<PhotovoltaicInfo>> stringListMap = new HashMap<>();
- for (String s : fileList) {
- //读取一个文件
- List<PhotovoltaicInfo> infos = file2Info(fs + s, true);
- //按逆变器聚合数据
- if (stringListMap.containsKey(infos.get(0).getInverter())) {
- stringListMap.get(infos.get(0).getInverter()).addAll(infos);
- } else {
- stringListMap.put(infos.get(0).getInverter(), infos);
- }
- }
- return stringListMap;
- }
- public List<Object> str2FileList(List<String> fileList) {
- List<ProEconPowerFittingAnalySis> fileLists = new ArrayList<>();
- for (String s : fileList) {
- String[] split = s.split("-");
- ProEconPowerFittingAnalySis fl = new ProEconPowerFittingAnalySis();
- /*fl.setPath(s);
- fl.setStation(split[0]);
- fl.setStationcn(InitialRunner.gfstationMap.get(split[0]));
- fl.setWindturbine(split[1]);
- fl.setTime(split[2]+"年"+split[3]+"月");
- fl.setInterval("五分钟");*/
- fl.setPath(s);
- fl.setStation(split[0]);
- fl.setStationcn(split[1]);
- fl.setWindturbineId(split[1]);
- fl.setTime(InitialRunner.newgfstationMap.get(split[0]));
- fl.setInterval(split[2] + "年" + split[3] + "月");
- fileLists.add(fl);
- }
- List<Object> objects = PowerFittingUtil.powerDataTree(fileLists, Constants.DATA_FITTING);
- return objects;
- }
- public List<String> getAllFileList() {
- //获取文件位置
- File file = new File(config.getFilePathPrepare() + "gf" + "一秒");
- //获取文件列表
- File[] files = file.listFiles();
- List<String> fileList = Arrays.stream(files).map(f -> f.getName()).collect(Collectors.toList());
- return fileList;
- }
- /**
- * 标准点计算
- */
- public void standardPointCalculate2() {
- List<String> allFileList = getAllFileList();
- Map<String, List<PhotovoltaicInfo>> stringListMap = mergeCalculat(allFileList);
- List<PhotovoltaicInfo> ptInfos = new ArrayList<>();
- for (Map.Entry<String, List<PhotovoltaicInfo>> entry : stringListMap.entrySet()) {
- List<PhotovoltaicInfo> value = entry.getValue();
- Optional<PhotovoltaicInfo> first = value.stream().sorted(Comparator.comparing(PhotovoltaicInfo::getActualP).reversed()).findFirst();
- ptInfos.add(first.get());
- }
- //文件第一行
- List<FixedVo> fixedVos = AnnotationTool.getFixedVoList(PhotovoltaicInfo.class);
- StringBuilder sb = new StringBuilder();
- String columnName = fixedVos.stream().map(FixedVo::getDes).collect(Collectors.joining(","));
- sb.append(columnName).append("\n");
- for (PhotovoltaicInfo ptInfo : ptInfos) {
- sb.append(ptInfo.getStation()).append(",").append(ptInfo.getInverter()).append(",")
- .append(DateUtils.date2StringL(new Date(ptInfo.getTime()))).append(",")
- .append(ptInfo.getT()).append(",").append(ptInfo.getS()).append(",")
- .append(ptInfo.getI()).append(",").append(ptInfo.getV())
- .append(",").append(ptInfo.getActualP()).append(",")
- .append(ptInfo.getAI()).append(",").append(ptInfo.getAV())
- .append(",").append(ptInfo.getBI()).append(",").append(ptInfo.getBV())
- .append(",").append(ptInfo.getCI()).append(",").append(ptInfo.getCV())
- .append("\n");
- }
- String fileName = config.getFilePathPrepare() + "bzd" + File.separator + "标准点.csv";
- File file = new File(fileName);
- file.delete();
- FileUtil.writeFile(fileName, sb.toString());
- }
- /**
- * 标准点计算
- *
- * @param stringListMap
- */
- public List<PhotovoltaicInfo> standardPointCalculate1(Map<String, List<PhotovoltaicInfo>> stringListMap) {
- List<PhotovoltaicInfo> ptInfos = new ArrayList<>();
- for (Map.Entry<String, List<PhotovoltaicInfo>> entry : stringListMap.entrySet()) {
- List<PhotovoltaicInfo> value = entry.getValue();
- Optional<PhotovoltaicInfo> first = value.stream().sorted(Comparator.comparing(PhotovoltaicInfo::getActualP).reversed()).findFirst();
- ptInfos.add(first.get());
- }
- return ptInfos;
- }
- public List<TableTitle> getTheoryTitel() {
- List<FixedVo> fixedVos = AnnotationTool.getFixedVoList(PhotovoltaicInfo.class);
- String[] ss = {"station", "datetime", "T", "S", "actualP"};
- List<String> strings = Arrays.asList(ss);
- List<TableTitle> collect = fixedVos.stream().map(d -> new TableTitle(d.getName(), d.getDes())).collect(Collectors.toList());
- collect = collect.stream().filter(c -> strings.contains(c.getKey())).collect(Collectors.toList());
- TableTitle title = new TableTitle();
- title.setKey("ideaP");
- title.setDes("理论功率");
- collect.add(title);
- return collect;
- }
- /**
- * 获得所有文件的值
- *
- * @param fileList
- * @return
- */
- public List<PhotovoltaicInfo> calculatFitting(List<String> fileList) {
- String fs = config.getFilePathPrepare() + "gf" + File.separator;
- List<PhotovoltaicInfo> infoList = new ArrayList<>();
- for (String s : fileList) {
- List<PhotovoltaicInfo> infos = file2Info(fs + s, true);
- if (infoList.size() == 0 || Objects.equals(infos.get(0).getStation(), infoList.get(0).getStation())) {
- infoList.addAll(infos);
- }
- }
- return infoList;
- }
- public List<double[]> oneFileFitting(List<PhotovoltaicInfo> infos) {
- WeightedObservedPoints points = new WeightedObservedPoints();
- double max = 0;
- for (PhotovoltaicInfo info : infos) {
- if (info.getS() < 1) {
- points.add(0, 0);
- }
- points.add(info.getS(), info.getActualP());
- if (info.getS() > max) {
- max = info.getS();
- }
- }
- double[] result = pncf.run(points);
- List<double[]> b = new ArrayList<>();
- for (int i = 0; i < max; i += 5) {
- double[] curve = new double[2];
- curve[0] = i;
- curve[1] = pncf.calcPoly(i, result);
- b.add(curve);
- }
- return b;
- }
- /**
- * 光伏绩效榜
- *
- * @param startdate
- * @param enddate
- */
- public List<FjjxbVo> getPhotovoltaicPerformanceList(long startdate, long enddate, int interval) {
- int oneday = 24 * 60 * 60;
- String bzcldPath = config.getFilePathPrepare() + "bzd" + File.separator + "标准点.csv";
- List<PhotovoltaicInfo> bzclds = file2Info(bzcldPath, true);
- Map<String, PhotovoltaicInfo> bzcldMap = bzclds.stream().collect(Collectors.toMap(PhotovoltaicInfo::getInverter, Function.identity()));
- //获取实际发电量
- List<ProBasicPowerstationPoint> rfdl = proBasicPowerstationPointService.getzfsPoints(null, "RFDL");
- List<FjjxbVo> infos = new ArrayList<>();
- //遍历逆变器
- for (ProBasicPowerstationPoint wstp : rfdl) {
- //场站
- String stationid = wstp.getWindpowerstationId();
- List<TsDoubleData> history = remoteService.adapterfd().getHistorySnap(wstp.getNemCode(), startdate + oneday * 1000, enddate, oneday);
- double d = 0;
- for (TsDoubleData data : history) {
- d += data.getDoubleValue();
- }
- FjjxbVo vo = new FjjxbVo();
- vo.setName(InitialRunner.newgfstationMap.get(stationid));
- vo.setSjfdl(d);
- //理论发电量
- double llfdl = 0;
- //光照平均值
- double gz = 0;
- int i = 0;
- double t = 5 / 60;
- List<List<PhotovoltaicInfo>> datas = getDatas(stationid, startdate, enddate, interval);
- //遍历逆变器
- for (List<PhotovoltaicInfo> data : datas) {
- if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
- CurrentVoltageCalc.CalcTheoryPowerHZJ(data, bzcldMap);
- } else {
- CurrentVoltageCalc.CalcTheoryPower(data, bzcldMap);
- }
- for (PhotovoltaicInfo datum : data) {
- llfdl += datum.getIdeaP() * t;
- gz += datum.getS();
- i++;
- }
- }
- vo.setLlfdl(llfdl);
- vo.setSpeed(gz / i);
- vo.setFnlly(vo.getSjfdl() / vo.getLlfdl() * 100);
- infos.add(vo);
- }
- return infos;
- }
- /**
- * 获取数据
- *
- * @return 逆变器,列表
- */
- public List<List<PhotovoltaicInfo>> getDatas(String stationid, long start, long end, int interval) {
- //间隔
- interval = 5 * 60; //5分钟-300
- //获得测点
- Map<String, String> zglpoints = getPoints(stationid, "zgl");
- Map<String, String> llglpoints = getPoints(stationid, "llgl");
- Map<String, String> adypoints = getPoints(stationid, "ady");
- Map<String, String> bdypoints = getPoints(stationid, "bdy");
- Map<String, String> cdypoints = getPoints(stationid, "cdy");
- Map<String, String> adlpoints = getPoints(stationid, "adl");
- Map<String, String> bdlpoints = getPoints(stationid, "bdl");
- Map<String, String> cdlpoints = getPoints(stationid, "cdl");
- List<ProBasicWeatherStation> weatherStations = weatherStationService.getBaseMapper().selectList(null);
- List<ProBasicWeatherStation> collect = weatherStations.stream().filter(c -> stationid.equals(c.getWindpowerstationId())).collect(Collectors.toList());
- String station = collect.get(0).getId();
- ProBasicPowerstationPoint zfsPoint = InitialRunner.newzfsMap.get(stationid);
- ProBasicPowerstationPoint zjwdPoint = InitialRunner.newzjwdMap.get(station);
- //总辐射
- // List<TsDoubleData> zfsDatas = adpClient.getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
- List<TsDoubleData> zfsDatas = remoteService.adapterfd().getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
- //组件温度
- // List<TsDoubleData> zjwdDatas = adpClient.getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
- List<TsDoubleData> zjwdDatas = remoteService.adaptergf().getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
- List<List<PhotovoltaicInfo>> infosLit = new ArrayList<>();
- //按逆变器
- for (String wtid : zglpoints.keySet()) {
- //总功率
- // List<TsDoubleData> zglDatas = adpClient.getHistorySnap(zglpoints.get(wtid), start, end, interval);
- List<TsDoubleData> zglDatas = remoteService.adaptergf().getHistorySnap(zglpoints.get(wtid), start, end, interval);
- List<TsDoubleData> llglDatas = remoteService.adapterfd().getHistorySnap(llglpoints.get(wtid), start, end, interval);
- //电网A相电压
- // List<TsDoubleData> adyDatas = adpClient.getHistorySnap(adypoints.get(wtid), start, end, interval);
- List<TsDoubleData> adyDatas = remoteService.adaptergf().getHistorySnap(adypoints.get(wtid), start, end, interval);
- //电网A相电流
- // List<TsDoubleData> adlDatas = adpClient.getHistorySnap(adlpoints.get(wtid), start, end, interval);
- List<TsDoubleData> adlDatas = remoteService.adaptergf().getHistorySnap(adlpoints.get(wtid), start, end, interval);
- List<PhotovoltaicInfo> infos = new ArrayList<>();
- List<TsDoubleData> bdyDatas = null, cdyDatas = null, bdlDatas = null, cdlDatas = null;
- if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
- //电网B相电压
- bdyDatas = adpClient.getHistorySnap(bdypoints.get(wtid), start, end, interval);
- //电网C相电压
- cdyDatas = adpClient.getHistorySnap(cdypoints.get(wtid), start, end, interval);
- //电网B相电流
- bdlDatas = adpClient.getHistorySnap(bdlpoints.get(wtid), start, end, interval);
- //电网C相电流
- cdlDatas = adpClient.getHistorySnap(cdlpoints.get(wtid), start, end, interval);
- }
- for (int j = 0; j < zfsDatas.size(); j++) {
- PhotovoltaicInfo info = new PhotovoltaicInfo();
- info.setStation(stationid);
- info.setInverter(wtid);
- long ts = zfsDatas.get(j).getTs();
- info.setTime(ts);
- info.setDatetime(DateUtils.date2StringL(new Date(ts)));
- info.setT(double3Decimal(zjwdDatas.get(j).getDoubleValue()));
- info.setS(double3Decimal(zfsDatas.get(j).getDoubleValue(), false));
- if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
- info.setAI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
- info.setBI(double3Decimal(bdlDatas.get(j).getDoubleValue(), false));
- info.setCI(double3Decimal(cdlDatas.get(j).getDoubleValue(), false));
- info.setAV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
- info.setBV(double3Decimal(bdyDatas.get(j).getDoubleValue(), true));
- info.setCV(double3Decimal(cdyDatas.get(j).getDoubleValue(), true));
- } else {
- if (adlDatas.size() >= 1) {
- info.setI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
- } else {
- info.setI(0);
- }
- if (adyDatas.size() >= 1) {
- info.setV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
- } else {
- info.setV(0);
- }
- }
- if (zglDatas.size() >= 1) {
- info.setActualP(double3Decimal(zglDatas.get(j).getDoubleValue(), false));
- } else {
- info.setActualP(0);
- }
- if (llglDatas.size() >= 1) {
- info.setIdeaP(double3Decimal(llglDatas.get(j).getDoubleValue(), false));
- } else {
- info.setIdeaP(0);
- }
- infos.add(info);
- }
- infosLit.add(infos);
- }
- return infosLit;
- }
- /**
- * 获取数据
- *
- * @return 逆变器,列表
- */
- public List<List<PhotovoltaicInfo>> getDatasnotfile(String stationid,List<String> inverters, long start, long end, int interval) {
- //间隔
- // interval = 5 * 60; //5分钟-300
- //获得测点
- // if (inverters.size()>1){
- // for (String s : inverters){
- Map<String, String> zglpoints = getPoints1(stationid, inverters, "zgl");
- Map<String, String> llglpoints = getPoints1(stationid, inverters, "llgl");
- Map<String, String> adypoints = getPoints1(stationid, inverters, "ady");
- Map<String, String> bdypoints = getPoints1(stationid, inverters, "bdy");
- Map<String, String> cdypoints = getPoints1(stationid, inverters, "cdy");
- Map<String, String> adlpoints = getPoints1(stationid, inverters, "adl");
- Map<String, String> bdlpoints = getPoints1(stationid, inverters, "bdl");
- Map<String, String> cdlpoints = getPoints1(stationid, inverters, "cdl");
- List<ProBasicWeatherStation> weatherStations = weatherStationService.getBaseMapper().selectList(null);
- List<ProBasicWeatherStation> collect = weatherStations.stream().filter(c -> stationid.equals(c.getWindpowerstationId())).collect(Collectors.toList());
- String station = collect.get(0).getId();
- ProBasicPowerstationPoint zfsPoint = InitialRunner.newzfsMap.get(stationid);
- ProBasicPowerstationPoint zjwdPoint = InitialRunner.newzjwdMap.get(station);
- //总辐射
- // List<TsDoubleData> zfsDatas = adpClient.getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
- List<TsDoubleData> zfsDatas = remoteService.adapterfd().getHistorySnap(zfsPoint.getNemCode(), start, end, interval);
- //组件温度
- // List<TsDoubleData> zjwdDatas = adpClient.getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
- List<TsDoubleData> zjwdDatas = remoteService.adaptergf().getHistorySnap(zjwdPoint.getNemCode(), start, end, interval);
- List<List<PhotovoltaicInfo>> infosLit = new ArrayList<>();
- //按逆变器
- for (String wtid : zglpoints.keySet()) {
- //总功率
- // List<TsDoubleData> zglDatas = adpClient.getHistorySnap(zglpoints.get(wtid), start, end, interval);
- List<TsDoubleData> zglDatas = remoteService.adaptergf().getHistorySnap(zglpoints.get(wtid), start, end, interval);
- List<TsDoubleData> llglDatas = remoteService.adapterfd().getHistorySnap(llglpoints.get(wtid), start, end, interval);
- //电网A相电压
- // List<TsDoubleData> adyDatas = adpClient.getHistorySnap(adypoints.get(wtid), start, end, interval);
- List<TsDoubleData> adyDatas = remoteService.adaptergf().getHistorySnap(adypoints.get(wtid), start, end, interval);
- //电网A相电流
- // List<TsDoubleData> adlDatas = adpClient.getHistorySnap(adlpoints.get(wtid), start, end, interval);
- List<TsDoubleData> adlDatas = remoteService.adaptergf().getHistorySnap(adlpoints.get(wtid), start, end, interval);
- List<PhotovoltaicInfo> infos = new ArrayList<>();
- List<TsDoubleData> bdyDatas = null, cdyDatas = null, bdlDatas = null, cdlDatas = null;
- if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
- //电网B相电压
- bdyDatas = adpClient.getHistorySnap(bdypoints.get(wtid), start, end, interval);
- //电网C相电压
- cdyDatas = adpClient.getHistorySnap(cdypoints.get(wtid), start, end, interval);
- //电网B相电流
- bdlDatas = adpClient.getHistorySnap(bdlpoints.get(wtid), start, end, interval);
- //电网C相电流
- cdlDatas = adpClient.getHistorySnap(cdlpoints.get(wtid), start, end, interval);
- }
- for (int j = 0; j < zfsDatas.size(); j++) {
- PhotovoltaicInfo info = new PhotovoltaicInfo();
- info.setStation(stationid);
- info.setInverter(wtid);
- long ts = zfsDatas.get(j).getTs();
- info.setTime(ts);
- info.setDatetime(DateUtils.date2StringL(new Date(ts)));
- info.setT(double3Decimal(zjwdDatas.get(j).getDoubleValue()));
- info.setS(double3Decimal(zfsDatas.get(j).getDoubleValue(), false));
- if ("HZJ_GDC".equals(stationid) || "AK_GDC".equals(stationid)) {
- info.setAI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
- info.setBI(double3Decimal(bdlDatas.get(j).getDoubleValue(), false));
- info.setCI(double3Decimal(cdlDatas.get(j).getDoubleValue(), false));
- info.setAV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
- info.setBV(double3Decimal(bdyDatas.get(j).getDoubleValue(), true));
- info.setCV(double3Decimal(cdyDatas.get(j).getDoubleValue(), true));
- } else {
- if (adlDatas.size() >= 1) {
- info.setI(double3Decimal(adlDatas.get(j).getDoubleValue(), false));
- } else {
- info.setI(0);
- }
- if (adyDatas.size() >= 1) {
- info.setV(double3Decimal(adyDatas.get(j).getDoubleValue(), true));
- } else {
- info.setV(0);
- }
- }
- if (zglDatas.size() >= 1) {
- info.setActualP(double3Decimal(zglDatas.get(j).getDoubleValue(), false));
- } else {
- info.setActualP(0);
- }
- if (llglDatas.size() >= 1) {
- info.setIdeaP(double3Decimal(llglDatas.get(j).getDoubleValue(), false));
- } else {
- info.setIdeaP(0);
- }
- infos.add(info);
- }
- infosLit.add(infos);
- }
- // }
- // }
- return infosLit;
- }
- private double double3Decimal(double d) {
- BigDecimal bd = new BigDecimal(d);
- return bd.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
- }
- private double double3Decimal(double d, boolean isMultFactor) {
- d = d < 1 ? 0 : d;
- if (isMultFactor) {
- d = d * 0.001;
- }
- return double3Decimal(d);
- }
- /**
- * 获得测点
- * 逆变器,测点
- */
- private Map<String, String> getPoints(String stationid, String key) {
- switch (key) {
- case "zgl":
- //总功率
- return InitialRunner.newzglMap.get(stationid).stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "llgl":
- //总功率
- return InitialRunner.newllglMap.get(stationid).stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "ady":
- List<ProBasicEquipmentPoint> adyPoints = null;
- if ("HZJ_GDC".equals(stationid)) {
- //电网A相电压
- adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
- } else {
- //电网A相电压
- adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
- }
- return adyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "bdy":
- List<ProBasicEquipmentPoint> bdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG008");
- return bdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "cdy":
- List<ProBasicEquipmentPoint> cdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG011");
- return cdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "adl":
- List<ProBasicEquipmentPoint> adlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG004");
- return adlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "bdl":
- List<ProBasicEquipmentPoint> bdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG007");
- return bdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- case "cdl":
- List<ProBasicEquipmentPoint> cdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG010");
- return cdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- }
- return new HashMap<>();
- }
- private Map<String, String> getPoints1(String stationid, List<String> inverters, String key) {
- // for (String wt : inverters) {
- switch (key) {
- case "zgl":
- //总功率
- Map<String, String> intial = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap = InitialRunner.newzglMap.get(stationid).stream()
- .filter(c -> !c.getNemCode().equals("INTIAL") && c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial.putAll(tempMap);
- }
- return intial;
- case "llgl":
- //总功率
- Map<String, String> intial1 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap1 = InitialRunner.newllglMap.get(stationid).stream().filter(c -> !c.getNemCode().equals("INTIAL") &&
- c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial1.putAll(tempMap1);
- }
- return intial1;
- case "ady":
- List<ProBasicEquipmentPoint> adyPoints = null;
- if ("HZJ_GDC".equals(stationid)) {
- //电网A相电压
- adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
- } else {
- //电网A相电压
- adyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG005");
- }
- Map<String, String> intial2 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap2 = adyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId()
- .equals(wt)).collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial2.putAll(tempMap2);
- }
- return intial2;
- case "bdy":
- List<ProBasicEquipmentPoint> bdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG008");
- Map<String, String> intial3 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap3 = bdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial3.putAll(tempMap3);
- }
- return intial3;
- case "cdy":
- List<ProBasicEquipmentPoint> cdyPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG011");
- Map<String, String> intial4 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap4 = cdyPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial4.putAll(tempMap4);
- }
- return intial4;
- case "adl":
- List<ProBasicEquipmentPoint> adlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG004");
- Map<String, String> intial5 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap5 = adlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial5.putAll(tempMap5);
- }
- return intial5;
- case "bdl":
- List<ProBasicEquipmentPoint> bdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG007");
- Map<String, String> intial6 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap6 = bdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial6.putAll(tempMap6);
- }
- return intial6;
- case "cdl":
- List<ProBasicEquipmentPoint> cdlPoints = proBasicEquipmentPointService.getPoints(stationid, null, "AIG010");
- Map<String, String> intial7 = new HashMap<>();
- for (String wt : inverters) {
- Map<String, String> tempMap7 = cdlPoints.stream().filter(c -> !c.getNemCode().equals("INTIAL")&& c.getWindturbineId().equals(wt))
- .collect(Collectors.toMap(ProBasicEquipmentPoint::getWindturbineId, ProBasicEquipmentPoint::getNemCode));
- intial7.putAll(tempMap7);
- }
- return intial7;
- }
- // }
- return new HashMap<>();
- }
- public int deleteFiles(List<String> fileList) {
- String fs = config.getFilePathPrepare() + "gf";
- List<PhotovoltaicInfo> infoList = new ArrayList<>();
- int count = 0;
- for (String s : fileList) {
- File file = new File(fs + s);
- if (file.delete()) count++;
- }
- return count;
- }
- public void downFiles(List<String> strings, HttpServletResponse response) {
- List<File> files = path2File(strings);
- String path = config.getFilePathPrepare() + "zip\\" + System.currentTimeMillis() + ".zip";
- String s = FileUtil.zipFiles(files, new File(path));
- FileUtil.download(s, response);
- }
- private List<File> path2File(List<String> strings) {
- List<File> files = new ArrayList<>();
- for (String string : strings) {
- files.add(new File(config.getFilePathPrepare() + "gf" + string));
- }
- return files;
- }
- public List<FixedVo> getFixedVos() {
- if (fixedVos == null) {
- fixedVos = AnnotationTool.getFixedVoList(PhotovoltaicInfo.class);
- uniforcodes = fixedVos.stream().filter(fv -> fv.getUniformCode() != null).collect(Collectors.toMap(FixedVo::getDes, FixedVo::getUniformCode));
- }
- return fixedVos;
- }
- public Map<String, String> getUniforcodes() {
- getFixedVos();
- return uniforcodes;
- }
- public List<ProBasicEquipment> wtByWplist(String wpids) {
- List<ProBasicEquipment> equipmentList = InitialRunner.newgfwtList.stream()
- .filter(oe -> wpids.contains(oe.getWindpowerstationId()))
- .sorted(Comparator.comparingInt(ProBasicEquipment::getOrderNum)) // 根据order_num字段排序
- .collect(Collectors.toList());
- return equipmentList;
- }
- /**
- * 通过大点的key获取小散点
- *
- * @param yk
- * @param wk
- * @return
- */
- public List<PhotovoltaicInfo> dataOrigin(String yk, String wk) {
- List<PhotovoltaicInfo> list = new ArrayList<>();
- if (!StringUtils.isEmpty(yk)) {
- String[] key = yk.split(",");
- for (String k : key) {
- Map<String, List<PhotovoltaicInfo>> mapYY = dataScangfService.getMapYY();
- List<PhotovoltaicInfo> photovoltaicInfos = mapYY.get(k);
- list.addAll(photovoltaicInfos);
- }
- }
- if (!StringUtils.isEmpty(wk)) {
- String[] kew = wk.split(",");
- for (String k : kew) {
- list.addAll(dataScangfService.getMapWY().get(k));
- }
- }
- return list;
- }
- }
|