stalker.models.studio.WorkingHours

Inheritance diagram of stalker.models.studio.WorkingHours
class stalker.models.studio.WorkingHours(working_hours=None, daily_working_hours=None, **kwargs)[source]

Bases: stalker.models.entity.Entity

A helper class to manage Studio working hours.

Working hours is a data class to store the weekly working hours pattern of the studio.

The data stored as a dictionary with the short day names are used as the key and the value is a list of two integers showing the working hours interval as the minutes after midnight. This is done in that way to ease the data transfer to TaskJuggler. The default value is defined in stalker.config.Config

wh = WorkingHours()
wh.working_hours = {
    'mon': [[540, 720], [820, 1080]], # 9:00 - 12:00, 13:00 - 18:00
    'tue': [[540, 720], [820, 1080]], # 9:00 - 12:00, 13:00 - 18:00
    'wed': [[540, 720], [820, 1080]], # 9:00 - 12:00, 13:00 - 18:00
    'thu': [[540, 720], [820, 1080]], # 9:00 - 12:00, 13:00 - 18:00
    'fri': [[540, 720], [820, 1080]], # 9:00 - 12:00, 13:00 - 18:00
    'sat': [], # saturday off
    'sun': [], # sunday off
}

The default value is 9:00 - 18:00 from Monday to Friday and Saturday and Sunday are off.

The working hours can be updated by the user supplied dictionary. If the user supplied dictionary doesn’t have all the days then the default values will be used for those days.

It is possible to use day index and day short names as a key value to reach the data:

from stalker import config
defaults = config.Config()

wh = WorkingHours()

# this is same by doing wh.working_hours['sun']
assert wh['sun'] == defaults.working_hours['sun']

# you can reach the data using the weekday number as index
assert wh[0] == defaults.working_hours['mon']

# working hours of sunday if defaults are used or any other day defined
# by the stalker.config.Config.day_order
assert wh[0] == defaults.working_hours[defaults.day_order[0]]
Parameters:working_hours – The dictionary that shows the working hours. The keys of the dictionary should be one of [‘mon’, ‘tue’, ‘wed’, ‘thu’, ‘fri’, ‘sat’, ‘sun’]. And the values should be a list of two integers like [[int, int], [int, int], …] format, showing the minutes after midnight. For missing days the default value will be used. If skipped the default value is going to be used.
__init__(working_hours=None, daily_working_hours=None, **kwargs)

Methods

__init__([working_hours, daily_working_hours])
is_working_hour(check_for_date) checks if the given datetime is in working hours
split_in_to_working_hours(start, end) splits the given start and end datetime objects in to working hours

Attributes

daily_working_hours
to_tjp returns TaskJuggler representation of this object
weekly_working_days returns the weekly working days by looking at the working hours
weekly_working_hours returns the total working hours in a week
working_hours
yearly_working_days returns the total working days in a year
is_working_hour(check_for_date)[source]

checks if the given datetime is in working hours

Parameters:check_for_date (datetime.datetime) – The time to check if it is a working hour
to_tjp

returns TaskJuggler representation of this object

weekly_working_hours

returns the total working hours in a week

weekly_working_days

returns the weekly working days by looking at the working hours settings

yearly_working_days

returns the total working days in a year

split_in_to_working_hours(start, end)[source]

splits the given start and end datetime objects in to working hours

created_by

The User who has created this object.

created_by_id

The id of the User who has created this entity.

date_created

A datetime.datetime instance showing the creation date and time of this object.

date_updated

A datetime.datetime instance showing the update date and time of this object.

description

Description of this object.

generic_data

This attribute can hold any kind of data which exists in SOM.

generic_text

This attribute can hold any text.

name

Name of this object

nice_name

Nice name of this object.

It has the same value with the name (contextually) but with a different format like, all the white spaces replaced by underscores (“_”), all the CamelCase form will be expanded by underscore (_) characters and it is always lower case.

notes

All the Notess attached to this entity.

It is a list of Note instances or an empty list, setting it to None will raise a TypeError.

plural_class_name

the plural name of this class

tags

A list of tags attached to this object.

It is a list of Tag instances which shows the tags of this object

tjp_id

returns TaskJuggler compatible id

type

The type of the object.

It is a Type instance with a proper Type.target_entity_type.

type_id

The id of the Type of this entity. Mainly used by SQLAlchemy to create a Many-to-One relates between SimpleEntities and Types.

updated_by

The User who has updated this object.

updated_by_id

The id of the User who has updated this entity.