database

package
v0.0.0-...-a73e329 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataFolder = "."

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

View Source
var DebugMode bool

Functions

func Debug

func Debug(debugMode bool)

func Exists

func Exists(name string) (err error)

func GetFamilies

func GetFamilies() (families []string)

Types

type Database

type Database struct {
	// 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) AddName

func (d *Database) AddName(table string, name string) (deviceID string, err error)

AddName will add a name to a table (devices/locations) and return the ID. If the device already exists it will just return it.

func (*Database) AddPrediction

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

AddPrediction will insert or update a prediction in the database

func (*Database) AddSensor

func (d *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 (d *Database) Close() (err error)

Close will close the database connection and remove the filelock.

func (*Database) Columns

func (d *Database) Columns() (columns []string, err error)

Columns will list the columns

func (*Database) Debug

func (d *Database) Debug(debugMode bool)

func (*Database) Delete

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

func (*Database) DeleteLocation

func (d *Database) DeleteLocation(locationName string) (err error)

func (*Database) Dump

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

Dump will output the string version of the database

func (*Database) Get

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

Get will retrieve the value associated with a key.

func (*Database) GetAllFingerprints

func (d *Database) GetAllFingerprints() (s []models.SensorData, err error)

GetAllFingerprints returns all the fingerprints

func (*Database) GetAllForClassification

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

GetAllForClassification will return a sensor data for classifying

func (*Database) GetAllFromPreparedQuery

func (d *Database) GetAllFromPreparedQuery(query string, args ...interface{}) (s []models.SensorData, err error)

GetAllFromPreparedQuery

func (*Database) GetAllFromQuery

func (d *Database) GetAllFromQuery(query string) (s []models.SensorData, err error)

func (*Database) GetAllNotForClassification

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

GetAllNotForClassification will return a sensor data for classifying

func (*Database) GetAverageGPS

func (d *Database) GetAverageGPS(location string) (lat float64, lon float64, err error)

GetAverageGPS will return an average wardrived GPS for a given location

func (*Database) GetDeviceCounts

func (d *Database) GetDeviceCounts() (counts map[string]int, err error)

func (*Database) GetDeviceCountsFromDevices

func (d *Database) GetDeviceCountsFromDevices(devices []string) (counts map[string]int, err error)

func (*Database) GetDeviceFirstTime

func (d *Database) GetDeviceFirstTime() (firstTime map[string]time.Time, err error)

func (*Database) GetDeviceFirstTimeFromDevices

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

func (*Database) GetDevices

func (d *Database) GetDevices() (devices []string, err error)

func (*Database) GetID

func (d *Database) GetID(table string, name string) (id string, err error)

GetID will get the ID of an element in a table (devices/locations) and return an error if it doesn't exist

func (*Database) GetIDToName

func (d *Database) GetIDToName(table string) (idToName map[string]string, err error)

func (*Database) GetKeys

func (d *Database) GetKeys(keylike string) (keys []string, err error)

func (*Database) GetLastSensorTimestamp

func (d *Database) GetLastSensorTimestamp() (timestamp int64, err error)

GetLastSensorTimestamp gets will retrieve the value associated with a key.

func (*Database) GetLatest

func (d *Database) GetLatest(device string) (s models.SensorData, err error)

GetLatest will return a sensor data for classifying

func (*Database) GetLocationCounts

func (d *Database) GetLocationCounts() (counts map[string]int, err error)

func (*Database) GetLocations

func (d *Database) GetLocations() (locations []string, err error)

func (*Database) GetName

func (d *Database) GetName(table string, id string) (name string, err error)

GetName will get the name of an element in a table (devices/locations) and return an error if it doesn't exist

func (*Database) GetPrediction

func (d *Database) GetPrediction(timestamp int64) (aidata []models.LocationPrediction, err error)

GetPrediction will retrieve models.LocationAnalysis associated with that timestamp

func (*Database) GetSensorFromGreaterTime

func (d *Database) GetSensorFromGreaterTime(timeBlockInMilliseconds int64) (sensors []models.SensorData, err error)

GetSensorFromGreaterTime will return a sensor data for a given timeframe

func (*Database) GetSensorFromTime

func (d *Database) GetSensorFromTime(timestamp interface{}) (s models.SensorData, err error)

GetSensorFromTime will return a sensor data for a given timestamp

func (*Database) MakeTables

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

MakeTables creates two tables, a `keystore` table:

KEY (TEXT)	VALUE (TEXT)

and also a `sensors` table for the sensor data:

TIMESTAMP (INTEGER)	DEVICE(TEXT) LOCATION(TEXT)

the sensor table will dynamically create more columns as new types of sensor data are inserted. The LOCATION column is optional and only used for learning/classification.

func (*Database) NumDevices

func (d *Database) NumDevices() (num int, err error)

func (*Database) Set

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

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

func (*Database) SetGPS

func (d *Database) SetGPS(p models.SensorData) (err error)

SetGPS will set a GPS value in the GPS database

func (*Database) TotalLearnedCount

func (d *Database) TotalLearnedCount() (count int64, err error)

TotalLearnedCount gets will retrieve the value associated with a key.

type DatabaseLock

type DatabaseLock struct {
	Locked map[string]bool
	sync.RWMutex
}

Jump to

Keyboard shortcuts

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