shota19

example

Jan 29th, 2021 (edited)
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.19 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import datetime
  5. import gantt
  6.  
  7. # Change font default
  8. gantt.define_font_attributes(fill='black', stroke='black', stroke_width=0, font_family="Verdana")
  9.  
  10. # Add vacations for everyone
  11. gantt.add_vacations(datetime.date(2014, 12, 25))
  12. gantt.add_vacations(datetime.date(2015, 1, 1))
  13. gantt.add_vacations(datetime.date(2015, 1, 13))
  14.  
  15. # Create two resources
  16. rANO = gantt.Resource('ANO')
  17. rJLS = gantt.Resource('JLS')
  18.  
  19. # Add vacations for one lucky resource
  20. rANO.add_vacations(
  21.     dfrom=datetime.date(2014, 12, 29),
  22.     dto=datetime.date(2015, 1, 4)
  23.     )
  24. rANO.add_vacations(
  25.     dfrom=datetime.date(2015, 1, 6),
  26.     dto=datetime.date(2015, 1, 8)
  27.     )
  28.  
  29. # Test if this resource is  avalaible for some dates
  30. print(rANO.is_available(datetime.date(2015, 1, 5)))
  31. print(rANO.is_available(datetime.date(2015, 1, 8)))
  32. print(rANO.is_available(datetime.date(2015, 1, 6)))
  33. print(rANO.is_available(datetime.date(2015, 1, 2)))
  34. print(rANO.is_available(datetime.date(2015, 1, 1)))
  35.  
  36.  
  37. # Create some tasks
  38. t1 = gantt.Task(name='tache1', start=datetime.date(2014, 12, 25), duration=4, percent_done=44, resources=[rANO], color="#FF8080")
  39. t2 = gantt.Task(name='tache2', start=datetime.date(2014, 12, 28), duration=6, resources=[rJLS])
  40. t7 = gantt.Task(name='tache7', start=datetime.date(2014, 12, 28), duration=5, percent_done=50)
  41. t3 = gantt.Task(name='tache3', start=datetime.date(2014, 12, 25), duration=4, depends_of=[t1, t7, t2], resources=[rJLS])
  42. t4 = gantt.Task(name='tache4', start=datetime.date(2015,  1,  1), duration=4, depends_of=t1, resources=[rJLS])
  43. t5 = gantt.Task(name='tache5', start=datetime.date(2014, 12, 23), duration=3)
  44. t6 = gantt.Task(name='tache6', start=datetime.date(2014, 12, 25), duration=4, depends_of=t7, resources=[rANO])
  45. t8 = gantt.Task(name='tache8', start=datetime.date(2014, 12, 25), duration=4, depends_of=t7, resources=[rANO, rJLS])
  46.  
  47.  
  48. # Create a project
  49. p1 = gantt.Project(name='Projet 1')
  50.  
  51. # Add tasks to this project
  52. p1.add_task(t1)
  53. p1.add_task(t7)
  54. p1.add_task(t2)
  55. p1.add_task(t3)
  56. p1.add_task(t5)
  57. p1.add_task(t8)
  58.  
  59.  
  60.  
  61. # Create another project
  62. p2 = gantt.Project(name='Projet 2', color='#FFFF40')
  63.  
  64. # Add tasks to this project
  65. p2.add_task(t2)
  66. p2.add_task(t4)
  67.  
  68.  
  69. # Create another project
  70. p = gantt.Project(name='Gantt')
  71. # wich contains the first two projects
  72. # and a single task
  73. p.add_task(p1)
  74. p.add_task(p2)
  75. p.add_task(t6)
  76.  
  77.  
  78. # Test cases for milestones
  79. # Create another project
  80. ptcm = gantt.Project(name='Test case for milestones')
  81.  
  82. tcm11 = gantt.Task(name='tcm11', start=datetime.date(2014, 12, 25), duration=4)
  83. tcm12 = gantt.Task(name='tcm12', start=datetime.date(2014, 12, 26), duration=5)
  84. ms1 = gantt.Milestone(name=' ', depends_of=[tcm11, tcm12])
  85. tcm21 = gantt.Task(name='tcm21', start=datetime.date(2014, 12, 30), duration=4, depends_of=[ms1])
  86. tcm22 = gantt.Task(name='tcm22', start=datetime.date(2014, 12, 30), duration=6, depends_of=[ms1])
  87. ms2 = gantt.Milestone(name='MS2', depends_of=[ms1, tcm21, tcm22])
  88. tcm31 = gantt.Task(name='tcm31', start=datetime.date(2014, 12, 30), duration=6, depends_of=[ms2])
  89. ms3 = gantt.Milestone(name='MS3', depends_of=[ms1])
  90.  
  91.  
  92. ptcm.add_task(tcm11)
  93. ptcm.add_task(tcm12)
  94. ptcm.add_task(ms1)
  95. ptcm.add_task(tcm21)
  96. ptcm.add_task(tcm22)
  97. ptcm.add_task(ms2)
  98. ptcm.add_task(tcm31)
  99. ptcm.add_task(ms3)
  100.  
  101.  
  102. p.add_task(ptcm)
  103.  
  104.  
  105. ##########################$ MAKE DRAW ###############
  106. p.make_svg_for_tasks(filename='test_full.svg', today=datetime.date(2014, 12, 31), start=datetime.date(2014,8, 22), end=datetime.date(2015, 1, 14))
  107. p.make_svg_for_tasks(filename='test_full2.svg', today=datetime.date(2014, 12, 31))
  108. 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))
  109. p1.make_svg_for_tasks(filename='test_p1.svg', today=datetime.date(2014, 12, 31))
  110. p2.make_svg_for_tasks(filename='test_p2.svg', today=datetime.date(2014, 12, 31))
  111. p.make_svg_for_resources(filename='test_resources.svg', today=datetime.date(2014, 12, 31), resources=[rANO, rJLS])
  112. p.make_svg_for_tasks(filename='test_weekly.svg', today=datetime.date(2014, 12, 31), scale=gantt.DRAW_WITH_WEEKLY_SCALE)
  113. ##########################$ /MAKE DRAW ###############
  114.  
Advertisement
Add Comment
Please, Sign In to add comment