Packages
smart_city
5.4.4
6.0.0
5.4.7
5.4.6
5.4.5
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.8
5.2.6
5.2.5
5.2.4
5.2.3
5.2.2
5.2.1
5.2.0
5.1.1
5.1.0
5.0.7
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.0.1
4.0.0
3.25.0
3.24.0
3.23.0
3.22.0
3.21.0
3.20.1
3.20.0
3.19.1
3.19.0
3.18.3
3.18.2
3.18.1
3.18.0
3.17.0
3.16.0
3.15.1
3.15.0
3.14.1
3.14.0
3.13.0
3.12.0
3.11.0
3.10.0
3.9.0
3.8.0
3.7.0
3.6.0
3.5.1
3.5.0
3.4.0
3.3.0
3.2.4
3.2.3
3.2.1
3.2.0
3.1.0
3.0.0
2.9.0
2.8.2
2.8.0
2.7.1
2.7.0
2.6.1
2.5.0
2.4.2
retired
2.4.1
2.4.0
2.3.0
2.2.0
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
A library for shared helper modules in the Smart Cities Data project.
Current section
Files
Jump to
Current section
Files
lib/smart_city/dataset.ex
defmodule SmartCity.Dataset do
@moduledoc """
Struct defining a dataset definition and functions for retrieving key elements
of the dataset for handling.
```javascript
const Dataset = {
"id": "", // UUID
"business": { // Project Open Data Metadata Schema v1.1
"authorEmail": "",
"authorName": "",
"benefitRating": 0, // value between 0.0 and 1.0
"categories": [""],
"conformsToUri": "",
"contactEmail": "",
"contactName": "",
"dataTitle": "", // user friendly (dataTitle)
"describedByMimeType": "",
"describedByUrl": "",
"description": "",
"homepage": "",
"issuedDate": "",
"keywords": [""],
"language": "",
"license": "",
"modifiedDate": "",
"orgTitle": "", // user friendly (orgTitle)
"parentDataset": "",
"publishFrequency": "",
"referenceUrls": [""],
"rights": "",
"riskRating": 0, // value between 0.0 and 1.0
"spatial": "",
"temporal": ""
},
"technical": {
"allow_duplicates": true
"authHeaders": {"header1": "", "header2": ""}
"authBody": {"name": "", "clientID": ""}
"authBodyEncodeMethod": "",
"authUrl": "",
"cadence": "",
"dataName": "", // ~r/[a-zA-Z_]+$/
"orgId": "",
"orgName": "", // ~r/[a-zA-Z_]+$/
"protocol": "", // List of protocols to use. Defaults to nil. Can be [http1, http2]
"schema": [{
"name": "",
"type": "",
"description": ""
}],
"sourceHeaders": {
"header1": "",
"header2": ""
},
"sourceQueryParams": {
"key1": "",
"key2": ""
},
"sourceType": "", // remote|stream|ingest|host
"sourceUrl": "",
"systemName": "", // ${orgName}__${dataName}
"topLevelSelector": ""
}
}
```
"""
alias SmartCity.Dataset.Business
alias SmartCity.Dataset.Technical
@type id :: term()
@type t :: %SmartCity.Dataset{
business: SmartCity.Dataset.Business.t(),
id: String.t(),
technical: SmartCity.Dataset.Technical.t(),
version: String.t()
}
@derive Jason.Encoder
defstruct version: "0.6", id: nil, business: nil, technical: nil
use Accessible
alias SmartCity.BaseStruct
@doc """
Returns a new `SmartCity.Dataset` struct. `SmartCity.Dataset.Business` and
`SmartCity.Dataset.Technical` structs will be created along the way.
## Parameters
- msg : map defining values of the struct to be created.
Can be initialized by
- map with string keys
- map with atom keys
- JSON
"""
@spec new(String.t() | map()) :: {:ok, map()} | {:error, term()}
def new(msg) do
msg
|> BaseStruct.new()
|> create()
end
defp create(%{id: id, business: biz, technical: tech}) do
struct =
struct(%__MODULE__{}, %{
id: id,
business: Business.new(biz),
technical: Technical.new(tech)
})
{:ok, struct}
rescue
e -> {:error, e}
end
defp create(msg) do
{:error, "Invalid Dataset: #{inspect(msg)}"}
end
@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is stream`
"""
def is_stream?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"stream" == sourceType
end
@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is remote`
"""
def is_remote?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"remote" == sourceType
end
@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is ingest`
"""
def is_ingest?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"ingest" == sourceType
end
@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is host`
"""
def is_host?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"host" == sourceType
end
end
defimpl Brook.Deserializer.Protocol, for: SmartCity.Dataset do
def deserialize(_struct, data) do
SmartCity.Dataset.new(data)
end
end