database

package
v0.0.0-...-9ea1666 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectorFunc

type ConnectorFunc func() (*gorm.DB, error)

ConnectorFunc is used to inject a database connection method into NewDatabaseConnection

func NewPostgreSQLConnector

func NewPostgreSQLConnector() ConnectorFunc

NewPostgreSQLConnector opens a connection to a postgresql database

func NewSQLiteConnector

func NewSQLiteConnector() ConnectorFunc

NewSQLiteConnector opens a connection to a local sqlite database

type Datastore

type Datastore interface {
	AddRoad(Road) error

	GetRoadByID(id string) (Road, error)
	GetRoadBySegmentID(segmentID string) (Road, error)
	GetRoadCount() int
	GetRoadsNearPoint(lat, lon float64, maxDistance uint64) ([]Road, error)
	GetRoadsWithinRect(lat0, lon0, lat1, lon1 float64) ([]Road, error)

	GetRoadSegmentByID(id string) (RoadSegment, error)

	GetSegmentsNearPoint(lat, lon float64, maxDistance uint64) ([]RoadSegment, error)
	GetSegmentsWithinRect(lat0, lon0, lat1, lon1 float64) ([]RoadSegment, error)

	RoadSegmentSurfaceUpdated(segmentID, surfaceType string, probability float64, timestamp time.Time) error
	UpdateRoadSegmentSurface(segmentID, surfaceType string, probability float64, timestamp time.Time) error

	CreateRoadSurfaceObserved(src *diwise.RoadSurfaceObserved) (*persistence.RoadSurfaceObserved, error)
	GetRoadSurfacesObserved() ([]persistence.RoadSurfaceObserved, error)
}

Datastore is an interface that is used to inject the database into different handlers to improve testability

func NewDatabaseConnection

func NewDatabaseConnection(connect ConnectorFunc, datafile io.Reader) (Datastore, error)

NewDatabaseConnection creates and returns a new instance of the Datastore interface

type Point

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

Point encapsulates a WGS84 coordinate

func NewPoint

func NewPoint(lat, lon float64) Point

NewPoint creates a new point instance to encapsulate the provided coordinate

func (Point) IsBoundedBy

func (p Point) IsBoundedBy(box *Rectangle) bool

IsBoundedBy returns true if the point is bounded by the provided bounding box

type Rectangle

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

Rectangle is a rectangle shaped box based on a NW and a SE coordinate

func NewBoundingBoxFromRectangles

func NewBoundingBoxFromRectangles(rect1, rect2 Rectangle) Rectangle

NewBoundingBoxFromRectangles creates a new instance of a Rectangle by creating a union of two others

func NewRectangle

func NewRectangle(pt1 Point, pt2 Point) Rectangle

NewRectangle takes two Points and returns a new Rectangle instance

func (Rectangle) DistanceFromPoint

func (r Rectangle) DistanceFromPoint(pt Point) uint64

DistanceFromPoint calculates the distance from a rectangle and an exterior point. For points within the rectangle, 0 is returned

func (Rectangle) Intersects

func (r Rectangle) Intersects(other Rectangle) bool

Intersects returns true if the two rectangles overlap in any way

type Road

type Road interface {
	ID() string

	AddSegment(RoadSegment)
	GetSegment(id string) (RoadSegment, error)
	GetSegmentIdentities() []string
	GetSegmentsWithinDistanceFromPoint(maxDistance uint64, pt Point) ([]RoadSegment, uint64)
	GetSegmentsWithinRect(Rectangle) ([]RoadSegment, uint64)

	BoundingBox() Rectangle
	IsWithinDistanceFromPoint(maxDistance uint64, pt Point) bool
	// contains filtered or unexported methods
}

Road is a road

type RoadSegment

type RoadSegment interface {
	ID() string
	RoadID() string
	BoundingBox() Rectangle
	Coordinates() [][2]float64
	IsWithinDistanceFromPoint(uint64, Point) bool
	SurfaceType() (string, float64)

	DateModified() *time.Time
	IsModified() bool
	// contains filtered or unexported methods
}

RoadSegment is a road segment

type RoadSegmentLine

type RoadSegmentLine interface {
	BoundingBox() Rectangle
	StartPoint() [2]float64
	EndPoint() [2]float64
}

RoadSegmentLine represents a straight part of a road segment

Jump to

Keyboard shortcuts

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