diff --git a/community/yoyo/Form_Component/Form_Component.py b/community/yoyo/Form_Component/Form_Component.py new file mode 100644 index 00000000..19bdfc9a --- /dev/null +++ b/community/yoyo/Form_Component/Form_Component.py @@ -0,0 +1,969 @@ +common = fused.load("https://github.com/fusedio/udfs/tree/b7fe87a/public/common/") + +@fused.udf(cache_max_age=0) +def udf( + config: dict | str = { + "parameter_name": "form", + "filter": [ + { + "column": "mission", + "type": "selectbox", + "default": "goes16", + "parameter_name": "mis" + }, + { + "column": "product_name", + "type": "selectbox", + "default": "ABI", + "parameter_name": "prod" + }, + { + "column": ["start_date", "end_date"], + "type": "daterange", + "parameter_name": ["start_meow", "end"] + }, + { + "type": "bounds", + "parameter_name": "bounds", + "default": [-125, 24, -66, 49], + "height": 240 + }, + { + "type": "text_input", + "default": "Sample text", + "parameter_name": "text" + }, + ], + "data_url": "https://unstable.udf.ai/fsh_aotlErnaYWdIlKcGg6huq/run?dtype_out_raster=png&dtype_out_vector=parquet" + }, + mapbox_token: str = "pk.eyJ1IjoiaXNhYWNmdXNlZGxhYnMiLCJhIjoiY2xicGdwdHljMHQ1bzN4cWhtNThvbzdqcSJ9.73fb6zHMeO_c8eAXpZVNrA", +): + import json + import jinja2 + + # normalize config + if isinstance(config, str): + cfg = json.loads(config) + else: + cfg = config + + global_param_name = cfg.get("parameter_name") + data_url = cfg.get("data_url") + + # normalize fields + normalized_fields = [] + for f in cfg.get("filter", []): + f_type = f.get("type") + raw_param = f.get("parameter_name") + + if f_type == "selectbox": + col = f.get("column") + default_val = f.get("default") + + if isinstance(raw_param, str) and raw_param: + channels = [raw_param] + else: + channels = [] + + alias_base = channels[0] if channels else col + + normalized_fields.append({ + "kind": "select", + "col": col, + "defaultValue": default_val, + "channels": channels, + "aliasBase": alias_base, + }) + + elif f_type == "daterange": + cols = f.get("column", []) + if isinstance(cols, list) and len(cols) == 2: + start_col, end_col = cols + else: + start_col, end_col = "start_date", "end_date" + + if isinstance(raw_param, list) and len(raw_param) == 2: + channels = [raw_param[0], raw_param[1]] + alias_base = raw_param[0] or start_col + elif isinstance(raw_param, str) and raw_param: + channels = [raw_param] + alias_base = raw_param + else: + channels = [] + alias_base = start_col + + normalized_fields.append({ + "kind": "date", + "startCol": start_col, + "endCol": end_col, + "defaultValue": f.get("default"), + "channels": channels, + "aliasBase": alias_base, + }) + + elif f_type == "bounds": + if isinstance(raw_param, str) and raw_param: + channels = [raw_param] + alias_base = raw_param + else: + channels = [] + alias_base = "bounds" + + default_bounds = f.get("default", [-180, -90, 180, 90]) + map_height_px = f.get("height", 240) + + normalized_fields.append({ + "kind": "bounds", + "channels": channels, + "aliasBase": alias_base, + "defaultBounds": default_bounds, + "mapHeightPx": map_height_px, + }) + + elif f_type == "text_input": + if isinstance(raw_param, str) and raw_param: + channels = [raw_param] + alias_base = raw_param + else: + channels = [] + alias_base = "text_input" + + default_val = f.get("default", "") + placeholder = f.get("placeholder", "") + + normalized_fields.append({ + "kind": "text_input", + "channels": channels, + "aliasBase": alias_base, + "defaultValue": default_val, + "placeholder": placeholder, + }) + + else: + pass + + GLOBAL_PARAM_NAME_JS = json.dumps(global_param_name) + DATA_URL_JS = json.dumps(data_url) + FIELDS_JS = json.dumps(normalized_fields) + MAPBOX_TOKEN_JS = json.dumps(mapbox_token) + + # template + template_src = r""" + + + + + + + + + + +
+
+
+
Loading…
+
+ +
+ {% for f in fields %} + {% if f.kind == "select" %} +
+ + +
+ + {% elif f.kind == "date" %} +
+ + +
+ + {% elif f.kind == "bounds" %} +
+ +
+
+ + {% elif f.kind == "text_input" %} +
+ + +
+ {% endif %} + {% endfor %} +
+
+ + +
+ +
+ + + + + + +""" + + rendered_html = jinja2.Template(template_src).render( + fields=normalized_fields, + GLOBAL_PARAM_NAME_JS=GLOBAL_PARAM_NAME_JS, + DATA_URL_JS=DATA_URL_JS, + FIELDS_JS=FIELDS_JS, + MAPBOX_TOKEN_JS=MAPBOX_TOKEN_JS, + ) + + return common.html_to_obj(rendered_html) \ No newline at end of file diff --git a/community/yoyo/Form_Component/README.MD b/community/yoyo/Form_Component/README.MD new file mode 100644 index 00000000..1ffed607 --- /dev/null +++ b/community/yoyo/Form_Component/README.MD @@ -0,0 +1,3 @@ + +Exported from Fused UDF Workbench + diff --git a/community/yoyo/Form_Component/meta.json b/community/yoyo/Form_Component/meta.json new file mode 100644 index 00000000..9d9a3b96 --- /dev/null +++ b/community/yoyo/Form_Component/meta.json @@ -0,0 +1,67 @@ +{ + "version": "0.0.3", + "job_config": { + "version": "0.0.3", + "name": null, + "steps": [ + { + "type": "udf", + "udf": { + "type": "geopandas_v2", + "name": "Form_Component", + "entrypoint": "udf", + "parameters": {}, + "metadata": { + "fused:name": "Form_Component", + "fused:slug": "Form_Component", + "fused:vizConfig": { + "tileLayer": { + "@@type": "TileLayer", + "minZoom": 0, + "maxZoom": 19, + "tileSize": 256 + }, + "rasterLayer": { + "@@type": "BitmapLayer", + "pickable": true + }, + "vectorLayer": { + "@@type": "GeoJsonLayer", + "stroked": true, + "filled": false, + "pickable": true, + "lineWidthMinPixels": 1, + "pointRadiusMinPixels": 1, + "getLineColor": { + "@@function": "colorContinuous", + "attr": "value", + "domain": [ + 0, + 10 + ], + "steps": 20, + "colors": "BurgYl", + "nullColor": [ + 184, + 184, + 184 + ] + }, + "getFillColor": [ + 208, + 208, + 208, + 40 + ] + } + }, + "fused:udfType": "auto" + }, + "source": "Form_Component.py", + "headers": [] + } + } + ], + "metadata": null + } +} \ No newline at end of file