My Projects |

Projects:

A Rail Usage Data Analysis System

Latest Project:
Data Structures and Algorithms
Image of Train

                                                
public void readFiles(String directoryPath) {

// Checking time taken before user is prompt to the menu (Reduced this from 90minutes to 3s)
long startTime = System.currentTimeMillis();
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();

if (listOfFiles == null) {
    System.out.println("No files found or I/O error occurred.");
    return;
}

// List of sheet names to skip
List skipSheetNames = List.of("Metadata", "Column_Descriptions", "Background_Infomation", "Cover_sheet");

for (File file : listOfFiles) {
    if (file.isFile() && file.getName().endsWith(".ods")) {
        // System.out.println("Detected .ods file: " + file.getName());

        try {
            SpreadSheet spreadSheet = new SpreadSheet(file);
            int sheetCount = spreadSheet.getNumSheets();

            for (int s = 0; s < sheetCount; s++) {
                com.github.miachm.sods.Sheet sheet = spreadSheet.getSheet(s);

                // If the sheet name is in the skip list, continue to the next sheet
                if (skipSheetNames.contains(sheet.getName())) {
                    //  System.out.println("Skipping sheet: " + sheet.getName());
                    continue;
                }
                
                Range range = sheet.getDataRange();
                // Using 2d array to get the array of arrays
                Object[][] values = range.getValues();

                // Adjust the starting index to skip metadata rows
                for (int i = 5; i < values.length; i++) {
                    List rowData = new ArrayList<>();
                    for (int j = 0; j < values[i].length; j++) {
                        Object cellValue = values[i][j];
                        if (cellValue != null && !cellValue.toString().isEmpty()) {
                            rowData.add(cellValue.toString());
                        }
                    }

                    if (!rowData.isEmpty()) {
                        data.add(rowData);
                    }
                }

                //   System.out.println("Successfully processed file: " + file.getName() + ", Sheet: " + (s + 1));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
long endTime = System.currentTimeMillis();
long timeTaken = endTime - startTime;
System.out.println("[Finished reading files in " + formatMillisToTime(timeTaken) + "] \n");
}
                                                
                                            

Feature A (Unoptimized version) required to read and store 3 years worth of station data in memory from a list of OpenDocumentSpreadsheet (.ods) files in a specified directory and should be flexible enough to support future data .