Пример #1
1
 public static void fileWithColdestTemperature() {
   String fileName = null;
   CSVRecord lowestSoFar = null;
   double lowestTemp = 99999;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVRecord currentRow = coldestHourInFile(fr.getCSVParser());
     double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
     if (currentTemp < lowestTemp) {
       lowestTemp = currentTemp;
       lowestSoFar = currentRow;
       fileName = f.getName();
     }
     /*
     if (lowestSoFar == null) {
     	lowestSoFar = currentRow;
     	fileName = f.getName();
     	selectedFr = fr;
     } else {
     	lowestSoFar = getLowestOfTwo(currentRow, lowestSoFar);
     	fileName = f.getName();
     	selectedFr = fr;
     }
     */
   }
   System.out.println("Coldest day was in file " + fileName);
   System.out.println("Coldest temperature on that day was " + lowestSoFar.get("TemperatureF"));
   System.out.println("All the Temperatures on the coldest day were:");
 }
 public static void testLowestHumidityInFile() {
   FileResource fr = new FileResource();
   CSVParser csv = fr.getCSVParser();
   CSVRecord record = lowestHumidityInFile(csv);
   System.out.println(
       "Lowest Humidity was " + record.get("Humidity") + " at " + record.get("DateUTC"));
 }
Пример #3
0
  /*	public boolean doesNameRepeats(FileResource fr, CSVRecord reader) {
  		int counter = 0;
  		int birthsNumbers = Integer.parseInt(reader.get(2));
  		for (CSVRecord secondReader : fr.getCSVParser(false)) {
  			if(secondReader.get(0).equals(name));
  			counter++;
  		}
  		if (counter > 1)
  			return true;
  		else
  			return false;
  	}
  */
  public void totalBirths(FileResource fr) {

    int totalBirths = 0;
    int totalGirls = 0;
    int totalBoys = 0;

    int uniqueBirths = 0;
    int uniqueGirls = 0;
    int uniqueBoys = 0;

    String uniqueName = "";

    for (CSVRecord reader : fr.getCSVParser(false)) {
      int brojRodjenih = Integer.parseInt(reader.get(2));
      totalBirths += brojRodjenih;

      // ---1--- ako se ime ne ponavlja, pokrecemo counter, ako ne, preskacemo counter
      uniqueBirths =
          uniqueBirths + (Integer.parseInt(reader.get(2)) - (Integer.parseInt(reader.get(2)) - 1));

      if (reader.get(1).equals("F")) totalGirls += brojRodjenih;
      else totalBoys += brojRodjenih;
    }
    System.out.println("Potpuni broj rodjenih: " + totalBirths);
    System.out.println("Broj zenske djece: " + totalGirls);
    System.out.println("Broj muske djece: " + totalBoys);
    System.out.println("Broj svih imena: " + uniqueBirths);
  }
 public static Double averageTemperatureWithHighHumidityInFile(CSVParser parser, int value) {
   Double average = null;
   int count = 0;
   for (CSVRecord record : parser) {
     String tempString = record.get("TemperatureF");
     String humidString = record.get("Humidity");
     if (humidString.equals("N/A") == false) {
       Double humid = Double.parseDouble(humidString);
       if (tempString.equals("-9999") == false && humid >= value) {
         double temp = Double.parseDouble(tempString);
         if (average == null) {
           average = temp;
           count++;
         } else {
           average += temp;
           count++;
         }
       }
     }
   }
   if (average == null) {
     return average;
   } else {
     return average / count;
   }
 }
Пример #5
0
 public static CSVRecord getLargestOfTwo(CSVRecord currentRow, CSVRecord largestSoFar) {
   double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
   double largestTemp = Double.parseDouble(largestSoFar.get("TemperatureF"));
   if (currentTemp > largestTemp) {
     largestSoFar = currentRow;
   }
   return largestSoFar;
 }
Пример #6
0
 public static double averageTemperatureInFile(CSVParser parser) {
   int count = 0;
   double tempAcc = 0;
   for (CSVRecord rec : parser) {
     tempAcc = tempAcc + Double.parseDouble(rec.get("TemperatureF"));
     count++;
   }
   return tempAcc / count;
 }
Пример #7
0
 public static CSVRecord getLowestOfTwo(CSVRecord currentRow, CSVRecord lowestSoFar) {
   double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
   double lowestTemp = Double.parseDouble(lowestSoFar.get("TemperatureF"));
   if (lowestTemp == -9999) {
     lowestSoFar = currentRow;
   }
   if (currentTemp < lowestTemp && currentTemp != -9999) {
     lowestSoFar = currentRow;
   }
   return lowestSoFar;
 }
 /**
  * if current temp is lower than lowest temp so far, returns true, else returns false
  *
  * @param current the current row examined
  * @param lowestSoFar the lowest record so far
  * @return
  */
 public static boolean coldestOfTwo(CSVRecord current, CSVRecord lowestSoFar) {
   if (lowestSoFar == null) {
     lowestSoFar = current;
   } else {
     double currentTemp = Double.parseDouble(current.get("TemperatureF"));
     double lowestTemp = Double.parseDouble(lowestSoFar.get("TemperatureF"));
     if (currentTemp < lowestTemp && currentTemp != -9999) {
       lowestSoFar = current;
     }
   }
   return (lowestSoFar == current);
 }
Пример #9
0
 public static CSVRecord coldestHourInFile(CSVParser parser) {
   CSVRecord lowestSoFar = null;
   double lowestTemp = 999999;
   for (CSVRecord currentRow : parser) {
     double currentTemp = Double.parseDouble(currentRow.get("TemperatureF"));
     if (currentTemp != -9999 & currentTemp < lowestTemp) {
       lowestTemp = currentTemp;
       lowestSoFar = currentRow;
     }
   }
   return lowestSoFar;
 }
 /**
  * gets CSVRecord with the lower humidity
  *
  * @param record
  * @param lowestSoFar
  * @return
  */
 public static CSVRecord getLowestOfTwo(CSVRecord record, CSVRecord lowestSoFar) {
   if (lowestSoFar == null) {
     lowestSoFar = record;
   } else {
     if (record.get("Humidity").equals("N/A") == false) {
       Double record_humidity = Double.parseDouble(record.get("Humidity"));
       Double lowest_humidity = Double.parseDouble(lowestSoFar.get("Humidity"));
       if (record_humidity < lowest_humidity) {
         lowestSoFar = record;
       }
     }
   }
   return lowestSoFar;
 }
Пример #11
0
 public static CSVRecord lowestHumidityInManyFiles() {
   CSVRecord lowestRecordSoFar = null;
   double lowestHumiditySoFar = 101;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVParser parser = fr.getCSVParser();
     CSVRecord record = lowestHumidityInFile(parser);
     double currentHumidity = Double.parseDouble(record.get("Humidity"));
     if (currentHumidity < lowestHumiditySoFar) {
       lowestHumiditySoFar = currentHumidity;
       lowestRecordSoFar = record;
     }
   }
   return lowestRecordSoFar;
 }
Пример #12
0
 public static CSVRecord lowestHumidityInFile(CSVParser parser) {
   CSVRecord lowestSoFarRecord = null;
   double lowestSoFar = 101;
   for (CSVRecord r : parser) {
     double currentHumidity;
     if (!r.get("Humidity").equals("N/A")) {
       currentHumidity = Double.parseDouble(r.get("Humidity"));
     } else {
       currentHumidity = 101;
     }
     if (currentHumidity < lowestSoFar) {
       lowestSoFar = currentHumidity;
       lowestSoFarRecord = r;
     }
   }
   return lowestSoFarRecord;
 }
Пример #13
0
  public void printNames() {
    FileResource fr = new FileResource();

    for (CSVRecord record : fr.getCSVParser(false)) {
      int numero = Integer.parseInt(record.get(2));
      if (numero <= 100) {
        System.out.println(
            "ime bebe: "
                + record.get(0)
                + "    \t"
                + "spol: "
                + record.get(1)
                + "    \t"
                + "broj istih imena u godini: "
                + record.get(2));
      }
    }
  }
 public static void testFileWithColdestTemp() {
   String lowestFile = fileWithColdestTemperature();
   FileResource lowestFile2 = new FileResource(lowestFile);
   String lowestFile1 = lowestFile.substring(lowestFile.lastIndexOf("\\") + 1);
   CSVParser csv = lowestFile2.getCSVParser();
   CSVRecord record = coldestHourInFile(csv);
   System.out.println("Coldest day was in file " + lowestFile1);
   System.out.println("Coldest temperature on that day was " + record.get("TemperatureF"));
   System.out.println("All the temperatures on that day are:");
   csv = lowestFile2.getCSVParser();
   for (CSVRecord row : csv) {
     System.out.println(
         lowestFile1.substring(8, lowestFile1.length() - 4)
             + " "
             + row.get("TimeEST")
             + " "
             + row.get("TemperatureF"));
   }
 }
Пример #15
0
 public static double averageTemperatureWithHighHumidityInFile(CSVParser parser, double value) {
   int count = 0;
   double tempAcc = 0;
   for (CSVRecord rec : parser) {
     double currentHumidity;
     if (!rec.get("Humidity").equals("N/A")) {
       currentHumidity = Double.parseDouble(rec.get("Humidity"));
     } else {
       currentHumidity = -1;
     }
     double currentTemp = Double.parseDouble(rec.get("TemperatureF"));
     if (currentHumidity > value && currentTemp != -9999) {
       tempAcc = tempAcc + currentTemp;
       count++;
     }
   }
   if (count == 0) {
     return -9999;
   } else {
     return tempAcc / count;
   }
 }
 /**
  * returns the average temperature in a file
  *
  * @param parser
  * @return
  */
 public static Double averageTemperatureInFile(CSVParser parser) {
   Double average = null;
   int count = 0;
   for (CSVRecord record : parser) {
     String tempString = record.get("TemperatureF");
     if (tempString.equals("-9999") == false) {
       double temp = Double.parseDouble(tempString);
       if (average == null) {
         average = temp;
         count++;
       } else {
         average += temp;
         count++;
       }
     }
   }
   if (average == null) {
     return average;
   } else {
     return average / count;
   }
 }
Пример #17
0
 public static void testColdestHourInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   CSVRecord coldest = coldestHourInFile(parser);
   System.out.println(coldest.get("TemperatureF") + " at " + coldest.get("TimeEST"));
 }
Пример #18
0
 public static void testLowestHumidityInManyFiles() {
   CSVRecord cvr = lowestHumidityInManyFiles();
   System.out.println("Lowest Humidity was " + cvr.get("Humidity") + " at " + cvr.get("DateUTC"));
 }
 public static void testColdestHourInFile() {
   FileResource fr = new FileResource();
   CSVParser csv = fr.getCSVParser();
   CSVRecord lowest = coldestHourInFile(csv);
   System.out.println(lowest.get("DateUTC") + " " + lowest.get("TemperatureF"));
 }