src/main/java/it/uniroma2/dicii/sabd/covidproject/Query2.java
/* Parse a line of the CSV dataset */
Parse a line of the CSV dataset
Parse a line of the CSV dataset
private static Tuple2<Double, RegionData> parseInputLine(String line) {
        try {
            /* Extract fields of interest from CSV line */
            CSVReader csvReader = new CSVReader(new StringReader(line));
            String[] csvFields = csvReader.readNext();
            csvReader.close();
            /* If province/state is not available, the country is considered */
            String regionName = (csvFields[0].equals("") ? csvFields[1] : csvFields[0]).replaceAll("[,*]","");
            Double latitude = Double.parseDouble(csvFields[2]);
            Double longitude = Double.parseDouble(csvFields[3]);
            /* Retrieve number of days available for computations of daily increments of confirmed cases.
             *  The considered period of observations starts from Monday, 27th January 2020.
             *  Furthermore, only completed week are considered */
            int availableDays = ((csvFields.length - 9) - ((csvFields.length - 9) % 7));
            /* Convert cumulative data to daily increments */
            Double[] confirmedDailyIncrements = GlobalDataUtils.convertCumulativeToIncrement(availableDays, csvFields);
            /* Build RegionData object, representing the parsed line */
            RegionData regionData = new RegionData();
            regionData.setName(regionName);
            regionData.setLatitude(latitude);
            regionData.setLongitude(longitude);
            regionData.setConfirmedDailyIncrements(confirmedDailyIncrements);
            /* Estimate Trend Line Coefficient associated to the world region */
            Double tlcEstimate = GlobalDataUtils.computeCoefficientEstimate(confirmedDailyIncrements);
            return new Tuple2<>(tlcEstimate, regionData);
        } catch (IOException | CsvValidationException e) {
            return new Tuple2<>(null, null); /* null in case of malformed input */
        }
    }
private static Tuple2 < Double , RegionData > parseInputLine ( String line ) { try { /* Extract fields of interest from CSV line */ CSVReader csvReader = new CSVReader ( new StringReader ( line ) ) ; String [ ] csvFields = csvReader . readNext ( ) ; csvReader . close ( ) ; /* If province/state is not available, the country is considered */ String regionName = ( csvFields [ 0 ] . equals ( "" ) ? csvFields [ 1 ] : csvFields [ 0 ] ) . replaceAll ( "[,*]" , "" ) ; Double latitude = Double . parseDouble ( csvFields [ 2 ] ) ; Double longitude = Double . parseDouble ( csvFields [ 3 ] ) ; /* Retrieve number of days available for computations of daily increments of confirmed cases.
             *  The considered period of observations starts from Monday, 27th January 2020.
             *  Furthermore, only completed week are considered */ int availableDays = ( ( csvFields . length - 9 ) - ( ( csvFields . length - 9 ) % 7 ) ) ; /* Convert cumulative data to daily increments */ Double [ ] confirmedDailyIncrements = GlobalDataUtils . convertCumulativeToIncrement ( availableDays , csvFields ) ; /* Build RegionData object, representing the parsed line */ RegionData regionData = new RegionData ( ) ; regionData . setName ( regionName ) ; regionData . setLatitude ( latitude ) ; regionData . setLongitude ( longitude ) ; regionData . setConfirmedDailyIncrements ( confirmedDailyIncrements ) ; /* Estimate Trend Line Coefficient associated to the world region */ Double tlcEstimate = GlobalDataUtils . computeCoefficientEstimate ( confirmedDailyIncrements ) ; return new Tuple2 < > ( tlcEstimate , regionData ) ; } catch ( IOException | CsvValidationException e ) { return new Tuple2 < > ( null , null ) ; /* null in case of malformed input */ } }
Parse a line of the CSV dataset
Parse a line of the CSV dataset