admin

package
v0.0.0-...-45a5a41 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DarkGrey     = "#1E232B"
	MediumGrey   = "#2A2E34"
	LightGrey    = "#3B3F46"
	DarkYellow   = "#EC9C04"
	MediumYellow = "#F5B301"
	LightYellow  = "#FED053"

	SpecialTag = "special"
	DefaultTag = "default"

	MaxLevel = 200
	MaxCells = 8000

	ItemTypeNode = iota
	ItemTypeWay
	ItemTypeRelation
)
View Source
const (
	OSMNode              = "node"
	OSMStop              = "stop"
	OSMStopEntryOnly     = "stop_entry_only"
	OSMStopExitOnly      = "stop_exit_only"
	OSMPlatform          = "platform"
	OSMPlatformEntryOnly = "platform_entry_only"
	OSMPlatformExitOnly  = "platform_exit_only"
	OSMWay               = "way"
	OSMRelation          = "relation"
)
View Source
const (
	ForeignKeysSQL = `PRAGMA foreign_keys=on;`

	CreateBussesSQL    = `` /* 274-byte string literal not displayed */
	CreateStationsSQL  = `` /* 188-byte string literal not displayed */
	CreateBusStopsSQL  = `` /* 333-byte string literal not displayed */
	CreatePointsSQL    = `` /* 392-byte string literal not displayed */
	CreateDistancesSQL = `` /* 395-byte string literal not displayed */

	CleanupPointsSQL                     = `DELETE FROM points WHERE 1;`
	CleanupDistancesSQL                  = `DELETE FROM distances WHERE 1;`
	InsertPointSQL                       = `INSERT INTO points (id, lat, lng, idx, is_stop, from_station_id, to_station_id) VALUES (?, ?, ?, ?, ?, ?, ?);`
	InsertDistanceSQL                    = `INSERT INTO distances (from_station_id, to_station_id, distance, minutes) VALUES (?, ?, ?, ?);`
	UpdateDistanceSQL                    = `UPDATE distances SET minutes = ? WHERE  from_station_id = ? AND to_station_id = ?;`
	BussesListSQL                        = `SELECT id, dir, name, from_station, to_station, no, color, website, urban, metropolitan, crawled FROM busses;`
	StationsListSQL                      = `SELECT id, name, street_name, lat, lng, outside, board FROM stations ORDER BY name ASC, street_name ASC;`
	NotCrawledBussesListSQL              = `` /* 131-byte string literal not displayed */
	ShortBusByIDSQL                      = `` /* 266-byte string literal not displayed */
	FullBusByIDSQL                       = `` /* 318-byte string literal not displayed */
	GetTimeTablesForStationAndBusByIDSQL = `SELECT enc_time FROM time_tables WHERE station_id = ? AND bus_id = ?;`
	InsertTimeTablesSQL                  = `INSERT INTO time_tables (bus_id, station_id, enc_time) VALUES (?, ?, ?);`
	UpdateBussesSQL                      = `UPDATE busses SET crawled = true WHERE id = ?;`
	InsertBusSQL                         = `` /* 152-byte string literal not displayed */
	InsertBusStopSQL                     = `INSERT INTO bus_stops (bus_id, station_id, station_index) VALUES (?, ?, ?);`
	InsertStationSQL                     = `INSERT INTO stations (id, name, lat, lng, outside, board) VALUES (?, ?, ?, ?, ?, ?);`
	StationByIDSQL                       = `SELECT name, lat, lng, outside, board FROM stations WHERE id = ?;`
)
View Source
const (
	RadiansPerDegree      = math.Pi / 180.0 //
	DegreesPerRadian      = 180.0 / math.Pi //
	EarthRadiusInMeters   = 6378137.0       // earth radius in meters
	NauticalMilesInMeters = 1852            // nautical mile is 1852 meters
)

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) int

func CrawlTimeTables

func CrawlTimeTables(logger *slog.Logger, bus *Busline) (map[int64]TimeTable, error)

func DistanceOnEdges

func DistanceOnEdges(lat1, lon1, lat2, lon2 float64) float64

func GetTilesInBBoxForZoom

func GetTilesInBBoxForZoom(northWestLat, northWestLong, southEastLat, southEastLong float64, zoom int) ([]XYZ, Bounds)

func Haversine

func Haversine(startLat, startLon, destLat, destLon float64) float64

func Heading

func Heading(startLat, startLon, destLat, destLon float64) float64

func ReverseGeocodeStreet

func ReverseGeocodeStreet(lat, lon float64) (*string, error)

func ServeTiles

func ServeTiles(logger *slog.Logger, pbfFilePath string, repo *Repository) func(w http.ResponseWriter, r *http.Request)

Types

type Alias

type Alias struct {
	OSMIndex  int      `json:"s"`
	OSMID     int64    `json:"i"`
	OSMName   string   `json:"n"`
	RATBVName string   `json:"r"`
	RATBVLink string   `json:"l"`
	Times     []uint16 `json:"t"`
}
func CrawlStationNamesAndLinks(logger *slog.Logger, bus *Busline) ([]Alias, error)

type Bounds

type Bounds struct {
	XFrom, XTo, YFrom, YTo int
}

type Busline

type Busline struct {
	OSMID          int64     `json:"i"`
	SiblingOSMID   int64     `json:"si"`
	Name           string    `json:"b"`
	From           string    `json:"f"`
	To             string    `json:"t"`
	Line           string    `json:"n"`
	Color          string    `json:"c"`
	Dir            int       `json:"d"`
	Link           string    `json:"w"`
	IsUrban        bool      `json:"u,omitempty"`
	IsMetropolitan bool      `json:"m,omitempty"`
	WasCrawled     bool      `json:"p"`
	Stations       []Station `json:"s"`
}

func NewBusline

func NewBusline(fromNode Node) Busline

func (*Busline) PrintStations

func (b *Busline) PrintStations() string

type Color

type Color struct {
	R, G, B, A float64
}

type DOW

type DOW int
const (
	Unknown           DOW = 0
	WeekDays          DOW = 1
	SaturdayAndSunday DOW = 2
	Saturday          DOW = 3
	Sunday            DOW = 4
)

func (DOW) MarshalJSON

func (d DOW) MarshalJSON() ([]byte, error)

func (*DOW) Parse

func (d *DOW) Parse(from string)

func (DOW) String

func (d DOW) String() string

type Data

type Data struct {
	Elements []Node `json:"elements"`
}

type Direction

type Direction int
const (
	NotSet Direction = 0
	Tour   Direction = 1
	Retour Direction = 2
)

func (Direction) String

func (d Direction) String() string

type FeatureRef

type FeatureRef struct {
	Id   int64
	Type int
	Zoom int
}

type IDraw

type IDraw interface {
	Draw(t *Tile)
	IsWay() bool
}

type JSONStyle

type JSONStyle struct {
	Color   string  `json:"color"`
	Width   int     `json:"width"`
	Dash    float64 `json:"dash"`
	Opacity float64 `json:"opacity"`
}

type LineNumberAndTime

type LineNumberAndTime struct {
	No        string    `json:"b"`
	BusOSMID  int64     `json:"-"`
	Direction Direction `json:"-"`
	Times     []uint16  `json:"t,omitempty"`
}

type Lines

type Lines []*LineNumberAndTime

func (Lines) GetFirstEntry

func (l Lines) GetFirstEntry(busID int64) (*Time, bool)

func (Lines) GetFirstEntryAfter

func (l Lines) GetFirstEntryAfter(busID int64, t *Time) (*Time, bool)

func (Lines) HasBus

func (l Lines) HasBus(busID int64) bool

type Member

type Member struct {
	Type string `json:"type"`
	Ref  int64  `json:"ref"`
	Role string `json:"role,omitempty"`
}

type Node

type Node struct {
	Type    string            `json:"type,omitempty"`    //
	ID      int64             `json:"id,omitempty"`      //
	Index   int64             `json:"idx,omitempty"`     //
	Lat     float64           `json:"lat"`               //
	Lon     float64           `json:"lon"`               //
	Tags    map[string]string `json:"tags,omitempty"`    //
	Members []Member          `json:"members,omitempty"` // relation members
	Nodes   []int64           `json:"nodes,omitempty"`   // way nodes
	IsStop  bool              `json:"stop,omitempty"`    //
}

func NodeFromPbf

func NodeFromPbf(n *osmpbf.Node) Node

func RelationFromPbf

func RelationFromPbf(r *osmpbf.Relation) Node

func (*Node) CleanupTags

func (n *Node) CleanupTags()

func (Node) Draw

func (n Node) Draw(onTile *Tile)

func (Node) IsWay

func (n Node) IsWay() bool

type PBFData

type PBFData struct {
	Places map[int64]Node
	Nodes  map[int64]Node
	Ways   map[int64]Way
	Findex S2Index
}

func ParsePbf

func ParsePbf(logger *slog.Logger, path string, repo *Repository, rules map[int][]Tag) (*PBFData, error)

func ReadPBFData

func ReadPBFData(logger *slog.Logger, filename string, repo *Repository) (*PBFData, error)

func (*PBFData) GetFeatures

func (o *PBFData) GetFeatures(northWestPoint, southEastPoint Node) []IDraw

type Repository

type Repository struct {
	*slog.Logger
	*sql.DB
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(logger *slog.Logger, filePath string) (*Repository, error)

func (*Repository) CleanupStreetPoints

func (r *Repository) CleanupStreetPoints() error

func (*Repository) CreateBus

func (r *Repository) CreateBus(bus *Busline) error

func (*Repository) CreateStation

func (r *Repository) CreateStation(station *Station) error

func (*Repository) CreateStop

func (r *Repository) CreateStop(busId, stationId int64, stationIndex int) error

func (*Repository) GetAllFullBusses

func (r *Repository) GetAllFullBusses() ([]Busline, error)

func (*Repository) GetAllTimetables

func (r *Repository) GetAllTimetables() ([]Station, error)

func (*Repository) GetBusByID

func (r *Repository) GetBusByID(id int64) (*Busline, error)

func (*Repository) GetBusses

func (r *Repository) GetBusses(notCrawled bool) ([]Busline, error)

func (*Repository) GetFullStationsBusByID

func (r *Repository) GetFullStationsBusByID(id int64) (*Busline, error)

func (*Repository) GetStationByID

func (r *Repository) GetStationByID(stationId int64) (*Station, error)

func (*Repository) GetStations

func (r *Repository) GetStations() ([]Station, error)

func (*Repository) GetStationsForBus

func (r *Repository) GetStationsForBus(busId int64) ([]int64, error)

func (*Repository) GetTimeTablesForStationAndBus

func (r *Repository) GetTimeTablesForStationAndBus(stationID, busID int64) ([]uint16, error)

func (*Repository) SaveTimeTables

func (r *Repository) SaveTimeTables(busID int64, stationsTables map[int64]TimeTable) error

func (*Repository) UpdateStreetName

func (r *Repository) UpdateStreetName(stationId int64, name string) error

type S2Index

type S2Index map[s2.CellID][]FeatureRef

func (S2Index) AddWay

func (s S2Index) AddWay(way Way, zoom int)

func (S2Index) GetFeatures

func (s S2Index) GetFeatures(northWestPoint, southEastPoint Node) []FeatureRef

type Station

type Station struct {
	OSMID         int64          `json:"i"`
	Index         int            `json:"d"`
	Name          string         `json:"n"`
	Street        sql.NullString `json:"-"`
	StreetName    string         `json:"s,omitempty"`
	Lat           float64        `json:"lt"`
	Lon           float64        `json:"ln"`
	HasBoard      bool           `json:"b,omitempty"`
	IsOutsideCity bool           `json:"o,omitempty"`
	IsTerminal    bool           `json:"-"`
	Lines         Lines          `json:"l,omitempty"`
}

func NewStation

func NewStation(fromNode Node) Station

func (Station) ID

func (s Station) ID() int64

type Style

type Style struct {
	Color Color
	Width int
	Dash  float64
}

func (*Style) Collect

func (s *Style) Collect(ctx *gg.Context)

func (*Style) UnmarshalJSON

func (s *Style) UnmarshalJSON(b []byte) error

type Tag

type Tag struct {
	Key, Val string
}

type Tile

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

func (*Tile) Draw

func (t *Tile) Draw(osmData *PBFData) []IDraw

func (*Tile) DrawPolyLine

func (t *Tile) DrawPolyLine(coords [][]float64, tags map[string]string)

func (*Tile) GetRelativeXY

func (t *Tile) GetRelativeXY(point Node) (float64, float64)

func (*Tile) IsCrossing

func (t *Tile) IsCrossing(firstPoint, secondPoint s2.Point) bool

func (*Tile) IsInside

func (t *Tile) IsInside(point Node) bool

type Time

type Time struct {
	Day        DOW `json:"d,omitempty"` // div id="web_class_title"
	Hour       int `json:"h,omitempty"` // div id="web_class_hours"
	Minute     int `json:"m,omitempty"` // div id="web_class_minutes"
	IsOptional bool
}

func (*Time) After

func (t *Time) After(s Time) bool

func (*Time) Compress

func (t *Time) Compress() uint16

func (*Time) Decompress

func (t *Time) Decompress(compressed uint16)

func (*Time) Diff

func (t *Time) Diff(s Time) uint16

func (Time) String

func (t Time) String() string

type TimeTable

type TimeTable struct {
	Name        string `json:"-"`
	Line        string `json:"-"`
	From        string `json:"-"`
	To          string `json:"-"`
	CurrentHour int    `json:"-"`
	CurrentDow  DOW    `json:"-"`
	RawTimes    []Time `json:"-"`
}

type Way

type Way struct {
	Tags    map[string]string
	NodeIDs []int64
	Nodes   []Node
	Id      int64
}

func WayFromPbf

func WayFromPbf(w *osmpbf.Way) Way

func (Way) Draw

func (w Way) Draw(onTile *Tile)

func (Way) IsWay

func (w Way) IsWay() bool

func (Way) MatchAny

func (w Way) MatchAny(rules map[int][]Tag) (int, bool)

func (*Way) SetNodes

func (w *Way) SetNodes(nodes map[int64]Node)

type XYZ

type XYZ struct {
	X, Y, Z int
}

Jump to

Keyboard shortcuts

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