Browse Source

停机损失多少电量test2

xushili 2 years ago
parent
commit
67e33cfc22
1 changed files with 109 additions and 2 deletions
  1. 109 2
      src/test/java/test/LosePowerTest.java

+ 109 - 2
src/test/java/test/LosePowerTest.java

@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
 @RunWith(SpringRunner.class)
 public class LosePowerTest {
 
-    @Autowired
+    @Resource
     private WindTurbineTestingPointAi2Mapper windTurbineTestingPointAi2Mapper;
     @Resource
     private RemoteServiceBuilder remoteServiceBuilder;
@@ -51,6 +51,112 @@ public class LosePowerTest {
         calc(start, end);
 
     }
+    //每行是一个故障
+    private void calc2(Date start, Date end) {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet = workbook.createSheet();
+
+        XSSFRow row0 = sheet.createRow(0);
+        row0.createCell(0).setCellValue("序号");
+        row0.createCell(1).setCellValue("场站");
+        row0.createCell(2).setCellValue("风机");
+        row0.createCell(3).setCellValue("月份");
+        row0.createCell(4).setCellValue("故障次数");
+        row0.createCell(5).setCellValue("故障时间(分钟)");
+        row0.createCell(6).setCellValue("损失电量(kWh)");
+        row0.createCell(7).setCellValue("机型");
+
+        int i = 1;
+        for (WindTurbineTestingPointAi2 wttpai2 : faultCodes) {
+
+            XSSFRow rowz = sheet.createRow(i);
+
+            List<TsPointData> historyRaw = remoteServiceBuilder.ShardingService().getHistoryRaw(wttpai2.getId(), start.getTime(), end.getTime());
+            //时间从大到小
+            historyRaw = historyRaw.stream().sorted(Comparator.comparing(TsPointData::getTs).reversed()).collect(Collectors.toList());
+
+            long duration = 0;//故障时间
+            long durationlj = 0;//停机时间
+            double ssdl = 0;//损失电量
+            long faultTime = historyRaw.get(0).getTs();
+            short gzcs = 0;//故障次数
+
+            short k = 0;//是否连续
+
+            short 当前风机是否有故障 = 0;
+            //测点列表
+            for (TsPointData tsPointData : historyRaw) {
+                //点值
+                int doubleValue = (int) tsPointData.getDoubleValue();
+                if (doubleValue == 4) {
+                    k = 0;
+                    continue;
+                } else if (doubleValue == 2) {
+                    duration = faultTime - tsPointData.getTs();
+                    //超过2小时,毫秒
+                    int 两小时 = 2 * 60 * 60 * 1000;
+                    int 一小时 = 1 * 60 * 60 * 1000;
+                    int 半小时 = 1 * 30 * 60 * 1000;
+                    if (duration > 一小时) {
+                        当前风机是否有故障 = 1;
+                        if (k == 0) gzcs++;
+                        k = 1;
+                        //一个故障一行excel
+                        XSSFRow row = sheet.createRow(i);
+                        i++;
+
+                        durationlj += duration;
+                        String s = llfdlMap.get(wttpai2.getWindturbineid());
+                        Map<String, TsPointData> h1 = remoteServiceBuilder.ShardingService().getHistorySection(s, tsPointData.getTs());
+                        Map<String, TsPointData> h2 = remoteServiceBuilder.ShardingService().getHistorySection(s, faultTime);
+                        double doubleValue2 = h2.get(s).getDoubleValue();
+                        double doubleValue1 = h1.get(s).getDoubleValue();
+                        ssdl = doubleValue2 - doubleValue1;
+
+                        row.createCell(0).setCellValue(i-1);
+                        row.createCell(1).setCellValue(wttpai2.getWindpowerstationid());
+                        row.createCell(2).setCellValue(wttpai2.getWindturbineid());
+                        row.createCell(3).setCellValue(DateFormatUtils.format(faultTime, "yyyy-MM"));
+                        row.createCell(4).setCellValue(1);
+                        row.createCell(5).setCellValue(duration / 60000);
+                        row.createCell(6).setCellValue(ssdl);
+                        row.createCell(7).setCellValue(wttpai2.getModelid());
+                    }else {
+                        k = 0;
+                    }
+                    faultTime = tsPointData.getTs();
+                } else {
+                    faultTime = tsPointData.getTs();
+                    k = 0;
+                    continue;
+                }
+            }
+
+            if(当前风机是否有故障==0){
+                rowz.createCell(0).setCellValue(i-1);
+                rowz.createCell(1).setCellValue(wttpai2.getWindpowerstationid());
+                rowz.createCell(2).setCellValue(wttpai2.getWindturbineid());
+                rowz.createCell(3).setCellValue(DateFormatUtils.format(faultTime, "yyyy-MM"));
+                rowz.createCell(4).setCellValue(gzcs);
+                rowz.createCell(5).setCellValue(durationlj / 60000);
+                rowz.createCell(6).setCellValue(ssdl);
+                rowz.createCell(7).setCellValue(wttpai2.getModelid());
+                i++;
+            }
+
+        }
+        //通过输出流将workbook对象下载到磁盘
+        FileOutputStream out = null;
+        try {
+            out = new FileOutputStream("D:\\计算\\麻黄山风电场202210-1小时.xlsx");
+            workbook.write(out);
+            out.flush();
+            out.close();
+            workbook.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 
     private void calc(Date start, Date end) {
         XSSFWorkbook workbook = new XSSFWorkbook();
@@ -74,6 +180,7 @@ public class LosePowerTest {
             XSSFRow row = sheet.createRow(i);
             i++;
             List<TsPointData> historyRaw = remoteServiceBuilder.ShardingService().getHistoryRaw(wttpai2.getId(), start.getTime(), end.getTime());
+            //时间从大到小
             historyRaw = historyRaw.stream().sorted(Comparator.comparing(TsPointData::getTs).reversed()).collect(Collectors.toList());
 
             long duration = 0;//故障时间
@@ -124,7 +231,7 @@ public class LosePowerTest {
             row.createCell(3).setCellValue(DateFormatUtils.format(faultTime, "yyyy-MM"));
             row.createCell(4).setCellValue(gzcs);
             row.createCell(5).setCellValue(durationlj / 60000);
-            row.createCell(6).setCellValue(ssdl / 1000.0);
+            row.createCell(6).setCellValue(ssdl);
             row.createCell(7).setCellValue(wttpai2.getModelid());
 
         }