Modelling time series data
I've been grappling with the following problem. I want to model time series data similar to the following in my Swagger definitions.
{
"disclaimer": "https://openexchangerates.org/terms/",
"license": "https://openexchangerates.org/license/",
"start_date": "2013-01-01",
"end_date": "2013-01-31",
"base": "AUD",
"rates": {
"2013-01-01": {
"BTC": 0.0778595876,
"EUR": 0.785518,
"HKD": 8.04136
},
"2013-01-02": {
"BTC": 0.0789400739,
"EUR": 0.795034,
"HKD": 8.138096
},
"2013-01-03": {
"BTC": 0.0785299961,
"EUR": 0.80092,
"HKD": 8.116954
}
}
}
Now within the rates object, the dates are variable, and then within that date, there can be different currencies depending on your search parameters.
I've been reading through the documentation and can't see a way to model this scenario but I'm sure there must be a way.
You could model rates as a map. It's basically a string-to-object map ("2013-01-01", "2013-01-02" etc. are the keys), and a single date object is a string-to-double map. In OAI, keys are always strings, and the value type is described using the additionalProperties keyword. Keys cannot be limited to a specific format or a set of values though.
Rates:
type: object
additionalProperties:
$ref: '#/definitions/Date'
Date:
type: object
additionalProperties:
type: number
format: double
That said, please use the Google group for general support questions like this one. GitHub issues are for bug reports and feature requests.
Thanks @hkosova. To further limit the key values, you'd need to use patternProperties which is not supported by the spec.
Alternatively, if you restructure your time series to have the date as a value (not as a key), it is easier to represent it:
Rates:
type: array
items:
type: object
properties:
date:
type: string
format: date
additionalProperties:
type: number
format: decimal