英文:
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();
}
英文:
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<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);
}
}
// allMonth
for (int i = 0; i < masterData.size(); i = i + 11) {
allMonth.add(masterData.get(i));
}
System.out.println("Total Month " + allMonth.size());
// allDay
for (int i = 1; i < masterData.size(); i = i + 11) {
allDay.add(masterData.get(i));
}
System.out.println("Total Day " + allDay.size());
// allTime
for (int i = 2; i < masterData.size(); i = i + 11) {
allTime.add(masterData.get(i));
}
System.out.println("Total Time " + allTime.size());
// allDHI
for (int i = 3; i < masterData.size(); i = i + 11) {
allDHI.add(masterData.get(i));
}
System.out.println("Total DHI " + allDHI.size());
// allDNI
for (int i = 4; i < masterData.size(); i = i + 11) {
allDNI.add(masterData.get(i));
}
System.out.println("Total DNI " + allDNI.size());
// allGHI
for (int i = 5; i < masterData.size(); i = i + 11) {
allGHI.add(masterData.get(i));
}
System.out.println("Total GHI " + allGHI.size());
// allDEW
for (int i = 6; i < masterData.size(); i = i + 11) {
allDEW.add(masterData.get(i));
}
System.out.println("Total DEW " + allDEW.size());
// allTemperature
for (int i = 7; i < masterData.size(); i = i + 11) {
allTemperature.add(masterData.get(i));
}
System.out.println("Total Temperature " + allTemperature.size());
// allPressure
for (int i = 8; i < masterData.size(); i = i + 11) {
allPressure.add(masterData.get(i));
}
System.out.println("Total Pressure " + allPressure.size());
// allHumidity
for (int i = 9; i < masterData.size(); i = i + 11) {
allHumidity.add(masterData.get(i));
}
System.out.println("Total Humidity " + allHumidity.size());
// allWS
for (int i = 10; i < masterData.size(); i = i + 11) {
allWS.add(masterData.get(i));
}
System.out.println("Total WS " + allWS.size());
System.out.println("Data Loading Done ^_^");
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<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) {
// fill data
}
res.add(data);
}
return res;
}
}
Then List<Data>
allows you to calculate results or group by e.g. day etc.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论