Commit 2f97f4e3 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

Merge branch 'fix_jinja2_template_plotter' into 'dev'

Add jinja template plotter - generate plotter

See merge request !16
parents 57b8dd0d dca17644
Pipeline #23578 passed with stages
in 51 minutes
# You may import any python packages that will be available in the environment you will run this plotter in
# Environments can change based on the experiment's settings
{% for ref, lib in uses.uses.items() %}# Library "{{ lib }}" is available under "{{ ref }}"
{% endfor %}
# Makes sure we won't require an X11 connection
import matplotlib
matplotlib.use('Agg')
import numpy
import itertools
class Plotter(baselib.Plotter):
{% if uses.parameters %}
# do initial setup work with the given parameters for the plotter
def setup(self, parameters):
super(Plotter, self).setup(parameters)
# Parameters available:
{% for p_name, param in uses.parameters.items() %}# Parameter "{{ p_name }}" with type "{{ param.type }}"
{% endfor %}
# get a parameter like:
# param1_value = parameters.get('param_1', self.param1_default)
return True
{% endif %}
# this will be called each time the sync'd input has more data available to be processed
def process(self, inputs):
fig, ax = super(Plotter, self).prepare_canvas()
# apply at the beginning of this function or before returning for needed modifications
super(Plotter, self).apply_parameters(ax)
# ax.set_title(self.title, fontdict={'fontsize':self.title_fontsize})
# ax.set_xlabel(self.xlabel, fontdict={'fontsize':self.axis_fontsize})
# ax.set_ylabel(self.ylabel, fontdict={'fontsize':self.axis_fontsize})
# ax.set_xlim((self.xlim_left,self.xlim_right))
# ax.set_ylim((self.ylim_bottom,self.ylim_top))
return super(Plotter, self).encode_figure(fig)
......@@ -101,11 +101,33 @@ def generate_algorithm(contents):
return template.render(contents=contents)
def generate_plotter(uses):
"""Generates a valid BEAT plotter from our stored template
Parameters:
contents (:py:class:`dict`): The plotter's JSON metadata
Returns:
str: The rendered template as a string
"""
uses = uses or {}
template = ENV.get_template('plotter.jinja2')
return template.render(uses=uses)
TEMPLATE_FUNCTION = dict(
databases=generate_database,
libraries=generate_library,
algorithms=generate_algorithm,
plotters=generate_plotter,
)
"""Functions for template instantiation within beat.editor"""
class PythonFileAlreadyExistsError(Exception):
......
......@@ -11,6 +11,7 @@ import {
generateDatabaseTemplate,
generateAlgorithmTemplate,
generateLibraryTemplate,
generatePlotterTemplate,
} from '@helpers/api';
import { copyObj } from '@helpers';
import type { BeatEntity, BeatObject } from '@helpers/beat';
......@@ -71,6 +72,11 @@ export default class EntityTemplateGenerationButton extends React.Component<Prop
uses = copyObj(this.props.data.contents.uses);
res = await generateLibraryTemplate(this.props.data.name, confirm, uses);
break;
case('plotter'):
// find the used libraries and parameters
uses = copyObj(this.props.data.contents.parameters);
res = await generatePlotterTemplate(this.props.data.name, confirm, this.props.data.contents);
break;
default:
throw new Error(`Cannot generate template for entity "${ this.props.entity }"`);
}
......
......@@ -98,12 +98,10 @@ export class PlotterEditor extends React.Component<Props, State> {
>
Save Changes (Changes are <ValidSchemaBadge entity='plotter' obj={this.props.data} />)
</Button>
{/*
<TemplateButton
data={this.props.data}
entity={'plotter'}
/>
*/}
</div>
<Form>
<FormGroup tag='fieldset'>
......
......@@ -108,3 +108,7 @@ export const generateAlgorithmTemplate = async (name: string, confirm: boolean,
export const generateLibraryTemplate = async (name: string, confirm: boolean, uses: StringObject) => {
return generateTemplate('libraries', {name, uses, confirm});
};
export const generatePlotterTemplate = async (name: string, confirm: boolean, uses: StringObject) => {
return generateTemplate('plotters', {name, uses, confirm});
};
......@@ -108,6 +108,11 @@ Installation Steps
$ conda activate beatedit
$ buildout
#. Note for development mode: Add the line ``dependent-scripts = true`` then use the ``buildout`` command to ensure to generate all the executables in the ``bin/``
folder even ``beat`` for ``beat.editor``: ::
$ buildout
#. In ``bin/`` you should several new executables for the project. The Python setup part is done.
#. Go into the root folder for the Javascript and install the dependencies via NPM: ::
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment