Documentation
¶
Overview ¶
Package statistics provides all components required to serve statistical data via an HTTP API. It includes the transport & persistence layers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
The HTTP type contains HTTP request handlers that serve statistical data.
func NewHTTP ¶
func NewHTTP(statistics Repository) *HTTP
NewHTTP returns a new instance of the HTTP type that will serve statistical data queried from the Repository implementation.
func (*HTTP) ForDate ¶
func (h *HTTP) ForDate(w http.ResponseWriter, r *http.Request)
ForDate handles an inbound HTTP GET request that returns an array of sensor statistics for a specific date from the Repository.
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
The PostgresRepository is a Repository implementation that queries statistical data from a postgres-compatible database.
func NewPostgresRepository ¶
func NewPostgresRepository(db *sql.DB) *PostgresRepository
NewPostgresRepository returns a new instance of the PostgresRepository type that will perform queries against the provided sql.DB instance.
func (*PostgresRepository) ForDate ¶
func (r *PostgresRepository) ForDate(ctx context.Context, date time.Time, sensor reading.SensorType) ([]Statistic, error)
ForDate queries the database for time-bucketed statistics on a given date for a sensor type. Statistics are averaged in 15 minute intervals.
func (*PostgresRepository) Latest ¶
func (r *PostgresRepository) Latest(ctx context.Context) (Statistics, error)
Latest returns a Statistics type whose fields will be populated with the most recent data available within the database.
type Repository ¶
type Repository interface {
Latest(ctx context.Context) (Statistics, error)
ForDate(ctx context.Context, date time.Time, sensor reading.SensorType) ([]Statistic, error)
}
The Repository interface describes types that can query statistical database from persistent storage.