Exemple #1
0
def _gen_machine_graph(start, end, machine_category,
        force_overwrite=False):
    """ Pie chart comparing machines usage. """
    filename = graphs.get_machine_graph_filename(start, end, machine_category)
    csv_filename = os.path.join(settings.GRAPH_ROOT, filename + '.csv')
    png_filename = os.path.join(settings.GRAPH_ROOT, filename + '.png')

    _check_directory_exists(csv_filename)
    _check_directory_exists(png_filename)

    if not settings.GRAPH_DEBUG or force_overwrite:
        if os.path.exists(csv_filename):
            if os.path.exists(png_filename):
                return

    machine_list = machine_category.machine_set.all()

    plt.subplots(figsize=(4, 4))

    data = []
    labels = []

    with open(csv_filename, 'wb') as csv_file:
        csv_writer = csv.writer(csv_file)
        for machine in machine_list.iterator():
            hours,jobs = usage.get_machine_usage(machine, start, end)
            if hours > 0:
                csv_writer.writerow([machine.name, hours, jobs])
                data.append(hours)
                labels.append(machine.name)

    plt.pie(data, labels=labels, autopct='%1.1f%%', shadow=True)

    del data
    del labels

    plt.tight_layout()
    plt.savefig(png_filename)
    plt.close()
Exemple #2
0
 def get_usage(self, start, end):
     from karaage.cache.usage import get_machine_usage
     return get_machine_usage(self, start, end)