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
Calculate hashvalues for files.
Change value of self.occupation.
Remove rows where the session work was less than 1min.
Helpermethod for mocking of datetime.datetime.now() in unittests.
Return datetime.now as pd.Timestamp.
Download the db_file to db_path_online from the SFTP server.
Calculate the current session time in hours and minutes.
Return todays startime in hours and minutes.
Return datetime object for today at midnight.
Load the config files and sets all necessary properties.
Read in the db file if it exists or creates a new one.
Merge local db with remote db.
Push the db_file from db_path_offline to the SFTP server.
Start a session and update database.
Update local database.
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_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