Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation #275

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/explanations/ingresses.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The [`CSVIngressHandler`](/reference/apidoc/_autosummary/buildingmotif.ingresses
- `rtype`: the filename that contained the row
- `fields`: key-value pairs for the row. The key is the column name; the value is the value of that column at the given row

Calling `generate_csv` on a `Template` will create an empty csv with headers. A `CSVIngress` made with this csv can be passed to `TemplateIngress` with that `Template`.

### XLSX / Spreadsheet Files

The [`XLSXIngressHandler`](/reference/apidoc/_autosummary/buildingmotif.ingresses.xlsx.html#buildingmotif.ingresses.xlsx.XLSXIngress) takes a path to an `.xlsx` file as an argument and generates a set of `Records` for each row for each sheet in the spreadsheet file.
Expand Down
47 changes: 38 additions & 9 deletions docs/guides/csv-import.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# CSV Import

Assume we have the following CSV file:

```
name,room,name-co2,name-temp,name-sp
tstat2,room345,co2-345,temp-345,sp-345
tstat3,room567,cow-567,temp-567,sp-567
```

And the following Template in a library called `csv-tutorial`:
Assume we have the following Template in a library called `csv-tutorial`:

```yml
my-thermostat:
Expand Down Expand Up @@ -42,6 +34,39 @@ my-tstat-points:
args: {"name": "co2"}
```

Loaded in memory like so:

```python
from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Library

bm = BuildingMOTIF("sqlite://") # in-memory

# load in the library containing our template and get the template
lib = Library.load(directory="csv-tutorial")
tstat_templ = lib.get_template_by_name('my-thermostat')
```

We can generate an empty csv file with the approiate column headers for a csvIngress with `generate_csv`:

```python
tstat_templ.generate_csv("data.csv")
```

which gives us `data.csv`:

```
name,room,name-co2,name-temp,name-sp
```

Assume we fill it out like so:

```
name,room,name-co2,name-temp,name-sp
tstat2,room345,co2-345,temp-345,sp-345
tstat3,room567,cow-567,temp-567,sp-567
```

We can create a CSV ingress handler using the built-in class ([`CSVIngressHandler`](/reference/apidoc/_autosummary/buildingmotif.ingresses.csv.html#buildingmotif.ingresses.csv.CSVIngress)):

```python
Expand All @@ -52,13 +77,17 @@ from buildingmotif.dataclasses import Model, Library, Template
from buildingmotif.ingresses import CSVIngress, TemplateIngress, Record

bm = BuildingMOTIF("sqlite://") # in-memory

BLDG = Namespace("urn:my_site/")
model = Model.create(BLDG) # create our model

lib = Library.load(directory="csv-tutorial") # load in the library containing our template
tstat_templ = lib.get_template_by_name('my-thermostat')

csv = CSVIngress("data.csv") # the CSV file above
ingress = TemplateIngress(tstat_templ.inline_dependencies(), None, csv)
graph = ingress.graph(BLDG)

print(graph.serialize()) # print the resulting model
```

Expand Down