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:");
 }
Beispiel #2
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 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"));
 }
  @Test
  public void testFileLowestHumidity() {

    CSVRecord coldestRecord = null;
    DirectoryResource dr = new DirectoryResource();
    String filename = "";

    for (File f : dr.selectedFiles()) {

      FileResource fr = new FileResource(f);

      CSVRecord record = WeatherCSVProblem.lowestHumidityInFile(fr.getCSVParser());

      if (coldestRecord == null) {
        coldestRecord = record;
      } else {
        double recordTemp = Double.parseDouble(record.get("Humidity"));
        double coldestTemp = Double.parseDouble(coldestRecord.get("Humidity"));

        if (recordTemp < coldestTemp) {
          coldestRecord = record;
          filename = f.getName();
        }
      }
    }
    System.out.println(filename);
    System.out.println(
        "Lowest Humidity " + coldestRecord.get("Humidity") + " at " + coldestRecord.get("DateUTC"));
  }
 public static void testAverageTemperatureWithHighHumidityInFile(int value) {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   Double average = averageTemperatureWithHighHumidityInFile(parser, value);
   if (average == null) {
     System.out.println("No temperatures with that humidity");
   } else {
     System.out.println("Average Temp when high Humidity is " + average);
   }
 }
 public static void testAverageTemperatureWithHighHumidityInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   double avgTem = averageTemperatureWithHighHumidityInFile(parser, 80);
   if (avgTem == -9999) {
     System.out.println("No temperatures with that humidity");
   } else {
     System.out.println("Average Temp when high Humidity is " + avgTem);
   }
 }
 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"));
   }
 }
 public static CSVRecord lowestHumidityInManyFiles() {
   CSVRecord lowestSoFar = null;
   DirectoryResource dir = new DirectoryResource();
   for (File file : dir.selectedFiles()) {
     FileResource fr = new FileResource(file);
     CSVParser csv = fr.getCSVParser();
     CSVRecord lowestInFile = lowestHumidityInFile(csv);
     lowestSoFar = getLowestOfTwo(lowestInFile, lowestSoFar);
   }
   return lowestSoFar;
 }
  @Test
  public void testAverageTemperatureInFile() {

    FileResource fr =
        new FileResource("../../resources/main/nc_weather/2013/weather-2013-08-10.csv");
    CSVParser parser = fr.getCSVParser();

    double average = WeatherCSVProblem.averageTemperatureInFile(parser);

    System.out.println("Average temperature in file is " + average);
  }
  @Test
  public void testLowestHumidityInFile() {

    FileResource fr =
        new FileResource("../../resources/main/nc_weather/2014/weather-2014-07-22.csv");
    CSVParser parser = fr.getCSVParser();

    CSVRecord rec = WeatherCSVProblem.lowestHumidityInFile(parser);

    System.out.println("Lowest Humidity was " + rec.get("Humidity") + " at " + rec.get("DateUTC"));
  }
  @Test
  public void testColdestHourInFile() {

    FileResource fr =
        new FileResource("../../resources/main/nc_weather/2014/weather-2014-05-01.csv");
    CSVParser parser = fr.getCSVParser();

    CSVRecord rec = WeatherCSVProblem.coldestHourInFile(parser);

    System.out.println("Coldest temperature on that day was " + rec.get("TemperatureF"));
  }
 public static CSVRecord hottestInManyDays() {
   CSVRecord largestSoFar = null;
   DirectoryResource dr = new DirectoryResource();
   for (File f : dr.selectedFiles()) {
     FileResource fr = new FileResource(f);
     CSVRecord currentRow = hottestHourInFile(fr.getCSVParser());
     if (largestSoFar == null) {
       largestSoFar = currentRow;
     } else {
       largestSoFar = getLargestOfTwo(currentRow, largestSoFar);
     }
   }
   return largestSoFar;
 }
 /**
  * Takes selected files and returns name of file with lowest temp
  *
  * @return name of file with lowest temperature
  */
 public static String fileWithColdestTemperature() {
   DirectoryResource dir = new DirectoryResource();
   CSVRecord lowestSoFar = null;
   File lowestFile = null;
   for (File fr : dir.selectedFiles()) {
     FileResource frR = new FileResource(fr);
     CSVParser csv = frR.getCSVParser();
     CSVRecord record = coldestHourInFile(csv);
     if (coldestOfTwo(record, lowestSoFar)) {
       lowestFile = fr;
     }
   }
   return lowestFile.getAbsolutePath();
 }
  @Test
  public void testAverageTemperatureWithHighHumidityInFile() {

    FileResource fr =
        new FileResource("../../resources/main/nc_weather/2013/weather-2013-09-02.csv");
    CSVParser parser = fr.getCSVParser();

    double average = WeatherCSVProblem.averageTemperatureWithHighHumidityInFile(parser, 80);

    if (Double.isNaN(average)) {
      System.out.println("No temperatures with that humidity");
    } else {
      System.out.println("Average Temp when high Humidity is " + average);
    }
  }
  @Test
  public void testFileWithColdestTemperature() {

    String filename = WeatherCSVProblem.fileWithColdestTemperature();
    System.out.println("Coldest day was in file " + filename);

    FileResource fr = new FileResource(filename);
    CSVParser parser = fr.getCSVParser();
    CSVRecord rec = WeatherCSVProblem.coldestHourInFile(parser);
    System.out.println(
        "Coldest temperature on that day was "
            + rec.get("TemperatureF")
            + " at "
            + rec.get("DateUTC"));
  }
 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;
 }
Beispiel #17
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 testColdestHourInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   CSVRecord coldest = coldestHourInFile(parser);
   System.out.println(coldest.get("TemperatureF") + " at " + coldest.get("TimeEST"));
 }
 public static void testAverageTemperatureInFile() {
   FileResource fr = new FileResource();
   CSVParser parser = fr.getCSVParser();
   double averageTemperature = averageTemperatureInFile(parser);
   System.out.println("Average temperature in file is " + averageTemperature);
 }
 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"));
 }