// loadFromCsv hydrates a CrimeFinder from CSV data.
loadFromCsv hydrates a CrimeFinder from CSV data.
// loadFromCsv hydrates a CrimeFinder from CSV data .
func (finder *CrimeFinder) loadFromCsv(rows CsvRows) error {
	locations := make(LocationLookup)
	numCrimes := 0
	for _, row := range rows {
		location, err := locations.getOrCreateFromCsvRow(row)
		if err != nil {
			continue
		}
		id, err := strconv.ParseInt(row[0], 0, 64)
		if err != nil {
			continue
		}
		crimeType := string(row[3])
		if !finder.CrimeTypes.Contains(crimeType) {
			finder.CrimeTypes = append(finder.CrimeTypes, crimeType)
		}
		location.Crimes = append(location.Crimes, &Crime{id, row[1], row[2], crimeType})
		numCrimes += 1
	}
	log.Printf("Loaded %v crimes and %v locations", numCrimes, len(locations))
	finder.LocationLookup = locations
	return nil
}
func ( finder * CrimeFinder ) loadFromCsv ( rows CsvRows ) error { locations := make ( LocationLookup ) numCrimes := 0 for _ , row := range rows { location , err := locations . getOrCreateFromCsvRow ( row ) if err != nil { continue } id , err := strconv . ParseInt ( row [ 0 ] , 0 , 64 ) if err != nil { continue } crimeType := string ( row [ 3 ] ) if ! finder . CrimeTypes . Contains ( crimeType ) { finder . CrimeTypes = append ( finder . CrimeTypes , crimeType ) } location . Crimes = append ( location . Crimes , & Crime { id , row [ 1 ] , row [ 2 ] , crimeType } ) numCrimes += 1 } log . Printf ( " " , numCrimes , len ( locations ) ) finder . LocationLookup = locations return nil }
loadFromCsv hydrates a CrimeFinder from CSV data.
loadFromCsv hydrates a CrimeFinder from CSV data .
// Parse the "id" column as an int64