Documentation
¶
Index ¶
- Constants
- Variables
- func CleanUp()
- func LoadStores()
- func SaveStores()
- func TakeMeasurements()
- type ArrivalStore
- func (store *ArrivalStore) CleanUp(currentTime time.Time)
- func (store *ArrivalStore) GetAllArrivals() map[string]models.Arrival
- func (store *ArrivalStore) GetArrival(serviceID, serviceDate string, station string) *models.Arrival
- func (store *ArrivalStore) GetNumberOfArrivals() int
- func (store *ArrivalStore) GetStationArrivals(station string, includeHidden bool) []models.Arrival
- func (store *ArrivalStore) InitStore()
- func (store *ArrivalStore) ProcessArrival(newArrival models.Arrival)
- func (store *ArrivalStore) ReadStore() error
- func (store *ArrivalStore) SaveStore() error
- type Counters
- type DepartureStore
- func (store *DepartureStore) CleanUp(currentTime time.Time)
- func (store *DepartureStore) GetAllDepartures() map[string]models.Departure
- func (store *DepartureStore) GetDeparture(serviceID, serviceDate string, station string) *models.Departure
- func (store *DepartureStore) GetNumberOfDepartures() int
- func (store *DepartureStore) GetStationDepartures(station string, includeHidden bool) []models.Departure
- func (store *DepartureStore) InitStore()
- func (store *DepartureStore) ProcessDeparture(newDeparture models.Departure)
- func (store *DepartureStore) ReadStore() error
- func (store *DepartureStore) SaveStore() error
- type DowntimeDetectionConfig
- type Measurement
- type ServiceStore
- func (store *ServiceStore) CleanUp(currentTime time.Time)
- func (store *ServiceStore) GetAllServices() map[string]models.Service
- func (store *ServiceStore) GetNumberOfServices() int
- func (store *ServiceStore) GetService(serviceID, serviceDate string) *models.Service
- func (store *ServiceStore) InitStore()
- func (store *ServiceStore) ProcessService(newService models.Service)
- func (store *ServiceStore) ReadStore() error
- func (store *ServiceStore) SaveStore() error
- type Store
- type StoreCollection
Constants ¶
const StatusDown = "DOWN"
StatusDown for when system is down
const StatusRecovering = "RECOVERING"
StatusRecovering for when system is recovering
const StatusUnknown = "UNKNOWN"
StatusUnknown for when no status has been determined (not enough information)
const StatusUp = "UP"
StatusUp for when system is up and has all data
Variables ¶
var StoresDataDirectory = "data/"
StoresDataDirectory is the location where stores are saved
Functions ¶
func TakeMeasurements ¶
func TakeMeasurements()
TakeMeasurements takes measurements for all stores and updates downtime status
Types ¶
type ArrivalStore ¶
type ArrivalStore struct { Store // contains filtered or unexported fields }
The ArrivalStore contains all arrivals
func (*ArrivalStore) CleanUp ¶
func (store *ArrivalStore) CleanUp(currentTime time.Time)
CleanUp removes outdated items
func (*ArrivalStore) GetAllArrivals ¶
func (store *ArrivalStore) GetAllArrivals() map[string]models.Arrival
GetAllArrivals simply returns all arrivals in the store
func (*ArrivalStore) GetArrival ¶
func (store *ArrivalStore) GetArrival(serviceID, serviceDate string, station string) *models.Arrival
GetArrival retrieves a single arrival
func (*ArrivalStore) GetNumberOfArrivals ¶
func (store *ArrivalStore) GetNumberOfArrivals() int
GetNumberOfArrivals returns the number of arrivals in the store (unfiltered)
func (*ArrivalStore) GetStationArrivals ¶
func (store *ArrivalStore) GetStationArrivals(station string, includeHidden bool) []models.Arrival
GetStationArrivals returns all arrivals for a given station
func (*ArrivalStore) InitStore ¶
func (store *ArrivalStore) InitStore()
InitStore initializes the arrival store by creating the arrivals map
func (*ArrivalStore) ProcessArrival ¶
func (store *ArrivalStore) ProcessArrival(newArrival models.Arrival)
ProcessArrival adds or updates an arrival in an arrival store
func (*ArrivalStore) ReadStore ¶
func (store *ArrivalStore) ReadStore() error
ReadStore reads the save store contents
func (*ArrivalStore) SaveStore ¶
func (store *ArrivalStore) SaveStore() error
SaveStore saves the arrivals store contents
type Counters ¶
type Counters struct { Received int `json:"received"` Processed int `json:"processed"` Error int `json:"error"` Duplicates int `json:"duplicate"` Outdated int `json:"outdated"` TooLate int `json:"too_late"` }
Counters stores some interesting counters for a store
type DepartureStore ¶
type DepartureStore struct { Store // contains filtered or unexported fields }
The DepartureStore contains all departures
func (*DepartureStore) CleanUp ¶
func (store *DepartureStore) CleanUp(currentTime time.Time)
CleanUp removes outdated items
func (*DepartureStore) GetAllDepartures ¶
func (store *DepartureStore) GetAllDepartures() map[string]models.Departure
GetAllDepartures simply returns all departures in the store
func (*DepartureStore) GetDeparture ¶
func (store *DepartureStore) GetDeparture(serviceID, serviceDate string, station string) *models.Departure
GetDeparture retrieves a single departure
func (*DepartureStore) GetNumberOfDepartures ¶
func (store *DepartureStore) GetNumberOfDepartures() int
GetNumberOfDepartures returns the number of departures in the store (unfiltered)
func (*DepartureStore) GetStationDepartures ¶
func (store *DepartureStore) GetStationDepartures(station string, includeHidden bool) []models.Departure
GetStationDepartures returns all departures for a given station
func (*DepartureStore) InitStore ¶
func (store *DepartureStore) InitStore()
InitStore initializes the departure store by creating the departures map and sets the downtime detection config
func (*DepartureStore) ProcessDeparture ¶
func (store *DepartureStore) ProcessDeparture(newDeparture models.Departure)
ProcessDeparture adds or updates a departure in a departure store
func (*DepartureStore) ReadStore ¶
func (store *DepartureStore) ReadStore() error
ReadStore reads the save store contents
func (*DepartureStore) SaveStore ¶
func (store *DepartureStore) SaveStore() error
SaveStore saves the departures store contents
type DowntimeDetectionConfig ¶
type DowntimeDetectionConfig struct { MinAverage float64 // Minimum average messages per second MinAverageNight float64 // Minimum average messages per second during night time NightStartHour int // Start hour of night NightEndHour int // End hour of night RecoveryTime int // Recovery time in minutes }
DowntimeDetectionConfig contains the configuration for this store's downtime detection
func (DowntimeDetectionConfig) CurrentMinimumAverage ¶
func (downtimeDetection DowntimeDetectionConfig) CurrentMinimumAverage(time time.Time) float64
CurrentMinimumAverage returns the minimum average, based on the current time
type Measurement ¶
Measurement is a struct to store the number of received and processed messages
type ServiceStore ¶
type ServiceStore struct { Store // contains filtered or unexported fields }
The ServiceStore contains all services
func (*ServiceStore) CleanUp ¶
func (store *ServiceStore) CleanUp(currentTime time.Time)
CleanUp removes outdated items
func (*ServiceStore) GetAllServices ¶
func (store *ServiceStore) GetAllServices() map[string]models.Service
GetAllServices simply returns all services in the store
func (*ServiceStore) GetNumberOfServices ¶
func (store *ServiceStore) GetNumberOfServices() int
GetNumberOfServices returns the number of services in the store (unfiltered)
func (*ServiceStore) GetService ¶
func (store *ServiceStore) GetService(serviceID, serviceDate string) *models.Service
GetService retrieves a single service
func (*ServiceStore) InitStore ¶
func (store *ServiceStore) InitStore()
InitStore initializes the service store by creating the services map
func (*ServiceStore) ProcessService ¶
func (store *ServiceStore) ProcessService(newService models.Service)
ProcessService adds or updates a service in a service store
func (*ServiceStore) ReadStore ¶
func (store *ServiceStore) ReadStore() error
ReadStore reads the save store contents
func (*ServiceStore) SaveStore ¶
func (store *ServiceStore) SaveStore() error
SaveStore saves the service store contents
type Store ¶
type Store struct { sync.RWMutex Counters Counters Status string MessagesAverage float64 LastStatusChange time.Time DowntimeDetection DowntimeDetectionConfig // contains filtered or unexported fields }
Store is the generic store struct
func (*Store) ResetCounters ¶
func (store *Store) ResetCounters()
ResetCounters resets all store counters
func (*Store) ResetStatus ¶
func (store *Store) ResetStatus()
ResetStatus resets the status and counters of a store
func (*Store) TakeMeasurement ¶
func (store *Store) TakeMeasurement()
TakeMeasurement takes a new measurement. This method is expected to be called approximately every 20s. This function re-calculates the average messages per minute if enough data is available and updates the store status accordingly.
type StoreCollection ¶
type StoreCollection struct { ArrivalStore ArrivalStore DepartureStore DepartureStore ServiceStore ServiceStore }
StoreCollection is the collection of all stores
var Stores StoreCollection
Stores is the stores collection. Initialize with InitializeStores()
func InitializeStores ¶
func InitializeStores() *StoreCollection
InitializeStores initializes all stores and resets their counters/status