db

package
v0.0.0-...-92f7fd9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVesselLastKnownPosition

func GetVesselLastKnownPosition(db *sql.DB, imo string) ([]float64, error)

func GetVesselRoute

func GetVesselRoute(db *sql.DB, mmsi string) ([][]float64, error)

func GetVesselsByIMOs

func GetVesselsByIMOs(db *sql.DB, imos []string) (map[string]Vessel, error)

func InitDB

func InitDB() (*sql.DB, error)

func InsertPositionReport

func InsertPositionReport(db *sql.DB, mmsi string, positionReport aisstream.PositionReport, timestamp models.CustomTime) error

id SERIAL PRIMARY KEY,

vessel_id INTEGER REFERENCES vessels(id),
mmsi TEXT REFERENCES vessels(mmsi),
latitude DECIMAL(10,8),
longitude DECIMAL(11,8),
timestamp TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

func UpdateLocationCoordinates

func UpdateLocationCoordinates(db *sql.DB, unlocode string, latitude, longitude float64) error

func UpdateTrackedVessels

func UpdateTrackedVessels(db *sql.DB, mmsis []string) (int64, error)

func UpsertLocations

func UpsertLocations(db *sql.DB, locations []models.MaerskLocation) error

func UpsertVessel

func UpsertVessel(db *sql.DB, vessel Vessel) error

Types

type Location

type Location struct {
	ID             int       `json:"id"`
	Unlocode       string    `json:"unlocode"`
	Name           string    `json:"name"`
	CountryCode    string    `json:"country_code"`
	Location       []float64 `json:"location"`
	IsAirport      bool      `json:"is_airport"`
	IsPort         bool      `json:"is_port"`
	IsTrainStation bool      `json:"is_train_station"`
	CreatedAt      time.Time `json:"created_at"`
	MaerskID       string    `json:"maersk_id"`
}

Location struct to match the database schema

func AutoComplete

func AutoComplete(db *sql.DB, text string) ([]Location, error)

func GetLocations

func GetLocations(db *sql.DB, unLoCodes []string) ([]Location, error)

type OceanProduct

type OceanProduct struct {
	ID                          int       `db:"id"`
	CarrierProductID            string    `db:"carrier_product_id"`
	ProductValidToDate          time.Time `db:"product_valid_to_date"`
	ProductValidFromDate        time.Time `db:"product_valid_from_date"`
	OriginCity                  string    `db:"origin_city"`
	OriginName                  string    `db:"origin_name"`
	OriginCountry               string    `db:"origin_country"`
	OriginPortUNLoCode          string    `db:"origin_port_un_lo_code"`
	OriginCarrierSiteGeoID      string    `db:"origin_carrier_site_geo_id"`
	OriginCarrierCityGeoID      string    `db:"origin_carrier_city_geo_id"`
	DestinationCity             string    `db:"destination_city"`
	DestinationName             string    `db:"destination_name"`
	DestinationCountry          string    `db:"destination_country"`
	DestinationPortUNLoCode     string    `db:"destination_port_un_lo_code"`
	DestinationCarrierSiteGeoID string    `db:"destination_carrier_site_geo_id"`
	DestinationCarrierCityGeoID string    `db:"destination_carrier_city_geo_id"`
	DepartureVesselCarrierCode  string    `db:"departure_vessel_carrier_code"`
	DepartureVesselName         string    `db:"departure_vessel_name"`
	DepartureVesselIMONumber    string    `db:"departure_vessel_imo_number"`
	DepartureVesselMMSI         string    `db:"departure_vessel_mmsi"`
	DepartureDateTime           time.Time `db:"departure_date_time"`
	ArrivalDateTime             time.Time `db:"arrival_date_time"`
	TransitTime                 int       `db:"transit_time"`
	CreatedAt                   time.Time `db:"created_at"`
}

type TransportLeg

type TransportLeg struct {
	ID                          int       `db:"id"`
	OceanProductID              int       `db:"ocean_product_id"`
	DepartureDateTime           time.Time `db:"departure_date_time"`
	ArrivalDateTime             time.Time `db:"arrival_date_time"`
	VesselCarrierCode           string    `db:"vessel_carrier_code"`
	VesselName                  string    `db:"vessel_name"`
	VesselIMONumber             string    `db:"vessel_imo_number"`
	VesselMMSI                  string    `db:"vessel_mmsi"`
	OriginCity                  string    `db:"origin_city"`
	OriginName                  string    `db:"origin_name"`
	OriginCountry               string    `db:"origin_country"`
	OriginPortUNLoCode          string    `db:"origin_port_un_lo_code"`
	OriginCarrierSiteGeoID      string    `db:"origin_carrier_site_geo_id"`
	OriginCarrierCityGeoID      string    `db:"origin_carrier_city_geo_id"`
	DestinationCity             string    `db:"destination_city"`
	DestinationName             string    `db:"destination_name"`
	DestinationCountry          string    `db:"destination_country"`
	DestinationPortUNLoCode     string    `db:"destination_port_un_lo_code"`
	DestinationCarrierSiteGeoID string    `db:"destination_carrier_site_geo_id"`
	DestinationCarrierCityGeoID string    `db:"destination_carrier_city_geo_id"`
	CreatedAt                   time.Time `db:"created_at"`
}

type Vessel

type Vessel struct {
	ID                int       `db:"id"`
	IMONumber         string    `db:"imo_number"`
	MMSI              string    `db:"mmsi"`
	Name              string    `db:"name"`
	IsTracked         bool      `db:"is_tracked"`
	CarrierCode       string    `db:"carrier_code"`
	AppearanceCount   int       `db:"appearance_count"`
	LastSeen          time.Time `db:"last_seen"`
	CreatedAt         time.Time `db:"created_at"`
	LastKnownPosition []float64 `db:"last_known_position"`
}

func GetTopVessels

func GetTopVessels(db *sql.DB, limit int) ([]Vessel, error)

GetTopVessels returns the most frequently appearing vessels

func GetVesselByIMO

func GetVesselByIMO(db *sql.DB, imo string) (Vessel, error)

func GetVesselByMMSI

func GetVesselByMMSI(db *sql.DB, mmsi string) (Vessel, error)

type VesselPosition

type VesselPosition struct {
	ID        int       `db:"id"`
	VesselID  int       `db:"vessel_id"`
	MMSI      string    `db:"mmsi"`
	Latitude  float64   `db:"latitude"`
	Longitude float64   `db:"longitude"`
	Timestamp time.Time `db:"timestamp"`
	CreatedAt time.Time `db:"created_at"`
}

type VesselRoute

type VesselRoute struct {
	ID             int       `db:"id"`
	VesselID       int       `db:"vessel_id"`
	OceanProductID int       `db:"ocean_product_id"`
	RouteType      string    `db:"route_type"`
	CreatedAt      time.Time `db:"created_at"`
}

Jump to

Keyboard shortcuts

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