Permalink
Browse files

Regenerate and fix

  • Loading branch information...
peter-edge committed Dec 31, 2017
1 parent 01e14a5 commit 57f47382fa8160af6c37944830d46fcaaa6bdf00
Showing with 12,817 additions and 10,130 deletions.
  1. +7 −11 code_store.go
  2. +1 −1 csv_store.go
  3. +20 −16 filters.go
  4. +12,759 −10,084 generated.go
  5. +19 −13 id_store.go
  6. +1 −1 openflights.go
  7. +4 −4 openflights_test.go
  8. +6 −0 util.go
@@ -2,7 +2,6 @@ package openflights

import (
"fmt"
"log"
"strings"
"unsafe"
)
@@ -72,7 +71,9 @@ func getAirportMap(idStore *IDStore, options CodeStoreOptions) (map[string]*Airp
if _, ok := m[strings.ToLower(s)]; ok {
err := fmt.Errorf("openflights: duplicate airport key: %s", s)
if options.NoFilterDuplicates || options.NoErrorOnDuplicates {
getLogFunc(options)(err.Error())
if options.LogFunc != nil {
options.LogFunc(err.Error())
}
} else {
return nil, err
}
@@ -88,7 +89,7 @@ func getAirlineMap(idStore *IDStore, options CodeStoreOptions) (map[string]*Airl
m := make(map[string]*Airline)
for _, airline := range idStore.IdToAirline {
if !options.NoFilterDuplicates {
include, err := includeAirline(airline, airlineCodeToAirlineIDToNumRoutes, getLogFunc(options))
include, err := includeAirline(airline, airlineCodeToAirlineIDToNumRoutes, options.LogFunc)
if err != nil {
return nil, err
}
@@ -100,7 +101,9 @@ func getAirlineMap(idStore *IDStore, options CodeStoreOptions) (map[string]*Airl
if _, ok := m[strings.ToLower(s)]; ok {
err := fmt.Errorf("openflights: duplicate airline key: %s", s)
if options.NoFilterDuplicates || options.NoErrorOnDuplicates {
getLogFunc(options)(err.Error())
if options.LogFunc != nil {
options.LogFunc(err.Error())
}
} else {
return nil, err
}
@@ -198,10 +201,3 @@ func routesIntersection(routesSlices ...[]*Route) []*Route {
}
return ret
}

func getLogFunc(options CodeStoreOptions) func(string, ...interface{}) {
if options.LogFunc != nil {
return options.LogFunc
}
return log.Printf
}
@@ -7,7 +7,7 @@ import (
)

func getCSVStore() (*CSVStore, error) {
airports, err := getOpenFlightsData("airports.dat")
airports, err := getOpenFlightsData("airports-extended.dat")
if err != nil {
return nil, err
}
@@ -7,23 +7,25 @@ import (

var (
filterAirportIDToAirportCode = map[string]string{
"2431": "RPVM",
"2919": "UATE",
"3769": "BFT",
"4330": "OIIE",
"7708": "ZYA",
"8420": "EDDB",
//"2431": "RPVM",
//"2919": "UATE",
//"3769": "BFT",
//"4330": "OIIE",
//"7708": "ZYA",
//"8420": "EDDB",
"11922": "IWK",
}
filterAirlineIDToAirlineCode = map[string]string{
"2883": "ZA",
"5424": "WA",
"2439": "VY",
"2051": "5D",
"5533": "TYR",
"1883": "CO",
"1879": "C3",
"2805": "C3",
"1615": "CP",
"2883": "ZA",
"5424": "WA",
"2439": "VY",
"2051": "5D",
"5533": "TYR",
"1883": "CO",
"1879": "C3",
"2805": "C3",
"1615": "CP",
"16459": "SKV",
}
// TODO(pedge): deal with the airlines not selected
selectAirlineCodeToAirlineID = map[string]string{
@@ -74,7 +76,9 @@ func includeAirline(airline *Airline, airlineCodeToAirlineIDToNumRoutes map[stri
}
}
if maxAirlineID != airline.Id {
logFunc("filtering airline %v because it only had %d routes when max was airline id %s with %d", airline, airlineNumRoutes, maxAirlineID, max)
if logFunc != nil {
logFunc("filtering airline %v because it only had %d routes when max was airline id %s with %d", airline, airlineNumRoutes, maxAirlineID, max)
}
return false, nil
}
}
22,843 generated.go

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -107,23 +107,23 @@ func (i *IDStore) GetAirlineByID(id string) (*Airline, error) {
func getIDToAirport(data []byte) (map[string]*Airport, error) {
records, err := getOpenFlightsRecords(data)
if err != nil {
return nil, err
return nil, fmt.Errorf("error reading airports: %v", err)
}
return getIDToAirportForRecords(records)
}

func getIDToAirline(data []byte) (map[string]*Airline, error) {
records, err := getOpenFlightsRecords(data)
if err != nil {
return nil, err
return nil, fmt.Errorf("error reading airlines: %v", err)
}
return getIDToAirlineForRecords(records)
}

func getRoutes(data []byte, idToAirport map[string]*Airport, idToAirline map[string]*Airline) ([]*Route, error) {
records, err := getOpenFlightsRecords(data)
if err != nil {
return nil, err
return nil, fmt.Errorf("error reading routes: %v", err)
}
return getRoutesForRecords(records, idToAirport, idToAirline)
}
@@ -172,23 +172,27 @@ func getRoutesForRecords(records [][]string, idToAirport map[string]*Airport, id
func getAirportForRecord(record []string) (*Airport, error) {
latitudeMicros, err := parseFloat(record[6], 1000000)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get airport for record %v: %v", record, err)
}
longitudeMicros, err := parseFloat(record[7], 1000000)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get airport for record %v: %v", record, err)
}
altitudeFeet, err := parseInt(record[8])
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get airport for record %v: %v", record, err)
}
timezoneOffsetMinutes, err := parseFloat(record[9], 60)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get airport for record %v: %v", record, err)
}
dstValue, ok := DST_value[fmt.Sprintf("DST_%s", record[10])]
if !ok {
return nil, fmt.Errorf("openflights: no DST value for '%s' in %v", record[10], record)
var dstValue int32
var ok bool
if record[10] != "" {
dstValue, ok = DST_value[fmt.Sprintf("DST_%s", record[10])]
if !ok {
return nil, fmt.Errorf("openflights: no DST value for '%s' in %v", record[10], record)
}
}
return &Airport{
Id: record[0],
@@ -209,7 +213,7 @@ func getAirportForRecord(record []string) (*Airport, error) {
func getAirlineForRecord(record []string) (*Airline, error) {
active, err := getOpenFlightsBool(record[7], record)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get airline for record %v: %v", record, err)
}
return &Airline{
Id: record[0],
@@ -245,7 +249,7 @@ func getRouteForRecord(record []string, idToAirport map[string]*Airport, idToAir
}
stops, err := parseInt(record[7])
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get route for record %v: %v", record, err)
}
return &Route{
Airline: airline,
@@ -257,7 +261,9 @@ func getRouteForRecord(record []string, idToAirport map[string]*Airport, idToAir
}

func getOpenFlightsRecords(data []byte) (_ [][]string, retErr error) {
records, err := csv.NewReader(bytes.NewReader(data)).ReadAll()
reader := csv.NewReader(bytes.NewReader(data))
reader.LazyQuotes = true
records, err := reader.ReadAll()
if err != nil {
return nil, err
}
@@ -43,7 +43,7 @@ type CodeStoreOptions struct {
// if set, an error will not be returned on a duplicate
NoErrorOnDuplicates bool
// if set, will log warnings during instantiation using this function
// in the style of log.Printf, otherwise will use the stdlib logger.
// in the style of log.Printf, otherwise will not print logs.
LogFunc func(string, ...interface{})
}

@@ -16,13 +16,13 @@ func TestGetAirport(t *testing.T) {
t,
&Airport{
Id: "1613",
Name: "Schwechat",
Name: "Vienna International Airport",
City: "Vienna",
Country: "Austria",
IataFaa: "VIE",
Icao: "LOWW",
LatitudeMicros: 48110278,
LongitudeMicros: 16569722,
LatitudeMicros: 48110298,
LongitudeMicros: 16569700,
AltitudeFeet: 600,
TimezoneOffsetMinutes: 60,
Dst: DST_DST_E,
@@ -85,7 +85,7 @@ func TestGetAllAirports(t *testing.T) {
ids[airport.Id] = true
}
require.Nil(t, <-callbackErr)
require.Equal(t, 8107, len(ids))
require.Equal(t, 10668, len(ids))
}

func TestGetMiles(t *testing.T) {
@@ -89,6 +89,9 @@ func containsString(slice []string, s string) bool {
}

func parseInt(s string) (int, error) {
if s == "" {
return 0, nil
}
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, err
@@ -97,6 +100,9 @@ func parseInt(s string) (int, error) {
}

func parseFloat(s string, multiplier int) (int, error) {
if s == "" {
return 0, nil
}
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return 0, err

0 comments on commit 57f4738

Please sign in to comment.