Skip to content

Commit

Permalink
Merge da669b6 into a45a1f1
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Jan 22, 2020
2 parents a45a1f1 + da669b6 commit 719b74a
Show file tree
Hide file tree
Showing 13 changed files with 729 additions and 643 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = scripts/*
omit = tests/*, scripts/*, docs/*, dragonfly_schema/_openapi.py, docs.py
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ python ./docs.py
```python
python ./scripts/export_samples.py
```

6. Validate a Model:
```python
python ./validate.py ./dragonfly_schema/samples/model_complete_simple.json
```
Note that `./dragonfly_schema/samples/model_complete_simple.json` should be replaced
with the path to the specific model JSON that you would like to validate.
22 changes: 4 additions & 18 deletions dragonfly_schema/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Model schema and the 3 geometry objects that define it."""
from pydantic import BaseModel, Field, validator, root_validator, constr
from pydantic import BaseModel, Field, validator, root_validator, constr, conlist
from typing import List, Union
from enum import Enum

Expand Down Expand Up @@ -29,14 +29,15 @@ class Room2D(NamedBaseModel):

type: constr(regex='^Room2D$') = 'Room2D'

floor_boundary: List[List[float]] = Field(
floor_boundary: List[conlist(float, min_items=2, max_items=2)] = Field(
...,
min_items=3,
description='A list of 2D points representing the outer boundary vertices of '
'the Room2D. The list should include at least 3 points and each point '
'should be a list of 2 (x, y) values.'
)

floor_holes: List[List[List[float]]] = Field(
floor_holes: List[conlist(conlist(float, min_items=2, max_items=2), min_items=3)] = Field(
None,
description='Optional list of lists with one list for each hole in the floor plate.'
'Each hole should be a list of at least 2 points and each point a list '
Expand Down Expand Up @@ -99,21 +100,6 @@ class Room2D(NamedBaseModel):
'(Radiance, EnergyPlus).'
)

@validator('floor_boundary')
def check_num_items(cls, v):
for i in v:
assert len(i) == 2, 'Number of floats must be 2 for (x, y).'
return v

@validator('floor_holes')
def check_num_items_holes(cls, v):
if v is not None:
for pt_list in v:
assert len(pt_list) >= 3, 'Floor holes must have at least 3 vertices.'
for pt in pt_list:
assert len(pt) == 2, 'Number of floats must be 2 for (x, y).'
return v

@root_validator
def check_segment_count(cls, values):
"Ensure len of boundary_conditions, window par, shading par match sement count."
Expand Down

0 comments on commit 719b74a

Please sign in to comment.