Welcome to querydb’s documentation!

Classes

querydb

class querydb.querydb.QueryDB(host='18.159.252.58', port='5432', username='ml', password='YtTbR3UBiDN9DaEf', database_name='chronicles')

A class to submit queries in Chronicles PostgreSQL database.

connect()

Connects to the Chronicles PostgreSQL database.

custom_query(sql_query, data=None)

Opens a connection to the database, executes a custom SQL query supplied by the user and returns all fetched rows of the result.

Parameters
  • sql_query (str) – The SQL query to execute, e.g., “SELECT COUNT(*) FROM “Acc” LIMIT 1000”

  • data – Parameters to be bound to variables in the operation.

Returns

A list with the rows of the query result.

disconnect()

Commits any pending transactions to the database and then closes the connection.

get_bluetooth_data(user_id)

Returns Bluetooth timestamps, mac addresses, names and RSSI values for user_id.

Parameters

user_id (str) – The user’s id, e.g. ‘CHR01-00002-GR1’.

Returns

A list containing tuples of timestamp in microseconds, device’s mac address, name and RSSI (Received Signal Strength Indicator). E.g., [(1628683227359681, ‘98:06:3C:E2:F2:8F’, ‘Samsung’, -58), …]

get_recordings_timestamps(user_id)

Returns a list of tuples with the first element of the tuple being the timestamp a recording event initiated and the second element being the timestamp the same recording event ended.

Parameters

user_id (str) – The id of the user, e.g., ‘CHR01-00002-GR1’.

get_sensor_data(sensor_name, user_id, from_timestamp=None, to_timestamp=None, since=None)

Returns the data for sensor_name of user user_id.

Parameters
  • sensor_name (str) – The name of the sensor whose data we want. Valid values include ‘Acc’, ‘Gyro’, ‘GyroUncalibrated’, ‘Hrm’, ‘Light’, ‘Linacc’, ‘Location’, ‘Magn’, ‘Motion’, ‘Pedometer’, ‘Ppg’, ‘Pressure’

  • user_id (str) – The id of the user, e.g., ‘CHR01-00002-GR1’.

  • from_timestamp (int) – Timestamp of Unix epoch time in microseconds after which to return data.

  • to_timestamp (int) – Timestamp of Unix epoch time in microseconds up until to return data.

  • since (datetime.timedelta) – The time interval since when we would like to fetch data, up until the present time. E.g., get_sensor_data(…, …, datetime.timedelta(days=3)) will return the data of the last 3 days.

  • arguments from_timestamp and to_timestamp are mutually (The) –

  • with since. So (exclusive) –

  • them both will throw an exception. (setting) –

  • Returns – A list of tuples with the respective data.

get_users_list()

Returns a list of all the users in the database that have submitted files for processing.

Indices and tables