-
Notifications
You must be signed in to change notification settings - Fork 10
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 #1 from robsyme/patch-1
Update pipeline-gantt.py
- Loading branch information
Showing
13 changed files
with
88 additions
and
56 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 |
---|---|---|
@@ -1 +1 @@ | ||
repository_type: pipeline | ||
repository_type: pipeline |
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
4Bi5xBK6E2Nbhj | ||
4LWT4uaXDaGcDY | ||
38QXz4OfQDpwOV | ||
2lXd1j7OwZVfxh | ||
2lXd1j7OwZVfxh |
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 |
---|---|---|
@@ -1,61 +1,90 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import tarfile | ||
from datetime import datetime | ||
from typing import IO | ||
from pathlib import Path | ||
|
||
import click | ||
import pandas as pd | ||
import plotly.express as px | ||
|
||
|
||
def extract_instance(fusion_logs: str, lines: IO) -> str: | ||
for i, line in enumerate(lines): | ||
try: | ||
log = json.loads(line) | ||
if 'instance-id' in log: | ||
return log['instance-id'] | ||
except json.JSONDecodeError: | ||
print(f"WARN: invalid JSON at '{fusion_logs}' line {i}") | ||
return "" | ||
def extract_instance(fusion_logs: Path) -> str: | ||
with fusion_logs.open() as file: | ||
for line_number, line in enumerate(file, start=1): | ||
try: | ||
log = json.loads(line) | ||
if "instance-id" in log: | ||
return log["instance-id"] | ||
except json.JSONDecodeError: | ||
print(f"WARN: invalid JSON at '{fusion_logs}' line {line_number}") | ||
return "" | ||
|
||
|
||
@click.command() | ||
@click.option('--title', default='Pipeline GANTT', help='Plot title.') | ||
@click.option('--input-file', type=click.Path(), help='The pipeline dump tar.gz input file.') | ||
@click.option('--output-file', type=click.Path(), help='The HTML output file') | ||
def build_gantt(title: str, input_file: str, output_file: str): | ||
@click.option("--title", default="Pipeline GANTT", help="Plot title.") | ||
@click.option( | ||
"--input-dir", type=click.Path(), help="The pipeline dump tar.gz input file." | ||
) | ||
@click.option("--output-file", type=click.Path(), help="The HTML output file") | ||
def build_gantt(title: str, input_dir: str, output_file: str): | ||
tasks = [] | ||
instance_ids = {} | ||
|
||
tar = tarfile.open(input_file, "r:gz") | ||
for member in tar.getmembers(): | ||
if member.name == "workflow-tasks.json": | ||
tasks = json.load(tar.extractfile(member)) | ||
if member.name.endswith(".fusion.log"): | ||
_, task_id, _ = member.name.split('/') | ||
instance_id = extract_instance(member.name, tar.extractfile(member)) | ||
instance_ids[int(task_id)] = instance_id | ||
for path in Path(input_dir).glob("workflow-tasks.json"): | ||
with path.open() as json_file: | ||
tasks = json.load(json_file) | ||
for path in Path(input_dir).glob("**/.fusion.log"): | ||
task_id = int(path.parent.name) | ||
instance_id = extract_instance(path) | ||
instance_ids[task_id] = instance_id | ||
|
||
for t in tasks: | ||
t['instanceId'] = instance_ids.get(t['taskId'], "unknow") | ||
|
||
data = [{k: v for k, v in t.items() if k in ['taskId', 'name', 'start', 'complete', 'memory', 'cpus', 'machineType', 'instanceId']} for t in tasks] | ||
df = pd.DataFrame({ | ||
'id': f"T{d['taskId']}", | ||
'name': d['name'], | ||
'size': f"{d['cpus']}c_{d['memory'] / 1024 ** 3:.0f}GB", | ||
'start': datetime.strptime(d['start'], '%Y-%m-%dT%H:%M:%SZ'), | ||
'complete': datetime.strptime(d['complete'], '%Y-%m-%dT%H:%M:%SZ'), | ||
'instance': f"{d['instanceId']} ({d['machineType']})" | ||
} | ||
for d in data | ||
) | ||
|
||
fig = px.timeline(df, title=title, x_start="start", x_end="complete", y="id", color="instance", text="name", pattern_shape="size") | ||
t["instanceId"] = instance_ids.get(t["taskId"], "unknow") | ||
|
||
data = [ | ||
{ | ||
k: v | ||
for k, v in t.items() | ||
if k | ||
in [ | ||
"taskId", | ||
"name", | ||
"start", | ||
"complete", | ||
"memory", | ||
"cpus", | ||
"machineType", | ||
"instanceId", | ||
] | ||
} | ||
for t in tasks | ||
] | ||
df = pd.DataFrame( | ||
{ | ||
"id": f"T{d['taskId']}", | ||
"name": d["name"], | ||
"size": f"{d['cpus']}c_{d['memory'] / 1024 ** 3:.0f}GB", | ||
"start": datetime.strptime(d["start"], "%Y-%m-%dT%H:%M:%SZ"), | ||
"complete": datetime.strptime(d["complete"], "%Y-%m-%dT%H:%M:%SZ"), | ||
"instance": f"{d['instanceId']} ({d['machineType']})", | ||
} | ||
for d in data | ||
) | ||
|
||
fig = px.timeline( | ||
df, | ||
title=title, | ||
x_start="start", | ||
x_end="complete", | ||
y="id", | ||
color="instance", | ||
text="name", | ||
pattern_shape="size", | ||
) | ||
fig.write_html(output_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
build_gantt() |
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 |
---|---|---|
|
@@ -52,4 +52,4 @@ process { | |
] | ||
} | ||
|
||
} | ||
} |
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
5 changes: 4 additions & 1 deletion
5
modules/nf-core/custom/dumpsoftwareversions/templates/dumpsoftwareversions.py
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
reports: | ||
multiqc_report.html: | ||
display: "MultiQC HTML report" | ||
display: "MultiQC HTML report" |