copier

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterValidator added in v0.8.1

type AfterValidator interface {
	AfterValidator(tl.Entity, *tl.EntityMap) error
}

AfterValidator is called for each fully validated entity before writing.

type AfterWrite added in v0.8.8

type AfterWrite interface {
	AfterWrite(string, tl.Entity, *tl.EntityMap) error
}

AfterWrite is called for after writing each entity.

type ApplyParentTimezoneFilter added in v0.10.0

type ApplyParentTimezoneFilter struct {
	// contains filtered or unexported fields
}

ApplyParentTimezoneFilter sets timezone based on the default agency timezone or parent stop timezone Can be used with NormalizeTimezoneFilter

func (*ApplyParentTimezoneFilter) Filter added in v0.10.0

func (e *ApplyParentTimezoneFilter) Filter(ent tl.Entity) []error

type BasicRouteTypeFilter added in v0.8.0

type BasicRouteTypeFilter struct{}

BasicRouteTypeFilter checks for extended route_type's and converts to basic route_types.

func (*BasicRouteTypeFilter) Filter added in v0.8.0

func (e *BasicRouteTypeFilter) Filter(ent tl.Entity, emap *tl.EntityMap) error

Filter converts extended route_types to basic route_types.

type Command added in v0.8.5

type Command struct {
	Options
	// contains filtered or unexported fields
}

Command

func (*Command) Parse added in v0.8.5

func (cmd *Command) Parse(args []string) error

func (*Command) Run added in v0.8.5

func (cmd *Command) Run() error

type Copier

type Copier struct {
	// Default options
	Options
	// Reader and writer
	Reader tl.Reader
	Writer tl.Writer
	// Entity selection strategy
	Marker Marker
	// Error handler, called for each entity
	ErrorHandler ErrorHandler

	*tl.EntityMap
	// contains filtered or unexported fields
}

Copier copies from Reader to Writer

func NewCopier

func NewCopier(reader tl.Reader, writer tl.Writer, opts Options) (*Copier, error)

NewCopier creates and initializes a new Copier.

func (*Copier) AddExtension

func (copier *Copier) AddExtension(ext interface{}) error

AddExtension adds an Extension to the copy process.

func (*Copier) AddValidator added in v0.8.0

func (copier *Copier) AddValidator(ext Validator, level int) error

AddValidator adds an additional entity validator.

func (*Copier) Copy

func (copier *Copier) Copy() *Result

Copy copies Base GTFS entities from the Reader to the Writer, returning the summary as a Result.

func (*Copier) CopyEntities added in v0.10.0

func (copier *Copier) CopyEntities(ents []tl.Entity) error

CopyEntities validates a slice of entities and writes those that pass validation.

func (*Copier) CopyEntity

func (copier *Copier) CopyEntity(ent tl.Entity) (error, error)

CopyEntity performs validation and saves errors and warnings. An entity error means the entity was not not written because it had an error or was filtered out; not fatal. A write error should be considered fatal and should stop any further write attempts. Any errors and warnings are added to the copier result.

func (*Copier) SetLogger added in v0.10.1

func (copier *Copier) SetLogger(g zerolog.Logger)

type ErrorGroup added in v0.8.0

type ErrorGroup struct {
	Filename  string
	ErrorType string
	Count     int
	Limit     int
	Errors    []error
}

ErrorGroup helps group errors together with a maximum limit on the number stored.

func NewErrorGroup added in v0.8.0

func NewErrorGroup(filename string, etype string, limit int) *ErrorGroup

NewErrorGroup returns a new ErrorGroup.

func (*ErrorGroup) Add added in v0.8.0

func (e *ErrorGroup) Add(err error)

Add an error to the error group.

type ErrorHandler

type ErrorHandler interface {
	HandleEntityErrors(tl.Entity, []error, []error)
	HandleSourceErrors(string, []error, []error)
}

ErrorHandler is called on each source file and entity; errors can be nil

type ExpandFilter added in v0.11.0

type ExpandFilter interface {
	Expand(tl.Entity, *tl.EntityMap) ([]tl.Entity, bool, error)
}

type Extension added in v0.8.1

type Extension interface {
	Copy(*Copier) error
}

Extension is run after normal copying has completed.

type Filter added in v0.8.1

type Filter interface {
	Filter(tl.Entity, *tl.EntityMap) error
}

Filter is called before validation.

type Marker

type Marker interface {
	IsMarked(string, string) bool
	IsVisited(string, string) bool
}

Marker visits and marks entities.

type NormalizeTimezoneFilter added in v0.10.0

type NormalizeTimezoneFilter struct{}

NormalizeTimezoneFilter changes a timezone alias to a normalized timezone, e.g. "US/Pacific" -> "America/Los_Angeles"

func (*NormalizeTimezoneFilter) Filter added in v0.10.0

func (e *NormalizeTimezoneFilter) Filter(ent tl.Entity) error

Validate .

type Options added in v0.8.0

type Options struct {
	// Batch size
	BatchSize int
	// Attempt to save an entity that returns validation errors
	AllowEntityErrors    bool
	AllowReferenceErrors bool
	// Interpolate any missing StopTime values: ArrivalTime/DepartureTime/ShapeDistTraveled
	InterpolateStopTimes bool
	// Create a stop-to-stop Shape for Trips without a ShapeID.
	CreateMissingShapes bool
	// Create missing Calendar entries
	NormalizeServiceIDs bool
	// Normalize timezones, e.g. US/Pacific -> America/Los_Angeles
	NormalizeTimezones bool
	// Simplify Calendars that use mostly CalendarDates
	SimplifyCalendars bool
	// Convert extended route types to primitives
	UseBasicRouteTypes bool
	// Copy extra files (requires CSV input)
	CopyExtraFiles bool
	// Simplify shapes
	SimplifyShapes float64
	// DeduplicateStopTimes
	DeduplicateJourneyPatterns bool
	// Default error handler
	ErrorHandler ErrorHandler
	// Journey Pattern Key Function
	JourneyPatternKey func(*tl.Trip) string
	// Named extensions
	Extensions []string
	// contains filtered or unexported fields
}

Options defines the settable options for a Copier.

type Prepare added in v0.8.1

type Prepare interface {
	Prepare(tl.Reader, *tl.EntityMap) error
}

Prepare is called before general copying begins.

type Result added in v0.8.0

type Result struct {
	WriteError                error
	InterpolatedStopTimeCount int
	EntityCount               map[string]int
	GeneratedCount            map[string]int
	SkipEntityErrorCount      map[string]int
	SkipEntityReferenceCount  map[string]int
	SkipEntityFilterCount     map[string]int
	SkipEntityMarkedCount     map[string]int
	Errors                    map[string]*ErrorGroup
	Warnings                  map[string]*ErrorGroup
	ErrorLimit                int
}

Result stores Copier results and statistics.

func NewResult added in v0.8.0

func NewResult() *Result

NewResult returns a new Result.

func (*Result) DisplayErrors added in v0.8.0

func (cr *Result) DisplayErrors()

DisplayErrors shows individual errors in log.Info

func (*Result) DisplaySummary added in v0.8.0

func (cr *Result) DisplaySummary()

DisplaySummary shows entity and error counts in log.Info

func (*Result) DisplayWarnings added in v0.8.0

func (cr *Result) DisplayWarnings()

DisplayWarnings shows individual warnings in log.Info

func (*Result) HandleEntityErrors added in v0.8.0

func (cr *Result) HandleEntityErrors(ent tl.Entity, errs []error, warns []error)

HandleEntityErrors .

func (*Result) HandleError added in v0.8.0

func (cr *Result) HandleError(fn string, errs []error)

HandleError .

func (*Result) HandleSourceErrors added in v0.8.0

func (cr *Result) HandleSourceErrors(fn string, errs []error, warns []error)

HandleSourceErrors .

type Validator added in v0.8.0

type Validator interface {
	Validate(tl.Entity) []error
}

Validator is called for each entity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL