From f8d54a3bf5981684cdf0a692d1d1feae6765fd0c Mon Sep 17 00:00:00 2001 From: Steffen Hauf <haufs@max-exfl015.desy.de> Date: Fri, 8 Jun 2018 13:35:58 +0200 Subject: [PATCH] Clean outdated files --- cal_to_zmq/Untitled.ipynb | 244 -------------------------------------- htmlform.py | 210 -------------------------------- 2 files changed, 454 deletions(-) delete mode 100644 cal_to_zmq/Untitled.ipynb delete mode 100644 htmlform.py diff --git a/cal_to_zmq/Untitled.ipynb b/cal_to_zmq/Untitled.ipynb deleted file mode 100644 index 9c5c115c1..000000000 --- a/cal_to_zmq/Untitled.ipynb +++ /dev/null @@ -1,244 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import zmq\n", - "import h5py\n", - "import os" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def writeLocalH5(self, localpath, c):\n", - "\n", - " folder = '{}/{}'.format(\n", - " localpath,\n", - " c['calibration_constant']['device_type_name'])\n", - "\n", - " fname = '{}/{}.h5'.format(\n", - " folder, c['calibration_constant_version']['begin_at'])\n", - "\n", - "\n", - " if not os.path.exists(folder):\n", - " os.makedirs(folder)\n", - " if not os.path.exists(fname):\n", - " f = h5py.File(fname, 'w')\n", - " else:\n", - " f = h5py.File(fname)\n", - "\n", - " baseKey = '/{}/{}'.format(\n", - " c['calibration_constant_version']['device_name'],\n", - " c['calibration_constant']['calibration_name'])\n", - "\n", - " index = 0\n", - "\n", - " while '{}/{}'.format(baseKey, index) in f:\n", - " index += 1\n", - "\n", - " baseKey = '{}/{}'.format(baseKey, index)\n", - " arr = c[\"data\"]\n", - "\n", - " self.currentH5File[baseKey + '/data'] = arr\n", - "\n", - " detcod = c['detector_condition']\n", - " if detcod is not None:\n", - " parms = None\n", - " if 'parameters' in detcod:\n", - " parms = detcod['parameters']\n", - " if parms is not None:\n", - " for condition in parms:\n", - " pname = condition['parameter_name']\n", - " for k in condition.keys():\n", - " if k != 'parameter_name':\n", - " hk = '{}/condition/{}/{}'.format(baseKey,\n", - " pname, k)\n", - " f[hk] = condition[k] \n", - "\n", - " f.close()\n", - "\n", - " return index, baseKey\n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - "\n", - "\n", - "def inject_constant(constant, tmp_path=\"\"):\n", - "# create a temporty h5 file first. We then send this file\n", - " pass\n" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "port=1234\n", - "context = zmq.Context()\n", - "socket = context.socket(zmq.REQ)\n", - "socket.connect(\"tcp://131.169.212.99:{:d}\".format(port))" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'success': True}\n" - ] - } - ], - "source": [ - "socket.send_pyobj({'foo': 'bar'})\n", - "reply = socket.recv_pyobj()\n", - "print(reply)" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'description': 'Foo', 'value': 0.0, 'parameter_name': 'Bar', 'flg_available': True, 'lower_deviation_value': 1.0, 'flg_logarithmic': False, 'upper_deviation_value': 1.0}\n" - ] - } - ], - "source": [ - "testOp = OperatingCondition()\n", - "testOp.description = \"Foo\"\n", - "testOp.value = 0\n", - "testOp.lower_deviation_value = 1\n", - "testOp.upper_deviation_value = 1\n", - "testOp.parameter_name = \"Bar\"\n", - "print(testOp.to_dict())" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Foo'" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "testOp.description" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import time\n", - "from datetime import datetime" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "t = time.time()" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'2018-01-16T15:38:58.824210'" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "datetime.now().isoformat()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.4.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/htmlform.py b/htmlform.py deleted file mode 100644 index e60719be5..000000000 --- a/htmlform.py +++ /dev/null @@ -1,210 +0,0 @@ -import htmlgen - - -class Input(htmlgen.Element): - type = htmlgen.html_attribute('type', default='text') - name = htmlgen.html_attribute('name') - value = htmlgen.html_attribute('value') - - def __init__(self, type, name=None, value=None): - super().__init__("input") - self.type = type - if name is not None: - self.name = name - if value is not None: - self.value = value - -class Checkbox(Input): - checked = htmlgen.boolean_html_attribute('checked') - - def __init__(self, name=None, checked=False): - super().__init__(type="checkbox", name=name) - self.checked=checked - -class WrapperDiv(htmlgen.Division): - def __init__(self, *children, css_classes=None, id=None): - super().__init__() - self.extend(children) - if css_classes: - self.add_css_classes(*css_classes) - if id is not None: - self.id = id - -py_type_to_html_input_type = { - str: 'text', - int: 'number', - float: 'number', - list: 'text', -} - -def make_input_element(var): - if var.type is bool: - input_elm = Checkbox(var.name, var.value) - else: - input_elm = Input(py_type_to_html_input_type[var.type], var.name, - str(var.value)) - if var.type is float: - input_elm.set_attribute('step', 'any') - - return input_elm - - -def build_page(config): - doc = htmlgen.Document(title="European XFEL Web Calibration") - - doc.add_stylesheets("/static/cal_styles.css", "https://fonts.googleapis.com/css?family=Aldrich") - - doc.add_scripts("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", - "https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js", - "/static/web_cal.js") - - - - class Detail(htmlgen.Element): - def __init__(self): - super().__init__("div") - self.add_css_classes("hidden_details") - - def generate_children(self): - for detector, run_types in config.items(): - for run_type, characterizations in run_types.items(): - for characterization, notebook in characterizations.items(): - form_div = build_form(notebook["parms"], notebook["name"], notebook["path"]) - form_div.set_attribute("id", "{}_{}_{}_detail".format(detector, run_type, characterization)) - yield form_div - - class Menu(htmlgen.Element): - def __init__(self): - super().__init__("ul") - self.add_css_classes('mainmenu') - - def generate_children(self): - for detector, run_types in config.items(): - det_item = htmlgen.ListItem(detector) - det_item.add_css_classes('mainmenu') - yield det_item - - for run_type, characterizations in run_types.items(): - run_type_item = htmlgen.ListItem(run_type) - run_type_item.add_css_classes('mainmenu', 'runtypemenu') - yield run_type_item - for characterization, notebook in characterizations.items(): - char_item = htmlgen.ListItem(characterization) - char_item.add_css_classes('mainmenu', 'runtypemenu', 'notebookmenuitem') - char_item.set_attribute("draggable", "true") - char_item.set_attribute("ondragstart", "drag(event)") - char_item.set_attribute("id", "{}_{}_{}".format(detector, run_type, characterization)) - - yield char_item - submit = Input('submit') - submit.id = 'submit-button' - submit.set_attribute('value', 'Run jobs') - submit.set_attribute('onClick', 'run_jobs()') - yield WrapperDiv(submit, id='submit-div') - - container = htmlgen.Division() - container.append(Detail()) - container.append(Menu()) - - pipeline = htmlgen.Division() - pipeline.add_css_classes('pipelinearea') - ser_execution_block = htmlgen.Division() - ser_execution_block.add_css_classes('serexecutionblock') - - par_execution_block = htmlgen.Division() - par_execution_block.add_css_classes('parexecutionblock') - par_execution_block.set_attribute("ondrop", "drop(event)") - par_execution_block.set_attribute("ondragover", "allowDrop(event)") - - ser_execution_block.append(par_execution_block) - pipeline.append(ser_execution_block) - - container.append(pipeline) - - doc.append_body(container) - return doc - - -def build_form(parameters, nbname, nbpath): - - class MyForm(htmlgen.Element): - action = htmlgen.html_attribute('action') - - def __init__(self): - super().__init__("form") - self.action = '/submit' - self.set_attribute('method', 'post') - - def generate_children(self): - - class InlineVar: - type = None - value = None - name = None - - - name = "NBNAME" - namediv = WrapperDiv(name, css_classes=['field_name', 'hidden']) - inbname = InlineVar() - inbname.type = str - inbname.value = nbpath - inbname.name = "nbname" - input_elm = make_input_element(inbname) - yield WrapperDiv(namediv, input_elm, css_classes=['form_field', 'hidden']) - - name = "Parallel runs" - namediv = WrapperDiv(name, css_classes=['field_name']) - runs = InlineVar() - runs.type = str - runs.value = "" - runs.name = name - input_elm = make_input_element(runs) - yield WrapperDiv(namediv, input_elm, css_classes=['form_field']) - - name = "Parallel modules" - namediv = WrapperDiv(name, css_classes=['field_name']) - modules = InlineVar() - modules.type = str - modules.value = "range(0,16)" - modules.name = name - input_elm = make_input_element(modules) - yield WrapperDiv(namediv, input_elm, css_classes=['form_field']) - - - yield htmlgen.Element("hr") - - for v in parameters: - name = v.metadata.get('display_name', v.name) - if v.type is bool: - namediv = WrapperDiv(name, css_classes=['field_name', 'field_name_bool']) - else: - namediv = WrapperDiv(name, css_classes=['field_name']) - input_elm = make_input_element(v) - yield WrapperDiv(namediv, input_elm, css_classes=['form_field']) - - #submit = Input('submit') - #submit.id = 'submit-button' - #submit.set_attribute('value', 'Run notebook') - #submit.add_css_classes('btn', 'btn-success') - #yield WrapperDiv(submit, id='submit-div') - - container = htmlgen.Division() - container.add_css_classes("form_container") - - notch_left = htmlgen.Division() - notch_left.add_css_classes("form_notch_left") - container.append(notch_left) - - content = htmlgen.Division() - content.add_css_classes("form_content") - - h3 = htmlgen.Heading(3, htmlgen.Emphasis(nbname)) - content.append(h3) - content.append(MyForm()) - container.append(content) - - notch_right = htmlgen.Division() - notch_right.add_css_classes("form_notch_right") - container.append(notch_right) - - return container \ No newline at end of file -- GitLab