public static SquirrelCensusDictionaryBuildResult buildFromRawCsvFile()

in app/java/src/main/java/com/google/cloudclientapi/SquirrelCensusDictionaryBuilder.java [38:79]


  public static SquirrelCensusDictionaryBuildResult buildFromRawCsvFile(String csvFilePath)
      throws FileNotFoundException, IOException {
    Dictionary<String, SquirrelSegment> colorAgeLocationToCount =
        new Hashtable<String, SquirrelSegment>();
    int numOfRowsProcessed = 0;
    int numOfRowsIgnored = 0;

    // Go through each row of the CSV file.
    FileReader reader = new FileReader(csvFilePath);
    CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT.withHeader());
    for (CSVRecord record : csvParser) {
      numOfRowsProcessed++;
      // Ignore rows where crucial columns are empty/unknown.
      boolean shouldIgnoreRow = false;
      for (String column : CSV_COLUMNS) {
        String value = record.get(column);
        if (value == null || value.isEmpty() || value.equals("?")) {
          numOfRowsIgnored++;
          shouldIgnoreRow = true;
        }
      }
      // Bump count in "Color/Age/Location" dictionary.
      if (!shouldIgnoreRow) {
        String key =
            String.format(
                "%s/%s/%s",
                record.get("Primary Fur Color"), record.get("Age"), record.get("Location"));
        SquirrelSegment currSegment = colorAgeLocationToCount.get(key);
        if (currSegment == null) {
          currSegment = new SquirrelSegment();
          colorAgeLocationToCount.put(key, currSegment);
        }
        bumpSquirrelSegmentCountsForCsvRow(currSegment, record);
      }
    }

    SquirrelCensusDictionaryBuildResult result = new SquirrelCensusDictionaryBuildResult();
    result.dictionary = colorAgeLocationToCount;
    result.numOfRowsProcessed = numOfRowsProcessed;
    result.numOfRowsIgnored = numOfRowsIgnored;
    return result;
  }