mistral-io-datasets/scripts/plot-single-job.py

78 lines
2.1 KiB
Python
Raw Normal View History

2020-08-18 13:55:37 +00:00
#!/usr/bin/env python3
import csv
import sys
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot
2020-08-18 14:26:29 +00:00
jobs = [sys.argv[1]]
prefix = sys.argv[2]
2020-08-18 13:55:37 +00:00
2020-08-18 14:26:29 +00:00
print("Plotting the job: " + str(jobs))
2020-08-18 13:55:37 +00:00
# Plot the timeseries
2020-08-18 14:26:29 +00:00
def plot(prefix, header, row):
2020-08-18 13:55:37 +00:00
x = { h : d for (h, d) in zip(header, row)}
jobid = x["jobid"]
del x["jobid"]
del x["coding_abs"]
del x["coding_abs_aggzeros"]
result = []
for k in x:
timeseries = x[k].split(":")
timeseries = [ float(x) for x in timeseries]
if sum(timeseries) == 0:
continue
timeseries = [ [k, x, s] for (s,x) in zip(timeseries, range(1, len(timeseries))) ]
result.extend(timeseries)
2020-08-18 14:46:05 +00:00
if len(result) == 0:
print("Empty job! Cannot plot!")
return
2020-08-18 13:55:37 +00:00
data = DataFrame(result, columns=["metrics", "segment", "value"])
groups = data.groupby(["metrics"])
metrics = DataFrame()
labels = []
for name, group in groups:
metrics[name] = [x[2] for x in group.values]
labels.append(name)
2020-08-18 14:46:05 +00:00
ax = metrics.plot(subplots=True, legend=False, sharex=True, grid = True, sharey=True, colormap='jet', marker='.', markersize=10, figsize=(8, 2 + 2 * len(labels)))
2020-08-18 13:55:37 +00:00
for (i, l) in zip(range(0, len(labels)), labels):
ax[i].set_ylabel(l)
pyplot.xlabel("Segment number")
2020-08-18 14:26:29 +00:00
pyplot.savefig(prefix + "timeseries" + jobid + ".png")
2020-08-18 13:55:37 +00:00
2020-08-18 14:46:05 +00:00
# Plot first 30 segments
if len(timeseries) <= 50:
return
2020-08-18 13:55:37 +00:00
ax = metrics.plot(subplots=True, legend=False, sharex=True, grid = True, sharey=True, colormap='jet', marker='.', markersize=10, xlim=(0,30))
for (i, l) in zip(range(0, len(labels)), labels):
ax[i].set_ylabel(l)
pyplot.xlabel("Segment number")
2020-08-18 14:26:29 +00:00
pyplot.savefig(prefix + "timeseries" + jobid + "-30.png")
2020-08-18 13:55:37 +00:00
2020-08-18 14:26:29 +00:00
### end plotting function
2020-08-18 13:55:37 +00:00
with open('job-io-datasets/datasets/job_codings.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
header = row
line_count += 1
continue
if not row[0].strip() in jobs:
continue
else:
2020-08-18 14:26:29 +00:00
plot(prefix, header, row)