gantt_project_maker package
Submodules
gantt_project_maker.colors module
Definition of CBS rbg colors. Based on the color rgb definitions from the cbs LaTeX template
- gantt_project_maker.colors.color_to_hex(color: str)[source]
Convert a named color into a hex code with a leading #
gantt_project_maker.excelwriter module
Functions and classes for writing the Excel fields
- class gantt_project_maker.excelwriter.WorkBook(workbook)[source]
Bases:
objectA class to hold all the Excel styles
- Parameters:
workbook – the Excel workbook to work on
- workbook
workbook
- left_align_italic
None
- left_align_italic_large
None
- left_align_italic_large_ul
None
- left_align_helvetica
None
- left_align_helvetica_bold
None
- left_align_bold
None
- left_align_bold_large
None
- left_align
None
- left_align_large_wrap
None
- left_align_large_wrap_top
None
- left_align_wrap
None
- left_align_large
None
- right_align
None
- header_format
None
- title_format
None
- section_heading
None
None
- merge_format
None
- date_format
None
- number_format
None
- gantt_project_maker.excelwriter.indent(line, n_char=5)[source]
Add an indent with white spaces at the beginning of the line
- gantt_project_maker.excelwriter.is_contributor(project, resource, is_contributing=False)[source]
check if resource is contributor of the project :param project: :param resource: :param is_contributing: bool
Returns:
- gantt_project_maker.excelwriter.project_to_period_label(project: type) str[source]
Take the start and end dates of the project and convert to a period label, like 24Q1 (first quarter of 2024) or 24Q324Q4 (third and last quarter of 2024)
- gantt_project_maker.excelwriter.update_width(label: str, max_width)[source]
Update the width of a label based on the current maximum width
- gantt_project_maker.excelwriter.write_header(header_info, workbook, worksheet, character_width, wb, column_widths, row_index)[source]
Write the header of an Excel sheet
- Parameters:
header_info (dict) – The header infor of this sheet
workbook (WorkBook) – The Excel workbook
worksheet (str) – The name of the sheet
character_width (float) – The width of the characters
wb (workbook) – The object to the workbook
column_widths (dict) – The columns widths for this sheet
row_index (int) – start writing at this row
- gantt_project_maker.excelwriter.write_project(project: type, header_info: dict, workbook: type, resource: type, worksheet, character_width: float, wb, row_index: int, level: int, total_hours: int | None = None)[source]
Write the project to a sheet
- Parameters:
project (Project) – The gantt chart project
header_info (dict) – The header of the Excel file
workbook (WorkBook) – The Excel workbook
resource (Resource) – if given, filter tasks on resource
worksheet (Worksheet) – The Excel worksheet
character_width (float) – The width of the fixed columns
wb (object) – The workbook object to
row_index (int) – The index of the current row
level (int) – The level of the indent
total_hours (int, optional) – Total of hours written on this project so ware
- Returns:
current row index, current project level, current total hours so fare
- Return type:
row_index, level, total_hours
- gantt_project_maker.excelwriter.write_project_to_excel(project: type, writer: type, sheet_name: str, resource: type | None = None, header_info: dict | None = None, column_widths: dict | None = None, character_width: float = 1.0, row_index: int = 0, header: bool = True)[source]
Write a multi index data frame to an Excel file with format
- Parameters:
project (dict) – Main project
writer (obj) – Excel writer
sheet_name (str) – Name of the sheet
resource (obj) – Resource to filter on. If none, do not filter
column_widths (dict) – Fix width of these columns.
header_info (dict) – Information on the header
character_width (float) – Width of one character. Default = 0.7
row_index (int) – start writing at this row
header (bool) – write the header,
- gantt_project_maker.excelwriter.write_resource(project: type, header_info: dict, workbook: type, worksheet, character_width: float, wb, row_index: int, level: int)[source]
Write the project to a sheet
- Parameters:
project (Project) – The gantt chart project
header_info (dict) – The header of the Excel file
workbook (WorkBook) – The Excel workbook
worksheet (Worksheet) – The Excel worksheet
character_width (float) – The width of the fixed columns
wb (object) – The workbook object to
row_index (int) – The index of the current row
level (int) – The level of the indent
Returns:
gantt_project_maker.gantt module
This is a python class to create gantt chart using SVG
Author: Alexandre Norman - norman at xael.org
Contributors:
Sébastien NOBILI - pipoprods at free.fr
Modified by:
Eelco van Vliet
- class gantt_project_maker.gantt.GroupOfResources(name, fullname=None)[source]
Bases:
objectClass for grouping resources
- add_resource(resource)[source]
Add a resource to the group of resources
Keyword arguments: resource – Resource object
- add_task(task)[source]
Tell the resource that we have assigned a task
Keyword arguments: task – Task object
- add_vacations(dfrom, dto=None)[source]
Add vacations to a resource beginning at [dfrom] to [dto] (included). If [dto] is not defined, vacation will be for [dfrom] day only
Keyword arguments: dfrom – datetime.date beginning of vacation dto – datetime.date end of vacation
- is_available(date_to_check)[source]
Returns True if any resource is available at a given date, False if not. Availability is tasks from the global VACATIONS and resource’s ones.
- Parameters:
date_to_check (object) – date day to look for
- is_vacant(from_date: date, to_date: date)[source]
Check if any resource from the group is unallocated between for a given timeframe. Returns a list of available ressource names.
- Parameters:
from_date (date) – First day
to_date (date) – Last day
- search_for_task_conflicts(all_tasks=False)[source]
Returns a dictionary of all days (datetime.date) containing for each overcharged day the list of task for this day.
It examines all resources’ member and group tasks.
Keyword arguments: all_tasks – if True return all tasks for all days, not just overcharged days
- class gantt_project_maker.gantt.Milestone(name, start=None, depends_of=None, color=None, fullname=None, display=True, parent=None)[source]
Bases:
TaskClass for manipulating Milestones
- check_conflicts_between_task_and_resources_vacations()[source]
Displays a warning for each conflict between milestones and vacation of resources affected to the milestone
And returns a dictionary for resource vacation conflicts
- csv(csv=None)[source]
Create CSV output from milestones
Keyword arguments: csv – None, dymmy object
- property end_date
Returns the last day of the milestone, either the one which was given at milestone creation or the one calculated after checking dependencies
- svg(prev_y=0, start=None, end=None, planning_start=None, planning_end=None, color=None, level=None, scale='d', title_align_on_left=False, offset=0)[source]
Return SVG for drawing this milestone.
Keyword arguments: prev_y – int, line to start to draw start – datetime.date of first day to draw end – datetime.date of last day to draw planning_start – datetime.date start date of planning planning_end – datetime.date end date of planning color – string of color for drawing the project level – int, indentation level of the project, not used here scale – drawing scale (d: days, w: weeks, m: months, q: quarterly) title_align_on_left – boolean, align milestone title on left offset – X offset from image border to start of drawing zone
- class gantt_project_maker.gantt.MySVGWriteDrawingWrapper(filename='noname.svg', size=('100%', '100%'), **extra)[source]
Bases:
DrawingHack to allow using a file descriptor as filename
- class gantt_project_maker.gantt.Project(name='', color=None, side_bar_color=None, project_start=None, project_end=None, font=None)[source]
Bases:
objectClass for handling projects
- add_task(task)[source]
Add a Task to the Project. Task can also be a subproject
Keyword arguments: task – Task or Project object
- csv(csv=None)[source]
Create CSV output from projects
Keyword arguments: csv – string, filename to save to OR file object OR None
- property end_date
Returns last day of the project
- is_in_project(task)[source]
Return True if the given Task is in the project, False if not
Keyword arguments: task – Task object
- make_svg_for_resources(filename: str, today: date | None = None, start: date | None = None, end: date | None = None, resources: list | None = None, one_line_for_tasks: bool = False, tag_filter: str = '', scale: str = 'd', title_align_on_left: bool = False, offset: float = 0, color_per_taks: bool = False)[source]
Draw resources affectation and output it to filename. If start or end are given, use them as reference, otherwise use project first and last day
And returns to a dictionary of dictionaries for vacation and task conflicts for resources
- Parameters:
color_per_taks (bool) – Use color per task
filename (str) – filename to save to OR file object
today (date) – Day marked as a reference
start (date) – First day to draw
end (date) – Last day to draw
resources (list)
one_line_for_tasks (bool) – Use only one line to display all tasks ?
tag_filter (bool) – Display only those tags
scale (str) – Drawing scale (d: days, w: weeks, m: months, q: quarterly)
title_align_on_left (bool) – Align task title on left
offset (float) – X offset from image border to start of drawing zone
- make_svg_for_tasks(filename, today=None, start=None, end=None, margin_left=None, margin_right=None, scale='d', title_align_on_left=False, offset=0)[source]
Draw gantt of tasks and output it to filename.
- Parameters:
filename (str) – Filename to save to OR file object
today (date) – Date of day marked as a reference
start (date) – The first day to draw
end (date) – The last day to draw
margin_left (int) – Number of week to add to the grid before the project start
margin_right (int) – Number of week to add to the grid after the project end
scale (str) – drawing scale (d: days, w: weeks, m: months, q: quarterly)
title_align_on_left (bool) – Align task title on left
offset (float) – X offset from image border to start of drawing zone
Notes
If start or end are given, use them as reference, otherwise use project first and last day
- property start_date
Returns first day of the project
- svg(prev_y=0, start=None, end=None, planning_start=None, planning_end=None, color=None, level=0, scale='d', title_align_on_left=False, offset=0)[source]
Draw all tasks and add project name with a purple bar on the left side.
- Parameters:
prev_y (int) – Line to start to draw
start (date) – First day to draw
end (date) – Last day to draw
planning_start (date) – not used here
planning_end (date) – not used here
color (str) – Color for drawing the project
level (int) – Indentation level of the project
scale (str) – Drawing scale (d: days, w: weeks, m: months, q: quarterly)
title_align_on_left (bool) – Align task title on left
offset (float) – X offset from image border to start of drawing zone
- Returns:
SVG code and number of lines drawn for the project.
- Return type:
svg, int
- class gantt_project_maker.gantt.Resource(name, fullname=None, color=None)[source]
Bases:
objectClass for handling resources assigned to tasks
- Parameters:
- add_group(group_of_resources)[source]
Tell the resource it belongs to a GroupOfResources
- Parameters:
group_of_resources (GroupOfResources) – The GroupOfResources to which a resource belongs to
- add_vacations(from_date: date, to_date: date | None = None)[source]
Add vacations to a resource beginning at from_date to to_date (included). If to_date is not defined, vacation will be for from_data day only
- Parameters:
from_date (date) – Beginning of vacation
to_date (date) – End of vacation
- is_available(date_of_this_day)[source]
Returns True if the resource is available at given date, False if not. Availability is tasks from the global VACATIONS and resource’s ones.
- Parameters:
date_of_this_day (date) – Day to look for
- class gantt_project_maker.gantt.Task(name: str, start: date | None = None, stop: date | None = None, duration: int | None = None, depends_of: list | None = None, resources: list | None = None, percent_done: int = 0, color: str | None = None, fullname: str | None = None, display: bool = True, state: str = '', owner: str = '', parent: str = '')[source]
Bases:
objectClass for manipulating Tasks
Notes
Initialize task object. Two of start, stop or duration may be given. This task can rely on other task and will be completed with resources. If percent done is given, a progress bar will be included on the task. If color is specified, it will be used for the task.
- Parameters:
name (str) – name of the task (id)
fullname (str) – Long name given to the resource
start (date) – First day of the task, default None
stop (date) – Last day of the task, default None
duration (int) – Duration of the task, default None
depends_of (list|None) – Tasks which are parents of this one, default None
resources (list|None) – Resources assigned to the task, default None
percent_done (int) – Percent of achievement, default 0
color (str, html color) – default None
display (bool) – Display this task, default True
state (str) – State of the task
owner (str) – Owner of the task
parent (str) – Parent of the task
- add_depends(depends_of)[source]
Adds dependency to a task
- Parameters:
depends_of (list) – Task which are parents of this one
- check_conflicts_between_task_and_resources_vacations()[source]
Displays a warning for each conflict between tasks and vacation of resources affected to the task
And returns a dictionary for resource vacation conflicts
- property end_date
Returns the last day of the task, either the one which was given at task creation or the one calculated after checking dependencies
- is_in_project(task)[source]
Return True if the given Task is itself… (lazy coding ;)
Keyword arguments: task – Task object
- set_end_date(end_date)[source]
Set a end date, overriding the previous end date :param end_date: End date :type end_date: datetime
- property start
- property start_date
Returns the first day of the task, either the one which was given at task creation or the one calculated after checking dependencies
- property stop
- svg(prev_y: int = 0, start: date | None = None, end: date | None = None, planning_start: date | None = None, planning_end: date | None = None, color: str | None = None, level: int | None = None, scale: str = 'd', title_align_on_left: bool = False, offset: float = 0)[source]
Get the SVG for drawing this task.
- Parameters:
prev_y (int) – line to start to draw
start (date) – First day to draw
end (date) – Last day to draw
planning_start (date) – Not used here
planning_end (date) – Not used here
color (str) – color for drawing the project
level (int) – Indentation level of the project, not used here
scale (str) – Drawing scale (d: days, w: weeks, m: months, q: quarterly)
title_align_on_left (bool) – align task title on left
offset (float) – X offset from image border to start of drawing zone
- Returns:
the svg containter with the start line
- Return type:
Container, number of lines
- gantt_project_maker.gantt.add_vacations(start_date: date, end_date: date | None = None)[source]
Add vacations to a resource beginning at start_date to end_date (included). If end_date is not defined, vacation will be for start_date day only
- Parameters:
start_date (date) – Beginning of a vacation
end_date – (date): End of a vacation
- gantt_project_maker.gantt.define_font_attributes(fill: str = 'black', stroke: str = 'black', stroke_width: float = 0, font_family: str = 'Verdana', font_weight: str = 'normal', font_size: int = 15)[source]
Define font attributes
- Parameters:
- gantt_project_maker.gantt.define_not_worked_days(list_of_days)[source]
Define specific days off
Keyword arguments: list_of_days – list of integer (0: Monday … 6: Sunday) - default [5, 6]
- gantt_project_maker.gantt.get_font_attributes(fill=None, stroke=None, stroke_width=None, font_family=None, font_weight=None, font_size=None)[source]
Return dictionary of font attributes
- gantt_project_maker.gantt.init_log_to_sysout(level=20)[source]
Init global variable __LOG__ used for logging purpose
Keyword arguments: level – logging level (from logging.debug to logging.critical)
- gantt_project_maker.gantt.task_within_range(task: ~gantt_project_maker.gantt.Task, planning_start: <module 'datetime' from '/home/docs/.asdf/installs/python/3.10.14/lib/python3.10/datetime.py'>, planning_end: <module 'datetime' from '/home/docs/.asdf/installs/python/3.10.14/lib/python3.10/datetime.py'>)[source]
Check if the task is in the range of the planning
gantt_project_maker.main module
This is the main start-up file of the project planner
- gantt_project_maker.main.check_if_items_are_available(requested_items: list, available_items: dict, label: str = '')[source]
Check is the passed items in the list are available in the keys of the dictionary
Args: requested_items (list): All requested items in the list available_items (dict): The dictionary with the keys for which the check is performed label (str, optional): Used for information to the screen
- gantt_project_maker.main.get_employee_name(employees_info, employee)[source]
get the full name of the employee from the settings file
- gantt_project_maker.main.get_info_from_file_or_settings(settings, key)[source]
Get the information directly from the settings or from a separate file if a filename is given :param settings: Settings file :type settings: dict :param key: Key of the settings file we want to read :type key: str
- Returns:
Structure with information from the settings or separate file
- Return type:
- gantt_project_maker.main.get_pasted_employees(args_employee, employees_info)[source]
get the list of full names or requested employees and return as a comma separated string
- gantt_project_maker.main.get_projects_from_arguments(projects_args) list[source]
Get the projects from the command line arguments and return a list
- gantt_project_maker.main.main(args)[source]
Wrapper allowing: func:postal_code2nuts to be called with string arguments in a CLI fashion
Instead of returning the value from: func:postal_code2nuts, it prints the result to the
stdoutin a nicely formatted message.- Parameters:
args (List[str]) – command line parameters as a list of strings (for example,
["--verbose", "42"]).
- gantt_project_maker.main.make_banner(width=80) None[source]
Make a banner with the start time :param width: Width of the banner. :type width: int, optional :param Defaults to 80:
- gantt_project_maker.main.parse_args(args)[source]
Parse command line parameters
- Parameters:
args (List[str]) – command line parameters as a list of strings (for example,
["--help"]).- Returns:
argparse.Namespace: command line parameters namespace
- Return type:
obj
gantt_project_maker.project_classes module
Class files for the gantt-project-maker project
- class gantt_project_maker.project_classes.BasicElement(label, project_leader_key=None, start=None, dependent_of=None, color=None, project_color=None, detail=False, display=True, dayfirst=False, variables_info=None, parent=None)[source]
Bases:
StartEndBase
- class gantt_project_maker.project_classes.Employee(label: str, full_name: str | None = None, vacations: dict | None = None, color: str | None = None)[source]
Bases:
objectClass holding information about one employee
- class gantt_project_maker.project_classes.EmployeesContributingToTask[source]
Bases:
objectClass holding all employees attached to a task with the number of hours
- class gantt_project_maker.project_classes.ProjectMileStone(label, project_leader_key=None, start=None, dependent_of=None, color=None, project_color=None, detail=False, display=True, dayfirst=True, variables_info=None, parent=None)[source]
Bases:
BasicElement
- class gantt_project_maker.project_classes.ProjectPlanner(programma_title: str | None = None, vacations_title: str | None = None, programma_color: str | None = None, vacation_color: str | None = None, output_file_name: Path | None = None, planning_start: datetime | None = None, planning_end: datetime | None = None, weeks_margin_left: int | None = None, weeks_margin_right: int | None = None, today: datetime | None = None, dayfirst: bool = False, scale: str | None = None, period_info: dict | None = None, excel_info: dict | None = None, details: bool | None = None, filter_employees: list | None = None, save_svg_as_pdf: bool = False, collaps_tasks: bool = False, periods: list | None = None, tasks_id: str = 'task', employee_id: str = 'employee', owner_id: str = 'owner', contributor_id: str = 'contributor', progress_file_info: dict | None = None)[source]
Bases:
objectProjectPlanner is class to handle the project planning and generate the output
- Parameters:
programma_title (str, optional) – Main titel of the whole project
vacations_title (str, optional) – Title of the vacations project
programma_color (str, optional) – First color of the bar
output_file_name (str, optional) – Base name of the output files
planning_start (datetime, optional) – Start of the program
planning_end (datetime, optional) – End of the program
weeks_margin_left (int, optional) – Shift the end of the planning so many weeks to the left without adding projects
weeks_margin_right (int, optional) – Shift the end of the planning so many weeks to the right without adding projects
today (datetime, optional) – Today’s date
dayfirst (bool, optional) – Parse date with the day first. Defaults to False
scale (str, optional) – Which scale is used for the output
period_info (dict, optional) – Information on the periods output
excel_info (dict, optional) – Information on the Excel output
details (bool, optional) – If true, include the details to the programs
filter_employees (list, optional) – If not None, only add task to which employees in this list contribute
- tasks_per_resource
Dataframe with tasks per resource
- Type:
DataFrame
- static add_global_information(fill='black', stroke='black', stroke_width=0, font_family='Verdana')[source]
Set global pen properties
- add_tasks_and_milestones(tasks_and_milestones=None, tasks_and_milestones_info=None, variables_info=None)[source]
Make all tasks en milestones
- add_vacations(vacations_info)[source]
Add all the vacations
- Parameters:
vacations_info (dict) – information of the vacations
- export_to_excel(excel_output_directory: Path, excel_output_formats: list | None = None) None[source]
Write planning to an Excel file
- Parameters:
excel_output_directory (Path) – Output directory of the Excel files
excel_output_formats (list) – List of Excel files to export as defined in the settings file.
- get_dependency(key: str) Resource[source]
Search the object to which the dependency ‘key’ refers to
- Parameters:
key (str) – Key of the dictionary to which the dependency refers to
- Returns:
Object to which the key refers to.
- Return type:
- get_employees(employees: str | list | dict) EmployeesContributingToTask[source]
Turn a list of employees-strings into a list of employees gantt.Resource objects
- make_projects(project_leader_key, subprojects_info, subprojects_title, subprojects_selection, subprojects_color=None, variables_info=None)[source]
Create all the projects given in subprojects_info
- Parameters:
project_leader_key (str) – The key of the project leader
subprojects_info (dict) – information per subproject
subprojects_title (dict) – Title of the subprojects
subprojects_selection (list) – List of the subprojects to include at the main level
subprojects_color (str, optional) – Color of the projects. Defaults to None
variables_info (dict, optional) – variables which can be used as replacements over the subprojects. Defaults to None
- make_task_or_milestone(project_leader_key: str | None = None, task_properties: dict | None = None, project_color=None, variables_info=None, parent=None) ProjectTask | ProjectMileStone[source]
Add all the general tasks and milestones
- Parameters:
- Return type:
Task or milestone
- write_excel_for_contributors(excel_file, header_info, summation_info=None, column_widths=None)[source]
A writer for the project plan of all contributors, one sheet per employee
- Parameters:
Returns:
- write_excel_for_leaders(excel_file, header_info, column_widths)[source]
A writer for the project plan of all employees, one sheet per employee
- Parameters:
Returns:
- write_planning(planning_output_directory, resource_output_directory, vacations_output_directory, write_resources=False, write_vacations=False, periods=None, suffix=None)[source]
Write the planning to the output definitions
Args: planning_output_directory (Path): Output directory of the svg files of the planning resource_output_directory (Path): Output directory of the svg files of the resources vacations_output_directory (Path): Output directory of the svg files of the vacations write_resources (bool, optional): Write the resource’s file as well. Default to False write_vacations (bool, optional): Write the vacation file as well. Default to False periods (list, optional): Periods we want to add. If None, add all periods. Default to None (all periods) suffix (str, optional): Add a suffix to the final filename. Defaults to None
- class gantt_project_maker.project_classes.ProjectTask(label, project_leader_key=None, start=None, end=None, duration=None, employees=None, dependent_of=None, color=None, project_color=None, detail=False, display=True, dayfirst=True, variables_info=None, parent=None)[source]
Bases:
BasicElement
- class gantt_project_maker.project_classes.StartEndBase(start: str, end: str | None = None, dayfirst=False, variables_info=None)[source]
Bases:
objectBasis van alle classes met een begin- en einddatum.
- class gantt_project_maker.project_classes.Vacation(start, end=None, employee=None, dayfirst=False)[source]
Bases:
StartEndBase
- gantt_project_maker.project_classes.add_vacation_employee(employee: Resource, vacations: dict) dict[source]
Add the vacations of an employee
- gantt_project_maker.project_classes.check_if_employee_in_contributing(filter_employees: list, contributing_employees: list) bool[source]
Check if any of the employees given in filter_employees is in contributing to this taks
- gantt_project_maker.project_classes.extend_suffix(output_filename: Path, extensions: list | str)[source]
Add an extra suffix to the base filename
- gantt_project_maker.project_classes.get_contributors_from_resources(projects_employee_global, contributors, all_resources)[source]
Get the contributors of this Task based on the global resources
- gantt_project_maker.project_classes.get_contributors_task(task, contributors)[source]
Get a list of contributors working on this Task based on the task resources.
- Parameters:
task
contributors
- Returns:
contributors
- Return type:
- gantt_project_maker.project_classes.get_nearest_saturday(date)[source]
Get the nearest Saturday with respect to ‘date’
- Parameters:
date (datetime.date) – The reference date
- Returns:
Nearest Saturday with respect to the reference date
- Return type:
- gantt_project_maker.project_classes.insert_variables(line: str, variables_info: dict | None = None)[source]
Replace variables inserted as {{ variable_name }} in line by the variables defined in variable_ifo
gantt_project_maker.utils module
Some utility functions
- gantt_project_maker.utils.check_if_date(value: str)[source]
Check if an argument is a valid date :param value: date/time string :type value: str
- Returns:
Date/time string
- Return type:
- Raises:
ArgumentTypeError – raised in case the value string is not a valid date/time string
- gantt_project_maker.utils.deep_copy_dict(properties: dict) dict[source]
Create a deep copy of a nested dictionary
- gantt_project_maker.utils.get_task_contribution(name, task, owner_id) dict[source]
Taks contribution