Skip to content

Commit

Permalink
Merge pull request #30 from NOAA-GSL/bug/idsse-428/event-port-raw
Browse files Browse the repository at this point in the history
Fix new EventPort bug
  • Loading branch information
Geary-Layne authored Oct 25, 2023
2 parents 8dbeefe + f18004a commit abd5857
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 45 deletions.
63 changes: 46 additions & 17 deletions python/idsse_common/idsse/common/schema/risk_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,73 @@
"minProperties": 1
},

"GeoDist": {
"description": "Mechanism for storing the geographic distribution result for a specific Condition/Location/Product(s)",
"Data": {
"description": "Mechanism for storing the a contiguous state (when the criteria is met or not met",
"type": "object",
"properties": {
"criteria": {"type": "array", "items": {"$ref": "#/ValueCount"}, "minItems": 1},
"raw": {"type": "array", "items": {"$ref": "#/ValueCount"}, "minItems": 1}
"name": {"type": "string"},
"type": {"type": "string", "enum": ["criteria", "raw"]},
"singleValue": {
"type": "array",
"items": {"type": "number"}
},
"geoDist": {
"type": "array",
"items": {"$ref": "#/ValueCount"}
}
},
"required": [
"criteria",
"raw"
"name",
"type",
"singleValue",
"geoDist"
]
},

"StateObj": {
"State": {
"description": "Mechanism for storing the a contiguous state (when the criteria is met or not met",
"type": "object",
"properties": {

"criteriaMet": {
"oneOf" : [
{"type": "boolean"},
{"type": "string", "enum": ["true", "false"]}
]
},
"startDt": {"$ref": "timing.json#/TimeString"},
"endDt": {"$ref": "timing.json#/TimeString"},
"durationInMin": {"type": "integer"},
"min": {"type": "number"},
"max": {"type": "number"},
"minAt": {"$ref": "timing.json#/TimeString"},
"maxAt": {"$ref": "timing.json#/TimeString"}
},
"required": [

"criteriaMet",
"startDt",
"endDt",
"durationInMin",
"min",
"max",
"minAt",
"maxAt"
]
},

"MetaData": {
"description": "Mechanism for storing the list of State Objects, these describe the met/notMet states for the full time frame",
"type": "object",
"properties": {
"criteria": {
"name": {"type": "string"},
"states": {
"type": "array",
"items": {"$ref": "#/StateObj"},
"items": {"$ref": "#/State"},
"minItems": 1
}
},
"required": [
"criteria"
"name",
"states"
]
},

Expand All @@ -69,17 +100,15 @@
"locationKey": {"type": "string"},
"productKey": {"type": "string"},
"validDt": {"type": "array", "items": {"$ref": "timing.json#/TimeString"}, "minItems": 1},
"singleValue": {"$ref": "#/SingleValue"},
"geoDist": {"$ref": "#/GeoDist"},
"metaData": {"$ref": "#/MetaData"}
"data": {"type": "array", "items": {"$ref": "#/Data"}, "minItems": 2},
"metaData": {"type": "array", "items": {"$ref": "#/MetaData"}, "minItems": 1}
},
"required": [
"conditionKey",
"locationKey",
"productKey",
"validDt",
"singleValue",
"geoDist",
"data",
"metaData"
]
}
Expand Down
2 changes: 0 additions & 2 deletions python/idsse_common/idsse/common/validate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ def get_validator(schema_name) -> Validator:
Validator: A validator loaded with schema and all dependencies
"""
current_path = os.path.dirname(os.path.realpath(__file__))
print('current_path:', current_path)
schema_dir = os.path.join(current_path, 'schema')
schema_filename = os.path.join(schema_dir, schema_name+'.json')
print('schema_filename:', schema_filename)
with open(schema_filename, 'r', encoding='utf8') as file:
schema = json.load(file)

Expand Down
61 changes: 35 additions & 26 deletions python/idsse_common/test/test_validate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,28 +340,37 @@ def simple_event_port_message() -> dict:
"locationKey": "Abq",
"productKey": "NBM",
"validDt": ["2022-11-12T00:00:00.000Z"],
"singleValue": {
"criteria": [0.18964463472366333],
"raw": [38.53400802612305]
},
"geoDist": {
"criteria": [{"0.18964463472366333": 1}],
"raw": [{"38.53400802612305": 1}]
},
"metaData": {
"criteria": [
{
"durationInMin": 0,
"min": 0.18964463472366333,
"minAt": "2022-11-12T00:00:00.000Z",
"max": 0.18964463472366333,
"startDt": "2022-11-12T00:00:00.000Z",
"endDt": "2022-11-12T00:00:00.000Z",
"maxAt": "2022-11-12T00:00:00.000Z",
"criteriaMet": "true"
}
]
}
"data": [
{
"name": "condition: Above Freeze Temp",
"type": "criteria",
"singleValue": [0.18964463472366333],
"geoDist": [{"0.18964463472366333": 1}]
},
{
"name": "part: A",
"type": "raw",
"singleValue": [38.53400802612305],
"geoDist": [{"38.53400802612305": 1}]
}
],
"metaData": [
{
"name": "condition: Above Freeze Temp",
"states": [
{
"durationInMin": 0,
"min": 0.18964463472366333,
"minAt": "2022-11-12T00:00:00.000Z",
"max": 0.18964463472366333,
"startDt": "2022-11-12T00:00:00.000Z",
"endDt": "2022-11-12T00:00:00.000Z",
"maxAt": "2022-11-12T00:00:00.000Z",
"criteriaMet": "true"
}
]
}
]
}
]
}
Expand Down Expand Up @@ -643,8 +652,8 @@ def test_validate_criteria_message_with_bad_mapping(criteria_validator: Validato
criteria_validator.validate(criteria_message)


def test_validate_event_port(event_port_validator: Validator,
simple_event_port_message: dict):
def test_validate_event_port_message(event_port_validator: Validator,
simple_event_port_message: dict):
try:
event_port_validator.validate(simple_event_port_message)
except ValidationError as exc:
Expand All @@ -653,15 +662,15 @@ def test_validate_event_port(event_port_validator: Validator,

def test_validate_event_port_message_with_bad_geo_dist(event_port_validator: Validator,
simple_event_port_message: dict):
criteria_geo_dist = simple_event_port_message['riskResults'][0]['geoDist']['criteria']
criteria_geo_dist = simple_event_port_message['riskResults'][0]['data'][0]['geoDist']
criteria_geo_dist.append({"not a number": 3})
with raises(ValidationError):
event_port_validator.validate(simple_event_port_message)


def test_validate_event_port_message_with_missing_metadata(event_port_validator: Validator,
simple_event_port_message: dict):
simple_event_port_message['riskResults'][0]['metaData']['criteria'].clear()
simple_event_port_message['riskResults'][0]['metaData'][0]['states'].clear()
with raises(ValidationError):
event_port_validator.validate(simple_event_port_message)

Expand Down

0 comments on commit abd5857

Please sign in to comment.