Skip to content

Commit

Permalink
feat(examples): added a dedicated examples folder
Browse files Browse the repository at this point in the history
added a sample function example, with valid plots and products output
  • Loading branch information
shinybrar committed Jan 31, 2024
1 parent 7d85967 commit 908de1a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
24 changes: 0 additions & 24 deletions workflow/cli/sample.py

This file was deleted.

49 changes: 49 additions & 0 deletions workflow/examples/function.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
12 changes: 12 additions & 0 deletions workflow/examples/sample.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 908de1a

Please sign in to comment.