# Case studies

Let's now see practical examples of using Live plugin.

Following examples use this set on handlers:

fahrToCel

// fahrToCel: 
function(temp) { return (temp - 32) * 5/9 }

setStatus

// setStatus: 
(value) => isNaN(value) ? 'unknown' : value < 50 ? 'ok' : value < 75 ? 'warning' : value < 95 ? 'critical' : 'down'

getWeather

// getWeather: 
function (weatherLabel) { 
        switch(weatherLabel) { 
            case "It's a sunny day!": 
                return "sun"; 
            case "Day to be on a cloud!": 
                return "cloudy";
            case "Sky is crying...": 
                return "rain"; 
            case "THUNDERS !": 
                return "lightning"; 
            default: return "night";
    } 
}

# Simple node

Imagine a graph with only one Live node: Weather widget

Weather widget is a graph node created by Zenetys.

Component shape depends on the value stored in its Status property.

Available values are: sun cloudy rain lightning & night.

Weather widget values

# Init

Live Attributes stored in graph root:

  • API: https://happy-weather-reports.net/api/v2
  • Refresh: 5
  • API Key: ZXhhbXBsZQ==

Weather widget content:

Live Attributes stored in graph node:

  • API Object: /cities/France?city=paris&date=now
  • Source: data.entries[1]

Live Properties stored in graph node:

  • status: =return handlers.getWeather(self.happy_expression);

# API Calls

When update process starts:

Weather widget:

  1. Widget requests /cities/France?city=paris&date=now API endpoint.
  2. Node uses ZXhhbXBsZQ== as Authorization header value to authenticate. API response:
{

    "status": 200,
    "data": {
        "entries": [
            {
                "continent": "Europe",

                "country": "France",

                "city": "Paris",

                "date": 1625945220790
            },
            {
                "temperature": {
                "value": 77,
                "unit": "Fahrenheit"
            },
            "clear_sky": false,
            "rain": false,
            "wind": true,
            "lightning": false,
            "happy_expression": "Day to be on a cloud!"
            }
        ]
    }
}

# Get exploitable data

Once raw data are received:

Weather widget As Source value is data.entries[1], node computed exploitable data is:

{
    "temperature": {
        "value": 77,
        "unit": "Fahrenheit"
    },
    "clear_sky": false,
    "rain": false,
    "wind": true,
    "lightning": false,
    "happy_expression": "Day to be on a cloud!"
}

# Get updated values

Updates values are finally computed.

Weather widget

  • status: JS instructions return cloudy which is Status property updated value.