database

package
v0.0.0-...-c8d5bbb Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_DATA_FOLDER = "."

Variables

View Source
var CALIBRATION_SQL = `` /* 748-byte string literal not displayed */

CALIBRATION_SQL is the sql json template for calibration objects

View Source
var DataFolder = DEFAULT_DATA_FOLDER

DataFolder is set to where you want each Sqlite3 database to be stored

View Source
var LOCATION_PREDICTION_SQL = `` /* 218-byte string literal not displayed */

LOCATION_PREDICTION_SQL is the sql json template for a location_prediction object.

View Source
var SENSOR_SQL = `` /* 296-byte string literal not displayed */

SENSOR_SQL is the sql json template for a sensor object.

View Source
var TABLES_SQL = `` /* 2875-byte string literal not displayed */

TABLES_SQL defines the main database tables and trigger functions.

Functions

func Exists

func Exists(name string) (err error)

Exists checks for the presense of a database file

func Fatal

func Fatal(err error, wrapper string)

Fatal wraps error with a wrapper and panics

func GetFamilies

func GetFamilies() (families []string)

GetFamilies returns list of family names

func GetMD5Hash

func GetMD5Hash(text string) string

GetMD5Hash creturns md5 hash of string

Types

type CalibrationModel

type CalibrationModel struct {
	Id                       int                                      `json:"id"`
	Probability_means        []float64                                `json:"probability_means"`
	ProbabilitiesOfBestGuess []float64                                `json:"probabilities_of_best_guess"`
	PercentCorrect           float64                                  `json:"percent_correct"`
	AccuracyBreakdown        map[string]float64                       `json:"accuracy_breakdown"`
	PredictionAnalysis       map[string]map[string]map[string]int     `json:"prediction_analysis"`
	AlgorithmEfficacy        map[string]map[string]models.BinaryStats `json:"algorithm_efficacy"`
	CalibrationTime          time.Time                                `json:"calibration_time"`
	CreateAt                 time.Time                                `json:"create_at"`
	UpdateAt                 time.Time                                `json:"update_at"`
}

type Database

type Database struct {
	LastInsertTime time.Time
	// contains filtered or unexported fields
}

Database is the main structure for holding the information pertaining to the name of the database.

func Open

func Open(family string, readOnly ...bool) (d *Database, err error)

Open will open the database for transactions by first aquiring a filelock.

func (*Database) AddCalibration

func (self *Database) AddCalibration(ProbabilityMeans []float64, ProbabilitiesOfBestGuess interface{}, PercentCorrect float64, AccuracyBreakdown interface{}, PredictionAnalysis interface{}, AlgorithmEfficacy interface{}) error

AddCalibration inserts calibration data as single transaction in a single row TODO INSERT AND GET AS A SINGLE TRANSACTION

func (*Database) AddPrediction

func (self *Database) AddPrediction(timestamp int64, aidata []models.LocationPrediction) error

AddPrediction will insert or update a prediction in the database

func (*Database) AddSensor

func (self *Database) AddSensor(s models.SensorData) (err error)

AddSensor will insert a sensor data into the database TODO: AddSensor should be special case of AddSensors

func (*Database) Close

func (self *Database) Close() (err error)

Close will close the database connection and remove the filelock.

func (*Database) Delete

func (self *Database) Delete() (err error)

Delete destroys database file

func (*Database) DeleteLocation

func (self *Database) DeleteLocation(location_id string) error

DeleteLocation deletes sensors that have a locationid

func (*Database) Dump

func (self *Database) Dump() (dumped string, err error)

Dump will output the string version of the database

func (*Database) Get

func (self *Database) Get(key string, v interface{}) error

// Get will retrieve the value associated with a key. // channel event listener makes database call synchronous

func (*Database) GetAllForClassification

func (self *Database) GetAllForClassification(clbk func(s []models.SensorData, err error))

GetAllForClassification will return a sensor data for classifying

func (*Database) GetAllFromQuery

func (self *Database) GetAllFromQuery(query string, args ...interface{}) ([]models.SensorData, error)

GetAllFromQuery

func (*Database) GetAllNotForClassification

func (self *Database) GetAllNotForClassification(clbk func(s []models.SensorData, err error))

GetAllForClassification will return a sensor data for classifying

func (*Database) GetCalibration

func (self *Database) GetCalibration() (CalibrationModel, error)

GetCalibration

func (*Database) GetDeviceCounts

func (self *Database) GetDeviceCounts() (map[string]int, error)

GetDeviceCounts get counts for devices

func (*Database) GetDeviceCountsFromDevices

func (self *Database) GetDeviceCountsFromDevices(devices []string) (map[string]int, error)

GetDeviceCountsFromDevices same as GetDeviceCounts but filters based on supplied devices

func (*Database) GetDeviceFirstTime

func (self *Database) GetDeviceFirstTime() (map[string]time.Time, error)

GetDeviceFirstTime returns map of timestamps for devices in the sensor table

func (*Database) GetDeviceFirstTimeFromDevices

func (self *Database) GetDeviceFirstTimeFromDevices(devices []string) (map[string]time.Time, error)

GetDeviceFirstTimeFromDevices same as GetDeviceFirstTime but only returns devices supplied in arguments.

func (*Database) GetDevices

func (self *Database) GetDevices() ([]string, error)

GetDevices returns list of deviceids

func (*Database) GetLastSensorInsertTimeWithLocationId

func (self *Database) GetLastSensorInsertTimeWithLocationId() (time.Time, error)

GetLastSensorInsertTimeWithLocationId gets the last updated_at timestamp for a sensor with a location.

func (*Database) GetLastSensorTimestamp

func (self *Database) GetLastSensorTimestamp() (int64, error)

Get will retrieve the value associated with a key.

func (*Database) GetLatest

func (self *Database) GetLatest(device_id string) (models.SensorData, error)

GetLatest will return a sensor data for classifying

func (*Database) GetLocationCounts

func (self *Database) GetLocationCounts() (map[string]int, error)

GetLocationCounts returns counts for locations

func (*Database) GetLocations

func (self *Database) GetLocations() ([]string, error)

GetLocations return list of locationids

func (*Database) GetPending

func (self *Database) GetPending() int

GetPending returns pending insert requests

func (*Database) GetPrediction

func (self *Database) GetPrediction(timestamp int64) ([]models.LocationPrediction, error)

GetPrediction will retrieve models.LocationAnalysis associated with that timestamp

func (*Database) GetSensorFromGreaterTime

func (self *Database) GetSensorFromGreaterTime(timeBlockInMilliseconds int64) ([]models.SensorData, error)

GetSensorFromGreaterTime will return a sensor data for a given timeframe

func (*Database) GetSensorFromTime

func (self *Database) GetSensorFromTime(timestamp interface{}) (models.SensorData, error)

GetSensorFromTime will return a sensor data for a given timestamp

func (*Database) Insert

func (self *Database) Insert(query string, executor func(*sql.Stmt) error) error

Insert runs an insert query. Since there can only be one writer, only one of these can be run at a time. It is prefered to use one of the pre-cannded insert functions that use the insertAsync or insertSync methods.

func (*Database) MakeTables

func (self *Database) MakeTables() (err error)

MakeTables creates database tables and triggers.

func (*Database) NumDevices

func (self *Database) NumDevices() (int, error)

NumDevices returns number of unique devices found in the sensor table

func (*Database) NumDevicesWithLocation

func (self *Database) NumDevicesWithLocation() (int, error)

NumDevices returns number of unique devices found in the sensor table that have locations

func (*Database) PrepareQuery

func (self *Database) PrepareQuery(query string) (*sql.Stmt, error)

PrepareQuery runs the database Prepare method on the supplied query.

func (*Database) Select

func (self *Database) Select(clbk func(string, *Database) error) error

Select runs a select query contained in a callback function. To have multiple readers a new database connection is opened and passed into the callback function. * TODO

  • - Add database connection pool for reads

func (*Database) Set

func (self *Database) Set(key string, value interface{}) error

Set will set a value in the database, when using it like a keystore.

func (*Database) SetBatch

func (self *Database) SetBatch(key string, value interface{}) error

Set will set a value in the database, when using it like a keystore.

func (*Database) SetGPS

func (self *Database) SetGPS(p models.SensorData) error

SetGPS will set a GPS value in the GPS database

func (*Database) StartRequestQueue

func (self *Database) StartRequestQueue()

StartRequestQueue starts insert queue for callbacks

func (*Database) TotalLearnedCount

func (self *Database) TotalLearnedCount() (int64, error)

Get will retrieve the value associated with a key.

Jump to

Keyboard shortcuts

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