Browse Source

started work on adding multi-dataset capability to DataEditor

master
phryk 8 months ago
parent
commit
68d16d2615
2 changed files with 82 additions and 40 deletions
  1. +66
    -29
      poobrains/svg/plot.py
  2. +16
    -11
      poobrains/themes/default/form/dataeditor.jinja

+ 66
- 29
poobrains/svg/plot.py View File

@@ -421,7 +421,7 @@ class Plot(base.SVG):

def dataset_griddable(self, dataset):

app.debugger.set_trace()
#app.debugger.set_trace()
valid_dtypes = [
int,
float
@@ -511,7 +511,7 @@ class Plot(base.SVG):
@locked_cached_property
def grid_x(self):

app.debugger.set_trace()
#app.debugger.set_trace()
if self.span_x == 0:
return [self.min_x]

@@ -650,12 +650,9 @@ class EditorNewSessionFieldset(poobrains.form.Fieldset):

session['editor-sessions'][handle] = {
'handle': handle,
'plot_kind': 'scatter',
'action': None,
'action_data': None,
'title': None,
'description': None,
'data': None,
'action_data': {},
'datasets': {},
}

return redirect(DataEditor.url(handle=handle, mode='full'))
@@ -663,7 +660,12 @@ class EditorNewSessionFieldset(poobrains.form.Fieldset):

class EditorLoadFieldset(poobrains.form.Fieldset):

title = "Add new dataset to session"

dataset = poobrains.form.fields.Select(choices=dataset_choices)
dataset_name = poobrains.form.fields.Text(label='Dataset name')
dataset_title = poobrains.form.fields.Text(label='Dataset title')
dataset_description = poobrains.form.fields.TextArea(label='Dataset description')
load_dataset = poobrains.form.Button(label='Load', type='submit')


@@ -674,14 +676,20 @@ class EditorLoadFieldset(poobrains.form.Fieldset):
super(EditorLoadFieldset, self).__init__(**kwargs)

self.editor_handle = editor_handle
action = session['editor-sessions'][self.editor_handle]['action']
editor_session = session['editor-sessions'][self.editor_handle]

if action.startswith('load.dynamic.'):
if editor_session['action'].startswith('load.dynamic.'):

dataset_name = action.split('.')[2]
dataset_name = editor_session['action'].split('.')[2]
self.fields['dataset'].value = '_%s' % dataset_name
self.fields['dataset'].readonly = True

self.fields['dataset_name'].value = editor_session['action_data']['dataset_name']
self.fields['dataset_name'].readonly = True

self.fields['dataset_description'].value = editor_session['action_data']['dataset_description']
self.fields['dataset_description'].readonly = True

if dataset_name in datasets:

dataset_class = datasets[dataset_name]
@@ -714,6 +722,11 @@ class EditorLoadFieldset(poobrains.form.Fieldset):
if submit == '%s.load_dataset' % self.name:

session['editor-sessions'][self.editor_handle]['action_data'] = {
'dataset_name': self.fields['dataset_name'].value,
'dataset_description': self.fields['dataset_description'].value
}

if dataset_name.startswith('_'):

dataset_name = dataset_name[1:]
@@ -723,16 +736,18 @@ class EditorLoadFieldset(poobrains.form.Fieldset):
session['editor-sessions'][instance.handle_string]['action'] = 'load.dynamic.%s' % dataset_name
self.summon_parameter_fieldset(datasets[dataset_name])
self.fields['dataset'].readonly = True
self.fields['dataset_name'].readonly = True
else: # directly loadable dataset

try:
dataset = StoredDataset.load(dataset_name)
dataset.permissions['read'].check(g.user)
instance.dataset = dataset
dataset.name = self.fields['dataset_name'].value
instance.datasets[dataset.name] = dataset
session['editor-sessions'][instance.handle_string]['action'] = None
session['editor-sessions'][instance.handle_string]['title'] = instance.dataset.title
session['editor-sessions'][instance.handle_string]['description'] = instance.dataset.description
session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
session['editor-sessions'][instance.handle_string]['datasets'][dataset.name]['title'] = dataset.title
session['editor-sessions'][instance.handle_string]['datasets'][dataset.name]['description'] = dataset.description
session['editor-sessions'][instance.handle_string]['datasets'][dataset.name]['data'] = dataset.data.to_dict()
except StoredDataset.DoesNotExist:
flash('Unknown stored dataset: %s' % dataset_name, 'error')

@@ -758,13 +773,19 @@ class EditorLoadFieldset(poobrains.form.Fieldset):

dataset = dataset_class()
dataset.fill(**param_values)
dataset.name = self.fields['dataset_name'].value
dataset.title = self.fields['dataset_title'].value
dataset.description = self.fields['dataset_description'].value

dataset.permissions['read'].check(g.user)
instance.dataset = dataset
instance.datasets[dataset.name] = dataset
session['editor-sessions'][instance.handle_string]['action'] = None
session['editor-sessions'][instance.handle_string]['title'] = instance.dataset.title
session['editor-sessions'][instance.handle_string]['description'] = instance.dataset.description
session['editor-sessions'][instance.handle_string]['data'] = instance.dataset.data.to_dict()
session['editor-sessions'][instance.handle_string]['datasets'][dataset.name] = {
'title': dataset.title,
'description': dataset.description,
'data': dataset.data.to_dict(),
'plot_kind': 'scatter',
}
del(self.fields['dynamic'])
self.fields['dataset'].readonly = False

@@ -780,7 +801,9 @@ class PlotKindFieldset(poobrains.form.Fieldset):
self.editor_handle = editor_handle
action = session['editor-sessions'][self.editor_handle]['action']

self.kind = poobrains.form.fields.Select(choices=[(kind, cls.__name__) for (kind, cls) in plot_kinds.items()], default=session['editor-sessions'][editor_handle]['plot_kind'])
k = next(iter(session['editor-sessions'][self.editor_handle]['datasets']))
default_plot_kind = session['editor-sessions'][self.editor_handle]['datasets'][k]['plot_kind'] # FIXME: Implement multiple plot modes within Plot
self.kind = poobrains.form.fields.Select(choices=[(kind, cls.__name__) for (kind, cls) in plot_kinds.items()], default=default_plot_kind)
self.apply = poobrains.form.Button(type='submit', label='Apply')


@@ -811,14 +834,23 @@ class DataEditor(poobrains.auth.ProtectedForm):

editor_session = session['editor-sessions'][self.handle_string]

self.dataset = Dataset()
self.dataset.name = self.handle_string
self.dataset.plot_kind = editor_session['plot_kind'] or 'scatter'
self.dataset.title = editor_session['title']
self.dataset.description = editor_session['description']
self.dataset.data = pandas.DataFrame.from_dict(editor_session['data'])
self.datasets = {}

for dataset_name in editor_session['datasets']:

if len(self.dataset.data):
dataset = Dataset()
dataset.name = dataset_name
dataset.plot_kind = editor_session['datasets'][dataset_name]['plot_kind'] or 'scatter'
dataset.title = editor_session['datasets'][dataset_name]['title']
dataset.description = editor_session['datasets'][dataset_name]['description']
dataset.data = pandas.DataFrame.from_dict(editor_session['datasets'][dataset_name]['data'])

self.datasets[dataset_name] = dataset

self.plot = Plot(datasets=list(self.datasets.values()))


if len(self.datasets):
self.plot_kind = PlotKindFieldset(self.handle_string)

if editor_session['action'] is None:
@@ -840,7 +872,7 @@ class DataEditor(poobrains.auth.ProtectedForm):

elif submit.startswith('load.'):
self.fields['load'].process(submit, self)
if len(self.dataset.data):
if len(self.datasets):
self.plot_kind = PlotKindFieldset(self.handle_string)
#session[self.handle_string] = self.data

@@ -848,8 +880,13 @@ class DataEditor(poobrains.auth.ProtectedForm):
self.fields['plot_kind'].process(submit, self)

elif submit == 'save_dataset':
stored_ds = self.dataset.save()
return redirect(stored_ds.url('edit'))
#stored_ds = self.dataset.save()
#return redirect(stored_ds.url('edit'))

for dataset in self.datasets.values():
if dataset.save():
flash('Saved dataset %s' % dataset.name)


elif submit == 'delete_session':
del(session['editor-sessions'][self.handle_string])


+ 16
- 11
poobrains/themes/default/form/dataeditor.jinja View File

@@ -1,17 +1,22 @@
{% extends 'form/form.jinja' %}

{% block fields %}
{% if content.dataset %}
{% if 'plot_kind' in content.fields %}
{{ content.fields['plot_kind'].render() }}
{% endif %}
<div class="dataeditor-plot">
{{ content.dataset.plot() }}
</div>
<details>
<summary>Data</summary>
<code>{{ content.dataset.data }}</code>
</details>
{% if content.datasets|length %}
{% if 'plot_kind' in content.fields %}
{{ content.fields['plot_kind'].render() }}
{% endif %}
<div class="dataeditor-plot">
{# content.dataset.plot() #}
FNORD
{{ content.plot.render('raw') }}
FNORD
</div>
{% for dataset in content.datasets.values() %}
<details>
<summary>{{ dataset.title }}</summary>
<code>{{ dataset.data }}</code>
</details>
{% endfor %}
{% endif %}

{{ content.render_fields() }}


Loading…
Cancel
Save