https://github.com/ficodes/smart-datamodel-views
https://github.com/ficodes/smart-datamodel-views
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ficodes/smart-datamodel-views
- Owner: Ficodes
- Created: 2020-03-04T09:49:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-25T10:06:10.000Z (over 5 years ago)
- Last Synced: 2025-03-10T20:47:46.380Z (over 1 year ago)
- Language: HTML
- Size: 53.7 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Smart Datamodel Views
Json rules and html templates for the consumption of generic NGSI datamodel 2 PoI operator.
Html templates are based on [nunjucks](https://mozilla.github.io/nunjucks/).
Json rules are based on [json-rules-engine](https://github.com/CacheControl/json-rules-engine/blob/master/src/engine-default-operators.js)
**Json rules examples**:
**To check if property exists explanation for icon**:
```json
"icon": {
"default": {
"fill": "rgba(121, 188, 106, 0.3)",
"stroke": "rgb(99, 112, 30)"
},
"rules": [
{
"event": {
"type": "existProp",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
},
"name": "availableSpotNumber",
"priority": 10,
"conditions": {
"all": [
{
"fact": "existProp",
"operator": "equal",
"params": {
"property": "availableSpotNumber"
},
"value": false
}
]
}
}
]
}
```
The default property is the result returned in the event that none of the rules is met.
If the object does not contain the property "availableSpotNumber", stop all other conditions and return success value.
The name and the "conditions.all.params.property" must be have the same value.
**Example to define template property:**
```json
{
"infoWindow": "{%OffStreetParking.html%}"
}
```
**Complete example for offStreetParking:**
```json
{
"id": "id",
"icon": {
"default": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png",
"rules": [
{
"event": {
"type": "existProp",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
}
},
"name": "availableSpotNumber",
"priority": 10,
"conditions": {
"all": [
{
"fact": "existProp",
"operator": "equal",
"params": {
"property": "availableSpotNumber"
},
"value": false
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 5
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 10
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 20
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": "https://cdn0.iconfinder.com/data/icons/4web-3/139/location-64.png"
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 40
}
]
}
}
]
},
"tooltip": "id",
"data": "$",
"title": [
"name",
"id"
],
"infoWindow": "{%OffStreetParking.html%}",
"currentLocation": "currentLocation",
"location": "location",
"style": {
"default": {
"fill": "rgba(121, 188, 106, 0.3)",
"stroke": "rgb(99, 112, 30)"
},
"rules": [
{
"event": {
"type": "existProp",
"params": {
"success": {
"fill": "rgba(51, 51, 51, 0.1)",
"stroke": "#333333"
}
}
},
"name": "availableSpotNumber",
"priority": 10,
"conditions": {
"all": [
{
"fact": "existProp",
"operator": "equal",
"params": {
"property": "availableSpotNumber"
},
"value": false
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": {
"fill": "rgba(150, 0, 24, 0.3)",
"stroke": "rgba(150, 0, 24, 0.9)"
}
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 5
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": {
"fill": "rgba(242, 147, 5, 0.3)",
"stroke": "rgba(242, 147, 5, 0.9)"
}
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 10
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": {
"fill": "rgba(238, 194, 11, 0.3)",
"stroke": "rgba(238, 194, 11, 0.9)"
}
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 20
}
]
}
},
{
"event": {
"type": "",
"params": {
"success": {
"fill": "rgba(121, 188, 106, 0.3)",
"stroke": "rgb(99, 112, 30)"
}
}
},
"conditions": {
"all": [
{
"fact": "availableSpotNumber",
"operator": "lessThanInclusive",
"value": 40
}
]
}
}
]
}
}
```
In ""data": "$"," $ refers to the entire object using the [jsonpath](https://github.com/json-path/JsonPath) lib.
```json
"title": [
"name",
"id"
],
```
Title will catch the value of the first property found