DbInteraction

class DbInteraction(user_config_path='.user_config.ini')[source]

Class for data interactions.

Parameters

user_config_path (str, optional) – Path to the user specific config, which will overwrite default settings. by default “.user_config.ini”

Attributes Summary

default_config_path

Methods Summary

calc_file_hashes

Calculate hashvalues for files.

change_occupation

Change value of self.occupation.

clean_db

Remove rows where the session work was less than 1min.

get_datetime_now

Helpermethod for mocking of datetime.datetime.now() in unittests.

get_pandas_now

Return datetime.now as pd.Timestamp.

get_remote_db

Download the db_file to db_path_online from the SFTP server.

get_session_time

Calculate the current session time in hours and minutes.

get_start_time

Return todays startime in hours and minutes.

get_today

Return datetime object for today at midnight.

load_config

Load the config files and sets all necessary properties.

load_db

Read in the db file if it exists or creates a new one.

merge_dbs

Merge local db with remote db.

push_remote_db

Push the db_file from db_path_offline to the SFTP server.

start_session

Start a session and update database.

update_db_locale

Update local database.

update_now_and_tomorrow

Update the instance variables yesterday, today and tomorrow.

Methods Documentation

calc_file_hashes() DataFrame

Calculate hashvalues for files.

Returns

Dataframe with file hashes.

Return type

pd.DataFrame

change_occupation(occupation: str) None[source]

Change value of self.occupation.

Parameters

occupation (str) – Current occupation.

clean_db() None

Remove rows where the session work was less than 1min.

get_datetime_now() datetime

Helpermethod for mocking of datetime.datetime.now() in unittests.

Returns

datetime.now()

Return type

datetime.datetime

get_pandas_now() Timestamp

Return datetime.now as pd.Timestamp.

Returns

current time as timestamp: pd.Timestamp

Return type

pd.Timestamp

get_remote_db() bool

Download the db_file to db_path_online from the SFTP server.

This uses the values specified at [“login”][“db_path”] in the config file.

Returns

Whether database retrieval succeeded or not.

Return type

bool

get_session_time()[source]

Calculate the current session time in hours and minutes.

Returns

String representation in hours and minutes

Return type

str

get_start_time()[source]

Return todays startime in hours and minutes.

Returns

String representing start time as %h:%M

Return type

str

get_today()[source]

Return datetime object for today at midnight.

Returns

datetime.datetime.now() but with the hours, minutes, seconds, microseconds set to 0

Return type

datetime.datetime

load_config() ConfigParser[source]

Load the config files and sets all necessary properties.

load_db(db_path: str) DataFrame

Read in the db file if it exists or creates a new one.

Parameters

db_path (str) – path to the db_file on the SFTP server

Returns

Loaded database.

Return type

pd.Dataframe

merge_dbs() DataFrame

Merge local db with remote db.

The overlap (same start) is replaced with the max value of end.

Returns

Local db merged with remote db, with striped overlap.

Return type

pd.Dataframe

push_remote_db() bool

Push the db_file from db_path_offline to the SFTP server.

This uses the values specified at [“login”][“db_path”] in the config file.

Returns

Whether database upload succeeded or not.

Return type

bool

start_session() None[source]

Start a session and update database.

update_db_locale() Tuple[str, str][source]

Update local database.

Returns

start_time and session_time

Return type

Tuple[str, str]

update_now_and_tomorrow()[source]

Update the instance variables yesterday, today and tomorrow.

In case the date has changed during the session. Preventing error in self.update_db_locale, due to a wrong date.