WorktimeCalculator
- class WorktimeCalculator(user_config_path='.user_config.ini')[source]
Class to calculate the worktime.
- 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
Add Year, Month, Week and Day columns to an existing Dataframe.
Calculate hashvalues for files.
Remove rows where the session work was less than 1min.
Generate a Dataframe with 'worktime' column.
Calculate the mean daily work time based on the contract details.
Helpermethod for mocking of datetime.datetime.now() in unittests.
Generate a Dataframe containing all needed holidays.
Read the manual_db file.
Return datetime.now as pd.Timestamp.
Return a Dataframe prepared for plotting.
Download the db_file to db_path_online from the SFTP server.
Calculate total Dataframe.
Initialize the holidays with the custom holidays from the config.
Load the config files and sets all necessary properties.
Load Database remote or locally.
Merge local db with remote db.
Push the db_file from db_path_offline to the SFTP server.
Split sessions which contain midnight to to sessions.
Methods Documentation
- classmethod add_time_columns(df: DataFrame, date_time_column_name: str = 'start') DataFrame [source]
Add Year, Month, Week and Day columns to an existing Dataframe.
- Parameters
df (pd.DataFrame) – Dataframe the columns should be added to.
date_time_column (str) – Name of the column containing the used date
- Returns
Dataframe with added Year, Month, Week and Day columns.
- Return type
pd.DataFrame
- calc_file_hashes() DataFrame
Calculate hashvalues for files.
- Returns
Dataframe with file hashes.
- Return type
pd.DataFrame
- clean_db() None
Remove rows where the session work was less than 1min.
- generate_contract_worktime_df() DataFrame [source]
Generate a Dataframe with ‘worktime’ column.
Generate a template like DataFrame containing the mean daily work time for each day counting as workday based on the contract details. This Template will be used later on to generate the manual_df and holiday_df.
- Returns
contract_worktime_df – Dataframe containing all workdays and their mean daily working time, since the 1st contract started until now
- Return type
pandas.DataFrame
- get_daily_worktime(frequenzy: str, worktime: Union[int, float], weekmask: str) float [source]
Calculate the mean daily work time based on the contract details.
- Parameters
frequenzy (str) – Timeperiod in which the the user is supposed to to work worktime*1h Supported values are: monthly, weekly
worktime (int, float) – Time in hours that the user is supposed to work in frequenzy
weekmask (str) – Listing of the abbreviated weekdays the user is supposed to work i.e.: “Mon Tue Wed Thu Fri Sat”
- Returns
daily_worktime
- Return type
float
- get_datetime_now() datetime
Helpermethod for mocking of datetime.datetime.now() in unittests.
- Returns
datetime.now()
- Return type
datetime.datetime
- get_holiday_df() DataFrame [source]
Generate a Dataframe containing all needed holidays.
They begin at the start of the first contract until now, as well as work time based on the contract parameters for those days.
- Returns
holiday_df – Dataframe containing all holidays from the start of the first contract until now, as well as work time based on the contract parameters for those days.
- Return type
pandas.DataFrame
- get_manual_df_with_workime() DataFrame [source]
Read the manual_db file.
That file contains information like sick time | vacation, specified by manual_db in the config. Then expands the given time periods to date_ranges on a daily base, drops the none workdays and adds the daily work time based on the contract parameters for that day.
- Returns
Dataframe containing the to a daily base expanded entry’s of manual_df.
- Return type
pandas.DataFrame
- get_pandas_now() Timestamp
Return datetime.now as pd.Timestamp.
- Returns
current time as timestamp: pd.Timestamp
- Return type
pd.Timestamp
- get_plot_df(rule='D', date_time_column='start') DataFrame [source]
Return a Dataframe prepared for plotting.
Dataframe with a DateTimeIndex, columns named by occupation and containing the worked time of that occupation for the given samplingrate
- Parameters
rule (str) – Resampling rule see pandas.DataFrame.resample
- Returns
Dataframe with a DateDimeIndex, columns named by occupation and containing the worktime of that occupation for the samplingrate
- Return type
pandas.DataFrame
- 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_total_df() DataFrame [source]
Calculate total Dataframe.
- Returns
Dataframe with ‘worktime’ and time columns
- Return type
pd.DataFrame
See also
- init_holidays() Union[HolidayBase, Dict] [source]
Initialize the holidays with the custom holidays from the config.
Returns the class instance from holiday, which matches the country and province given in the config and updates it with the special holidays, also given in the config
- Returns
HolidayBase object for the given country and province or an empty dict.
- Return type
Union[HolidayBase, Dict]
- load_db() DataFrame [source]
Load Database remote or locally.
Tries to load the database directly from the server if possible, else it loads the local database or throws an exception that isn’t possible either.
- Returns
db – Database with the actually worked time
- Return type
pandas.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
- split_date_overlap_session() None [source]
Split sessions which contain midnight to to sessions.
The first lasting until midnight and the second starting at midnight.
df before: start end 1.1.1970 21:00:00 2.1.1970 02:00:00 df after: start end 1.1.1970 21:00:00 2.1.1970 00:00:00 2.1.1970 00:00:00 2.1.1970 02:00:00