JsonStatDimension¶
-
class
jsonstat.
JsonStatDimension
(did=None, size=None, pos=None, role=None)[source]¶ Represents a JsonStat Dimension. It is contained into a JsonStat Dataset.
>>> from jsonstat import JsonStatDimension >>> json_string = '''{ ... "label" : "concepts", ... "category" : { ... "index" : { "POP" : 0, "PERCENT" : 1 }, ... "label" : { "POP" : "population", ... "PERCENT" : "weight of age group in the population" } ... } ... } ... ''' >>> dim = JsonStatDimension(did="concept", role="metric").from_string(json_string) >>> len(dim) 2 >>> dim.category(0).index 'POP' >>> dim.category('POP').label 'population' >>> dim.category(1) JsonStatCategory(label='weight of age group in the population', index='PERCENT', pos=1) >>> print(dim) +-----+-----------+-----------------------------------------+ | pos | idx | label | +-----+-----------+-----------------------------------------+ | 0 | 'POP' | 'population' | | 1 | 'PERCENT' | 'weight of age group in the population' | +-----+-----------+-----------------------------------------+ >>> json_string_dimension_sex = ''' ... { ... "label" : "sex", ... "category" : { ... "index" : { ... "M" : 0, ... "F" : 1, ... "T" : 2 ... }, ... "label" : { ... "M" : "men", ... "F" : "women", ... "T" : "total" ... } ... } ... } ... ''' >>> dim = JsonStatDimension(did="sex").from_string(json_string_dimension_sex) >>> len(dim) 3
-
__init__
(did=None, size=None, pos=None, role=None)[source]¶ initialize a dimension
Warning
this is an internal library function (it is not public api)
Parameters: - did – id of dimension
- size – size of dimension (nr of values)
- pos – position of dimension into the dataset
- role – of dimension
-
did
()¶ id of this dimension
-
label
()¶ label of this dimension
-
role
()¶ role of this dimension (can be time, geo or metric)
-
pos
()¶ position of this dimension with respect to the data set to which this dimension belongs
-
querying methods¶
parsing methods¶
JsonStatDimension.
from_string
(json_string)[source]¶parse a json string
Parameters: json_string – Returns: itself to chain calls
JsonStatDimension.
from_json
(json_data)[source]¶Parse a json structure representing a dimension
From json-stat.org
It is used to describe a particular dimension. The name of this object must be one of the strings in the id array. There must be one and only one dimension ID object for every dimension in the id array.jsonschema for dimension is about:
"dimension": { "type": "object", "properties": { "version": {"$ref": "#/definitions/version"}, "href": {"$ref": "#/definitions/href"}, "class": {"type": "string", "enum": ["dimension"]}, "label": {"type": "string"}, "category": {"$ref": "#/definitions/category"}, "note": {"type": "array"}, }, "additionalProperties": false },
Parameters: json_data – Returns: itself to chain call