2021-03-24 21:46:51 +00:00
|
|
|
from abc import ABC
|
2020-04-26 13:17:03 +00:00
|
|
|
from owrx.modes import Modes
|
2020-03-29 19:40:29 +00:00
|
|
|
from owrx.config import Config
|
2021-03-24 21:46:51 +00:00
|
|
|
from owrx.form.validator import Validator
|
2021-02-08 19:30:12 +00:00
|
|
|
from owrx.form.converter import Converter, NullConverter, IntConverter, FloatConverter, EnumConverter
|
2021-02-07 20:36:08 +00:00
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
class Input(ABC):
|
2021-03-24 21:46:51 +00:00
|
|
|
def __init__(self, id, label, infotext=None, converter: Converter = None, validator: Validator = None, disabled=False, removable=False):
|
2020-03-29 18:14:34 +00:00
|
|
|
self.id = id
|
|
|
|
self.label = label
|
|
|
|
self.infotext = infotext
|
2021-02-07 20:36:08 +00:00
|
|
|
self.converter = self.defaultConverter() if converter is None else converter
|
2021-03-24 21:46:51 +00:00
|
|
|
self.validator = validator
|
2021-02-22 22:49:28 +00:00
|
|
|
self.disabled = disabled
|
|
|
|
self.removable = removable
|
|
|
|
|
|
|
|
def setDisabled(self, disabled=True):
|
|
|
|
self.disabled = disabled
|
|
|
|
|
|
|
|
def setRemovable(self, removable=True):
|
|
|
|
self.removable = removable
|
2021-02-07 20:36:08 +00:00
|
|
|
|
|
|
|
def defaultConverter(self):
|
|
|
|
return NullConverter()
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
def bootstrap_decorate(self, input):
|
|
|
|
return """
|
2021-02-22 22:49:28 +00:00
|
|
|
<div class="form-group row" data-field="{id}">
|
2020-03-29 18:14:34 +00:00
|
|
|
<label class="col-form-label col-form-label-sm col-3" for="{id}">{label}</label>
|
2021-02-22 22:49:28 +00:00
|
|
|
<div class="col-9 p-0 removable-group {removable}">
|
2021-02-22 22:52:57 +00:00
|
|
|
<div class="removable-item">
|
2021-02-22 22:49:28 +00:00
|
|
|
{input}
|
|
|
|
{infotext}
|
|
|
|
</div>
|
|
|
|
{removebutton}
|
2020-03-29 18:14:34 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
""".format(
|
2021-02-22 22:49:28 +00:00
|
|
|
id=self.id,
|
|
|
|
label=self.label,
|
|
|
|
input=input,
|
2021-03-24 21:46:51 +00:00
|
|
|
infotext="<small>{text}</small>".format(text=self.infotext) if self.infotext else "",
|
2021-02-22 22:49:28 +00:00
|
|
|
removable="removable" if self.removable else "",
|
2021-03-03 22:25:00 +00:00
|
|
|
removebutton='<button type="button" class="btn btn-sm btn-danger option-remove-button">Remove</button>'
|
2021-02-22 22:49:28 +00:00
|
|
|
if self.removable
|
|
|
|
else "",
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_classes(self, error):
|
|
|
|
classes = ["form-control", "form-control-sm"]
|
|
|
|
if error:
|
|
|
|
classes.append("is-invalid")
|
|
|
|
return " ".join(classes)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_properties(self, value, error):
|
2021-02-22 22:49:28 +00:00
|
|
|
props = {
|
2021-03-24 21:46:51 +00:00
|
|
|
"class": self.input_classes(error),
|
2021-02-22 22:49:28 +00:00
|
|
|
"id": self.id,
|
|
|
|
"name": self.id,
|
|
|
|
"placeholder": self.label,
|
|
|
|
"value": value,
|
|
|
|
}
|
|
|
|
if self.disabled:
|
|
|
|
props["disabled"] = "disabled"
|
|
|
|
return props
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input_properties(self, value, error):
|
|
|
|
return " ".join('{}="{}"'.format(prop, value) for prop, value in self.input_properties(value, error).items())
|
2021-02-22 22:49:28 +00:00
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_errors(self, errors):
|
|
|
|
return "".join("""<div class="invalid-feedback">{msg}</div>""".format(msg=e) for e in errors)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
|
|
|
return "<input {properties} />{errors}".format(
|
|
|
|
properties=self.render_input_properties(value, errors), errors=self.render_errors(errors)
|
|
|
|
)
|
|
|
|
|
|
|
|
def render(self, config, errors):
|
2021-02-07 22:15:57 +00:00
|
|
|
value = config[self.id] if self.id in config else None
|
2021-03-24 21:46:51 +00:00
|
|
|
error = errors[self.id] if self.id in errors else []
|
|
|
|
return self.bootstrap_decorate(self.render_input(self.converter.convert_to_form(value), error))
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
def parse(self, data):
|
2021-03-24 21:46:51 +00:00
|
|
|
value = self.converter.convert_from_form(data[self.id][0])
|
|
|
|
if self.validator is not None:
|
|
|
|
self.validator.validate(self.id, value)
|
|
|
|
return {self.id: value} if self.id in data else {}
|
2020-03-29 18:14:34 +00:00
|
|
|
|
2021-02-22 22:49:28 +00:00
|
|
|
def getLabel(self):
|
|
|
|
return self.label
|
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
class TextInput(Input):
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_properties(self, value, errors):
|
|
|
|
props = super().input_properties(value, errors)
|
2021-02-22 22:49:28 +00:00
|
|
|
props["type"] = "text"
|
|
|
|
return props
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NumberInput(Input):
|
2021-02-07 20:36:08 +00:00
|
|
|
def __init__(self, id, label, infotext=None, append="", converter: Converter = None):
|
|
|
|
super().__init__(id, label, infotext, converter=converter)
|
2020-03-29 18:49:37 +00:00
|
|
|
self.step = None
|
2021-02-07 17:21:57 +00:00
|
|
|
self.append = append
|
2020-03-29 18:49:37 +00:00
|
|
|
|
2021-02-07 20:36:08 +00:00
|
|
|
def defaultConverter(self):
|
|
|
|
return IntConverter()
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_properties(self, value, errors):
|
|
|
|
props = super().input_properties(value, errors)
|
2021-02-22 22:49:28 +00:00
|
|
|
props["type"] = "number"
|
|
|
|
if self.step:
|
|
|
|
props["step"] = self.step
|
|
|
|
return props
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
2021-02-07 17:21:57 +00:00
|
|
|
if self.append:
|
|
|
|
append = """
|
|
|
|
<div class="input-group-append">
|
|
|
|
<span class="input-group-text">{append}</span>
|
|
|
|
</div>
|
|
|
|
""".format(
|
|
|
|
append=self.append
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
append = ""
|
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
return """
|
2021-02-07 17:21:57 +00:00
|
|
|
<div class="input-group input-group-sm">
|
2021-02-22 22:49:28 +00:00
|
|
|
{input}
|
2021-02-07 17:21:57 +00:00
|
|
|
{append}
|
|
|
|
</div>
|
2020-03-29 18:14:34 +00:00
|
|
|
""".format(
|
2021-03-24 21:46:51 +00:00
|
|
|
input=super().render_input(value, errors),
|
2021-02-07 17:21:57 +00:00
|
|
|
append=append,
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
2021-02-07 20:36:08 +00:00
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
class FloatInput(NumberInput):
|
2021-02-07 20:36:08 +00:00
|
|
|
def __init__(self, id, label, infotext=None, converter: Converter = None):
|
|
|
|
super().__init__(id, label, infotext, converter=converter)
|
2020-03-29 18:49:37 +00:00
|
|
|
self.step = "any"
|
|
|
|
|
2021-02-07 20:36:08 +00:00
|
|
|
def defaultConverter(self):
|
|
|
|
return FloatConverter()
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LocationInput(Input):
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
|
|
|
# TODO display errors
|
2020-03-29 18:49:37 +00:00
|
|
|
return """
|
|
|
|
<div class="row">
|
|
|
|
{inputs}
|
|
|
|
</div>
|
2020-03-29 19:40:29 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col map-input" data-key="{key}" for="{id}"></div>
|
|
|
|
</div>
|
2020-03-29 18:49:37 +00:00
|
|
|
""".format(
|
2020-03-29 19:40:29 +00:00
|
|
|
id=self.id,
|
2021-03-24 21:46:51 +00:00
|
|
|
inputs="".join(self.render_sub_input(value, id, errors) for id in ["lat", "lon"]),
|
2020-03-29 19:40:29 +00:00
|
|
|
key=Config.get()["google_maps_api_key"],
|
2020-03-29 18:49:37 +00:00
|
|
|
)
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_sub_input(self, value, id, errors):
|
2020-03-29 18:49:37 +00:00
|
|
|
return """
|
|
|
|
<div class="col">
|
2021-02-22 22:49:28 +00:00
|
|
|
<input type="number" class="{classes}" id="{id}" name="{id}" placeholder="{label}" value="{value}"
|
|
|
|
step="any" {disabled}>
|
2020-03-29 18:49:37 +00:00
|
|
|
</div>
|
|
|
|
""".format(
|
|
|
|
id="{0}-{1}".format(self.id, id),
|
|
|
|
label=self.label,
|
2021-03-24 21:46:51 +00:00
|
|
|
classes=self.input_classes(errors),
|
2020-03-29 18:49:37 +00:00
|
|
|
value=value[id],
|
2021-02-22 22:49:28 +00:00
|
|
|
disabled="disabled" if self.disabled else "",
|
2020-03-29 18:49:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def parse(self, data):
|
2021-01-20 16:01:46 +00:00
|
|
|
return {self.id: {k: float(data["{0}-{1}".format(self.id, k)][0]) for k in ["lat", "lon"]}}
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TextAreaInput(Input):
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
2020-03-29 18:14:34 +00:00
|
|
|
return """
|
2021-02-22 22:49:28 +00:00
|
|
|
<textarea class="{classes}" id="{id}" name="{id}" style="height:200px;" {disabled}>{value}</textarea>
|
2021-03-24 21:46:51 +00:00
|
|
|
{errors}
|
2020-03-29 18:14:34 +00:00
|
|
|
""".format(
|
2021-03-24 21:46:51 +00:00
|
|
|
id=self.id,
|
|
|
|
classes=self.input_classes(errors),
|
|
|
|
value=value,
|
|
|
|
disabled="disabled" if self.disabled else "",
|
|
|
|
errors=self.render_errors(errors),
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CheckboxInput(Input):
|
2021-02-21 23:57:02 +00:00
|
|
|
def __init__(self, id, checkboxText, infotext=None, converter: Converter = None):
|
|
|
|
super().__init__(id, "", infotext=infotext, converter=converter)
|
2020-03-29 18:14:34 +00:00
|
|
|
self.checkboxText = checkboxText
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
2020-03-29 18:14:34 +00:00
|
|
|
return """
|
2021-02-22 22:49:28 +00:00
|
|
|
<div class="{classes}">
|
2021-02-22 23:11:51 +00:00
|
|
|
<input type="hidden" name="{id}" value="0" {disabled}>
|
|
|
|
<input class="form-check-input" type="checkbox" id="{id}" name="{id}" value="1" {checked} {disabled}>
|
2021-02-22 22:49:28 +00:00
|
|
|
<label class="form-check-label" for="{id}">
|
|
|
|
{checkboxText}
|
|
|
|
</label>
|
2021-03-24 21:46:51 +00:00
|
|
|
{errors}
|
2021-02-22 22:49:28 +00:00
|
|
|
</div>
|
2020-03-29 18:14:34 +00:00
|
|
|
""".format(
|
|
|
|
id=self.id,
|
2021-03-24 21:46:51 +00:00
|
|
|
classes=self.input_classes(errors),
|
2020-03-29 18:14:34 +00:00
|
|
|
checked="checked" if value else "",
|
2021-02-22 22:49:28 +00:00
|
|
|
disabled="disabled" if self.disabled else "",
|
2020-03-29 18:14:34 +00:00
|
|
|
checkboxText=self.checkboxText,
|
2021-03-24 21:46:51 +00:00
|
|
|
errors=self.render_errors(errors)
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_classes(self, error):
|
|
|
|
classes = ["form-check", "form-control-sm"]
|
|
|
|
if error:
|
|
|
|
classes.append("is-invalid")
|
|
|
|
return " ".join(classes)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
def parse(self, data):
|
2021-02-22 23:11:51 +00:00
|
|
|
if self.id in data:
|
|
|
|
return {self.id: self.converter.convert_from_form("1" in data[self.id])}
|
|
|
|
return {}
|
2020-03-29 18:14:34 +00:00
|
|
|
|
2021-02-22 22:49:28 +00:00
|
|
|
def getLabel(self):
|
|
|
|
return self.checkboxText
|
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
class Option(object):
|
|
|
|
# used for both MultiCheckboxInput and DropdownInput
|
|
|
|
def __init__(self, value, text):
|
|
|
|
self.value = value
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
|
|
|
|
class MultiCheckboxInput(Input):
|
|
|
|
def __init__(self, id, label, options, infotext=None):
|
|
|
|
super().__init__(id, label, infotext=infotext)
|
|
|
|
self.options = options
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
|
|
|
# TODO display errors
|
|
|
|
return "".join(self.render_checkbox(o, value, errors) for o in self.options)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
def checkbox_id(self, option):
|
|
|
|
return "{0}-{1}".format(self.id, option.value)
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_checkbox(self, option, value, errors):
|
2020-03-29 18:14:34 +00:00
|
|
|
return """
|
|
|
|
<div class="{classes}">
|
2021-02-22 22:49:28 +00:00
|
|
|
<input class="form-check-input" type="checkbox" id="{id}" name="{id}" {checked} {disabled}>
|
2020-03-29 18:14:34 +00:00
|
|
|
<label class="form-check-label" for="{id}">
|
|
|
|
{checkboxText}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
""".format(
|
|
|
|
id=self.checkbox_id(option),
|
2021-03-24 21:46:51 +00:00
|
|
|
classes=self.input_classes(errors),
|
2020-03-29 18:14:34 +00:00
|
|
|
checked="checked" if option.value in value else "",
|
|
|
|
checkboxText=option.text,
|
2021-02-22 22:49:28 +00:00
|
|
|
disabled="disabled" if self.disabled else "",
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def parse(self, data):
|
|
|
|
def in_response(option):
|
|
|
|
boxid = self.checkbox_id(option)
|
|
|
|
return boxid in data and data[boxid][0] == "on"
|
|
|
|
|
|
|
|
return {self.id: [o.value for o in self.options if in_response(o)]}
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_classes(self, error):
|
|
|
|
classes = ["form-check", "form-control-sm"]
|
|
|
|
if error:
|
|
|
|
classes.append("is-invalid")
|
|
|
|
return " ".join(classes)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServicesCheckboxInput(MultiCheckboxInput):
|
|
|
|
def __init__(self, id, label, infotext=None):
|
2021-01-20 16:01:46 +00:00
|
|
|
services = [Option(s.modulation, s.name) for s in Modes.getAvailableServices()]
|
2020-03-29 18:14:34 +00:00
|
|
|
super().__init__(id, label, services, infotext)
|
|
|
|
|
|
|
|
|
2020-04-25 15:33:30 +00:00
|
|
|
class Js8ProfileCheckboxInput(MultiCheckboxInput):
|
|
|
|
def __init__(self, id, label, infotext=None):
|
|
|
|
profiles = [
|
|
|
|
Option("normal", "Normal (15s, 50Hz, ~16WPM)"),
|
|
|
|
Option("slow", "Slow (30s, 25Hz, ~8WPM"),
|
|
|
|
Option("fast", "Fast (10s, 80Hz, ~24WPM"),
|
|
|
|
Option("turbo", "Turbo (6s, 160Hz, ~40WPM"),
|
|
|
|
]
|
|
|
|
super().__init__(id, label, profiles, infotext)
|
|
|
|
|
|
|
|
|
2020-03-29 18:14:34 +00:00
|
|
|
class DropdownInput(Input):
|
2021-02-07 20:36:08 +00:00
|
|
|
def __init__(self, id, label, options, infotext=None, converter: Converter = None):
|
2021-02-08 00:16:02 +00:00
|
|
|
try:
|
|
|
|
isEnum = issubclass(options, DropdownEnum)
|
|
|
|
except TypeError:
|
|
|
|
isEnum = False
|
|
|
|
if isEnum:
|
|
|
|
self.options = [o.toOption() for o in options]
|
|
|
|
if converter is None:
|
|
|
|
converter = EnumConverter(options)
|
|
|
|
else:
|
|
|
|
self.options = options
|
2021-02-07 20:36:08 +00:00
|
|
|
super().__init__(id, label, infotext=infotext, converter=converter)
|
2020-03-29 18:14:34 +00:00
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
2020-03-29 18:14:34 +00:00
|
|
|
return """
|
2021-02-22 22:49:28 +00:00
|
|
|
<select class="{classes}" id="{id}" name="{id}" {disabled}>{options}</select>
|
2021-03-24 21:46:51 +00:00
|
|
|
{errors}
|
2020-03-29 18:14:34 +00:00
|
|
|
""".format(
|
2021-03-24 21:46:51 +00:00
|
|
|
classes=self.input_classes(errors),
|
2021-02-22 22:49:28 +00:00
|
|
|
id=self.id,
|
|
|
|
options=self.render_options(value),
|
|
|
|
disabled="disabled" if self.disabled else "",
|
2021-03-24 21:46:51 +00:00
|
|
|
errors=self.render_errors(errors),
|
2020-03-29 18:14:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def render_options(self, value):
|
|
|
|
options = [
|
|
|
|
"""
|
|
|
|
<option value="{value}" {selected}>{text}</option>
|
|
|
|
""".format(
|
|
|
|
text=o.text,
|
|
|
|
value=o.value,
|
|
|
|
selected="selected" if o.value == value else "",
|
|
|
|
)
|
|
|
|
for o in self.options
|
|
|
|
]
|
|
|
|
return "".join(options)
|
2021-02-07 20:36:08 +00:00
|
|
|
|
|
|
|
|
2021-02-08 00:16:02 +00:00
|
|
|
class DropdownEnum(Enum):
|
2021-02-07 20:36:08 +00:00
|
|
|
def toOption(self):
|
|
|
|
return Option(self.name, str(self))
|
2021-02-23 17:32:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ModesInput(DropdownInput):
|
|
|
|
def __init__(self, id, label):
|
|
|
|
options = [Option(m.modulation, m.name) for m in Modes.getAvailableModes()]
|
|
|
|
super().__init__(id, label, options)
|
2021-02-27 21:15:19 +00:00
|
|
|
|
|
|
|
|
2021-02-27 22:14:41 +00:00
|
|
|
class ExponentialInput(Input):
|
|
|
|
def __init__(self, id, label, unit, infotext=None):
|
2021-02-27 21:44:48 +00:00
|
|
|
super().__init__(id, label, infotext=infotext)
|
2021-02-27 22:14:41 +00:00
|
|
|
self.unit = unit
|
2021-02-27 21:15:19 +00:00
|
|
|
|
|
|
|
def defaultConverter(self):
|
|
|
|
return IntConverter()
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def input_properties(self, value, errors):
|
|
|
|
props = super().input_properties(value, errors)
|
2021-02-27 21:15:19 +00:00
|
|
|
props["type"] = "number"
|
|
|
|
props["step"] = "any"
|
|
|
|
return props
|
|
|
|
|
2021-03-24 21:46:51 +00:00
|
|
|
def render_input(self, value, errors):
|
2021-02-27 21:15:19 +00:00
|
|
|
append = """
|
|
|
|
<div class="input-group-append">
|
2021-02-27 22:14:41 +00:00
|
|
|
<select class="input-group-text exponent" name="{id}-exponent" {disabled}>
|
|
|
|
<option value="0" selected>{unit}</option>
|
|
|
|
<option value="3">k{unit}</option>
|
|
|
|
<option value="6">M{unit}</option>
|
|
|
|
<option value="9">G{unit}</option>
|
|
|
|
<option value="12">T{unit}</option>
|
2021-02-27 21:15:19 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
""".format(
|
|
|
|
id=self.id,
|
2021-02-27 21:44:48 +00:00
|
|
|
disabled="disabled" if self.disabled else "",
|
2021-02-27 22:14:41 +00:00
|
|
|
unit=self.unit,
|
2021-02-27 21:15:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return """
|
2021-02-27 22:14:41 +00:00
|
|
|
<div class="input-group input-group-sm exponential-input">
|
2021-02-27 21:15:19 +00:00
|
|
|
{input}
|
|
|
|
{append}
|
|
|
|
</div>
|
|
|
|
""".format(
|
2021-03-24 21:46:51 +00:00
|
|
|
input=super().render_input(value, errors),
|
2021-02-27 21:15:19 +00:00
|
|
|
append=append,
|
|
|
|
)
|
|
|
|
|
|
|
|
def parse(self, data):
|
|
|
|
exponent_id = "{}-exponent".format(self.id)
|
|
|
|
if self.id in data and exponent_id in data:
|
|
|
|
value = int(float(data[self.id][0]) * 10 ** int(data[exponent_id][0]))
|
|
|
|
return {self.id: value}
|
|
|
|
return {}
|