Skip to content

Instantly share code, notes, and snippets.

@davidbeijinho
Created October 21, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbeijinho/08aab3a8d40b2b09232c8e2b891f84ee to your computer and use it in GitHub Desktop.
Save davidbeijinho/08aab3a8d40b2b09232c8e2b891f84ee to your computer and use it in GitHub Desktop.
create chart
import os
import yaml
from os.path import join
def clean_list(ignore_list, base_list):
for ignored_element in ignore_list:
if ignored_element in base_list:
base_list.remove(ignored_element)
return base_list
def calculate_time(schedule):
pieces = schedule.split()
total = int(pieces[1]) + (int(pieces[0])/60)
return total
def add_record (schedule, name, records):
records.append([ name, calculate_time(schedule) ])
return records
def get_schedules():
ignore_files = ["sitespeed-cronjob-patch.yaml", "upstream.yaml"]
schedules = []
for root, dirs, files in os.walk('./'):
files = clean_list(ignore_files, files)
for name in files:
file_name, file_extension = os.path.splitext(join(root, name))
if file_extension == '.yaml':
with open(join(root, name), 'r') as stream:
data_loaded = yaml.safe_load(stream)
if data_loaded.get('kind') == "CronJob":
schedules = add_record(data_loaded["spec"]["schedule"], name, schedules)
return schedules
def print_chart(values):
import pandas as pd
import plotly.express as px
df = pd.DataFrame(values,columns=['FileName','Time']).sort_values("Time")
fig = px.bar(df, y = 'FileName', x = 'Time')
fig.show()
times = get_schedules()
print_chart(times)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment