From a74c9d60feaa771051470b7027d615e9bd9daee7 Mon Sep 17 00:00:00 2001 From: smahmed776 Date: Sat, 10 Jun 2023 15:13:14 +0000 Subject: [PATCH] update script to write in appropriate folder --- .../SERIAL_SINGLE_MEASUREMENT.md | 50 ++++ .../a1-[autogen]/docstring.txt | 28 ++ .../a1-[autogen]/parameters.yaml | 6 + .../a1-[autogen]/python_code.txt | 42 +++ .../appendix/hardware.md | 0 .../appendix/media.md | 0 .../appendix/notes.md | 0 .../Serial_timeseries/SERIAL_TIMESERIES.md | 50 ++++ .../a1-[autogen]/docstring.txt | 32 +++ .../a1-[autogen]/parameters.yaml | 12 + .../a1-[autogen]/python_code.txt | 71 +++++ .../Serial_timeseries/appendix/hardware.md | 0 .../Serial_timeseries/appendix/media.md | 0 .../Serial_timeseries/appendix/notes.md | 0 .../ARITHMETIC/SUBTRACT/examples/EX1/app.txt | 188 +++++++++++++ .../SUBTRACT/examples/EX1/example.md | 3 + .../SUBTRACT/examples/EX1/output.txt | 0 .../DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md | 57 ++++ .../ARRAY_VIEW/a1-[autogen]/docstring.txt | 13 + .../ARRAY_VIEW/a1-[autogen]/parameters.yaml | 0 .../ARRAY_VIEW/a1-[autogen]/python_code.txt | 88 ++++++ .../ARRAY_VIEW/appendix/hardware.md | 0 .../ARRAY_VIEW/appendix/media.md | 0 .../ARRAY_VIEW/appendix/notes.md | 0 .../ARRAY_VIEW/examples/EX1/app.txt | 134 +++++++++ .../ARRAY_VIEW/examples/EX1/example.md | 5 + .../ARRAY_VIEW/examples/EX1/output.txt | 0 .../MATRIX_VIEW/examples/EX1/app.txt | 125 +++++++++ .../MATRIX_VIEW/examples/EX1/example.md | 3 + .../MATRIX_VIEW/examples/EX1/output.txt | 0 docs/nodes/a1-[autogen]/docstring.txt | 23 ++ docs/nodes/a1-[autogen]/parameters.yaml | 0 docs/nodes/a1-[autogen]/python_code.txt | 258 ++++++++++++++++++ docs/nodes/appendix/hardware.md | 0 docs/nodes/appendix/media.md | 0 docs/nodes/appendix/notes.md | 0 .../flojoy-io/docs/a1-[autogen]/docstring.txt | 0 .../docs/a1-[autogen]/parameters.yaml | 0 .../docs/a1-[autogen]/python_code.txt | 65 +++++ .../bin/flojoy-io/docs/appendix/hardware.md | 0 .../bin/flojoy-io/docs/appendix/media.md | 0 .../bin/flojoy-io/docs/appendix/notes.md | 0 .../docs/autogen/a1-[autogen]/docstring.txt | 0 .../docs/autogen/a1-[autogen]/parameters.yaml | 0 .../docs/autogen/a1-[autogen]/python_code.txt | 118 ++++++++ .../docs/autogen/appendix/hardware.md | 0 .../flojoy-io/docs/autogen/appendix/media.md | 0 .../flojoy-io/docs/autogen/appendix/notes.md | 0 .../bin/flojoy-io/docs/autogen/scaffold.md | 50 ++++ .../flojoy-io/docs/generate_nodesidebar.md | 50 ++++ docs/nodes/write_doc_string.md | 50 ++++ 51 files changed, 1521 insertions(+) create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/SERIAL_SINGLE_MEASUREMENT.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/hardware.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/media.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/notes.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/SERIAL_TIMESERIES.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/hardware.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/media.md create mode 100644 docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/notes.md create mode 100644 docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/app.txt create mode 100644 docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/example.md create mode 100644 docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/output.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/hardware.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/media.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/notes.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/app.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/example.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/output.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/app.txt create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/example.md create mode 100644 docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/output.txt create mode 100644 docs/nodes/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/appendix/hardware.md create mode 100644 docs/nodes/appendix/media.md create mode 100644 docs/nodes/appendix/notes.md create mode 100644 docs/nodes/bin/flojoy-io/docs/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/bin/flojoy-io/docs/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/bin/flojoy-io/docs/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/bin/flojoy-io/docs/appendix/hardware.md create mode 100644 docs/nodes/bin/flojoy-io/docs/appendix/media.md create mode 100644 docs/nodes/bin/flojoy-io/docs/appendix/notes.md create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/docstring.txt create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/parameters.yaml create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/python_code.txt create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/appendix/hardware.md create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/appendix/media.md create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/appendix/notes.md create mode 100644 docs/nodes/bin/flojoy-io/docs/autogen/scaffold.md create mode 100644 docs/nodes/bin/flojoy-io/docs/generate_nodesidebar.md create mode 100644 docs/nodes/write_doc_string.md diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/SERIAL_SINGLE_MEASUREMENT.md b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/SERIAL_SINGLE_MEASUREMENT.md new file mode 100644 index 0000000000..9f78e9cd56 --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/SERIAL_SINGLE_MEASUREMENT.md @@ -0,0 +1,50 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/docstring.txt b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..06bca41f7d --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/docstring.txt @@ -0,0 +1,28 @@ + + Node to take a single reading of data from an Ardunio, + or a similar serial device. + For example you can record temperature following this tutorial: + + https://learn.adafruit.com/thermistor/using-a-thermistor + + with Serial.println(steinhart) as the only line printing. + + It is important that the last line Arduino is returning is the + data with a new line at the end (i.e. println()). + + The other lines must be returned with print() + with print(",") between each line. + + For example: + + print(reading0) + print(",") + println(reading1) + + If there is more than one column, the SELECT_ARRAY node must be + used after this node. + + params: + BAUD_RATE: Baud rate for the serial device. + com_port: COM port of the serial device + \ No newline at end of file diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/parameters.yaml b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..5c8db91024 --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/parameters.yaml @@ -0,0 +1,6 @@ +baudrate: + default: 9600 + type: float +comport: + default: /dev/ttyUSB0 + type: string diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/python_code.txt b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..630ef6eb4d --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/a1-[autogen]/python_code.txt @@ -0,0 +1,42 @@ +from flojoy import flojoy, DataContainer +from time import sleep +import serial +import numpy as np +from datetime import datetime +import plotly.graph_objects as go + + +@flojoy +def SERIAL_SINGLE_MEASUREMENT(dc_inputs, params): + + print("parameters passed to SERIAL_TIMESERIES: ", params) + COM_PORT = params["comport"] + BAUD = int(params["baudrate"]) + + ser = serial.Serial(COM_PORT, timeout=1, baudrate=BAUD) + # The first reading is commonly empty. + s = ser.readline().decode() + + # Some readings may be empty. Try a second time if so. + if s != "": + reading = s[:-2].split(",") + else: + s = ser.readline().decode() + reading = s[:-2].split(",") + + reading = np.array(reading) + reading = reading.astype("float64") + + data = go.Line(x=[0], y=[0], mode="markers") + fig = go.Figure(data=data) + return DataContainer(type="plotly", fig=fig, x=[0], y=reading) + + +@flojoy +def SERIAL_SINGLE_MEASUREMENT_MOCK(dc, params): + print("Running mock version of Serial") + + x = np.linspace(0, 100, 100) + y = np.linspace(0, 100, 100) + + return DataContainer(x=x, y=y) diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/hardware.md b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/media.md b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/notes.md b/docs/nodes/INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/SERIAL_TIMESERIES.md b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/SERIAL_TIMESERIES.md new file mode 100644 index 0000000000..3c067475fd --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/SERIAL_TIMESERIES.md @@ -0,0 +1,50 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/docstring.txt b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..a41d748979 --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/docstring.txt @@ -0,0 +1,32 @@ + + Node to take simple time dependent 1d data from an Ardunio, + or a similar serial device. + For example, you can record temperature following this tutorial: + + https://learn.adafruit.com/thermistor/using-a-thermistor + + with Serial.println(steinhart) as the only line printing. + + It is important that the last line Arduino is returning is the + data with a new line at the end (i.e. println()). + + The other lines must be returned with print() + with print(",") between each line. + + For example: + + print(reading0) + print(",") + println(reading1) + + If there is more than one column, the SELECT_ARRAY node must be + used after this node. + + params: + num_readings: Number of points to record. + record_period: Length between two recordings in seconds. + BAUD_RATE: Baud rate for the serial device. + com_port: COM port of the serial device + + num_readings * record_period is roughly the run length in seconds. + \ No newline at end of file diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/parameters.yaml b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..272e50f951 --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/parameters.yaml @@ -0,0 +1,12 @@ +baudrate: + default: 9600 + type: int +comport: + default: /dev/ttyACM0 + type: string +num_readings: + default: 100 + type: int +record_period: + default: 1 + type: float diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/python_code.txt b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..10999aefcf --- /dev/null +++ b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/a1-[autogen]/python_code.txt @@ -0,0 +1,71 @@ +from flojoy import flojoy, DataContainer +from time import sleep +import serial +import numpy as np +from datetime import datetime +import plotly.graph_objects as go + + +@flojoy +def SERIAL_TIMESERIES(dc_inputs, params): + + + COM_PORT = params.get("com_port", "/dev/ttyUSB0") + BAUD = params.get("baudrate", 9600) + NUM = params.get("num_readings", 100) + RECORD_PERIOD = params.get("record_period", 1) + + ser = serial.Serial(COM_PORT, timeout=1, baudrate=BAUD) + readings = [] + times = [] + # The first reading is commonly empty. + s = ser.readline().decode() + + for i in range(NUM): + ts = datetime.now() + s = ser.readline().decode() + # Some readings may be empty. + if s != "": + reading = s[:-2].split(",") + if len(reading) == 1: + reading = reading[0] + readings.append(reading) + + ts = datetime.now() + seconds = float( + ts.hour * 3600 + ts.minute * 60 + ts.second + ts.microsecond / 10**6 + ) + + times.append(seconds) + + if len(times) > 0: + time1 = seconds - times[i] + else: + # Estimate execution time. + time1 = 0.1 + + if time1 < RECORD_PERIOD: + sleep(RECORD_PERIOD - time1) + + times = np.array(times) + try: + times -= times[0] + except IndexError: + raise IndexError("No data detected from the Arduino") + + readings = np.array(readings) + readings = readings.astype("float64") + # If there are two or more columns return a Plotly figure. + if readings.ndim == 2: + data = go.Line(x=times, y=readings[:, 0], mode="markers") + fig = go.Figure(data=data) + return DataContainer(type="plotly", fig=fig, x=times, y=readings) + else: + return DataContainer(x=times, y=readings) + + +@flojoy +def SERIAL_TIMESERIES_MOCK(dc, params): + x = np.linspace(0, 100, 100) + y = np.linspace(0, 100, 100) + return DataContainer(x=x, y=y) diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/hardware.md b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/media.md b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/notes.md b/docs/nodes/INSTRUMENTS/Serial/Serial_timeseries/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/app.txt b/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/app.txt new file mode 100644 index 0000000000..0f8e5f7ffe --- /dev/null +++ b/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/app.txt @@ -0,0 +1,188 @@ +{ + "rfInstance": { + "nodes": [ + { + "width": 190, + "height": 115, + "id": "END-06a4da40-a0ae-44ad-873b-9b65d096880a", + "type": "TERMINATOR", + "data": { + "id": "END-06a4da40-a0ae-44ad-873b-9b65d096880a", + "label": "END", + "func": "END", + "type": "TERMINATOR", + "ctrls": {}, + "selected": true + }, + "position": { + "x": 1481.1276538172046, + "y": 301.7443219065692 + }, + "selected": true, + "positionAbsolute": { + "x": 1481.1276538172046, + "y": 301.7443219065692 + }, + "dragging": true + }, + { + "width": 150, + "height": 135, + "id": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881", + "type": "default", + "data": { + "id": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881", + "label": "LINSPACE", + "func": "LINSPACE", + "type": "SIMULATION", + "ctrls": { + "start": { + "functionName": "LINSPACE", + "param": "start", + "value": "10" + }, + "end": { + "functionName": "LINSPACE", + "param": "end", + "value": "0" + }, + "step": { + "functionName": "LINSPACE", + "param": "step", + "value": "1000" + } + }, + "selected": false + }, + "position": { + "x": 335.60460405758, + "y": 414.5947652926823 + }, + "selected": false, + "positionAbsolute": { + "x": 335.60460405758, + "y": 414.5947652926823 + }, + "dragging": true + }, + { + "width": 150, + "height": 135, + "id": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65", + "type": "default", + "data": { + "id": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65", + "label": "LINSPACE_1", + "func": "LINSPACE", + "type": "SIMULATION", + "ctrls": { + "start": { + "functionName": "LINSPACE", + "param": "start", + "value": "10" + }, + "end": { + "functionName": "LINSPACE", + "param": "end", + "value": "0" + }, + "step": { + "functionName": "LINSPACE", + "param": "step", + "value": "1000" + } + }, + "selected": false + }, + "position": { + "x": 337.2242660007536, + "y": 164.02507602827643 + }, + "selected": false, + "positionAbsolute": { + "x": 337.2242660007536, + "y": 164.02507602827643 + }, + "dragging": true + }, + { + "width": 99, + "height": 115, + "id": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0", + "type": "ARITHMETIC", + "data": { + "id": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0", + "label": "SUBTRACT", + "func": "SUBTRACT", + "type": "ARITHMETIC", + "ctrls": {}, + "inputs": [ + { + "name": "y", + "id": "sub_y", + "type": "target" + } + ], + "selected": false + }, + "position": { + "x": 984.775645730269, + "y": 300.51837909623805 + }, + "selected": false, + "positionAbsolute": { + "x": 984.775645730269, + "y": 300.51837909623805 + }, + "dragging": true + } + ], + "edges": [ + { + "source": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0", + "sourceHandle": "main", + "target": "END-06a4da40-a0ae-44ad-873b-9b65d096880a", + "targetHandle": "END", + "id": "reactflow__edge-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0main-END-06a4da40-a0ae-44ad-873b-9b65d096880aEND" + }, + { + "source": "LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65", + "sourceHandle": "main", + "target": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0", + "targetHandle": "SUBTRACT", + "id": "reactflow__edge-LINSPACE-0c193475-a070-4357-b9f6-1cc8320c8a65main-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0SUBTRACT" + }, + { + "source": "LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881", + "sourceHandle": "main", + "target": "SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0", + "targetHandle": "sub_y", + "id": "reactflow__edge-LINSPACE-b70dcbec-87fc-47bd-98dc-26c01de91881main-SUBTRACT-be7bf775-eca1-4008-9d78-7164cf815da0sub_y" + } + ], + "viewport": { + "x": 296.7009684013002, + "y": 78.64846027544155, + "zoom": 0.8997754917401063 + } + }, + "ctrlsManifest": [ + { + "type": "input", + "name": "Slider", + "id": "INPUT_PLACEHOLDER", + "hidden": false, + "minHeight": 1, + "minWidth": 2, + "layout": { + "x": 0, + "y": 0, + "h": 2, + "w": 2, + "minH": 1, + "minW": 2, + "i": "INPUT_PLACEHOLDER" + } + } + ] +} diff --git a/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/example.md b/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/example.md new file mode 100644 index 0000000000..3589dec9a3 --- /dev/null +++ b/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/example.md @@ -0,0 +1,3 @@ +In this example, we `SUBTRACT` the outputs of two identical `LINSPACE` nodes. + +As expected, when we check the output of the app, we see 0 everywhere, as expected! \ No newline at end of file diff --git a/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/output.txt b/docs/nodes/TRANSFORMERS/ARITHMETIC/SUBTRACT/examples/EX1/output.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md new file mode 100644 index 0000000000..df7ba600e6 --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/ARRAY_VIEW.md @@ -0,0 +1,57 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + +import Example1 from './examples/EX1/example.md'; +import App1 from '!!raw-loader!./examples/EX1/app.txt'; +import Data1 from '!!raw-loader!./examples/EX1/output.txt'; + + + {App1} + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/docstring.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..e21a596bd1 --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/docstring.txt @@ -0,0 +1,13 @@ + + The ARRAY_VIEW node takes "ordered_pair", "dataframe", "matrix", and "image" as input type + and displays its visualization in array format. + + Parameters + ---------- + None + + Returns + ------- + plotly + Visualization of the input data in array format + \ No newline at end of file diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/parameters.yaml b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/python_code.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..654c9a9a47 --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/a1-[autogen]/python_code.txt @@ -0,0 +1,88 @@ +from flojoy import flojoy, DataContainer +import plotly.graph_objects as go +import numpy as np +import pandas as pd + +CELL_SIZE = 50 +FONT_SIZE = 10 +MAX_ALLOWED_SHAPE = 10 +l_dot = "$\\ldots$" + + +def numpy_array_as_table(arr: np.ndarray, placeholder: str): + if arr.size > MAX_ALLOWED_SHAPE: + converted_type = arr.astype(object) + new_arr = converted_type[:MAX_ALLOWED_SHAPE] + new_arr[MAX_ALLOWED_SHAPE - 2] = l_dot + else: + new_arr = arr + return new_arr.reshape(-1, 1) + + +@flojoy +def ARRAY_VIEW(dc_inputs: list[DataContainer], params: dict) -> DataContainer: + + + dc_input = dc_inputs[0] + match dc_input.type: + case "ordered_pair": + data = dc_input.y + cell_values = numpy_array_as_table(data, l_dot) + case "dataframe": + data = pd.DataFrame(dc_input.m).to_numpy(dtype=object) + data = data[:, :-1] + cell_values = numpy_array_as_table(data, l_dot) + case "matrix": + data = dc_input.m + cell_values = numpy_array_as_table(data, l_dot) + case "image": + red = dc_input.r + green = dc_input.g + blue = dc_input.b + + if dc_input.a == None: + merge = np.stack((red, green, blue), axis=2) + else: + alpha = dc_inputs[0].a + merge = np.stack((red, green, blue, alpha), axis=2) + + merge = merge.reshape(-1, merge.shape[-1]) + cell_values = numpy_array_as_table(merge, l_dot) + case _: + raise ValueError( + f"unsupported DataContainer type passed for ARRAY_VIEW: {dc_input.type}" + ) + + fig = go.Figure( + data=[ + go.Table( + header=dict(line={"width": 0}, values=[]), + cells=dict( + values=cell_values, + line={"width": 3}, + font={"size": FONT_SIZE}, + height=CELL_SIZE, + align="center", + format=[".3"], + ), + ) + ] + ) + if dc_input.type == "image" or dc_input.type == "dataframe": + width = MAX_ALLOWED_SHAPE * CELL_SIZE + 800 + + else: + width = MAX_ALLOWED_SHAPE * CELL_SIZE + 80 + height = width + 80 + fig.layout = go.Layout( + autosize=False, + width=width, + height=height, + margin=dict(l=0, r=0, t=0, b=0), + xaxis=dict(visible=False), + yaxis=dict(visible=False), + hovermode="closest", + font=dict(size=FONT_SIZE), + ) + + return DataContainer(type="plotly", fig=fig) diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/hardware.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/media.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/notes.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/app.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/app.txt new file mode 100644 index 0000000000..c3cb26e982 --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/app.txt @@ -0,0 +1,134 @@ +{ + "rfInstance": { + "nodes": [ + { + "width": 210, + "height": 130, + "id": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "type": "TERMINATOR", + "data": { + "id": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "label": "END", + "func": "END", + "type": "TERMINATOR", + "ctrls": {}, + "selected": false + }, + "position": { + "x": 1066.7749715880866, + "y": 253.50666759254665 + }, + "selected": false, + "positionAbsolute": { + "x": 1066.7749715880866, + "y": 253.50666759254665 + }, + "dragging": true + }, + { + "width": 150, + "height": 150, + "id": "LINSPACE-1fbf482b-1149-49c0-8733-fa70d153dba3", + "type": "default", + "data": { + "id": "LINSPACE-1fbf482b-1149-49c0-8733-fa70d153dba3", + "label": "LINSPACE", + "func": "LINSPACE", + "type": "SIMULATION", + "ctrls": { + "start": { + "functionName": "LINSPACE", + "param": "start", + "value": 10 + }, + "end": { + "functionName": "LINSPACE", + "param": "end", + "value": 0 + }, + "step": { + "functionName": "LINSPACE", + "param": "step", + "value": 1000 + } + }, + "selected": false + }, + "position": { + "x": -51.90922250527529, + "y": 240.49397658402108 + }, + "selected": false, + "positionAbsolute": { + "x": -51.90922250527529, + "y": 240.49397658402108 + }, + "dragging": true + }, + { + "width": 240, + "height": 260, + "id": "ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162", + "type": "PLOTLY_VISOR", + "data": { + "id": "ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162", + "label": "ARRAY VIEW", + "func": "ARRAY_VIEW", + "type": "DATA_STRUCTURE", + "ctrls": {}, + "selected": true + }, + "position": { + "x": 450.5469442156465, + "y": 183.00350555773372 + }, + "selected": true, + "positionAbsolute": { + "x": 450.5469442156465, + "y": 183.00350555773372 + }, + "dragging": true + } + ], + "edges": [ + { + "source": "LINSPACE-1fbf482b-1149-49c0-8733-fa70d153dba3", + "sourceHandle": "main", + "target": "ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162", + "targetHandle": "ARRAY_VIEW", + "id": "reactflow__edge-LINSPACE-1fbf482b-1149-49c0-8733-fa70d153dba3main-ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162ARRAY_VIEW" + }, + { + "source": "ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162", + "sourceHandle": "main", + "target": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "targetHandle": "END", + "id": "reactflow__edge-ARRAY_VIEW-f74a04cc-1bc3-4bf8-bb01-d7b621375162main-END-d1db4ad1-e647-4059-b60f-173210b3f769END" + } + ], + "viewport": { + "x": 383.94248946966945, + "y": 153.35910915060867, + "zoom": 1.1608238532718647 + } + }, + "ctrlsManifest": [ + { + "type": "input", + "name": "Slider", + "id": "INPUT_PLACEHOLDER", + "hidden": false, + "minHeight": 1, + "minWidth": 2, + "layout": { + "x": 0, + "y": 0, + "h": 2, + "w": 2, + "minH": 1, + "minW": 2, + "i": "INPUT_PLACEHOLDER" + } + } + ] +} \ No newline at end of file diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/example.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/example.md new file mode 100644 index 0000000000..3bb70ef9ce --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/example.md @@ -0,0 +1,5 @@ +In this example, `LINSPACE` passes the array that the value continuously decreases as the indices increase. + +The first index value is `10` and the last index value is `0`. + +The array is passed down to `ARRAY_VIEW`, and the visualization of this result is available. \ No newline at end of file diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/output.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/ARRAY_VIEW/examples/EX1/output.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/app.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/app.txt new file mode 100644 index 0000000000..505c6a6fbc --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/app.txt @@ -0,0 +1,125 @@ +{ + "rfInstance": { + "nodes": [ + { + "width": 150, + "height": 150, + "id": "MATMUL-6b9405af-2106-43ff-bea1-dbab31afe1c0", + "type": "MATRIX_MANIPULATION", + "data": { + "id": "MATMUL-6b9405af-2106-43ff-bea1-dbab31afe1c0", + "label": "MATMUL", + "func": "MATMUL", + "type": "MATRIX_MANIPULATION", + "ctrls": {}, + "inputs": [ + { + "name": "y", + "id": "matmul_y", + "type": "target" + } + ], + "selected": false + }, + "position": { + "x": 51.30881719559784, + "y": 253.37565457062772 + }, + "selected": false, + "positionAbsolute": { + "x": 51.30881719559784, + "y": 253.37565457062772 + }, + "dragging": true + }, + { + "width": 210, + "height": 130, + "id": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "type": "TERMINATOR", + "data": { + "id": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "label": "END", + "func": "END", + "type": "TERMINATOR", + "ctrls": {}, + "selected": false + }, + "position": { + "x": 1066.7749715880866, + "y": 253.50666759254665 + }, + "selected": false, + "positionAbsolute": { + "x": 1066.7749715880866, + "y": 253.50666759254665 + }, + "dragging": true + }, + { + "width": 240, + "height": 260, + "id": "MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8f", + "type": "PLOTLY_VISOR", + "data": { + "id": "MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8f", + "label": "MATRIX VIEW", + "func": "MATRIX_VIEW", + "type": "DATA_STRUCTURE", + "ctrls": {}, + "selected": true + }, + "position": { + "x": 536.733844813559, + "y": 179.07792896180706 + }, + "selected": true, + "positionAbsolute": { + "x": 536.733844813559, + "y": 179.07792896180706 + }, + "dragging": true + } + ], + "edges": [ + { + "source": "MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8f", + "sourceHandle": "main", + "target": "END-d1db4ad1-e647-4059-b60f-173210b3f769", + "targetHandle": "END", + "id": "reactflow__edge-MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8fmain-END-d1db4ad1-e647-4059-b60f-173210b3f769END" + }, + { + "source": "MATMUL-6b9405af-2106-43ff-bea1-dbab31afe1c0", + "sourceHandle": "main", + "target": "MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8f", + "targetHandle": "MATRIX_VIEW", + "id": "reactflow__edge-MATMUL-6b9405af-2106-43ff-bea1-dbab31afe1c0main-MATRIX_VIEW-0839dd9e-2f8a-42ea-9df3-c1b362f56e8fMATRIX_VIEW" + } + ], + "viewport": { + "x": 383.94248946966945, + "y": 153.35910915060867, + "zoom": 1.1608238532718647 + } + }, + "ctrlsManifest": [ + { + "type": "input", + "name": "Slider", + "id": "INPUT_PLACEHOLDER", + "hidden": false, + "minHeight": 1, + "minWidth": 2, + "layout": { + "x": 0, + "y": 0, + "h": 2, + "w": 2, + "minH": 1, + "minW": 2, + "i": "INPUT_PLACEHOLDER" + } + } + ] +} \ No newline at end of file diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/example.md b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/example.md new file mode 100644 index 0000000000..886bc215e5 --- /dev/null +++ b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/example.md @@ -0,0 +1,3 @@ +In this example, `MATMULT` multiplies two matrices which are `a : np.ndarray = np.asarray([[3,1,2], [5,6,4], [5,8,9]])` and `b : np.ndarray = np.asarray([[1,2,3], [4,5,6], [7,8,9]])`. + +The calculation is passed down to `MATRIX_VIEW`, and the visualization of this result is available. diff --git a/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/output.txt b/docs/nodes/VISUALIZERS/DATA_STRUCTURE/MATRIX_VIEW/examples/EX1/output.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/a1-[autogen]/docstring.txt b/docs/nodes/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..ac2ac123d8 --- /dev/null +++ b/docs/nodes/a1-[autogen]/docstring.txt @@ -0,0 +1,23 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{{DocstringSource}} +{{PythonSource}} +{{ParametersSource}} + + + + \ No newline at end of file diff --git a/docs/nodes/a1-[autogen]/parameters.yaml b/docs/nodes/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/a1-[autogen]/python_code.txt b/docs/nodes/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..683158da87 --- /dev/null +++ b/docs/nodes/a1-[autogen]/python_code.txt @@ -0,0 +1,258 @@ +import os +import yaml +import sys + +path = os.path + +N_PATH = "nodes/" + + +def get_md_file_content(file_path: str, node_label: str, has_example: bool): + file_dir, _ = path.split(file_path) + nodes_index = file_dir.replace("\\", "/").find(N_PATH) + node_path = file_dir[nodes_index:].replace("\\", "/").replace(N_PATH, "") + node_file_path = ( + file_path[nodes_index:] + .replace("\\", "/") + .replace(N_PATH, "") + .replace(".md", ".py") + ) + appendix_folder_path = path.join(file_dir[nodes_index:], "appendix/").replace( + "\\", "/" + ) + + common_section = .format( + node_file_path=node_file_path + ) + + example_section_default = + +[//]: # (Examples) + +## Examples + + + + + + + .format( + node_label=node_label, node_path=node_path + ) + + example_section = + +[//]: # (Examples) + +## Examples + +import Example1 from './examples/EX1/example.md'; +import App1 from '!!raw-loader!./examples/EX1/app.txt'; +import Data1 from '!!raw-loader!./examples/EX1/output.txt'; + + + {{App1}} + + + + + + + .format( + node_label=node_label + ) + + appendix_section = + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{{Notes}} +{{Hardware}} +{{Media}} + + +.format( + appendix_folder_path=appendix_folder_path + ) + + return ( + common_section + example_section + appendix_section + if has_example + else common_section + example_section_default + appendix_section + ) + + +def write_file_recursive(file_path: str, content: str): + # Split the path into directory and file name + directory, _ = path.split(file_path) + + # Create directories recursively if they don't exist + os.makedirs(directory, exist_ok=True) + + # Write the file + with open(file_path, "w") as file: + file.write(content) + + +def process_python_file(input_file_path: str, output_path: str, manifest_map: dict): + with open(input_file_path, "r") as file: + content = file.read() + + # Extract docstring + docstring = extract_docstring(content) + + # Extract function code + function_code = extract_function_code(content) + autogen_dir_name = "a1-[autogen]" + # Write docstring to a file + docstring_file_path = path.join(output_path, autogen_dir_name, "docstring.txt") + if not path.exists(docstring_file_path): + write_file_recursive(docstring_file_path, docstring) + + # Write function code to a file + function_code_file_path = path.join( + output_path, autogen_dir_name, "python_code.txt" + ) + if not path.exists(function_code_file_path): + write_file_recursive(function_code_file_path, function_code) + + # write parameters + input_dir, input_file_name = path.split(input_file_path) + node_name = input_file_name.replace(".py", "") + map_item = manifest_map.get(node_name, None) + param_content = "" + if map_item is not None: + params: dict | None = map_item.get("parameters", None) + if params is not None and len(params.keys()) > 0: + param_content = yaml.dump(params) + + parameters_file_path = path.join(output_path, autogen_dir_name, "parameters.yaml") + if not path.exists(parameters_file_path): + write_file_recursive(parameters_file_path, param_content) + + # appendix + appendix_dir_path = path.join(output_path, "appendix") + for f in ["hardware.md", "media.md", "notes.md"]: + if not path.exists(path.join(appendix_dir_path, f)): + write_file_recursive(path.join(appendix_dir_path, f), "") + else: + lines = [ + { + "prev": "./appendix/notes.md", + "new": "!!raw-loader!./appendix/notes.md", + }, + { + "prev": "./appendix/hardware.md", + "new": "!!raw-loader!./appendix/hardware.md", + }, + { + "prev": "./appendix/media.md", + "new": "!!raw-loader!./appendix/media.md", + }, + ] + md_file_path = path.join( + output_path, path.basename(input_file_path).replace(".py", ".md") + ) + with open(md_file_path) as appendix_f: + c = appendix_f.read() + appendix_f.close() + for line in lines: + if line["new"] in c: + pass + else: + c = c.replace(line["prev"], line["new"]) + write_file_recursive(md_file_path, c) + + # examples + has_example = False + example_dir_path = path.join(output_path, "examples", "EX1") + for f in ["app.txt", "example.md", "output.txt"]: + if path.exists(path.join(input_dir, f)): + has_example = True + with open(path.join(input_dir, f), "r") as file: + c = file.read() + file.close() + if not path.exists(path.join(example_dir_path, f)): + write_file_recursive(path.join(example_dir_path, f), c) + else: + has_example = False + # write md file with file name + md_file_path = path.join( + output_path, path.basename(input_file_path).replace(".py", ".md") + ) + md_file_content = get_md_file_content( + md_file_path, input_file_name.replace(".py", ""), has_example=has_example + ) + if not path.exists(md_file_path): + write_file_recursive(md_file_path, md_file_content) + + +def extract_docstring(content: str): + # Find the start and end of the docstring + if '' in content: + docstring_start = content.find('') + docstring_end = content.find('', docstring_start + 3) + + # Extract the docstring + docstring = content[docstring_start + 3 : docstring_end] + return docstring + return "" + + +def extract_function_code(content: str): + # Find the start of the function code + docstring = extract_docstring(content) + content = content.replace(docstring, "").replace('', "") + + return content + + +def generate_manifest_map(): + manifest_map = {} + for root, _, files in os.walk(manifest_dir): + for file in files: + allowed_file_ext = [".manifest.yaml", ".manifest.yml"] + if any(ext in file for ext in allowed_file_ext): + m_content = None + with open(path.join(root, file), "r") as f: + read_file = f.read() + m_content = yaml.load(read_file, Loader=yaml.FullLoader) + f.close() + manifest_map[m_content["COMMAND"][0]["key"]] = m_content["COMMAND"][0] + return manifest_map + + +nodes_dir = "." +manifest_dir = path.join(nodes_dir, "MANIFEST") + + +def write_doc_string(docs_dir: str): + file_path = None + manifest_map = generate_manifest_map() + for root, _, files in os.walk(nodes_dir): + for file in files: + if ( + file.endswith(".py") + and "test" not in file + and file.split(".py")[0] != "__init__" + ): + docs_file_path = path.join(docs_dir, "nodes", root) + file_path = path.join(root, file) + process_python_file(file_path, docs_file_path, manifest_map) + + +docs_dir = "" +if __name__ == "__main__": + docs_dir_path = sys.argv[1] + docs_dir = path.abspath(path.join(docs_dir_path, "docs")) +write_doc_string(docs_dir=docs_dir) diff --git a/docs/nodes/appendix/hardware.md b/docs/nodes/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/appendix/media.md b/docs/nodes/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/appendix/notes.md b/docs/nodes/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/docstring.txt b/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/parameters.yaml b/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/python_code.txt b/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..063a8e06ab --- /dev/null +++ b/docs/nodes/bin/flojoy-io/docs/a1-[autogen]/python_code.txt @@ -0,0 +1,65 @@ +import os +import json + +path = os.path +NODES_DIR = path.join("docs", "nodes") + + +def write_file(file_path: str, content: str): + # Write the file + with open(file_path, "w") as file: + file.write(content) + + +def load_nodes_map(): + with open("nodes_sidebar_map.json", "r") as f: + content = f.read() + f.close() + return json.loads(content) + + +def update_map( + map_file: dict[str, list[str]], + nodes_map: dict[str, str | list[str]], + file_path: str, +): + for key, item in nodes_map.items(): + if item == "": + continue + formatted_path = file_path.replace("\\", "/").replace(".md", "") + if isinstance(item, list): + for i in item: + if f"{i}/" in formatted_path.upper(): + if map_file.get(key, None) is not None: + map_file[key].append(formatted_path) + else: + map_file[key] = [formatted_path] + else: + if f"{item}/" in formatted_path.upper(): + if map_file.get(key, None) is not None: + map_file[key].append(formatted_path) + else: + map_file[key] = [formatted_path] + return map_file + + +def write_nodesidebar(): + file_path = None + nodes_map: dict[str, str | list[str]] = load_nodes_map() + + new_map: dict[str, list[str]] = {} + for root, _, files in os.walk(NODES_DIR): + for file in files: + if file.endswith(".md") and "appendix" not in root: + path_index = root.index("nodes") + path_from_second_dir = root[path_index:] + file_path = path.join(path_from_second_dir, file) + new_map = update_map(new_map, nodes_map, file_path) + break + break + write_file( + path.join(path.curdir, "nodeSidebar.json"), json.dumps(new_map, indent=4) + ) + + +write_nodesidebar() diff --git a/docs/nodes/bin/flojoy-io/docs/appendix/hardware.md b/docs/nodes/bin/flojoy-io/docs/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/appendix/media.md b/docs/nodes/bin/flojoy-io/docs/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/appendix/notes.md b/docs/nodes/bin/flojoy-io/docs/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/docstring.txt b/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/docstring.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/parameters.yaml b/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/parameters.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/python_code.txt b/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/python_code.txt new file mode 100644 index 0000000000..4b0df96498 --- /dev/null +++ b/docs/nodes/bin/flojoy-io/docs/autogen/a1-[autogen]/python_code.txt @@ -0,0 +1,118 @@ +import re +import os +import json +import time +from pathlib import Path + + +def write_node_template_file(NODE_NAME, head, TEMPLATE): + node_docs_page = TEMPLATE.replace('[NODE_NAME]', NODE_NAME) + + head_for_template_file = head.replace('../docs/nodes', '') + if NODE_NAME not in head_for_template_file: + head_for_template_file = os.path.join(head_for_template_file, NODE_NAME) + + node_docs_page = node_docs_page.replace('[NODE_DIRECTORY_HEAD]', head_for_template_file) + + file_path = os.path.join(head, NODE_NAME, NODE_NAME+'.md') + + if file_path.count(NODE_NAME) > 2: + file_path = file_path.replace(NODE_NAME + '/', '') + + if os.path.exists(file_path) == False: + print('~ Creating file:', file_path) + # Path.touch(file_path) + f = open(file_path, 'w') + f.write(node_docs_page) + f.close() + else: + print('~ Doc page exists', file_path) + + +def create_subdirs(NODE_NAME, head, FOLDER_NAME, subfiles): + if FOLDER_NAME == 'EX1': + autogen_folder = os.path.join(head, NODE_NAME, 'examples', FOLDER_NAME) + else: + autogen_folder = os.path.join(head, NODE_NAME, FOLDER_NAME) + + if autogen_folder.count(NODE_NAME) > 1: + autogen_folder = autogen_folder.replace(NODE_NAME + '/', '') + + if os.path.isdir(autogen_folder) == False: + if FOLDER_NAME == 'EX1': + examples_folder, EX1_folder = os.path.split(autogen_folder) + os.mkdir(examples_folder) + os.mkdir(autogen_folder) + + for i in range(len(subfiles)): + subfile_path = os.path.join(autogen_folder, subfiles[i]) + if os.path.exists(subfile_path) == False: + Path(subfile_path).touch() + + # some file cleanup + if os.path.exists("output.md"): + os.remove("output.md") + if os.path.exists("parameters.yml"): + os.remove("parameters.yml") + +def scaffold_node_directories(): + ''' + Read the contents of sidebar.js to inventory all of the Node documenation pages + For nodes that do not have a documentaiton directory structure set up yet, + create the directories and stub files to reduce effort in doing this manually. + ''' + f = open('../nodeSidebar.json') + s = f.read() + f.close() + + js = json.loads(s) + + saved_directory = os.getcwd() + + f2 = open('TEMPLATE.md') + TEMPLATE = f2.read() + f.close() + + for key in js.keys(): + for path in js[key]: + path = '../docs/' + path + head, tail = os.path.split(path) + + folder_items = os.listdir(head) + + for item in folder_items: + if '.' in item: + if item.split('.')[1] == 'md': + NODE_NAME = item.split('.')[0] + new_node_folder = os.path.join(head, NODE_NAME) + if os.path.isdir(new_node_folder) == False: + # + # 1. Create a new folder for the node if it does not already exist + # + if NODE_NAME not in head: + os.mkdir(new_node_folder) + time.sleep(0.5) + else: + print ('~ ', new_node_folder, ' already exists') + # + # 2. Write the NODE.md file in the NODE folder + # + write_node_template_file(NODE_NAME, head, TEMPLATE) + # + # 3. create the autogen_directory and its contents + # + create_subdirs(NODE_NAME, head, 'a1-[autogen]', + ('docstring.txt', 'python_code.txt', 'parameters.yaml')) + # + # 4. create appendix directory and its contents + # + create_subdirs(NODE_NAME, head, 'appendix', + ('hardware.md', 'media.md', 'notes.md')) + # + # 5. create appendix directory and its contents + # + create_subdirs(NODE_NAME, head, 'EX1', + ('app.txt', 'output.txt', 'example.md')) + + +scaffold_node_directories() diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/appendix/hardware.md b/docs/nodes/bin/flojoy-io/docs/autogen/appendix/hardware.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/appendix/media.md b/docs/nodes/bin/flojoy-io/docs/autogen/appendix/media.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/appendix/notes.md b/docs/nodes/bin/flojoy-io/docs/autogen/appendix/notes.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/nodes/bin/flojoy-io/docs/autogen/scaffold.md b/docs/nodes/bin/flojoy-io/docs/autogen/scaffold.md new file mode 100644 index 0000000000..b58f841f5d --- /dev/null +++ b/docs/nodes/bin/flojoy-io/docs/autogen/scaffold.md @@ -0,0 +1,50 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/bin/flojoy-io/docs/generate_nodesidebar.md b/docs/nodes/bin/flojoy-io/docs/generate_nodesidebar.md new file mode 100644 index 0000000000..7fb8d4f65a --- /dev/null +++ b/docs/nodes/bin/flojoy-io/docs/generate_nodesidebar.md @@ -0,0 +1,50 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/write_doc_string.md b/docs/nodes/write_doc_string.md new file mode 100644 index 0000000000..7541b30dc3 --- /dev/null +++ b/docs/nodes/write_doc_string.md @@ -0,0 +1,50 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import Parameters from '@site/src/components/Parameters'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; +import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml'; + +{DocstringSource} +{PythonSource} +{ParametersSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + +