diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-09-25 16:20:21 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-09-25 16:20:21 +0100 |
| commit | a8df0575dc88714ee08f65e57e74eb3ada6f248f (patch) | |
| tree | 006cf3b97944833bb3b7df84b259e55c2d704ccc | |
| parent | Add annotation time to download (diff) | |
| download | AnnotateChange-a8df0575dc88714ee08f65e57e74eb3ada6f248f.tar.gz AnnotateChange-a8df0575dc88714ee08f65e57e74eb3ada6f248f.zip | |
Update schema to always include time index
| -rw-r--r-- | app/utils/dataset_schema.json | 15 | ||||
| -rw-r--r-- | app/utils/datasets.py | 19 |
2 files changed, 28 insertions, 6 deletions
diff --git a/app/utils/dataset_schema.json b/app/utils/dataset_schema.json index c21194c..ac52adc 100644 --- a/app/utils/dataset_schema.json +++ b/app/utils/dataset_schema.json @@ -9,6 +9,7 @@ "name", "n_obs", "n_dim", + "time", "series" ], "properties": { @@ -61,8 +62,7 @@ "title": "The Time Schema", "default": null, "required": [ - "format", - "raw" + "index" ], "properties": { "format": { @@ -72,6 +72,17 @@ "default": "", "pattern": "^(.*)$" }, + "index": { + "$id": "#/properties/time/properties/index", + "type": "array", + "title": "Integer index of the series, starting from 0.", + "items": { + "$id": "#/properties/time/properties/index/items", + "type": "integer", + "title": "The index items schema", + "default": null + } + }, "raw": { "$id": "#/properties/time/properties/raw", "type": "array", diff --git a/app/utils/datasets.py b/app/utils/datasets.py index 887ad0f..db2c514 100644 --- a/app/utils/datasets.py +++ b/app/utils/datasets.py @@ -61,10 +61,21 @@ def validate_dataset(filename): return "Number of dimensions and number of series don't match" if "time" in data.keys(): - if len(data["time"]["raw"]) != data["n_obs"]: - return "Number of time points doesn't match number of observations" - if None in data["time"]["raw"]: - return "Null is not supported in time axis. Use 'NaN' instead." + if not "format" in data["time"] and "raw" in data["time"]: + return "'raw' must be accompanied by format" + if "format" in data["time"] and not "raw" in data["time"]: + return "Format must be accompanied by 'raw'" + if "index" in data["time"]: + if not data["time"]["index"][0] == 0: + return "Index should start at zero." + if not len(data["time"]["index"]) == data["n_obs"]: + return "Number of indices must match number of observations" + if "raw" in data["time"]: + if len(data["time"]["raw"]) != data["n_obs"]: + return "Number of time points doesn't match number of observations" + if None in data["time"]["raw"]: + return "Null is not supported in time axis. Use 'NaN' instead." + has_missing = False for var in data["series"]: |
