CSStorage Class Reference

Inherits from NSObject
Declared in CSStorage.h

Overview

Handles sensor data storage in an SQLite database

Data is first stored in a buffer in memory. After each 1000 datapoints it is written to disk. Disk storage is limited to 100mb. If this limit is exceeded or the disk is full, 20% of the oldest datapoints are removed.

– initWithPath:

- (id)initWithPath:(NSString *)databaseFilePath

– storeSensor:description:deviceType:device:dataType:value:timestamp:

Store a new sensor data point in the buffer. Note that if the db is full, 20% of rows will be removed and the function is called again.

- (void)storeSensor:(NSString *)sensor description:(NSString *)description deviceType:(NSString *)deviceType device:(NSString *)device dataType:(NSString *)dataType value:(NSString *)value timestamp:(double)timestamp

Parameters

sensor

Name of the sensor to store the value in

description

Description of the sensor

deviceType

Device type text

device

String identifier of the device

dataType

Don’t know

value

Can be a JSON string or just a string representation of the value to store

timestamp

In seconds since 1970 representing when the value occured

Declared In

CSStorage.h

– getSensorDataPointsFromId:limit:

- (NSArray *)getSensorDataPointsFromId:(long long)start limit:(size_t)limit

– getDataFromSensor:andDeviceType:from:to:

Retrieve all the sensor data stored in the database between a certain time interval by sensor name and device type.

- (NSArray *)getDataFromSensor:(NSString *)sensorName andDeviceType:(NSString *)deviceType from:(NSDate *)startDate to:(NSDate *)endDate

Parameters

sensorName

The name of the sensor to get the data from

deviceType

The name of the deviceType to get the data from

startDate

The date and time at which to start looking for datapoints

endDate

The date and time at which to stop looking for datapoints

Return Value

an array of values, each value is a dictonary that descirbes the data point

Declared In

CSStorage.h

– getDataFromSensor:from:to:andOrder:withLimit:

Retrieve all the sensor data stored in the database between a certain time interval.

- (NSArray *)getDataFromSensor:(NSString *)name from:(NSDate *)startDate to:(NSDate *)endDate andOrder:(NSString *)order withLimit:(int)nrOfPoints

Parameters

name

The name of the sensor to get the data from

startDate

The date and time at which to start looking for datapoints

endDate

The date and time at which to stop looking for datapoints

order

Whether the returning datapoints are ordered in an ascending or descending way. Valid values are ‘ASC’ and ‘DESC’

nrOfPoints

Limit to the nr of points that will be returned. This will take into account the ordering to select only the latest (descending) or first (ascending)

Return Value

an array of values, each value is a dictonary that descirbes the data point

Declared In

CSStorage.h

– removeDataBeforeId:

- (void)removeDataBeforeId:(long long)rowId

– removeDataBeforeTime:

Removes all data from before a certain date from buffer and main data store

- (void)removeDataBeforeTime:(NSDate *)dateThreshold

Parameters

dateThreshold

NSDate which marks the threshold, all data older than (from before) the date will be removed

Declared In

CSStorage.h

– getLastDataPointId

- (long long)getLastDataPointId

– flush

- (void)flush

– storeSensorDescription:forSensor:description:deviceType:device:

- (void)storeSensorDescription:(NSString *)jsonDescription forSensor:(NSString *)sensor description:(NSString *)description deviceType:(NSString *)deviceType device:(NSString *)device

– getSensorDescriptionForSensor:description:deviceType:device:

- (NSString *)getSensorDescriptionForSensor:(NSString *)sensor description:(NSString *)description deviceType:(NSString *)deviceType device:(NSString *)device

– trimLocalStorageTo:

Reduces nr of rows in database by removing a percentage of the oldest rows from the db and freeing up pages for new incoming data @param: percentToKeep The percentage of rows to keep

- (void)trimLocalStorageTo:(double)percentToKeep

Declared In

CSStorage.h

– getDbSize

- (NSNumber *)getDbSize

– trimLocalStorageToRowsToKeep:

Delete all rows of the database except the nrToKeep most recent rows based on id field

- (void)trimLocalStorageToRowsToKeep:(size_t)nrToKeep

Parameters

nrToKeep

Number of most recent rows to keep (oldest rows will be removed first)

Declared In

CSStorage.h

– getNumberOfRowsInTable:

Queries the number of rows in the table and returns the result

- (long)getNumberOfRowsInTable:(NSString *)table

Parameters

table

Name of the table to query

Return Value

Number of rows in the table

Declared In

CSStorage.h

+ deleteFileWithPath:error:

Helper function to delete file on storage

+ (void)deleteFileWithPath:(NSString *)path error:(NSError **)err

Parameters

path

file path

err

error

Declared In

CSStorage.h

– changeStorageEncryptionEnabled:

Change whether to use encrytion for local storage

- (void)changeStorageEncryptionEnabled:(BOOL)enable

Declared In

CSStorage.h