browser

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

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Data Browser Matsch | Mazia

DOI GitHub tests

Introduction

Data Browser Matsch | Mazia is a user-friendly web-based application to visualize and download micrometeorological and biophysical time series of the Long-Term Socio-Ecological Research site Matsch | Mazia in South Tyrol, Italy. It is designed both for the general public and researchers. The Data Browser Matsch | Mazia drop-down menus allow the user to query the InfluxDB database in the backend by selecting the measurements, time range, land use and elevation. Interactive Grafana dashboards show dynamic graphs of the time series.

Components

Data Browser Matsch | Mazia is a web application composed of three parts:

  1. Two backends: InfluxDB and SnipeIT.
  2. A frontend written in Go that talks to the backends.
  3. A HTML/JavaScript client that implements the user interface and makes HTTP requests to the frontend.

About this repository

This repository contains the frontend code and the HTML/JavaScript client.

Issues

If you encounter a bug or have a feature suggestion, please first check the open issues to see if your request is already being discussed. If an issue does not already exit, feel free to file an issue.

Contributing

If you would like to contribute, please first check the open issues to see if the feature or bug is already being discussed or worked on. If not please feel free to file an issue before sending any code.

To finally contribute fork the repository, create a dedicated feature branch containing the appropriate changes and make a Merge Request for review.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Documentation

Overview

Package browser is the root package for the browser web application and contains all domain types.

Index

Constants

View Source
const DefaultCollectionInterval = 15 * time.Minute

DefaultCollectionInterval is the default interval with which LTER stations aggregate measured points.

View Source
const UserContextKey userContextKey = "BrowserLTER"

UserContextKey is the context key for retrieving the user off of context.

Variables

View Source
var (
	ErrAuthentication    = errors.New("user not authenticated")
	ErrDataNotFound      = errors.New("no data points")
	ErrInvalidRequest    = errors.New("invalid request")
	ErrInternal          = errors.New("internal error")
	ErrInvalidToken      = errors.New("invalid token")
	ErrUserNotFound      = errors.New("user not found")
	ErrUserNotValid      = errors.New("user is not valid")
	ErrUserAlreadyExists = errors.New("user already exists")
	ErrGroupsNotFound    = errors.New("no groups found")

	// Location denotes the time location of the LTER stations, which is UTC+1.
	Location = time.FixedZone("+0100", 60*60)

	// Build version & commit SHA.
	Version string
	Commit  string
)

Roles is a list of all supported Roles.

Functions

func AppendStringIfMissing

func AppendStringIfMissing(slice []string, s string) []string

AppendStringIfMissing will append the given string to the given slice if it is missing.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

Types

type Database

type Database interface {
	// Series returns a TimeSeries filtered with the given SeriesFilter. Points
	// in a TimeSeries should always have a continuous time range as for
	// https://gitlab.inf.unibz.it/lter/browser/issues/10
	Series(context.Context, *SeriesFilter) (TimeSeries, error)

	// GroupsByStation will return a slice of groupped measurements stored in
	// the Database for the given station.
	GroupsByStation(context.Context, int64) ([]Group, error)

	// Maintenance will return a list of measurement names which correspond to
	// maintenance observations.
	Maintenance(context.Context) ([]string, error)

	// Query returns a query Stmt for the given SeriesFilter.
	Query(context.Context, *SeriesFilter) *Stmt
}

Database represents a backend for retrieving time series data.

type Group

type Group uint8

Group combines multiple measurements to a single entity.

const (
	AirTemperature Group = iota
	RelativeHumidity
	SoilTemperature
	SoilTemperatureDepth00
	SoilTemperatureDepth02
	SoilTemperatureDepth05
	SoilTemperatureDepth10
	SoilTemperatureDepth20
	SoilTemperatureDepth40
	SoilTemperatureDepth50
	SoilWaterContent
	SoilWaterContentDepth02
	SoilWaterContentDepth05
	SoilWaterContentDepth20
	SoilWaterContentDepth40
	SoilWaterContentDepth50
	SoilElectricalConductivity
	SoilElectricalConductivityDepth02
	SoilElectricalConductivityDepth05
	SoilElectricalConductivityDepth20
	SoilElectricalConductivityDepth40
	SoilElectricalConductivityDepth50
	SoilDielectricPermittivity
	SoilDielectricPermittivityDepth02
	SoilDielectricPermittivityDepth05
	SoilDielectricPermittivityDepth20
	SoilDielectricPermittivityDepth40
	SoilDielectricPermittivityDepth50
	SoilWaterPotential
	SoilWaterPotentialDepth05
	SoilWaterPotentialDepth20
	SoilWaterPotentialDepth40
	SoilWaterPotentialDepth50
	SoilHeatFlux
	SoilSurfaceTemperature
	Wind
	WindSpeed
	WindDirection
	WindGust
	Precipitation
	PrecipitationTotal
	PrecipitationIntensity
	SnowHeight
	LeafWetnessDuration
	SunshineDuration
	PhotosyntheticallyActiveRadiation
	PhotosyntheticallyActiveRadiationTotal
	PhotosyntheticallyActiveRadiationDiffuse
	PhotosyntheticallyActiveRadiationAtSoilLevel
	NDVIRadiations
	PRIRadiations
	ShortWaveRadiation
	ShortWaveRadiationIncoming
	ShortWaveRadiationOutgoing
	LongWaveRadiation
	LongWaveRadiationIncoming
	LongWaveRadiationOutgoing
	AtmosphericPressure
	NoGroup
)

func AppendGroupIfMissing

func AppendGroupIfMissing(slice []Group, g Group) []Group

AppendGroupIfMissing will append the given to group to the given slice if it is missing.

func FilterGroupsByRole

func FilterGroupsByRole(groups []Group, r Role) []Group

FilterGroupsByRole will filter the give groups by the given role returning only groups the role is allowed to access.

func GroupsByRole

func GroupsByRole(r Role) []Group

GroupsByRole will return a list of groups for the given role.

func GroupsByType

func GroupsByType(t GroupType) []Group

func (Group) Public

func (g Group) Public() string

Public returns the group name as string for the public user.

func (Group) String

func (g Group) String() string

func (Group) SubGroups

func (g Group) SubGroups() []Group

SubGroups will return a list of sub groups. An empty slice indicates that no sub groups are defined.

type GroupType

type GroupType uint8
const (
	ParentGroup GroupType = iota
	SubGroup
)

type Measurement

type Measurement struct {
	Label       string
	Aggregation string
	Unit        string
	Depth       *int64
	Station     *Station
	Points      []*Point
}

Measurement represents a single measurements with metadata and its points.

type Point

type Point struct {
	Timestamp time.Time
	Value     float64
}

Point represents a single measured point.

type Role

type Role string

Role represents a role a User is part of.

const (
	Public      Role = "Public"
	FullAccess  Role = "FullAccess"
	External    Role = "External"
	DefaultRole Role = Public
)

func NewRole

func NewRole(s string) Role

NewRole returns a new role from the given string. If the string cannot be parsed to a role the default role will be returned.

func (*Role) UnmarshalJSON

func (r *Role) UnmarshalJSON(b []byte) error

type SeriesFilter

type SeriesFilter struct {
	Groups   []Group
	Stations []string
	Landuse  []string
	Start    time.Time
	End      time.Time

	// WithSTD determines if the Series should contain standard deviations.
	WithSTD bool

	// Maintenance is a list of raw label names corresponding to measurements
	// used for maintenance technicians.
	Maintenance []string
}

SeriesFilter represents a filter for filtering TimeSeries.

func ParseSeriesFilterFromRequest

func ParseSeriesFilterFromRequest(r *http.Request) (*SeriesFilter, error)

ParseSeriesFilterFromRequest parses form values from the given http.Request and returns a a valid SeriesFilter or an error. It performs basic validation for the given dates.

type Station

type Station struct {
	ID        int64
	Name      string
	Landuse   string
	Elevation int64
	Latitude  float64
	Longitude float64
	Image     string
	Dashboard string
}

Station represents a meteorological station of the LTER project.

type StationService

type StationService interface {
	// Station returns the station by the given id or an error.
	Station(ctx context.Context, id int64) (*Station, error)

	// Stations retrieves metadata about all stations.
	Stations(ctx context.Context) (Stations, error)
}

StationService represents a service for retriving stations.

type Stations

type Stations []*Station

Stations represents a group of meteorological stations.

func (Stations) Landuse

func (s Stations) Landuse() []string

Landuse returns a sorted list of the landuse for all stations, removing duplicates.

func (Stations) String

func (s Stations) String() string

String converts stations to a JSON string.

type Stmt

type Stmt struct {
	Query    string
	Database string
}

Stmt is a query statement composed of the actual query and the database it is performed on.

type TimeSeries

type TimeSeries []*Measurement

TimeSeries represents a group Measurements.

type User

type User struct {
	Name     string
	Email    string
	Picture  string
	Provider string
	License  bool
	Role     Role
}

User represents an authenticated user.

func UserFromContext

func UserFromContext(ctx context.Context) *User

UserFromContext reads user information from the given context. If the context has no user information a default user will be returned.

func (*User) Valid

func (u *User) Valid() bool

Valid determines if a user is valid. A valid user must have a username, name and email.

type UserService

type UserService interface {
	// Get retrieves a user if it exists
	Get(context.Context, *User) (*User, error)
	// Create a new User in the UsersStore
	Create(context.Context, *User) error
	// Delete the user from the UsersStore
	Delete(context.Context, *User) error
	// Update updates the given user
	Update(context.Context, *User) error
}

UserService is the storage and retrieval of authentication information.

Directories

Path Synopsis
cmd
internal
encoding/csv
Package csv writes comma-separated values (CSV) files using the LTER default CSV format.
Package csv writes comma-separated values (CSV) files using the LTER default CSV format.
encoding/csvf
Package csvf writes comma-separated values (CSV) files using the LTER friendly format.
Package csvf writes comma-separated values (CSV) files using the LTER friendly format.
http
Package http handles everything related to HTTP.
Package http handles everything related to HTTP.
influx
Package influx provides the implementation of the browser.Database interface using InfluxDB as backend.
Package influx provides the implementation of the browser.Database interface using InfluxDB as backend.
middleware
Package middleware implements a simple middleware pattern for HTTP handlers, along with implementation for some common middleware.
Package middleware implements a simple middleware pattern for HTTP handlers, along with implementation for some common middleware.
mock
Package mock provides mock implementations of various interfaces used only for testing.
Package mock provides mock implementations of various interfaces used only for testing.
oauth2
Package oauth2 provides an handler for handling OAuth2 authentication flows and the implementation of several OAuth2 providers.
Package oauth2 provides an handler for handling OAuth2 authentication flows and the implementation of several OAuth2 providers.
ql
Package ql provides an API for building InfluxQL queries.
Package ql provides an API for building InfluxQL queries.
snipeit
Package snipeit provides a service for retriving information stored in SnipeIT.
Package snipeit provides a service for retriving information stored in SnipeIT.

Jump to

Keyboard shortcuts

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