storage

package
v0.0.0-...-81f0056 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2018 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const HistoryMax = 100

HistoryMax is the maximum number of points allowed to be stored in the history

View Source
const HistoryMin = 60

HistoryMin is the number of positions retained when the history is full

View Source
const RTree_M = 5 //max entries per node.
View Source
const RTree_m = 2 //min entries per node.	40% of M is best

Variables

View Source
var UnknownInfo = ShipInfo{
	Draught:      0,
	Length:       0,
	Width:        0,
	LengthOffset: 0,
	WidthOffset:  0,
	VesselType:   ShipType(0),
}

UnknownInfo contains the default values used when there is no information available about a ship-related property. Should have been const but time.Time isn't.

View Source
var UnknownPos = ShipPos{
	Pos:         geo.Point{math.NaN(), math.NaN()},
	PosAccuracy: false,
	NavStatus:   ShipNavStatus(15),
	BowHeading:  uint16(math.NaN()),
	Course:      float32(math.NaN()),
	Speed:       float32(math.NaN()),
	RateOfTurn:  float32(math.NaN()),
}

UnknownPos contains the default values used when there is no information available about a position-related property. Should have been const, but math.NaN() is a function and 0.0/0.0 (or any indirection thereof) gives a division by zero error. This is intentional: https://github.com/golang/go/issues/2196#issuecomment-66058380

Functions

func CheckErr

func CheckErr(err error, message string)

CheckErr is a function for checking an error. Takes the error and a message as input and does log.Fatalf() if error.

func Matches

func Matches(matches *[]Match, db *ShipDB) string

Matches produces the geojson FeatureCollection containing all the matching ships along with the length and name of the ship.

Types

type Accuracy

type Accuracy bool

Accuracy contains the accuracy of the ships position.

func (Accuracy) MarshalJSON

func (a Accuracy) MarshalJSON() ([]byte, error)

MarshalJSON is used by the json Marshaler. The json value of the Accuracy-object is the string description of the accuracy.

func (Accuracy) String

func (a Accuracy) String() string

String returns the string representation of the accuracy (either high or low).

type Geometry

type Geometry struct {
	Coordinates []geo.Point `json:"coordinates"`
}

Geometry is used to create GeoJSON "geometry" fields. Works for both GeoJSON "Point" and "LineString" objects.

func (Geometry) MarshalJSON

func (g Geometry) MarshalJSON() ([]byte, error)

MarshalJSON returns either a GeoJSON "Point" or a GeoJSON "LineString" object.

type Match

type Match struct {
	MMSI uint32
	Lat  float64
	Long float64
}

Match is used to store a match found when searching the tree.

type Mmsi

type Mmsi uint32

Mmsi stands for Maritime Mobile Service Identity and is used to identify the sender of AIS messages. It should be displayed as 9 digits.

func (Mmsi) CountryCode

func (m Mmsi) CountryCode() string

CountryCode returns the country identified by the "Maritime Identification Digits" of the mmsi.

func (*Mmsi) String

func (m *Mmsi) String() string

String returns the string representation of the Mmsi-object. E.g. "Ship, Norway" or "Coastal Station, France".

func (Mmsi) Type

func (m Mmsi) Type() string

Type returns the type of the type of vessel according to the MMSI. E.g. "Ship", "Coastal Station", "MOB —Man Overboard Device", etc.

type RTree

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

RTree is a two-dimensional R*-tree implementation with float64 positions and uint32 values

func NewRTree

func NewRTree() *RTree

NewRTree returns a pointer to a new R-Tree object.

func (*RTree) FindWithin

func (rt *RTree) FindWithin(r *geo.Rectangle) *[]Match

FindWithin returns all the boats that overlaps a given rectangle of the map [0].

func (*RTree) InsertData

func (rt *RTree) InsertData(lat, long float64, mmsi uint32) error

InsertData inserts a new boat into the tree structure.

func (*RTree) NumOfBoats

func (rt *RTree) NumOfBoats() int

NumOfBoats return the total number of boats stored in the structure.

func (*RTree) Update

func (rt *RTree) Update(mmsi uint32, oldLat, oldLong, newLat, newLong float64) error

Update is used to update the location of a boat that is already stored in the structure. It deletes the old entry, and inserts a new entry.

type ShipDB

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

ShipDB contains all the ships.

func NewShipDB

func NewShipDB() *ShipDB

NewShipDB creates and returns a pointer to a new ShipInfo object.

func (*ShipDB) Coords

func (db *ShipDB) Coords(mmsi uint32) (lat, long float64)

Coords returns the coordinates of the ship.

func (*ShipDB) Known

func (db *ShipDB) Known(mmsi uint32) bool

Known returns true if the given mmsi is stored in the structure.

func (*ShipDB) Select

func (db *ShipDB) Select(mmsi uint32) string

Select returns the info about the ship and its tracklog as a geojson FeatureCollection object.

func (*ShipDB) UpdateDynamic

func (db *ShipDB) UpdateDynamic(mmsi uint32, update ShipPos)

UpdateDynamic updates the ship's dynamic information.

func (*ShipDB) UpdateStatic

func (db *ShipDB) UpdateStatic(mmsi uint32, update ShipInfo)

UpdateStatic updates the ship's static information.

type ShipInfo

type ShipInfo struct {
	VesselType   ShipType  `json:"vesseltype,omitempty"`
	Draught      uint8     `json:"draught,omitempty"`
	Length       uint16    `json:"length,omitempty"`
	Width        uint16    `json:"width,omitempty"`
	LengthOffset int16     `json:"lengthoffset,omitempty"` // from center
	WidthOffset  int16     `json:"widthoffset,omitempty"`  // from center
	Callsign     string    `json:"callSign,omitempty"`
	ShipName     string    `json:"name,omitempty"`
	Dest         string    `json:"destination,omitempty"`
	ETA          time.Time `json:"eta,omitempty"`
}

ShipInfo stores information gathered from AIS message 5 and 24.

type ShipNavStatus

type ShipNavStatus uint8

ShipNavStatus contains the navigation status code. E.g. "Under way using engine", "At anchor", "Not under command", etc.

func (*ShipNavStatus) MarshalJSON

func (s *ShipNavStatus) MarshalJSON() ([]byte, error)

MarshalJSON is used by the json Marshaler. The json value of the ShipNavStatus-object is the navigation status as a string.

func (*ShipNavStatus) Stopped

func (s *ShipNavStatus) Stopped() bool

Stopped returns true if the ship is "At anchor" or "Moored".

func (*ShipNavStatus) String

func (s *ShipNavStatus) String() string

String() returns the navigation status as a string.

type ShipPos

type ShipPos struct {
	At          time.Time     `json:"time,omitempty"`     // Calculated from UTCSecond and time packet was received
	Pos         geo.Point     `json:"position"`           // A GeoJSON object must have a position, therefore this field can not be omitted
	PosAccuracy Accuracy      `json:"accuracy,omitempty"` // High or low
	NavStatus   ShipNavStatus `json:"navstatus,omitempty"`
	BowHeading  uint16        `json:"heading,omitempty"`    // in degrees with zero north
	Course      float32       `json:"cog,omitempty"`        // Direction of movement, in degrees with zero north
	Speed       float32       `json:"sog,omitempty"`        // in knots
	RateOfTurn  float32       `json:"rateofturn,omitempty"` // in degrees/minute
}

ShipPos stores information gathered from AIS message type 1-3, 18-19 and 27.

type ShipType

type ShipType uint8

ShipType contains the ship type code. E.g. "Fishing", "Sailing", "Tug", "Cargo", etc.

func (ShipType) MarshalJSON

func (t ShipType) MarshalJSON() ([]byte, error)

MarshalJSON is used by the json Marshaler The json value of the ShipType-object is the ship type as a string.

func (*ShipType) String

func (t *ShipType) String() string

String returns the ship type as a string.

Jump to

Keyboard shortcuts

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