shuttletracker

package module
v0.0.0-...-cb43c44 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

README

Shuttle Tracker Build Status codecov GoDoc

Tracks and maps RPI's shuttles with Go, Postgres, Vue.js, TypeScript, and Leaflet. Check it out in action at shuttles.rpi.edu.

Looking to contribute? Please review our Contribution Guidelines.

More project documentation can be found on the Repository Wiki.

If you encounter issues setting up, check the Common Installation Problems for potential solutions.

Setting up (Linux / WSL)

  1. Install Go. Shuttle Tracker requires Go 1.11 or newer, and we recommend using the latest stable Go release.
    • Other instructions found here
  2. Clone the repository to your computer. This can be done with git clone https://github.com/wtg/shuttletracker.
  3. Ensure you have Postgres downloaded, installed.
    • This can be done with sudo apt-get install postgresql
  4. Create a postgres databased titled "shuttletracker". (WE HIGHLY RECOMMEND USING PGADMIN)
    • This can be done by running createdb shuttletracker. If there is an error createdb: could not connect to database postgres: FATAL: role "<username>" does not exist, it is due that adminstrator has not created a PostgreSQL user account for you. It can be fixed by psql -U postgres in terminal, CREATE USER <username>;, ALTER USER <username> SUPERUSER CREATEDB; in postgres=#. And you can confirm the success by running \du in postgres=#.
    • Alternatively, download the Postgres management software pgAdmin. Click on the Servers drop down, then the Databases drop down, and add a database titled "shuttletracker" by right-clicking on Databases and selecting create.
  5. Switch to the Shuttle Tracker directory (cd shuttletracker)
  6. Rename conf.json.sample to conf.json
  7. Edit conf.json with the following, if necessary:
    • Postgres.URL: URL where Postgres is located. This will generally look like postgres://user:password@localhost/shuttletracker?sslmode=disable where user and password are replaced
  8. Install Node.js and npm
    • This can be done with sudo apt-get install nodejs.
    • Make sure you are on version 10.16.0 or higher by running node -v.
    • If your version of node is old, install n by running npm install -g n.
    • Type apt-get remove nodejs to remove all versions of node installed through apt-get.
    • Type n stable to install the latest version of nodejs. Type node -v after to verify.
  9. Switch to the ./frontend directory.
  10. Run npm install
  11. Build the frontend using npx vue-cli-service build --mode development
    • Note: if you are working on the frontend, you may instead use npx vue-cli-service build --mode development --watch in another terminal to continuously watch for changes and rebuild.
  12. Go back up to the project root directory and build Shuttle Tracker by running go build -o shuttletracker ./cmd/shuttletracker
  13. Start the app by running ./shuttletracker
  14. Add yourself as an administrator by using ./shuttletracker admins --add RCS_ID, replacing RCS_ID with your RCS ID. See the "Administrators" section below for more information.
  15. Visit http://localhost:8080/ to view the tracking application and http://localhost:8080/admin to view the administration panel.
  16. (Optional) Import live data from /routes, /stops, and /vehicles.

Setting up (macOS)

  1. Install Go. Shuttle Tracker requires Go 1.11 or newer, and we recommend using the latest stable Go release.
  2. Clone the repository to your computer. This can be done with git clone git@github.com:wtg/shuttletracker.git. If you receive a "permission denied" error, ensure you have added your SSH key to your GitHub account.
  3. Download Postgres.app and Postico. Postgres.app allows a Postgres server to be started using a graphical interface, while Postico allows a PostgreSQL database to be managed using a graphical interface.
  4. Open Postgres.app and create a new Postgres server by pressing the + in the sidebar. Name the server "shuttletracker" and specify its port as 5432. Then press start to run the server.
  5. Open Postico and create a new database named "shuttletracker" by pressing "+ Database".
  6. Switch to the Shuttle Tracker directory (cd shuttletracker)
  7. Rename conf.json.sample to conf.json
  8. Edit conf.json with the following, if necessary:
    • Postgres.URL: URL where Postgres is located. This will generally look like postgres://user:password@localhost/shuttletracker?sslmode=disable where user and password are replaced
  9. Install Node.js and npm. Be sure to download the latest LTS version. Do not download the current version or errors will occur when building the project
  10. Switch to the ./frontend directory.
  11. Run npm install
  12. Build the frontend using npx vue-cli-service build --mode development
    • Note: if you are working on the frontend, you may instead use npx vue-cli-service build --mode development --watch in another terminal to continuously watch for changes and rebuild.
  13. Go back up to the project root directory and build Shuttle Tracker by running go build -o shuttletracker ./cmd/shuttletracker
  14. Start the app by running ./shuttletracker
  15. Add yourself as an administrator by using ./shuttletracker admins --add RCS_ID, replacing RCS_ID with your RCS ID. See the "Administrators" section below for more information.
  16. Visit http://localhost:8080/ to view the tracking application and http://localhost:8080/admin to view the administration panel.
  17. (Optional) Import live data from /routes, /stops, and /vehicles.

Configuration

Shuttle Tracker needs configuration to run properly. The preferred method during development is to create a conf.json file. See conf.json.sample for an example of what it should contain.

Updater.DataFeed: API with tracking information from iTrak. For RPI, this is a unique API URL that we can get data from. It's private, and a Shuttle Tracker developer can provide it to you if necessary. However, by default, Shuttle Tracker will reach out to the instance running at shuttles.rpi.edu to piggyback off of its data feed. This means that most developers will not have to configure this key.

Environment variables

Most keys can be overridden with environment variables. The variables names usually take the format PACKAGE_KEY. For example, overriding the iTRAK updater's update interval could be done with a variable named UPDATER_UPDATEINTERVAL.

Database URL

The database URL is a special case. Following the above convention, it can be set with POSTGRES_URL. However, for ease of deployment on Dokku, it can also be set with DATABASE_URL.

Administrators

The admin interface (at /admin) is only accessible to users who have been added as administrators. There is a command-line utility to do this: shuttletracker admins. It has two flags: --add RCS_ID and --remove RCS_ID. Replace RCS_ID with a valid RCS ID.

Example usage
> ./shuttletracker admins
No Shuttle Tracker administrators.
> ./shuttletracker admins --add naraya5
Added naraya5.
> ./shuttletracker admins --add lazare2
Added lazare2.
> ./shuttletracker admins
naraya5
lazare2
> ./shuttletracker admins --remove lazare2
Removed lazare2.
> ./shuttletracker admins
naraya5

Setting up (Windows)

  1. Download Go. Shuttle Tracker targets Go version 1.11 and newer, but we recommend using the latest stable release of Go.
  2. Open your System Properties by searching Edit the system environment variables then press Environment Variables....
  • Ensure your GOPATH variable is set correctly in the User variables for (Username).
  • Select Path under User variables for (Username) and make sure %GOPATH%\bin is on the list.
  • Make sure GOROOT is set correctly under System variables.
  • Select Path under System variables Make sure GOROOT\bin is on the list.

This step should be done for you already.

3a

3b

3c

  1. Open a command prompt by pressing windows + r, then type cmd and hit ok, or search for command prompt.
  2. Run go get github.com/wtg/shuttletracker.
  3. Switch to the Shuttle Tracker directory ($GOPATH/src/github.com/wtg/shuttletracker).
  4. Download and run the installer PostgreSQL from here. Select the latest version. When prompted to set a password, make it something simple, as you will be using this later, for example shuttle. Use default options for everything else. Remember your password.
  5. When complete, open pgAdmin from your search bar. If you do not see pgAdmin restart your computer. In the Object Browser, open Servers, then open your PostgreSQL server. You will need to enter your password from step 8. Once this is done, right click on Databases and select New Database. Name it shuttletracker and hit Ok.

11

11

  1. Navigate to your shuttle tracker directory ($GOPATH/src/github.com/wtg/shuttletracker) and rename conf.json.sample to conf.json
  2. Edit conf.json with the following, if necessary:
    • Postgres.URL: URL where Postgres is located which will be the default with postgres:password@localhost added before the database name, where password is your password from step 8. For example: "URL": "postgres://postgres:shuttle@localhost/shuttletracker?sslmode=disable".

11

  1. Install Node.js and npm. Download the recommended version and install. Restart your command prompt.
  2. Navigate to the frontend directory within the shuttle tracker directory ($GOPATH/src/github.com/wtg/shuttletracker/frontend).
  3. Run npm install
  4. Build the frontend using npx vue-cli-service build --mode development
    • Note: if you are working on the frontend, you may instead use npx vue-cli-service build --mode development --watch in another terminal to continuously watch for changes and rebuild.

11

  1. Go back up to the project root directory (using cd ..) and build Shuttle Tracker by running go build -o shuttletracker.exe cmd/shuttletracker/main.go
  2. Start the app by running shuttletracker.exe in the project root directory.
  3. Add yourself as an administrator by using shuttletracker.exe admins --add RCS_ID, replacing RCS_ID with your RCS ID. See the "Administrators" section above for more information.
  4. Visit http://localhost:8080/ to view the tracking application and http://localhost:8080/admin to view the administration panel.
  5. Copy the information from vehicles, routes, and stops into the admin panel if you want to mimic the current shuttle tracker site.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFormNotFound = errors.New("Form not found")

ErrFormNotFound indicates that a Form is not found.

View Source
var (
	// ErrLocationNotFound indicates that a Location is not in the database.
	ErrLocationNotFound = errors.New("location not found")
)
View Source
var (
	// ErrMessageNotFound indicates that a Message is not in the database.
	ErrMessageNotFound = errors.New("message not found")
)
View Source
var ErrRouteNotFound = errors.New("Route not found")

ErrRouteNotFound indicates that a Route is not in the service.

View Source
var ErrStopNotFound = errors.New("Stop not found")

ErrStopNotFound indicates that a Stop is not in the service.

View Source
var ErrUserNotFound = errors.New("User not found")

ErrUserNotFound indicates that a User is not in the service.

View Source
var ErrVehicleNotFound = errors.New("Vehicle not found")

ErrVehicleNotFound indicates that a Vehicle is not in the service.

Functions

This section is empty.

Types

type DataFeedResponse

type DataFeedResponse struct {
	Body       []byte
	StatusCode int
	Headers    http.Header
}

DataFeedResponse contains information from the iTRAK data feed.

type ETAService

type ETAService interface {
	Subscribe(func(VehicleETA))
	CurrentETAs() map[int64]VehicleETA
}

ETAService is an interface for interacting with vehicle estimated times of arrival.

type FeedbackService

type FeedbackService interface {
	GetAdminForm() *Form
	GetForm(id int64) (*Form, error)
	GetForms() ([]*Form, error)
	CreateForm(form *Form) error
	DeleteForm(id int64) error
}

FeedbackService is an interface for interacting with Feedback.

type Form

type Form struct {
	ID      int64     `json:"id"`
	Message string    `json:"message"`
	Prompt  string    `json:"prompt"`
	Created time.Time `json:"created"`
	Admin   bool      `json:"admin"`
}

details of each form

type Location

type Location struct {
	ID        int64     `json:"id"`
	TrackerID string    `json:"tracker_id"`
	Latitude  float64   `json:"latitude"`
	Longitude float64   `json:"longitude"`
	Heading   float64   `json:"heading"`
	Speed     float64   `json:"speed"`
	Time      time.Time `json:"time"`
	Created   time.Time `json:"created"`

	// VehicleID is a pointer to an int64 because it may be null.
	VehicleID *int64 `json:"vehicle_id"`

	// RouteID is a pointer to an int64 because it may be null.
	RouteID *int64 `json:"route_id"`
}

Location represents information about a vehicle's location.

type LocationService

type LocationService interface {
	CreateLocation(location *Location) error
	DeleteLocationsBefore(before time.Time) (int, error)
	LocationsSince(vehicleID int64, since time.Time) ([]*Location, error)
	LatestLocation(vehicleID int64) (*Location, error)
	LatestLocations() ([]*Location, error)
	Location(id int64) (*Location, error)
	SubscribeLocations() chan *Location
}

LocationService is an interface for interacting with information about vehicle positions.

type Message

type Message struct {
	Message string    `json:"message"`
	Enabled bool      `json:"enabled"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
	Link    string    `json:"link"`
}

Message represents a message displayed to users.

type MessageService

type MessageService interface {
	Message() (*Message, error)
	SetMessage(message *Message) error
}

MessageService is an interface for interacting with Messages.

type ModelService

type ModelService interface {
	VehicleService
	RouteService
	StopService
	LocationService
}

ModelService is a collection of interfaces related to vehicles, routes, stops, and their locations.

type Point

type Point struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Point represents a latitude/longitude pair.

type Route

type Route struct {
	ID          int64         `json:"id"`
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Enabled     bool          `json:"enabled"`
	Color       string        `json:"color"`
	Width       int64         `json:"width"`
	StopIDs     []int64       `json:"stop_ids"`
	Created     time.Time     `json:"created"`
	Updated     time.Time     `json:"updated"`
	Points      []Point       `json:"points"`
	Active      bool          `json:"active"`
	Schedule    RouteSchedule `json:"schedule"`
}

Route represents a set of coordinates to draw a path on our tracking map

type RouteActiveInterval

type RouteActiveInterval struct {
	ID        int64        `json:"id"`
	RouteID   int64        `json:"route_id"`
	StartDay  time.Weekday `json:"start_day"`
	StartTime time.Time    `json:"start_time"`
	EndDay    time.Weekday `json:"end_day"`
	EndTime   time.Time    `json:"end_time"`
}

RouteActiveInterval represents a time interval during which a Route is active.

type RouteSchedule

type RouteSchedule []RouteActiveInterval

RouteSchedule represents multiple time intervals during which a Route is active.

type RouteService

type RouteService interface {
	Route(id int64) (*Route, error)
	Routes() ([]*Route, error)
	CreateRoute(route *Route) error
	DeleteRoute(id int64) error
	ModifyRoute(route *Route) error
}

RouteService is an interface for interacting with Routes.

type Stop

type Stop struct {
	ID        int64     `json:"id"`
	Latitude  float64   `json:"latitude"`
	Longitude float64   `json:"longitude"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`

	// Name and Description are pointers because they may be nil.
	Name        *string `json:"name"`
	Description *string `json:"description"`
}

Stop is a place where vehicles frequently stop.

type StopETA

type StopETA struct {
	StopID   int64     `json:"stop_id"`
	ETA      time.Time `json:"eta"`
	Arriving bool      `json:"arriving"`
}

StopETA represents a time when a Vehicle is expected to arrive at a Stop.

type StopService

type StopService interface {
	Stop(id int64) (*Stop, error)
	Stops() ([]*Stop, error)
	CreateStop(stop *Stop) error
	CreateStopWithID(stop *Stop) error
	DeleteStop(id int64) error
}

StopService is an interface for interacting with Stops.

type UpdaterService

type UpdaterService interface {
	GetLastResponse() *DataFeedResponse
}

UpdaterService is an interface for interacting with vehicle location updates.

type User

type User struct {
	ID       int64
	Username string
}

User represents a user.

type UserService

type UserService interface {
	CreateUser(*User) error
	DeleteUser(username string) error
	UserExists(username string) (bool, error)
	Users() ([]*User, error)
}

UserService is an interface for interacting with Users.

type Vehicle

type Vehicle struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
	Enabled   bool      `json:"enabled"`
	TrackerID string    `json:"tracker_id"`
}

Vehicle represents an object being tracked.

type VehicleETA

type VehicleETA struct {
	VehicleID int64     `json:"vehicle_id"`
	RouteID   int64     `json:"route_id"`
	StopETAs  []StopETA `json:"stop_etas"`
	Updated   time.Time `json:"updated"`
}

VehicleETA contains information about a Vehicle, its current Route, and its ETAs to Stops.

type VehicleService

type VehicleService interface {
	Vehicle(id int64) (*Vehicle, error)
	VehicleWithTrackerID(id string) (*Vehicle, error)
	Vehicles() ([]*Vehicle, error)
	EnabledVehicles() ([]*Vehicle, error)
	CreateVehicle(vehicle *Vehicle) error
	DeleteVehicle(id int64) error
	ModifyVehicle(vehicle *Vehicle) error
}

VehicleService is an interface for interacting with Vehicles.

Directories

Path Synopsis
cmd
shuttletracker
Package main bundles together all of shuttletracker's subpackages to create, configure, and run the shuttle tracker.
Package main bundles together all of shuttletracker's subpackages to create, configure, and run the shuttle tracker.

Jump to

Keyboard shortcuts

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