|
| 1 | +from ..services import LATEST_INTEGRATION_VERSION, ServiceDockerData, ServiceType |
| 2 | +from ._utils import OM, PC, create_fake_thumbnail_url, register |
| 3 | +from .constants import FUNCTION_SERVICE_KEY_PREFIX |
| 4 | + |
| 5 | + |
| 6 | +def build_input(schema): |
| 7 | + return { |
| 8 | + "label": schema["title"], |
| 9 | + "description": schema["description"], |
| 10 | + "type": "ref_contentSchema", |
| 11 | + "contentSchema": schema, |
| 12 | + } |
| 13 | + |
| 14 | + |
| 15 | +# SEE https://github.com/hgrecco/pint/blob/master/pint/default_en.txt |
| 16 | +META = ServiceDockerData.parse_obj( |
| 17 | + { |
| 18 | + "integration-version": LATEST_INTEGRATION_VERSION, |
| 19 | + "key": f"{FUNCTION_SERVICE_KEY_PREFIX}/data-iterator/demo-units", |
| 20 | + "version": "0.1.0", |
| 21 | + "type": ServiceType.BACKEND, |
| 22 | + "name": "Demo Units", |
| 23 | + "description": "Demo that takes base units as inputs and transform them in the outputs", |
| 24 | + "authors": [PC, OM], |
| 25 | + "contact": PC.email, |
| 26 | + "thumbnail": create_fake_thumbnail_url("demo-units"), |
| 27 | + "inputs": { |
| 28 | + "length": build_input( |
| 29 | + { |
| 30 | + "title": "Distance", |
| 31 | + "description": "Distance base unit", |
| 32 | + "minimum": 0, |
| 33 | + "maximum": 10, |
| 34 | + "x_unit": "m", |
| 35 | + "type": "number", |
| 36 | + } |
| 37 | + ), |
| 38 | + "time": build_input( |
| 39 | + { |
| 40 | + "title": "Time", |
| 41 | + "description": "Positive time base unit", |
| 42 | + "minimum": 0, |
| 43 | + "x_unit": "s", |
| 44 | + "type": "number", |
| 45 | + } |
| 46 | + ), |
| 47 | + "current": build_input( |
| 48 | + { |
| 49 | + "title": "Current", |
| 50 | + "description": "Current base unit", |
| 51 | + "x_unit": "A", |
| 52 | + "type": "number", |
| 53 | + } |
| 54 | + ), |
| 55 | + "luminosity": build_input( |
| 56 | + { |
| 57 | + "title": "Luminosity", |
| 58 | + "description": "Luminosity base unit", |
| 59 | + "x_unit": "cd", |
| 60 | + "type": "number", |
| 61 | + } |
| 62 | + ), |
| 63 | + "mass": build_input( |
| 64 | + { |
| 65 | + "title": "Mass", |
| 66 | + "description": "Positive mass base unit", |
| 67 | + "minimum": 0, |
| 68 | + "x_unit": "g", |
| 69 | + "type": "number", |
| 70 | + } |
| 71 | + ), |
| 72 | + "substance": build_input( |
| 73 | + { |
| 74 | + "title": "Substance", |
| 75 | + "description": "Substance base unit", |
| 76 | + "minimum": 0, |
| 77 | + "x_unit": "mol", |
| 78 | + "type": "number", |
| 79 | + } |
| 80 | + ), |
| 81 | + "temperature": build_input( |
| 82 | + { |
| 83 | + "title": "Temperature", |
| 84 | + "description": "Temperature in Kelvin", |
| 85 | + "minimum": 0, |
| 86 | + "x_unit": "K", |
| 87 | + "type": "number", |
| 88 | + } |
| 89 | + ), |
| 90 | + "angle": build_input( |
| 91 | + { |
| 92 | + "title": "Angle", |
| 93 | + "description": "Angle in degrees", |
| 94 | + "x_unit": "deg", |
| 95 | + "type": "number", |
| 96 | + } |
| 97 | + ), |
| 98 | + }, |
| 99 | + "outputs": { |
| 100 | + "length": build_input( |
| 101 | + { |
| 102 | + "title": "Distance", |
| 103 | + "description": "Distance converted to millimeter", |
| 104 | + "x_unit": "mm", |
| 105 | + "type": "number", |
| 106 | + } |
| 107 | + ), |
| 108 | + "time": build_input( |
| 109 | + { |
| 110 | + "title": "Time", |
| 111 | + "description": "Time in minutes", |
| 112 | + "minimum": 0, |
| 113 | + "x_unit": "min", |
| 114 | + "type": "number", |
| 115 | + } |
| 116 | + ), |
| 117 | + "current": build_input( |
| 118 | + { |
| 119 | + "title": "Current", |
| 120 | + "description": "Current in milliAmpere", |
| 121 | + "x_unit": "mA", |
| 122 | + "type": "number", |
| 123 | + } |
| 124 | + ), |
| 125 | + "luminosity": build_input( |
| 126 | + { |
| 127 | + "title": "Luminosity", |
| 128 | + "description": "Luminosity with the same units", |
| 129 | + "x_unit": "cd", |
| 130 | + "type": "number", |
| 131 | + } |
| 132 | + ), |
| 133 | + "mass": build_input( |
| 134 | + { |
| 135 | + "title": "Mass", |
| 136 | + "description": "Mass in kg", |
| 137 | + "minimum": 0, |
| 138 | + "x_unit": "kg", |
| 139 | + "type": "number", |
| 140 | + } |
| 141 | + ), |
| 142 | + "substance": build_input( |
| 143 | + { |
| 144 | + "title": "Substance", |
| 145 | + "description": "Substance with no change in units", |
| 146 | + "minimum": 0, |
| 147 | + "x_unit": "mol", |
| 148 | + "type": "number", |
| 149 | + } |
| 150 | + ), |
| 151 | + "temperature": build_input( |
| 152 | + { |
| 153 | + "title": "Temperature", |
| 154 | + "description": "Temperature converted to celcius", |
| 155 | + "minimum": 0, |
| 156 | + "x_unit": "°C", |
| 157 | + "type": "number", |
| 158 | + } |
| 159 | + ), |
| 160 | + "angle": build_input( |
| 161 | + { |
| 162 | + "title": "Angle", |
| 163 | + "description": "Angle converted to radians", |
| 164 | + "x_unit": "rad", |
| 165 | + "type": "number", |
| 166 | + } |
| 167 | + ), |
| 168 | + }, |
| 169 | + }, |
| 170 | +) |
| 171 | + |
| 172 | + |
| 173 | +# TODO: register ONLY when dev-feature is enabled |
| 174 | +REGISTRY = register(META) |
0 commit comments