def main():
    """
    Run all the plots in this category and time the caches.
    :return:
    """
    # run all the plots in this category
    config = cea.config.Configuration()
    from cea.plots.categories import list_categories
    from cea.plots.cache import NullPlotCache, PlotCache, MemoryPlotCache
    import time

    def plot_the_whole_category(cache):
        for category in list_categories():
            if category.label != label:
                # skip other categories
                continue
            print('category:', category.name, ':', category.label)
            for plot_class in category.plots:
                print('plot_class:', plot_class)
                parameters = {
                    k: config.get(v) for k, v in plot_class.expected_parameters.items()
                }
                plot = plot_class(config.project, parameters=parameters, cache=cache)
                assert plot.name, 'plot missing name: %s' % plot
                assert plot.category_name == category.name
                print('plot:', plot.name, '/', plot.id(), '/', plot.title)

                missing_input_files = plot.missing_input_files()
                if missing_input_files:
                    for locator_method, args in missing_input_files:
                        print('Input file not found: {}'.format(locator_method(*args)))
                else:
                    # plot the plot!
                    plot.plot()

    null_plot_cache = NullPlotCache()
    plot_cache = PlotCache(config.project)
    memory_plot_cache = MemoryPlotCache(config.project)
    # test plots with cache
    t0 = time.time()
    for i in range(3):
        plot_the_whole_category(plot_cache)
    time_with_cache = (time.time() - t0) / 3
    # test plots with memory cache
    t0 = time.time()
    for i in range(3):
        plot_the_whole_category(memory_plot_cache)
    time_with_memory_cache = (time.time() - t0) / 3
    # test plots without cache
    # t0 = time.time()
    # for i in range(3):
    #     plot_the_whole_category(null_plot_cache)
    # time_without_cache = (time.time() - t0) / 3
    # print('Average without cache: %.2f seconds' % time_without_cache)
    print('Average with cache: %.2f seconds' % time_with_cache)
    print('Average with memory cache: %.2f seconds' % time_with_memory_cache)
Example #2
0
                parameters = {
                    k: config.get(v)
                    for k, v in plot_class.expected_parameters.items()
                }
                plot = plot_class(config.project,
                                  parameters=parameters,
                                  cache=cache)
                assert plot.name, 'plot missing name: %s' % plot
                assert plot.category_name == category.name
                print('plot:', plot.name, '/', plot.id(), '/', plot.title)

                # plot the plot!
                plot.plot()

    null_plot_cache = NullPlotCache()
    plot_cache = PlotCache(config.project)

    # test plots with cache
    t0 = time.time()
    for i in range(3):
        plot_category(plot_cache)
    time_with_cache = (time.time() - t0) / 3

    # test plots without cache
    t0 = time.time()
    for i in range(3):
        plot_category(null_plot_cache)
    time_without_cache = (time.time() - t0) / 3

    print('Average without cache: %.2f seconds' % time_without_cache)
    print('Average with cache: %.2f seconds' % time_with_cache)