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:");
 }
  @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"));
  }
  // read a DNA string from a file
  private static String readStringFromFile() {
    // TODO Auto-generated method stub
    FileResource FR = new FileResource();
    String dna = FR.asString();

    return dna;
  } // end readStringFromfile() method;
 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"));
 }
 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 void quiz1_q1() {
    FileResource fr = new FileResource("../secretmessage1.txt");
    String encrypted = fr.asString();

    int[] key = new int[4];
    key = tryKeyLength(encrypted, 4, 'e');
    for (int i = 0; i < 4; i++) {
      System.out.println(key[i]);
    }
  }
 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);
   }
 }
示例#8
0
 public static String[] getCommon() {
   FileResource resource = new FileResource("data/common.txt");
   String[] common = new String[20];
   int index = 0;
   for (String s : resource.words()) {
     common[index] = s;
     index += 1;
   }
   return common;
 }
  public void testTryKeyLength() {

    FileResource fr = new FileResource("athens_keyflute.txt");
    String encrypted = fr.asString();

    int[] key = new int[5];
    key = tryKeyLength(encrypted, 5, 'e');
    for (int i = 0; i < 5; i++) {
      System.out.println(key[i]);
    }
  }
  @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 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"));
  }
 public void testStorageFinder() {
   String dnaString = "";
   // FileResource dna = new FileResource("dna/brca1line.fa");
   FileResource dna = new FileResource("dna/GRch38dnapart.fa");
   dnaString = dna.asString();
   // String dnaString="ATGCCATAG";
   StorageResource sr = storeAll(dnaString);
   printGenes(sr);
   System.out.println("Number of genes: " + sr.size());
   System.out.println("Number of CTG : " + ctgCounter(dnaString));
   System.out.println("The length of longer gene is : " + longestGene(sr));
 }
  public void breakVigenere() {

    // read in the encrypted message
    FileResource fr = new FileResource();
    String encrypted = fr.asString();

    // read in the dictionary of valid words
    FileResource dictRes = new FileResource("dictionaries/English");
    HashSet<String> dict = readDictionary(dictRes);

    String decrypted = breakForLanguage(encrypted, dict);
    System.out.println(decrypted);
  }
 public void runMarkov() {
   FileResource fr = new FileResource();
   String st = fr.asString();
   st = st.replace('\n', ' ');
   int seed = 643;
   int order = 3;
   int words = 200;
   //  st =  new String("This is single test string for testing");
   //  String[] st1 =  new String("This is single test").split("\\s+");
   //  WordGram wg = new WordGram(st1, 0, 4);
   //  wg.textShiftAdd(st);
   MarkovWord markovWord = new MarkovWord(order);
   runModel(markovWord, st, words, seed);
 }
示例#17
0
 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 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"));
  }
  @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);
    }
  }
示例#21
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);
  }
示例#22
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;
 }
示例#23
0
 public static void countWords(FileResource resource, String[] common, int[] counts) {
   for (String word : resource.words()) {
     word = word.toLowerCase();
     int index = indexOf(common, word);
     if (index != -1) {
       counts[index] += 1;
     }
   }
 }
示例#24
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"));
   }
 }
示例#26
0
  /** Iterates over every word in a file and counting number of unique words in a file. */
  private void findUnique() {

    myWords.clear();
    myFreqs.clear();

    FileResource fr = new FileResource();

    for (String word : fr.words()) {

      word = word.toLowerCase();
      int index = myWords.indexOf(word);
      if (index == -1) {
        myWords.add(word);
        myFreqs.add(1);
      } else {
        int freq = myFreqs.get(index);
        myFreqs.set(index, freq + 1);
      }
    }
  }
  public void testBreakForAllLanguages() {

    // read in the encrypted message
    FileResource fr2 = new FileResource("athens_keyflute.txt");
    String encrypted = fr2.asString();

    HashMap<String, HashSet<String>> myMap = new HashMap<String, HashSet<String>>();

    FileResource fr = new FileResource("dictionaries/English");
    HashSet<String> dict = readDictionary(fr);

    myMap.put("English", dict);

    FileResource fr1 = new FileResource("dictionaries/Spanish");
    HashSet<String> dict1 = readDictionary(fr1);

    myMap.put("Spanish", dict1);

    breakForAllLanguages(encrypted, myMap);
  }
  /*
   *  method to return a HashSet of words lower-cased and read from the file
   *  passed in as a parameter
   */
  public HashSet<String> readDictionary(FileResource fr) {

    // create a HashSet which you will be returning
    HashSet<String> dict = new HashSet<String>();

    for (String line : fr.lines()) {

      // convert to lowercase and add to the dictionary
      line = line.toLowerCase();
      dict.add(line);
    }
    return dict;
  }
示例#29
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"));
 }
示例#30
0
 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);
 }