Exemple #1
0
def create_gant(start, sprints, duration, name):
    # Change font default
    gantt.define_font_attributes(fill='white',
                                 stroke='white',
                                 stroke_width=1,
                                 font_family="Ubuntu")

    p1 = gantt.Project(name=name)

    if not isinstance(start, datetime.date):
        start_date = parse(start)
    else:
        start_date = start

    end_date = start_date + relativedelta(days=(duration + 2) * sprints)
    print(start_date, end_date)
    curr_t = None
    # Create some tasks
    for sprint in range(sprints):
        t = gantt.Task(name=f'Sprint {sprint}',
                       start=start_date,
                       duration=10,
                       percent_done=44,
                       color="#0000FF",
                       depends_of=curr_t)
        curr_t = t
        p1.add_task(t)

    p1.make_svg_for_tasks(filename='test_full.svg',
                          today=datetime.date.today(),
                          start=start_date,
                          end=end_date)
Exemple #2
0
 def __init__(self):
     gantt.define_font_attributes(fill='black',
                                  stroke='black',
                                  stroke_width=0,
                                  font_family="Verdana")
     self.chart = None
     self.tasks = {}
Exemple #3
0
    def gen(self):
        # Change font default
        gantt.define_font_attributes(fill='black',
                                     stroke='black',
                                     stroke_width=0,
                                     font_family="Verdana")

        self.gproject = gantt.Project(name=self.project.name)

        resources = {}
        for pid in self.peoples.idarray():
            resources[pid] = gantt.Resource(pid)

        for entity in self.entityes:
            resarray = []
            for people in entity.people:
                resarray.append(resources[people])

            task = gantt.Task(
                name=entity.id,
                fullname=entity.name,
                start=entity.starttime,
                stop=entity.endtime,
                #duration=(entity.endtime - entity.starttime).days,
                resources=resarray)
            self.gproject.add_task(task)

        tasks = self.gproject.get_tasks()
        for entity in self.entityes:
            task = None
            for t in tasks:
                if t.name == entity.id:
                    task = t
                    break
            froms = entity.dfrom
            for d in froms:
                for t in tasks:
                    if t.name == d.name:
                        task.add_depends([t])
                        break
        return self.gproject
Exemple #4
0
	def gen(self):
		# Change font default
		gantt.define_font_attributes(fill='black',
			stroke='black',
			stroke_width=0,
			font_family="Verdana")

		self.gproject = gantt.Project(name=self.project.name)

		resources = {}
		for pid in self.peoples.idarray():
			resources[pid] = gantt.Resource(pid)

		for entity in self.entityes:
			resarray = []
			for people in entity.people:
				resarray.append(resources[people])
			
			task = gantt.Task(name=entity.id,
				fullname=entity.name,
		                start=entity.starttime,
				stop=entity.endtime,
		                #duration=(entity.endtime - entity.starttime).days,
                		resources=resarray)
			self.gproject.add_task(task)

		tasks = self.gproject.get_tasks()
		for entity in self.entityes:
			task = None
			for t in tasks:
				if t.name == entity.id:
					task = t
					break
			froms = entity.dfrom
			for d in froms:
				for t in tasks:
					if t.name == d.name:
						task.add_depends([t])
						break
		return self.gproject
Exemple #5
0
            index_resource = [r[i].name for i in range(len(r))].index(next_vac_name)
            task.resources = [r[index_resource]]
            task.color = "#%02x%02x%02x" % (255 * index_resource, 255, 255)
            for m in range(len(r) - 1, -1, -1):
                if m != index_resource:  # Remove task from unused resource(s)
                    idx = [r[m].tasks[ii].name for ii in range(len(r[m].tasks))].index(task.name)
                    r[m].tasks.pop(idx)
    print task.name, task.start
    if "3.6" in task.name:
        pass
    return task


# Change font default
gantt.define_font_attributes(fill="black", stroke="black", stroke_width=0, font_family="Verdana")

# Add vacations for everyone
gantt.add_vacations(date(2016, 7, 20), date(2016, 8, 10))


# Create two resources
rN = gantt.Resource("N")
rK = gantt.Resource("K")
rAll = [rN, rK]
rAllGroup = [gantt.GroupOfResources("Group of N, K")]
# rN_K.add_resource(rN)
# rN_K.add_resource(rK)

# Add vacations for one lucky resource
rN.add_vacations(dfrom=date(2016, 8, 2), dto=date(2015, 8, 10))
Exemple #6
0
def get_gantt_1():
    # Change font default
    gantt.define_font_attributes(fill='black',
                                 stroke='black',
                                 stroke_width=0,
                                 font_family="Verdana")

    # Add vacations for everyone
    gantt.add_vacations(datetime.date(2014, 12, 25))
    gantt.add_vacations(datetime.date(2015, 1, 1))
    gantt.add_vacations(datetime.date(2015, 1, 13))

    # Create two resources
    rANO = gantt.Resource('ANO')
    rJLS = gantt.Resource('JLS')

    # Add vacations for one lucky resource
    rANO.add_vacations(dfrom=datetime.date(2014, 12, 29),
                       dto=datetime.date(2015, 1, 4))
    rANO.add_vacations(dfrom=datetime.date(2015, 1, 6),
                       dto=datetime.date(2015, 1, 8))

    # Test if this resource is  avalaible for some dates
    print(rANO.is_available(datetime.date(2015, 1, 5)))
    print(rANO.is_available(datetime.date(2015, 1, 8)))
    print(rANO.is_available(datetime.date(2015, 1, 6)))
    print(rANO.is_available(datetime.date(2015, 1, 2)))
    print(rANO.is_available(datetime.date(2015, 1, 1)))

    # Create some tasks
    t1 = gantt.Task(name='tache1',
                    start=datetime.date(2014, 12, 25),
                    duration=4,
                    percent_done=44,
                    resources=[rANO],
                    color="#FF8080")
    t2 = gantt.Task(name='tache2',
                    start=datetime.date(2014, 12, 28),
                    duration=6,
                    resources=[rJLS])
    t7 = gantt.Task(name='tache7',
                    start=datetime.date(2014, 12, 28),
                    duration=5,
                    percent_done=50)
    t3 = gantt.Task(name='tache3',
                    start=datetime.date(2014, 12, 25),
                    duration=4,
                    depends_of=[t1, t7, t2],
                    resources=[rJLS])
    t4 = gantt.Task(name='tache4',
                    start=datetime.date(2015, 1, 1),
                    duration=4,
                    depends_of=t1,
                    resources=[rJLS])
    t5 = gantt.Task(name='tache5',
                    start=datetime.date(2014, 12, 23),
                    duration=3)
    t6 = gantt.Task(name='tache6',
                    start=datetime.date(2014, 12, 25),
                    duration=4,
                    depends_of=t7,
                    resources=[rANO])
    t8 = gantt.Task(name='tache8',
                    start=datetime.date(2014, 12, 25),
                    duration=4,
                    depends_of=t7,
                    resources=[rANO, rJLS])

    # Create a project
    p1 = gantt.Project(name='Projet 1')

    # Add tasks to this project
    p1.add_task(t1)
    p1.add_task(t7)
    p1.add_task(t2)
    p1.add_task(t3)
    p1.add_task(t5)
    p1.add_task(t8)

    # Create another project
    p2 = gantt.Project(name='Projet 2', color='#FFFF40')

    # Add tasks to this project
    p2.add_task(t2)
    p2.add_task(t4)

    # Create another project
    p = gantt.Project(name='Gantt')
    # wich contains the first two projects
    # and a single task
    p.add_task(p1)
    p.add_task(p2)
    p.add_task(t6)

    # Test cases for milestones
    # Create another project
    ptcm = gantt.Project(name='Test case for milestones')

    tcm11 = gantt.Task(name='tcm11',
                       start=datetime.date(2014, 12, 25),
                       duration=4)
    tcm12 = gantt.Task(name='tcm12',
                       start=datetime.date(2014, 12, 26),
                       duration=5)
    ms1 = gantt.Milestone(name=' ', depends_of=[tcm11, tcm12])
    tcm21 = gantt.Task(name='tcm21',
                       start=datetime.date(2014, 12, 30),
                       duration=4,
                       depends_of=[ms1])
    tcm22 = gantt.Task(name='tcm22',
                       start=datetime.date(2014, 12, 30),
                       duration=6,
                       depends_of=[ms1])
    ms2 = gantt.Milestone(name='MS2', depends_of=[ms1, tcm21, tcm22])
    tcm31 = gantt.Task(name='tcm31',
                       start=datetime.date(2014, 12, 30),
                       duration=6,
                       depends_of=[ms2])
    ms3 = gantt.Milestone(name='MS3', depends_of=[ms1])

    ptcm.add_task(tcm11)
    ptcm.add_task(tcm12)
    ptcm.add_task(ms1)
    ptcm.add_task(tcm21)
    ptcm.add_task(tcm22)
    ptcm.add_task(ms2)
    ptcm.add_task(tcm31)
    ptcm.add_task(ms3)

    p.add_task(ptcm)

    ##########################$ MAKE DRAW ###############
    p.make_svg_for_tasks(filename='./media/gantt/test_full.svg',
                         today=datetime.date(2014, 12, 31),
                         start=datetime.date(2014, 8, 22),
                         end=datetime.date(2015, 1, 14))
    p.make_svg_for_tasks(filename='./media/gantt/test_full2.svg',
                         today=datetime.date(2014, 12, 31))
    p.make_svg_for_tasks(filename='test.svg',
                         today=datetime.date(2014, 12, 31),
                         start=datetime.date(2015, 1, 3),
                         end=datetime.date(2015, 1, 6))
    p1.make_svg_for_tasks(filename='test_p1.svg',
                          today=datetime.date(2014, 12, 31))
    p2.make_svg_for_tasks(filename='test_p2.svg',
                          today=datetime.date(2014, 12, 31))
    p.make_svg_for_resources(filename='test_resources.svg',
                             today=datetime.date(2014, 12, 31),
                             resources=[rANO, rJLS])
    p.make_svg_for_tasks(filename='test_weekly.svg',
                         today=datetime.date(2014, 12, 31),
                         scale=gantt.DRAW_WITH_WEEKLY_SCALE)
    ##########################$ /MAKE DRAW ###############

    return '/media/gantt/test_full2.svg'
Exemple #7
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import datetime
import gantt

import logging
gantt.init_log_to_sysout(level=logging.CRITICAL)

# Change font default
gantt.define_font_attributes(fill='black',
                             stroke='black',
                             stroke_width=0,
                             font_family="Verdana")

# Add vacations for everyone
gantt.add_vacations(datetime.date(2014, 12, 25))
gantt.add_vacations(datetime.date(2015, 1, 1))
gantt.add_vacations(datetime.date(2015, 1, 13))

# Create two resources
rANO = gantt.Resource('ANO')
rJLS = gantt.Resource('JLS')

# Add vacations for one lucky resource
rANO.add_vacations(dfrom=datetime.date(2014, 12, 29),
                   dto=datetime.date(2015, 1, 4))
rANO.add_vacations(dfrom=datetime.date(2015, 1, 6),
                   dto=datetime.date(2015, 1, 8))

# Test if this resource is  avalaible for some dates
Exemple #8
0
def generate_chart(df, start_date, end_date, save_file, input_root=None, max_depth=None):
    # Function to recursively define the order that nodes will be placed in
    def populate_order(value, current_depth):
        if max_depth:
            if current_depth == int(max_depth):
                return

        if node_data.loc[value, "CHILDREN"] == []:
            return

        else:
            children = node_data.loc[value, "CHILDREN"]
            for child in children:
                if children.index(child) + 1 <= math.ceil(len(children) / 2):
                    if child not in task_order.list:
                        task_order.add_left(child, task_order.list.index(value))
                        populate_order(child, current_depth + 1)

                else:
                    if child not in task_order.list:
                        task_order.add_right(child, task_order.list.index(value))
                        populate_order(child, current_depth + 1)

    gantt.define_font_attributes(fill='black',
                                 stroke='black',
                                 stroke_width=0,
                                 font_family="Verdana")

    # Import node data
    node_data = df
    node_data.replace(to_replace="nan", value="NONE", inplace=True)
    node_data["CHILDREN"] = node_data["CHILDREN"].apply(cell_to_list)
    node_data["PARENTS"] = node_data["PARENTS"].apply(cell_to_list)
    node_data["START"] = node_data["START"]

    project_list = node_data["PROJECT"].drop_duplicates().tolist()
    resource_list = node_data["RESOURCE"].drop_duplicates().tolist()
    roots = []

    # Find all root nodes
    for node in node_data.index:
        if node_data.loc[node, "PARENTS"] == []:
            roots.append(node)

    nodes = node_data.index.tolist()
    tasks = {}
    resources = {}
    projects = {}
    master_project = gantt.Project(name="Master Schedule")

    # Create resource objects
    for resource in resource_list:
        resources[resource] = gantt.Resource(name=resource)

    # Create project objects
    for project in project_list:
        projects[project] = gantt.Project(name=project)

    # Create task objects
    for node in nodes:
        datel = node_data.loc[node, "START"]
        year = int(datel[:4])
        month = int(datel[5:7])
        day = int(datel[8:10])
        tasks[node] = gantt.Task(name=node,
                                 start=datetime.date(year, month, day),
                                 duration=int(float(node_data.loc[node, "DURATION"])),
                                 resources=[resources[node_data.loc[node, "RESOURCE"]]],
                                 color=choose_color(node_data.loc[node, "RESOURCE"]))

    # Add dependencies to tasks
    for node in nodes:
        tasks[node].add_depends(depends_of=[tasks[i] if i != "NONE" else None for i in node_data.loc[node, "CHILDREN"]])

    task_order = Order()
    root_priority = []

    # If user selected a specific node to view, set it as the root
    if input_root:
        roots = [input_root]

    # Create a priority list of roots based off of number of child nodes
    for root in roots:
        root_priority.append([root, len(node_data.loc[root, "CHILDREN"])])

    root_priority = sorted(root_priority, key=lambda x: x[1], reverse=True)

    # Higher priority roots will be placed in chart first
    print("Arranging Nodes...\n=========================================")
    for root in root_priority:
        task_order.list.append(root[0])
        populate_order(root[0], 1)
        print("Node {} completed".format(root))

    # Rearrange roots according to their "center of mass" based off of child nodes
    print("Rearranging Roots...\n=========================================")
    for root in roots:
        best_index = 0
        task_order.list.remove(root)
        best_dcount = len(task_order.list)
        for i in range(len(task_order.list)):
            count_left = 0
            count_right = 0
            for child in node_data.loc[root, "CHILDREN"]:
                count_left += task_order.list[:i].count(child)
                count_right += task_order.list[i:].count(child)

            dcount = abs(count_right - count_left)

            if dcount < best_dcount:
                best_dcount, best_index = dcount, i

        task_order.add_right(root, best_index)
        print("Root {} completed".format(root))

    # Assign tasks to projects
    for key in task_order.list:
        projects[node_data.loc[key, "PROJECT"]].add_task(tasks[key])

    master_project.add_task(projects["Main"])

    # Create svg
    master_project.make_svg_for_tasks(filename=save_file,
                                      start=start_date,
                                      end=end_date)
Exemple #9
0
def dispatch(inputfile, outputfile, verbose, project_name, today, prefixdays,
             suffixdays, weeklyscale):
    global resource_list
    global task_list

    # Change font default
    gantt.define_font_attributes(fill='black',
                                 stroke='black',
                                 stroke_width=0,
                                 font_family="Verdana")

    df = read_excel(inputfile)  # , sheet_name="Data"¨)

    resource_list = []
    resources = split_items_by_comma(remove_nan(df['Owner'].unique()))

    if verbose != "no":
        print("Found resources", resources)

    for resource in resources:
        resource_list.append(gantt_resource(resource))

    if verbose != "no":
        #  print(df[1])
        print(len(df))

    task_list = []
    for i in range(len(df)):
        task = gantt_task(df["Task#"][i], df["Name"][i], df["Start Date"][i],
                          df["End Date"][i], df["#days long"][i],
                          df["%Done"][i], df["Owner"][i], df["Priority"][i],
                          df["Depend On"][i])
        task_list.append(task)
    for task in task_list:
        task.add_dependencies()
    task_index_list = list(range(len(task_list)))
    while len(task_index_list) > 0:
        unfinished_task = []
        for i in task_index_list:
            task = task_list[i]
            task.start_date = get_start_date(task)
            if task.end_date is None:
                if task.duration is not None:
                    if not task.is_milestone:
                        task.end_date = task.start_date + \
                            datetime.timedelta(days=task.duration)
            if verbose != "no":
                print("Task", task.name, "started at", task.start_date,
                      "end date", "duration", task.duration, task.end_date,
                      "owner", [_.name for _ in task.owner_list],
                      "is milestone", task.is_milestone, "depends_of",
                      [_.name for _ in task.depend_on])
            if task.generate_task_object() == 0:
                unfinished_task.append(i)
        task_index_list = unfinished_task

    # test printing
    p = gantt.Project(name=project_name)
    for task in task_list:
        p.add_task(task.task)

    start_date = get_earliest_start_date(task_list)
    end_date = get_latest_end_date(task_list)
    if weeklyscale == "yes":
        p.make_svg_for_tasks(
            filename=outputfile,
            today=string_to_date(today),
            start=start_date - datetime.timedelta(days=prefixdays),
            end=end_date + datetime.timedelta(days=suffixdays),
            scale=gantt.DRAW_WITH_WEEKLY_SCALE)
    else:
        p.make_svg_for_tasks(
            filename=outputfile,
            today=string_to_date(today),
            start=start_date - datetime.timedelta(days=prefixdays),
            end=end_date + datetime.timedelta(days=suffixdays),
            scale=gantt.DRAW_WITH_DAILY_SCALE)
def generate_diagram(project):
    gantt.define_font_attributes(
        fill='black',
        stroke='black',
        stroke_width=0,
        font_family="Verdana",
    )

    gantt.define_not_worked_days([])

    main_project = gantt.Project(name=project.title)

    gantt_performers = []
    gantt_tasks = []

    # taskdb = TaskDB(project=project)
    # tasks = taskdb.get_all_tasks()
    # tasks = Task.objects.filter(project=project)
    for performer in project.performers.all():
        if performer.tasks.all():
            gantt_performer = gantt.Project(name=performer.name)
            gantt_performers.append(gantt_performer)
            for task in performer.tasks.all():
                gantt_task = gantt.Task(name=task.title,
                                        start=task.date_start,
                                        duration=task.duration)
                gantt_performer.add_task(gantt_task)

    # for task in tasks:
    #     gantt_task = gantt.Task(
    #         name=task.title,
    #         start=task.date_start,
    #         duration=task.duration
    #     )
    #     if task.performers.all():
    #         for performer in task.performers.all():
    #             gantt_performer = gantt.Project(name=performer.name)
    #             gantt_performer.add_task(gantt_task)
    #             gantt_performers.append(gantt_performer)
    #     else:
    #         gantt_tasks.append(gantt_task)

    [main_project.add_task(task) for task in gantt_tasks]
    [main_project.add_task(task) for task in gantt_performers]

    today_time = datetime.datetime.now()
    today_date = datetime.date(today_time.year, today_time.month,
                               today_time.day)

    main_project.make_svg_for_tasks(filename=os.path.join(
        TMP_PATH,
        str(project.user) + '.svg'),
                                    today=today_date,
                                    start=project.date_start,
                                    end=project.date_end)

    with open(os.path.join(TMP_PATH, str(project.user) + '.svg'), 'r') as f:
        svg_string = f.read()

    svg_string = svg_string.replace('lightgray', '#D3D3D3').replace(
        'gray', '#808080').replace('#0000FF ', '#C2C5CC')

    with open(os.path.join(TMP_PATH, str(project.user) + '.svg'), 'w') as f:
        f.write(svg_string)

    drawing = svg2rlg(os.path.join(TMP_PATH, str(project.user) + '.svg'))
    renderPM.drawToFile(drawing,
                        os.path.join(TMP_PATH,
                                     str(project.user) + '.jpg'),
                        fmt="jpg")

    os.remove(os.path.join(TMP_PATH, str(project.user) + '.svg'))

    return os.path.join(TMP_PATH, str(project.user) + '.jpg')