365天的数据点按月-小时的基础存储到数组中。

huangapple go评论90阅读模式
英文:

365 Days Data points store into Arrays over Monthly-Hourly Basis

问题

try {
    ArrayList<String> GOCIds = new ArrayList<String>();

    Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
    for (Sheet sheet : workbook) {
        System.out.println("=> " + sheet.getSheetName());
    }
    Sheet sheet = workbook.getSheetAt(0);

    DataFormatter dataFormatter = new DataFormatter();
    System.out.println("Excel Data Loading....");
    for (Row row : sheet) {
        for (Cell cell : row) {
            String tempValue = dataFormatter.formatCellValue(cell);
            GOCIds.add(tempValue);
        }
    }

    // Extracting data for different arrays
    for (int i = 0; i < masterData.size(); i = i + 11) {
        allMonth.add(masterData.get(i));
        allDay.add(masterData.get(i + 1));
        allTime.add(masterData.get(i + 2));
        allDHI.add(masterData.get(i + 3));
        allDNI.add(masterData.get(i + 4));
        allGHI.add(masterData.get(i + 5));
        allDEW.add(masterData.get(i + 6));
        allTemperature.add(masterData.get(i + 7));
        allPressure.add(masterData.get(i + 8));
        allHumidity.add(masterData.get(i + 9));
        allWS.add(masterData.get(i + 10));
    }

    System.out.println("Data Loading Done ^_^");
} catch (Exception e) {
    e.printStackTrace();
}
英文:

365天的数据点按月-小时的基础存储到数组中。

I have scanned the data from excel to Arraylist but there is all data included under a single place. I have data defined in the above image up to 31st December for every day over the period 7:30 & 8:30. So for each day, there will be 2 rows. hence, 365 days * 2 variable * 8 columns data. And I need to store the data like Month 1 (January) 1st - 31st days of data in different arrays. As I have calculated the mean of 8 columns.

try {
ArrayList&lt;String&gt; GOCIds = new ArrayList&lt;String&gt;();
Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
for (Sheet sheet : workbook) {
System.out.println(&quot;=&gt; &quot; + sheet.getSheetName());
}
Sheet sheet = workbook.getSheetAt(0);
DataFormatter dataFormatter = new DataFormatter();
System.out.println(&quot;Excel Data Loading....&quot;);
for (Row row : sheet) {
for (Cell cell : row) {
String tempValue = dataFormatter.formatCellValue(cell);
GOCIds.add(tempValue);
}
}
// allMonth
for (int i = 0; i &lt; masterData.size(); i = i + 11) {
allMonth.add(masterData.get(i));
}
System.out.println(&quot;Total Month &quot; + allMonth.size());
// allDay
for (int i = 1; i &lt; masterData.size(); i = i + 11) {
allDay.add(masterData.get(i));
}
System.out.println(&quot;Total Day &quot; + allDay.size());
// allTime
for (int i = 2; i &lt; masterData.size(); i = i + 11) {
allTime.add(masterData.get(i));
}
System.out.println(&quot;Total Time &quot; + allTime.size());
// allDHI
for (int i = 3; i &lt; masterData.size(); i = i + 11) {
allDHI.add(masterData.get(i));
}
System.out.println(&quot;Total DHI &quot; + allDHI.size());
// allDNI
for (int i = 4; i &lt; masterData.size(); i = i + 11) {
allDNI.add(masterData.get(i));
}
System.out.println(&quot;Total DNI &quot; + allDNI.size());
// allGHI
for (int i = 5; i &lt; masterData.size(); i = i + 11) {
allGHI.add(masterData.get(i));
}
System.out.println(&quot;Total GHI &quot; + allGHI.size());
// allDEW
for (int i = 6; i &lt; masterData.size(); i = i + 11) {
allDEW.add(masterData.get(i));
}
System.out.println(&quot;Total DEW &quot; + allDEW.size());
// allTemperature
for (int i = 7; i &lt; masterData.size(); i = i + 11) {
allTemperature.add(masterData.get(i));
}
System.out.println(&quot;Total Temperature &quot; + allTemperature.size());
// allPressure
for (int i = 8; i &lt; masterData.size(); i = i + 11) {
allPressure.add(masterData.get(i));
}
System.out.println(&quot;Total Pressure &quot; + allPressure.size());
// allHumidity
for (int i = 9; i &lt; masterData.size(); i = i + 11) {
allHumidity.add(masterData.get(i));
}
System.out.println(&quot;Total Humidity &quot; + allHumidity.size());
// allWS
for (int i = 10; i &lt; masterData.size(); i = i + 11) {
allWS.add(masterData.get(i));
}
System.out.println(&quot;Total WS &quot; + allWS.size());
System.out.println(&quot;Data Loading Done ^_^&quot;);

Can you please guide how can i load monthly-hourly data in 8 different arrays so that I can calculate the means for each of them easily ?

答案1

得分: 1

我首先认为您需要将所有数据从 Excel 文件加载到模型中。

public final class Data {
    private int month;    // [0:11]
    private int day;      // [1:31]
    private long time;
    private int dhi;
    private int dni;
    private int ghi;
    private int dewPoint;
    private double temperature;
    private double pressure;
    private double relativeHumidity;
    private double windSpeed;
}

public static List<Data> readDataFromExcel(Path xlsx) throws Exception {
    try(Workbook workbook = WorkbookFactory.create(Files.newInputStream(xlsx))) {
        List<Data> res = new ArrayList<>();

        for(Row row : workbook.getSheetAt(0)) {
            Data data = new Data();

            for(Cell cell : row) {
                // 填充数据
            }

            res.add(data);
        }

        return res;
    }
}

然后,List<Data> 允许您计算结果或按天等进行分组。

英文:

I think first of all you have to load all data from excel file to the model.

public final class Data {
private int month;    // [0:11]
private int day;      // [1:31]
private long time;
private int dhi;
private int dni;
private int ghi;
private int dewPoint;
private double remperature;
private double pressure;
private double relativeHumidity;
private double windSpeed;
}
public static List&lt;Data&gt; readDataFromExcel(Path xlsx) throws Exception {
try(Workbook workbook = WorkbookFactory.create(Files.newInputStream(xlsx))) {
List&lt;Data&gt; res = new ArrayList&lt;&gt;();
for(Row row : workbook.getSheetAt(0)) {
Data data = new Data();
for(Cell cell : row) {
// fill data
}
res.add(data);
}
return res;
}
}

Then List&lt;Data&gt; allows you to calculate results or group by e.g. day etc.

huangapple
  • 本文由 发表于 2020年9月6日 11:49:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63760531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定