diff --git a/workflow/cli/sample.py b/workflow/cli/sample.py deleted file mode 100644 index 9723402..0000000 --- a/workflow/cli/sample.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Sample CHIME/FRB Workflow Compatible Function.""" - -from typing import Dict, List, Tuple, Union - - -def fraction( - numerator: float, denominator: Union[float, str] -) -> Tuple[Dict[str, float], List[str], List[str]]: - """Sample CHIME/FRB Workflow Compatible Function. - - Args: - numerator (float): Numerator of the fraction - denominator (float): Denominator of the fraction - - Returns: - Tuple[Dict[str, float], List[str], List[str]]: - The fraction of the numerator and denominator as a dictionary. - """ - denominator = float(denominator) - fraction: float = numerator / denominator - result = {"fraction": fraction} - products: List[str] = ["/tmp/sample.csv"] - plots: List[str] = ["/tmp/sample.png"] - return result, products, plots diff --git a/workflow/examples/function.py b/workflow/examples/function.py new file mode 100644 index 0000000..5c1b9eb --- /dev/null +++ b/workflow/examples/function.py @@ -0,0 +1,49 @@ +"""Sample CHIME/FRB Workflow Compatible Function.""" + +from pathlib import Path +from typing import Dict, List, Tuple + + +def math( + a: float | int, b: float | int +) -> Tuple[Dict[str, float], List[str], List[str]]: + """Sample CHIME/FRB Workflow Compatible Function. + + Args: + a (float | int): A number + b (float | int): Another number + + Raises: + error: If the arguments are not + + Returns: + Tuple[Dict[str, float], List[str], List[str]]: + The results, products, and plots + """ + try: + assert isinstance(a, (float, int)), "a must be a number" + assert isinstance(b, (float, int)), "b must be a number" + results: Dict[str, float] = { + "sum": a + b, + "difference": a - b, + "product": a * b, + "quotient": a / b, + "power": a**b, + "root": a ** (1 / b), + "log": a ** (1 / b), + } + # Make a csv file with results + with open("/tmp/sample.csv", "w") as file: + for key, value in results.items(): + file.write(f"{key},{value}\n") + products: List[str] = ["/tmp/sample.csv"] + # Get the directory of whereever this file is + current: Path = Path(__file__).parent + # Copy sample svg file to /tmp + source: Path = current / "sample.svg" + destination: Path = Path("/tmp/sample.svg") + destination.write_text(source.read_text()) + plots: List[str] = [destination.as_posix()] + return results, products, plots + except AssertionError as error: + raise error diff --git a/workflow/cli/sample.yaml b/workflow/examples/pipelines-sample.yaml similarity index 100% rename from workflow/cli/sample.yaml rename to workflow/examples/pipelines-sample.yaml diff --git a/workflow/examples/sample.svg b/workflow/examples/sample.svg new file mode 100644 index 0000000..a16ce96 --- /dev/null +++ b/workflow/examples/sample.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + +