src/main/java/it/uniroma2/dicii/sabd/covidproject/Query3.java
/* Parse a line of the CSV dataset */
Parse a line of the CSV dataset
Parse a line of the CSV dataset
private static Iterator<Tuple2<Integer, 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("[,*\"]","");
            System.out.println(regionName);
            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 month are considered and a month is assumed to be a 4-week period */
            int availableDays = ((csvFields.length - 9) - ((csvFields.length - 9) % 28));
            /* Convert cumulative data to daily increments of confirmed cases */
            Double[] confirmedDailyIncrements = GlobalDataUtils.convertCumulativeToIncrement(availableDays, csvFields);
            int numberOfMonths = confirmedDailyIncrements.length / 28;
            /* For each month, a RegionData object, representing the monthly trend line coefficient of a region,
             * is produced */
            List<Tuple2<Integer, RegionData>> output = new ArrayList<>();
            for (int i = 0; i < numberOfMonths; i++) {
                Double[] monthlyIncrements = new Double[28];
                System.arraycopy(confirmedDailyIncrements, i * 28, monthlyIncrements, 0, 28);
                RegionData monthlyRegionData = new RegionData();
                monthlyRegionData.setName(regionName);
                monthlyRegionData.setTrendLineCoefficient(GlobalDataUtils.computeCoefficientEstimate(monthlyIncrements));
                monthlyRegionData.setLatitude(latitude);
                monthlyRegionData.setLongitude(longitude);
                monthlyRegionData.setMonth(i);
                output.add(new Tuple2<>(i, monthlyRegionData));
            }
            return output.iterator();
        } catch (CsvValidationException | IOException e) {
            List<Tuple2<Integer, RegionData>> failedOutput = new ArrayList<>();
            failedOutput.add(new Tuple2<>(null, null));
            return failedOutput.iterator();
        }
    }
private static Iterator < Tuple2 < Integer , 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 ( "[,*\"]" , "" ) ; System . out . println ( regionName ) ; 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 month are considered and a month is assumed to be a 4-week period */ int availableDays = ( ( csvFields . length - 9 ) - ( ( csvFields . length - 9 ) % 28 ) ) ; /* Convert cumulative data to daily increments of confirmed cases */ Double [ ] confirmedDailyIncrements = GlobalDataUtils . convertCumulativeToIncrement ( availableDays , csvFields ) ; int numberOfMonths = confirmedDailyIncrements . length / 28 ; /* For each month, a RegionData object, representing the monthly trend line coefficient of a region,
             * is produced */ List < Tuple2 < Integer , RegionData > > output = new ArrayList < > ( ) ; for ( int i = 0 ; i < numberOfMonths ; i ++ ) { Double [ ] monthlyIncrements = new Double [ 28 ] ; System . arraycopy ( confirmedDailyIncrements , i * 28 , monthlyIncrements , 0 , 28 ) ; RegionData monthlyRegionData = new RegionData ( ) ; monthlyRegionData . setName ( regionName ) ; monthlyRegionData . setTrendLineCoefficient ( GlobalDataUtils . computeCoefficientEstimate ( monthlyIncrements ) ) ; monthlyRegionData . setLatitude ( latitude ) ; monthlyRegionData . setLongitude ( longitude ) ; monthlyRegionData . setMonth ( i ) ; output . add ( new Tuple2 < > ( i , monthlyRegionData ) ) ; } return output . iterator ( ) ; } catch ( CsvValidationException | IOException e ) { List < Tuple2 < Integer , RegionData > > failedOutput = new ArrayList < > ( ) ; failedOutput . add ( new Tuple2 < > ( null , null ) ) ; return failedOutput . iterator ( ) ; } }
Parse a line of the CSV dataset
Parse a line of the CSV dataset