From feb59e309f8eeeb18e2483cca2fea8f863423e40 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 27 Sep 2023 13:28:49 -0400 Subject: [PATCH 1/9] Add Schemas for Stock and Flow not entirely sure what some of the tables are, need to update --- src/acsets/schemas/catlab/StockFlow.json | 183 ++++++++++++++++++++++ src/acsets/schemas/catlab/StockFlowp.json | 90 +++++++++++ 2 files changed, 273 insertions(+) create mode 100644 src/acsets/schemas/catlab/StockFlow.json create mode 100644 src/acsets/schemas/catlab/StockFlowp.json diff --git a/src/acsets/schemas/catlab/StockFlow.json b/src/acsets/schemas/catlab/StockFlow.json new file mode 100644 index 0000000..5027369 --- /dev/null +++ b/src/acsets/schemas/catlab/StockFlow.json @@ -0,0 +1,183 @@ +{ + "version": { + "ACSets": "0.0.0", + "ACSetSchema": "0.0.1" + }, + "Ob": [ + { + "title": "Stocks", + "description": "A variable in the model", + "name": "S" + }, + { + "title": "Sum Aux", + "description": "Sum Auxiliary Variable", + "name": "SV" + }, + { + "title": "Linkage", + "description": null, + "name": "LS" + }, + { + "title": "Flow", + "description": "A flow between stocks", + "name": "F" + }, + { + "title": "Input", + "description": "The input arcs", + "name": "I" + }, + { + "title": "Output", + "description": "The output arcs", + "name": "O" + }, + { + "title": "Variable?", + "description": null, + "name": "V" + }, + { + "title": "Linkage Variable?", + "description": null, + "name": "LV" + }, + { + "title": "Linkage Sum Variables?", + "description": null, + "name": "LSV" + } + ], + "Hom": [ + { + "title": "LS to stock", + "description": null, + "name": "lss", + "codom": "S", + "dom": "LS" + }, + { + "title": "LS to SV", + "description": null, + "name": "lssv", + "codom": "SV", + "dom": "LS" + }, + { + "title": "Input to Function", + "description": null, + "name": "ifn", + "codom": "F", + "dom": "I" + }, + { + "title": "Input variable", + "description": null, + "name": "is", + "codom": "S", + "dom": "I" + }, + { + "title": "Output of Function", + "description": null, + "name": "ofn", + "codom": "F", + "dom": "O" + }, + { + "title": "Output Variable", + "description": null, + "name": "os", + "codom": "S", + "dom": "O" + }, + { + "title": "Variable Result of Function", + "description": null, + "name": "fv", + "codom": "V", + "dom": "F" + }, + { + "title": "S of V", + "description": null, + "name": "lvs", + "codom": "S", + "dom": "LV" + }, + { + "title": "V of LV", + "description": null, + "name": "lvv", + "codom": "V", + "dom": "LV" + }, + { + "title": "SV of LSV", + "description": null, + "name": "lsvsv", + "codom": "SV", + "dom": "LSV" + }, + { + "title": "V of LSV", + "description": null, + "name": "lsvv", + "codom": "V", + "dom": "LSV" + } + ], + "AttrType": [ + { + "name": "Name", + "title": "Name of Entity", + "description": null, + "ty" : "str" + }, + { + "name": "FuncDynam", + "title": "Dynamics Function", + "description": null, + "ty" : "str" + } + ], + "Attr": [ + { + "title": "Stock Name", + "description": null, + "name": "sname", + "codom": "Name", + "dom": "S" + }, + { + "title": "SV Name", + "description": null, + "name": "svname", + "codom": "Name", + "dom": "SV" + }, + { + "title": "Function Name", + "description": null, + "name": "fname", + "codom": "Name", + "dom": "F" + }, + { + "title": "Variable Name", + "description": null, + "name": "vname", + "codom": "Name", + "dom": "V" + }, + { + "title": "Dynamics Function of Variable", + "description": null, + "name": "funcDynam", + "codom": "FuncDynam", + "dom": "V" + } + ] +} \ No newline at end of file diff --git a/src/acsets/schemas/catlab/StockFlowp.json b/src/acsets/schemas/catlab/StockFlowp.json new file mode 100644 index 0000000..45cf24c --- /dev/null +++ b/src/acsets/schemas/catlab/StockFlowp.json @@ -0,0 +1,90 @@ +{ + "version": { + "ACSets": "0.0.0", + "ACSetSchema": "0.0.1" + }, + "Ob": [ + { + "name": "Flow", + "title": "Flow", + "description": null + }, + { + "name": "Stock", + "title": "Stock", + "description": null + }, + { + "name": "Link", + "title": "Link", + "description": null + } + ], + "Hom": [ + { + "name": "u", + "codom": "Stock", + "dom": "Flow", + "title" :"upstream", + "description": null + }, + { + "name": "d", + "codom": "Stock", + "dom": "Flow", + "title" :"downstream", + "description": null + }, + { + "name": "s", + "codom": "Stock", + "dom": "Link", + "title" :"source", + "description": null + }, + { + "name": "t", + "codom": "Flow", + "dom": "Link", + "title" :"target", + "description": null + } + ], + "AttrType": [ + { + "name": "Name", + "title":"Names", + "description": "Name of an entity in the model.", + "ty": "str" + }, + { + "name": "FuncFlow", + "title" :"Flow Functions", + "description": "A representation of the flow function. Currently a math expression in string form.", + "ty": "str" + } + ], + "Attr": [ + { + "title" :"Stock Name", + "description": null, + "name": "sname", + "codom": "Name", + "dom": "Stock" + }, + { + "title" :"Flow Name", + "description": null, + "name": "fname", + "codom": "Name", + "dom": "Flow" + }, + { + "title" :"Flow Function", + "description": null, + "name": "ϕf", + "codom": "FuncFlow", + "dom": "Flow" + } + ] +} \ No newline at end of file From d00aae664a5e1bd1627516eb15fc9bcf12eeb707 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 09:46:04 +0200 Subject: [PATCH 2/9] Lint --- src/acsets/schemas/catlab/StockFlow.json | 343 +++++++++++----------- src/acsets/schemas/catlab/StockFlowp.json | 157 +++++----- 2 files changed, 251 insertions(+), 249 deletions(-) diff --git a/src/acsets/schemas/catlab/StockFlow.json b/src/acsets/schemas/catlab/StockFlow.json index 5027369..d5aae43 100644 --- a/src/acsets/schemas/catlab/StockFlow.json +++ b/src/acsets/schemas/catlab/StockFlow.json @@ -1,183 +1,184 @@ { "version": { - "ACSets": "0.0.0", - "ACSetSchema": "0.0.1" + "ACSets": "0.0.0", + "ACSetSchema": "0.0.1", + "Catlab": "0.0.0" }, "Ob": [ - { - "title": "Stocks", - "description": "A variable in the model", - "name": "S" - }, - { - "title": "Sum Aux", - "description": "Sum Auxiliary Variable", - "name": "SV" - }, - { - "title": "Linkage", - "description": null, - "name": "LS" - }, - { - "title": "Flow", - "description": "A flow between stocks", - "name": "F" - }, - { - "title": "Input", - "description": "The input arcs", - "name": "I" - }, - { - "title": "Output", - "description": "The output arcs", - "name": "O" - }, - { - "title": "Variable?", - "description": null, - "name": "V" - }, - { - "title": "Linkage Variable?", - "description": null, - "name": "LV" - }, - { - "title": "Linkage Sum Variables?", - "description": null, - "name": "LSV" - } + { + "title": "Stocks", + "description": "A variable in the model", + "name": "S" + }, + { + "title": "Sum Aux", + "description": "Sum Auxiliary Variable", + "name": "SV" + }, + { + "title": "Linkage", + "description": null, + "name": "LS" + }, + { + "title": "Flow", + "description": "A flow between stocks", + "name": "F" + }, + { + "title": "Input", + "description": "The input arcs", + "name": "I" + }, + { + "title": "Output", + "description": "The output arcs", + "name": "O" + }, + { + "title": "Variable?", + "description": null, + "name": "V" + }, + { + "title": "Linkage Variable?", + "description": null, + "name": "LV" + }, + { + "title": "Linkage Sum Variables?", + "description": null, + "name": "LSV" + } ], "Hom": [ - { - "title": "LS to stock", - "description": null, - "name": "lss", - "codom": "S", - "dom": "LS" - }, - { - "title": "LS to SV", - "description": null, - "name": "lssv", - "codom": "SV", - "dom": "LS" - }, - { - "title": "Input to Function", - "description": null, - "name": "ifn", - "codom": "F", - "dom": "I" - }, - { - "title": "Input variable", - "description": null, - "name": "is", - "codom": "S", - "dom": "I" - }, - { - "title": "Output of Function", - "description": null, - "name": "ofn", - "codom": "F", - "dom": "O" - }, - { - "title": "Output Variable", - "description": null, - "name": "os", - "codom": "S", - "dom": "O" - }, - { - "title": "Variable Result of Function", - "description": null, - "name": "fv", - "codom": "V", - "dom": "F" - }, - { - "title": "S of V", - "description": null, - "name": "lvs", - "codom": "S", - "dom": "LV" - }, - { - "title": "V of LV", - "description": null, - "name": "lvv", - "codom": "V", - "dom": "LV" - }, - { - "title": "SV of LSV", - "description": null, - "name": "lsvsv", - "codom": "SV", - "dom": "LSV" - }, - { - "title": "V of LSV", - "description": null, - "name": "lsvv", - "codom": "V", - "dom": "LSV" - } + { + "title": "LS to stock", + "description": null, + "name": "lss", + "codom": "S", + "dom": "LS" + }, + { + "title": "LS to SV", + "description": null, + "name": "lssv", + "codom": "SV", + "dom": "LS" + }, + { + "title": "Input to Function", + "description": null, + "name": "ifn", + "codom": "F", + "dom": "I" + }, + { + "title": "Input variable", + "description": null, + "name": "is", + "codom": "S", + "dom": "I" + }, + { + "title": "Output of Function", + "description": null, + "name": "ofn", + "codom": "F", + "dom": "O" + }, + { + "title": "Output Variable", + "description": null, + "name": "os", + "codom": "S", + "dom": "O" + }, + { + "title": "Variable Result of Function", + "description": null, + "name": "fv", + "codom": "V", + "dom": "F" + }, + { + "title": "S of V", + "description": null, + "name": "lvs", + "codom": "S", + "dom": "LV" + }, + { + "title": "V of LV", + "description": null, + "name": "lvv", + "codom": "V", + "dom": "LV" + }, + { + "title": "SV of LSV", + "description": null, + "name": "lsvsv", + "codom": "SV", + "dom": "LSV" + }, + { + "title": "V of LSV", + "description": null, + "name": "lsvv", + "codom": "V", + "dom": "LSV" + } ], "AttrType": [ - { - "name": "Name", - "title": "Name of Entity", - "description": null, - "ty" : "str" - }, - { - "name": "FuncDynam", - "title": "Dynamics Function", - "description": null, - "ty" : "str" - } + { + "name": "Name", + "title": "Name of Entity", + "description": null, + "ty": "str" + }, + { + "name": "FuncDynam", + "title": "Dynamics Function", + "description": null, + "ty": "str" + } ], "Attr": [ - { - "title": "Stock Name", - "description": null, - "name": "sname", - "codom": "Name", - "dom": "S" - }, - { - "title": "SV Name", - "description": null, - "name": "svname", - "codom": "Name", - "dom": "SV" - }, - { - "title": "Function Name", - "description": null, - "name": "fname", - "codom": "Name", - "dom": "F" - }, - { - "title": "Variable Name", - "description": null, - "name": "vname", - "codom": "Name", - "dom": "V" - }, - { - "title": "Dynamics Function of Variable", - "description": null, - "name": "funcDynam", - "codom": "FuncDynam", - "dom": "V" - } + { + "title": "Stock Name", + "description": null, + "name": "sname", + "codom": "Name", + "dom": "S" + }, + { + "title": "SV Name", + "description": null, + "name": "svname", + "codom": "Name", + "dom": "SV" + }, + { + "title": "Function Name", + "description": null, + "name": "fname", + "codom": "Name", + "dom": "F" + }, + { + "title": "Variable Name", + "description": null, + "name": "vname", + "codom": "Name", + "dom": "V" + }, + { + "title": "Dynamics Function of Variable", + "description": null, + "name": "funcDynam", + "codom": "FuncDynam", + "dom": "V" + } ] } \ No newline at end of file diff --git a/src/acsets/schemas/catlab/StockFlowp.json b/src/acsets/schemas/catlab/StockFlowp.json index 45cf24c..f342bb9 100644 --- a/src/acsets/schemas/catlab/StockFlowp.json +++ b/src/acsets/schemas/catlab/StockFlowp.json @@ -1,90 +1,91 @@ { "version": { - "ACSets": "0.0.0", - "ACSetSchema": "0.0.1" + "ACSets": "0.0.0", + "ACSetSchema": "0.0.1", + "Catlab": "0.0.0" }, "Ob": [ - { - "name": "Flow", - "title": "Flow", - "description": null - }, - { - "name": "Stock", - "title": "Stock", - "description": null - }, - { - "name": "Link", - "title": "Link", - "description": null - } + { + "name": "Flow", + "title": "Flow", + "description": null + }, + { + "name": "Stock", + "title": "Stock", + "description": null + }, + { + "name": "Link", + "title": "Link", + "description": null + } ], "Hom": [ - { - "name": "u", - "codom": "Stock", - "dom": "Flow", - "title" :"upstream", - "description": null - }, - { - "name": "d", - "codom": "Stock", - "dom": "Flow", - "title" :"downstream", - "description": null - }, - { - "name": "s", - "codom": "Stock", - "dom": "Link", - "title" :"source", - "description": null - }, - { - "name": "t", - "codom": "Flow", - "dom": "Link", - "title" :"target", - "description": null - } + { + "name": "u", + "codom": "Stock", + "dom": "Flow", + "title": "upstream", + "description": null + }, + { + "name": "d", + "codom": "Stock", + "dom": "Flow", + "title": "downstream", + "description": null + }, + { + "name": "s", + "codom": "Stock", + "dom": "Link", + "title": "source", + "description": null + }, + { + "name": "t", + "codom": "Flow", + "dom": "Link", + "title": "target", + "description": null + } ], "AttrType": [ - { - "name": "Name", - "title":"Names", - "description": "Name of an entity in the model.", - "ty": "str" - }, - { - "name": "FuncFlow", - "title" :"Flow Functions", - "description": "A representation of the flow function. Currently a math expression in string form.", - "ty": "str" - } + { + "name": "Name", + "title": "Names", + "description": "Name of an entity in the model.", + "ty": "str" + }, + { + "name": "FuncFlow", + "title": "Flow Functions", + "description": "A representation of the flow function. Currently a math expression in string form.", + "ty": "str" + } ], "Attr": [ - { - "title" :"Stock Name", - "description": null, - "name": "sname", - "codom": "Name", - "dom": "Stock" - }, - { - "title" :"Flow Name", - "description": null, - "name": "fname", - "codom": "Name", - "dom": "Flow" - }, - { - "title" :"Flow Function", - "description": null, - "name": "ϕf", - "codom": "FuncFlow", - "dom": "Flow" - } + { + "title": "Stock Name", + "description": null, + "name": "sname", + "codom": "Name", + "dom": "Stock" + }, + { + "title": "Flow Name", + "description": null, + "name": "fname", + "codom": "Name", + "dom": "Flow" + }, + { + "title": "Flow Function", + "description": null, + "name": "ϕf", + "codom": "FuncFlow", + "dom": "Flow" + } ] } \ No newline at end of file From ac884479f879a89896c653c9fe25a07c04accb67 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 09:46:13 +0200 Subject: [PATCH 3/9] Add jscon schemata --- src/acsets/schemas/jsonschema/StockFlow.json | 202 ++++++++++++++++++ src/acsets/schemas/jsonschema/StockFlowp.json | 82 +++++++ 2 files changed, 284 insertions(+) create mode 100644 src/acsets/schemas/jsonschema/StockFlow.json create mode 100644 src/acsets/schemas/jsonschema/StockFlowp.json diff --git a/src/acsets/schemas/jsonschema/StockFlow.json b/src/acsets/schemas/jsonschema/StockFlow.json new file mode 100644 index 0000000..642eb1b --- /dev/null +++ b/src/acsets/schemas/jsonschema/StockFlow.json @@ -0,0 +1,202 @@ +{ + "$id": "https://raw.githubusercontent.com/AlgebraicJulia/py-acsets/main/src/acsets/jsonschema/StockFlow.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "F": { + "properties": { + "fname": { + "title": "Fname", + "type": "string" + }, + "fv": { + "title": "Fv", + "type": "integer" + } + }, + "title": "F", + "type": "object" + }, + "I": { + "properties": { + "ifn": { + "title": "Ifn", + "type": "integer" + }, + "is": { + "title": "Is", + "type": "integer" + } + }, + "title": "I", + "type": "object" + }, + "LS": { + "properties": { + "lss": { + "title": "Lss", + "type": "integer" + }, + "lssv": { + "title": "Lssv", + "type": "integer" + } + }, + "title": "LS", + "type": "object" + }, + "LSV": { + "properties": { + "lsvsv": { + "title": "Lsvsv", + "type": "integer" + }, + "lsvv": { + "title": "Lsvv", + "type": "integer" + } + }, + "title": "LSV", + "type": "object" + }, + "LV": { + "properties": { + "lvs": { + "title": "Lvs", + "type": "integer" + }, + "lvv": { + "title": "Lvv", + "type": "integer" + } + }, + "title": "LV", + "type": "object" + }, + "O": { + "properties": { + "ofn": { + "title": "Ofn", + "type": "integer" + }, + "os": { + "title": "Os", + "type": "integer" + } + }, + "title": "O", + "type": "object" + }, + "S": { + "properties": { + "sname": { + "title": "Sname", + "type": "string" + } + }, + "title": "S", + "type": "object" + }, + "SV": { + "properties": { + "svname": { + "title": "Svname", + "type": "string" + } + }, + "title": "SV", + "type": "object" + }, + "V": { + "properties": { + "funcDynam": { + "title": "Funcdynam", + "type": "string" + }, + "vname": { + "title": "Vname", + "type": "string" + } + }, + "title": "V", + "type": "object" + } + }, + "properties": { + "F": { + "items": { + "$ref": "#/definitions/F" + }, + "title": "F", + "type": "array" + }, + "I": { + "items": { + "$ref": "#/definitions/I" + }, + "title": "I", + "type": "array" + }, + "LS": { + "items": { + "$ref": "#/definitions/LS" + }, + "title": "Ls", + "type": "array" + }, + "LSV": { + "items": { + "$ref": "#/definitions/LSV" + }, + "title": "Lsv", + "type": "array" + }, + "LV": { + "items": { + "$ref": "#/definitions/LV" + }, + "title": "Lv", + "type": "array" + }, + "O": { + "items": { + "$ref": "#/definitions/O" + }, + "title": "O", + "type": "array" + }, + "S": { + "items": { + "$ref": "#/definitions/S" + }, + "title": "S", + "type": "array" + }, + "SV": { + "items": { + "$ref": "#/definitions/SV" + }, + "title": "Sv", + "type": "array" + }, + "V": { + "items": { + "$ref": "#/definitions/V" + }, + "title": "V", + "type": "array" + } + }, + "required": [ + "S", + "SV", + "LS", + "F", + "I", + "O", + "V", + "LV", + "LSV" + ], + "title": "StockFlow.json", + "type": "object" +} \ No newline at end of file diff --git a/src/acsets/schemas/jsonschema/StockFlowp.json b/src/acsets/schemas/jsonschema/StockFlowp.json new file mode 100644 index 0000000..7a585ed --- /dev/null +++ b/src/acsets/schemas/jsonschema/StockFlowp.json @@ -0,0 +1,82 @@ +{ + "$id": "https://raw.githubusercontent.com/AlgebraicJulia/py-acsets/main/src/acsets/jsonschema/StockFlowp.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "Flow": { + "properties": { + "d": { + "title": "D", + "type": "integer" + }, + "fname": { + "title": "Fname", + "type": "string" + }, + "u": { + "title": "U", + "type": "integer" + }, + "ϕf": { + "title": "Φf", + "type": "string" + } + }, + "title": "Flow", + "type": "object" + }, + "Link": { + "properties": { + "s": { + "title": "S", + "type": "integer" + }, + "t": { + "title": "T", + "type": "integer" + } + }, + "title": "Link", + "type": "object" + }, + "Stock": { + "properties": { + "sname": { + "title": "Sname", + "type": "string" + } + }, + "title": "Stock", + "type": "object" + } + }, + "properties": { + "Flow": { + "items": { + "$ref": "#/definitions/Flow" + }, + "title": "Flow", + "type": "array" + }, + "Link": { + "items": { + "$ref": "#/definitions/Link" + }, + "title": "Link", + "type": "array" + }, + "Stock": { + "items": { + "$ref": "#/definitions/Stock" + }, + "title": "Stock", + "type": "array" + } + }, + "required": [ + "Flow", + "Stock", + "Link" + ], + "title": "StockFlowp.json", + "type": "object" +} \ No newline at end of file From 6cc5dd59596c016c6cf78607ec56dfa499782b9a Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 09:52:44 +0200 Subject: [PATCH 4/9] Get title and descriptions into output --- src/acsets/acsets.py | 2 +- src/acsets/schemas/jsonschema/StockFlow.json | 40 +++++++++++-------- src/acsets/schemas/jsonschema/StockFlowp.json | 14 +++---- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/acsets/acsets.py b/src/acsets/acsets.py index b0b9475..0d8fdf3 100644 --- a/src/acsets/acsets.py +++ b/src/acsets/acsets.py @@ -259,7 +259,7 @@ def __init__( ob: create_model( ob.name, **{ - prop.name: (Union[self.valtype(prop), None], None) + prop.name: (Union[self.valtype(prop), None], Field(title=ob.title, description=ob.description)) for prop in self.props_outof(ob) }, ) diff --git a/src/acsets/schemas/jsonschema/StockFlow.json b/src/acsets/schemas/jsonschema/StockFlow.json index 642eb1b..05879f5 100644 --- a/src/acsets/schemas/jsonschema/StockFlow.json +++ b/src/acsets/schemas/jsonschema/StockFlow.json @@ -5,11 +5,13 @@ "F": { "properties": { "fname": { - "title": "Fname", + "description": "A flow between stocks", + "title": "Flow", "type": "string" }, "fv": { - "title": "Fv", + "description": "A flow between stocks", + "title": "Flow", "type": "integer" } }, @@ -19,11 +21,13 @@ "I": { "properties": { "ifn": { - "title": "Ifn", + "description": "The input arcs", + "title": "Input", "type": "integer" }, "is": { - "title": "Is", + "description": "The input arcs", + "title": "Input", "type": "integer" } }, @@ -33,11 +37,11 @@ "LS": { "properties": { "lss": { - "title": "Lss", + "title": "Linkage", "type": "integer" }, "lssv": { - "title": "Lssv", + "title": "Linkage", "type": "integer" } }, @@ -47,11 +51,11 @@ "LSV": { "properties": { "lsvsv": { - "title": "Lsvsv", + "title": "Linkage Sum Variables?", "type": "integer" }, "lsvv": { - "title": "Lsvv", + "title": "Linkage Sum Variables?", "type": "integer" } }, @@ -61,11 +65,11 @@ "LV": { "properties": { "lvs": { - "title": "Lvs", + "title": "Linkage Variable?", "type": "integer" }, "lvv": { - "title": "Lvv", + "title": "Linkage Variable?", "type": "integer" } }, @@ -75,11 +79,13 @@ "O": { "properties": { "ofn": { - "title": "Ofn", + "description": "The output arcs", + "title": "Output", "type": "integer" }, "os": { - "title": "Os", + "description": "The output arcs", + "title": "Output", "type": "integer" } }, @@ -89,7 +95,8 @@ "S": { "properties": { "sname": { - "title": "Sname", + "description": "A variable in the model", + "title": "Stocks", "type": "string" } }, @@ -99,7 +106,8 @@ "SV": { "properties": { "svname": { - "title": "Svname", + "description": "Sum Auxiliary Variable", + "title": "Sum Aux", "type": "string" } }, @@ -109,11 +117,11 @@ "V": { "properties": { "funcDynam": { - "title": "Funcdynam", + "title": "Variable?", "type": "string" }, "vname": { - "title": "Vname", + "title": "Variable?", "type": "string" } }, diff --git a/src/acsets/schemas/jsonschema/StockFlowp.json b/src/acsets/schemas/jsonschema/StockFlowp.json index 7a585ed..5b6bfe1 100644 --- a/src/acsets/schemas/jsonschema/StockFlowp.json +++ b/src/acsets/schemas/jsonschema/StockFlowp.json @@ -5,19 +5,19 @@ "Flow": { "properties": { "d": { - "title": "D", + "title": "Flow", "type": "integer" }, "fname": { - "title": "Fname", + "title": "Flow", "type": "string" }, "u": { - "title": "U", + "title": "Flow", "type": "integer" }, "ϕf": { - "title": "Φf", + "title": "Flow", "type": "string" } }, @@ -27,11 +27,11 @@ "Link": { "properties": { "s": { - "title": "S", + "title": "Link", "type": "integer" }, "t": { - "title": "T", + "title": "Link", "type": "integer" } }, @@ -41,7 +41,7 @@ "Stock": { "properties": { "sname": { - "title": "Sname", + "title": "Stock", "type": "string" } }, From 8c8ca7a0d403aa16a9a0fad76c55175e513450e3 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 09:59:40 +0200 Subject: [PATCH 5/9] Add example and tests for example validity --- src/acsets/schemas/__init__.py | 8 ++++ src/acsets/schemas/examples/StockFlow.json | 53 ++++++++++++++++++++++ tests/test_examples.py | 23 ++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/acsets/schemas/__init__.py create mode 100644 src/acsets/schemas/examples/StockFlow.json create mode 100644 tests/test_examples.py diff --git a/src/acsets/schemas/__init__.py b/src/acsets/schemas/__init__.py new file mode 100644 index 0000000..7229e07 --- /dev/null +++ b/src/acsets/schemas/__init__.py @@ -0,0 +1,8 @@ +"""Schemas and examples.""" + +from pathlib import Path + +HERE = Path(__file__).parent.resolve() +CATLAB = HERE.joinpath("catlab") +JSONSCHEMA = HERE.joinpath("jsonschema") +EXAMPLES = HERE.joinpath("examples") diff --git a/src/acsets/schemas/examples/StockFlow.json b/src/acsets/schemas/examples/StockFlow.json new file mode 100644 index 0000000..6ed4fd1 --- /dev/null +++ b/src/acsets/schemas/examples/StockFlow.json @@ -0,0 +1,53 @@ +{ + "Flow": [ + { + "_id": 1, + "u": 1, + "d": 2, + "fname": "NewIncidence", + "ϕf": "p.cβ*u.S*u.I/p.N" + }, + { + "_id": 2, + "u": 2, + "d": 3, + "fname": "NewRecovery", + "ϕf": "(u.I/p.tr)" + } + ], + "Stock": [ + { + "_id": 1, + "sname": "S" + }, + { + "_id": 2, + "sname": "I" + }, + { + "_id": 3, + "sname": "R" + } + ], + "Link": [ + { + "_id": 1, + "s": 1, + "t": 1 + }, + { + "_id": 2, + "s": 2, + "t": 1 + }, + { + "_id": 3, + "s": 2, + "t": 2 + } + ], + "Name": [ + ], + "FuncFlow": [ + ] +} \ No newline at end of file diff --git a/tests/test_examples.py b/tests/test_examples.py new file mode 100644 index 0000000..deb6f9b --- /dev/null +++ b/tests/test_examples.py @@ -0,0 +1,23 @@ +"""Test that the examples are valid.""" + +import json +import unittest + +import jsonschema +from acsets.schemas import EXAMPLES, CATLAB, JSONSCHEMA + + +class TestExamples(unittest.TestCase): + """Test all examples are valid wrt their related schema.""" + + def test_examples_valid(self): + """Test examples.""" + for example in EXAMPLES.glob("*.json"): + with self.subTest(example=example.name): + jsonschema_path = JSONSCHEMA.joinpath(example.name) + self.assertTrue( + jsonschema_path.is_file(), msg="No corresponding JSON schema for example" + ) + jsonschema_obj = json.loads(jsonschema_path.read_text()) + example_obj = json.loads(example.read_text()) + jsonschema.validate(instance=example_obj, schema=jsonschema_obj) From 3e3fcffb5d0add9fb402b02689f84bb799462714 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 10:06:32 +0200 Subject: [PATCH 6/9] Update example --- src/acsets/schemas/examples/StockFlow.json | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/acsets/schemas/examples/StockFlow.json b/src/acsets/schemas/examples/StockFlow.json index 6ed4fd1..9bfe32c 100644 --- a/src/acsets/schemas/examples/StockFlow.json +++ b/src/acsets/schemas/examples/StockFlow.json @@ -1,5 +1,5 @@ { - "Flow": [ + "F": [ { "_id": 1, "u": 1, @@ -15,7 +15,7 @@ "ϕf": "(u.I/p.tr)" } ], - "Stock": [ + "S": [ { "_id": 1, "sname": "S" @@ -49,5 +49,12 @@ "Name": [ ], "FuncFlow": [ - ] + ], + "SV": [], + "LS": [], + "I": [], + "O": [], + "V": [], + "LV": [], + "LSV": [] } \ No newline at end of file From 04704385a7023f794a818d5baa0430a40fb43a1b Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 10:15:03 +0200 Subject: [PATCH 7/9] Update setup.cfg --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 552b740..8ba557d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -68,6 +68,7 @@ where = src tests = pytest coverage + jsonschema docs = sphinx sphinx-rtd-theme From e124b1ff729235efbc2c0273e2edc328160a7a83 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 16:02:15 +0200 Subject: [PATCH 8/9] Automatically make empty lists --- src/acsets/acsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acsets/acsets.py b/src/acsets/acsets.py index 0d8fdf3..f32a8e9 100644 --- a/src/acsets/acsets.py +++ b/src/acsets/acsets.py @@ -267,7 +267,7 @@ def __init__( } self.ob_models = ob_models self.model = create_model( - self.name, **{ob.name: (list[ob_models[ob]], ...) for ob in self.obs} # type: ignore + self.name, **{ob.name: (list[ob_models[ob]], Field(default_factory=list)) for ob in self.obs} # type: ignore ) def valtype(self, prop: Property): From b2ea336624c4249d94053a11b0f1d7ef43bc3ed7 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 28 Sep 2023 16:03:17 +0200 Subject: [PATCH 9/9] Fix example --- .../{StockFlow.json => StockFlowp.json} | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) rename src/acsets/schemas/examples/{StockFlow.json => StockFlowp.json} (80%) diff --git a/src/acsets/schemas/examples/StockFlow.json b/src/acsets/schemas/examples/StockFlowp.json similarity index 80% rename from src/acsets/schemas/examples/StockFlow.json rename to src/acsets/schemas/examples/StockFlowp.json index 9bfe32c..3018218 100644 --- a/src/acsets/schemas/examples/StockFlow.json +++ b/src/acsets/schemas/examples/StockFlowp.json @@ -1,5 +1,5 @@ { - "F": [ + "Flow": [ { "_id": 1, "u": 1, @@ -15,7 +15,7 @@ "ϕf": "(u.I/p.tr)" } ], - "S": [ + "Stock": [ { "_id": 1, "sname": "S" @@ -45,16 +45,5 @@ "s": 2, "t": 2 } - ], - "Name": [ - ], - "FuncFlow": [ - ], - "SV": [], - "LS": [], - "I": [], - "O": [], - "V": [], - "LV": [], - "LSV": [] + ] } \ No newline at end of file