Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from lsst-dm/u/womullan/summaryschedule
summary schedule:
- Loading branch information
Showing
13 changed files
with
829 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ __pycache__ | |
venv | ||
gantt.* | ||
.DS_Store | ||
cartoon.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
# RHL generate the block schedule diagram from the milestones with | ||
# Summary Chart entries. | ||
|
||
import os | ||
import sys | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from .cartoon import show_activities, add_legend, Activity, AdvanceRow, Milestone, Nrow, Rotation | ||
from .cartoon_config import \ | ||
categoryNrow, categoryColors, wrappedDescrip, categoryGrouping, specials, \ | ||
nRowOfMilestones, milestoneHeight, legend_location | ||
|
||
|
||
def blockschedule(args, milestones): | ||
# Process Summary Chart activities/milestones and celebratory milestones | ||
|
||
activities, celebrations = process_milestones(milestones) | ||
|
||
blocks = create_blocks(activities, celebrations) | ||
|
||
plt.figure(figsize=(10, 8)) | ||
show_activities(blocks, height=1, fontsize=5, show_today=True, title=os.path.split(args.pmcs_data)[1], | ||
show_weeks=args.show_weeks, startDate=args.start_date, endDate=args.end_date) | ||
|
||
add_legend(categoryColors, blocks, categoryGrouping, legend_location=legend_location) | ||
|
||
plt.savefig(args.output) | ||
|
||
|
||
def create_blocks(activities, celebrations): | ||
# | ||
# Convert those activities to a set of block descriptions | ||
# | ||
blocks = {} | ||
row = 1 | ||
for category in activities: | ||
blocks[category] = [] | ||
|
||
nrow = categoryNrow.get(category, 5) | ||
nrow, rot = (nrow, None) if isinstance(nrow, int) else nrow | ||
|
||
blocks[category] = [Nrow(nrow), Rotation(rot)] | ||
|
||
color = categoryColors.get(category) | ||
if color is None: | ||
print(f"No colour is defined for category {category}", file=sys.stderr) | ||
color = ("white", "red") | ||
color, border = (color, None) if isinstance(color, str) else color | ||
|
||
row += 1 | ||
|
||
for descrip in sorted(activities[category]): | ||
start = np.min([start for (code, start, due) in activities[category][descrip]]) | ||
due = np.max([due for (code, start, due) in activities[category][descrip]]) # noqa: E221,E272 | ||
|
||
if descrip in specials: | ||
nrow, rot, nadvance = specials[descrip] | ||
if nrow is not None: | ||
blocks[category].append(Nrow(nrow)) | ||
if rot is not None: | ||
blocks[category].append(Rotation(rot)) | ||
if nadvance is not None: | ||
blocks[category].append(AdvanceRow(nadvance)) | ||
|
||
if descrip[0] == '"' and descrip[-1] == '"': | ||
descrip = descrip[1:-1] | ||
|
||
blocks[category].append(Activity(descrip, start, due, color, border, | ||
wrappedDescrip=wrappedDescrip.get(descrip))) | ||
|
||
# | ||
# Order/group according to categoryGrouping[] | ||
# | ||
if categoryGrouping is None: | ||
grouping = [[cat] for cat in activities] | ||
else: | ||
grouping = categoryGrouping | ||
|
||
_blocks = [] | ||
for cats in grouping: | ||
sub = [] | ||
for cat in cats: | ||
for a in blocks[cat]: | ||
sub.append(a) | ||
|
||
_blocks.append(sub) | ||
|
||
blocks = _blocks | ||
# | ||
# Handle celebrations milestones now that we've ordered the blocks | ||
# | ||
Milestone.height = milestoneHeight | ||
Milestone.rotation = 0 | ||
|
||
milestones = [] | ||
for c in celebrations: | ||
name, start = c | ||
milestones.append(Milestone(name, start)) | ||
|
||
milestones = sorted(milestones, key=lambda a: a.t0) | ||
for i, ml in enumerate(milestones): | ||
ml.drow = i % nRowOfMilestones | ||
|
||
milestones.append(AdvanceRow((nRowOfMilestones - 1)*milestoneHeight)) | ||
|
||
blocks = [milestones] + blocks | ||
|
||
return blocks | ||
|
||
|
||
def process_milestones(milestones): | ||
# Process Summary Chart activities/milestones and celebrations milestones | ||
|
||
activities = {} | ||
celebrations = [] | ||
|
||
for ms in milestones: | ||
summarychart, code, start, due = ms.summarychart, ms.code, ms.start, ms.due | ||
|
||
celebrate = False | ||
if ms.summarychart: | ||
pass | ||
elif ms.celebrate: | ||
celebrate = ms.celebrate.lower() | ||
else: | ||
continue | ||
# | ||
# handle dates, either of which may have been omitted | ||
# | ||
if start is None: | ||
if due is None: # HACK | ||
print(f"{ms} has no date field; skipping", file=sys.stderr) | ||
continue | ||
else: | ||
start = due | ||
elif due is None: | ||
due = start | ||
# | ||
# Is it a celebrations milestone rather than an activity? | ||
# | ||
if celebrate in ("top", "y"): # it's a celebrations milestone | ||
if celebrate == "y": | ||
continue | ||
|
||
celebrations.append((ms.name, due)) | ||
continue | ||
|
||
if '.' not in summarychart: | ||
summarychart = f"{summarychart}.{summarychart}" | ||
|
||
category, descrip = summarychart.split(".") | ||
category = category.replace(' ', '_') | ||
|
||
if "," in descrip: | ||
descrip = f'"{descrip}"' | ||
|
||
if category not in activities: | ||
activities[category] = {} | ||
|
||
if descrip not in activities[category]: | ||
activities[category][descrip] = [] | ||
|
||
activities[category][descrip].append((code, start, due)) | ||
|
||
return activities, celebrations |
Oops, something went wrong.