curves
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
curves [2020/07/30 12:50] – created atolstov | curves [2022/05/24 08:52] (current) – [Get value from the curve via Lua] emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{ network: | ||
======Curves====== | ======Curves====== | ||
+ | =====Introduction===== | ||
+ | {{ : | ||
Curve is a way to define output value from a pre-defined pair table of a discrete set of known data points. Such as standard or desired value. | Curve is a way to define output value from a pre-defined pair table of a discrete set of known data points. Such as standard or desired value. | ||
- | It can be represented as a black-box, where is some INPUT have corresponding OUTPUT.(svg) | + | Curve can be represented as a function f, which is a blackbox, where is some **INPUT x** have corresponding |
Curve is using a piecewise linear interpolation, | Curve is using a piecewise linear interpolation, | ||
Line 21: | Line 23: | ||
* There is strict algebraic function and value should be calculated. | * There is strict algebraic function and value should be calculated. | ||
* The function should be sequentually or time-to-time changed. | * The function should be sequentually or time-to-time changed. | ||
- | <del> | ||
- | To define curve algebraically, | ||
- | To define curve algebraically, | + | To define curve algebraically, |
- | For example: | + | For example:\\ |
- | (0 to 100 line; 0 1 0 1 / 24 hour ; temperature citoterm falling | + | At minimum it can be two points.\\ |
+ | {{ :curve: | ||
+ | Binary logic function.\\ | ||
+ | {{ : | ||
+ | Table parameter definition\\ | ||
+ | {{ : | ||
+ | Saturation function\\ | ||
+ | {{ : | ||
+ | Algebraic defined calculated function. For example sin(x) with 6 points approximation.\\ | ||
+ | {{ : | ||
- | To get the OUTPUT | + | =====New curve creation===== |
+ | Let's create a new curve. \\ | ||
+ | Click on "New curve" button.\\ | ||
+ | {{ : | ||
+ | Type in a Title and go on the next tab '' | ||
+ | {{ : | ||
+ | Optionally, you can check "Use the existing String register to store the curve parameters" | ||
+ | {{ : | ||
+ | |||
+ | Here is a curve editor. There is a domain of a function definition, range of a function and every point X and Y coordinates.\\ | ||
+ | {{ : | ||
+ | To create a new point click twice on a line. To remove it click with holding Alt button.\\ | ||
+ | {{ : | ||
+ | Then you can both move point or specify its value using form in the right.\\ | ||
+ | {{ : | ||
+ | At the end, when all the rest of parameters set let's look at the result . In our example it would more precise approximation of sin(x) with 7 point defined\\ | ||
+ | {{ : | ||
+ | =====Select a curve to put in register===== | ||
+ | To get the value you need: | ||
+ | - Have a curve | ||
+ | - Have a string register for dashboard element to put selected curve in it | ||
+ | - Optionally, have yet another string register for store that curve all the time | ||
+ | |||
+ | Now, it is time to create a register with value type " | ||
+ | |||
+ | Then, create a new dashboard. | ||
+ | {{ : | ||
+ | Click the "Add dashboard" | ||
+ | {{ : | ||
+ | Type in the Title and go on. | ||
+ | {{ : | ||
+ | Go to a visual editor. | ||
+ | |||
+ | |||
+ | To do this, there is a dashboard element " | ||
+ | {{ : | ||
+ | Drag' | ||
+ | {{ : | ||
+ | |||
+ | Pick a register to be used later in Lua script to get value. | ||
+ | {{ : | ||
+ | Let's test it. | ||
+ | Now, you need to put the curve to string register via dashboard. | ||
+ | {{ : | ||
+ | Click and select the one you want to pick. There is a icon for open curve editor. | ||
+ | {{ : | ||
+ | There is a picked one. | ||
+ | {{ : | ||
+ | | ||
+ | {{ : | ||
+ | |||
+ | =====Get value from the curve via Lua ===== | ||
+ | |||
+ | To get the **OUTPUT | ||
- a Lua script to work with string register and | - a Lua script to work with string register and | ||
- include a Lua lib, which will provide access to that function. | - include a Lua lib, which will provide access to that function. | ||
Line 36: | Line 98: | ||
- Call a GetCurveValue function and pass to it this '' | - Call a GetCurveValue function and pass to it this '' | ||
+ | <code lua - curves.lib> | ||
+ | --[[ | ||
+ | The function does curve conversion f(inputValue) = outputValue | ||
+ | Example of a curve, having multiple ranges of kx + b, set in a register of a String type with Json | ||
+ | [{" | ||
+ | --]] | ||
+ | function getCurveValue (curveReg, inputValue) | ||
- | + | local s, e = 1, 2 -- start & end indexes of the subranges | |
- | <code lua - curves.lib> | + | |
- | function GetCurveValue ( curve_register, x_to_find_y | + | |
- | | + | |
- | | + | |
- | --Curve handler | + | |
- | INPUT: | + | |
- | Put curve register as first argument and X coordinate as second. | + | |
- | OUTPUT: | + | |
- | Get as result status if it is inside curve range of outside(false) and the Y value as second output argument | + | |
- | | + | |
- | EXAMPLE: | + | |
- | curve_status, value = GetCurveValue( " | + | |
| | ||
- | | + | for _, sub_ in ipairs(tab) do |
- | table = cjson.decode( R ( curve_register ) ) | + | if ( (sub_.range[s] <= inputValue) |
- | -- inRangeCurve( table, x_to_find_y ) | + | |
- | | + | |
- | if ( value.range[1] <= x_to_find_y | + | |
- | | + | |
- | in_range_status, | + | |
- | return in_range_status, y | + | |
end | end | ||
end | end | ||
- | | + | -- edge cases |
- | -- in_range_status, | + | |
- | | + | |
- | | + | |
- | elseif | + | elseif |
- | | + | |
- | | + | |
- | return in_range_status, | + | |
end | end | ||
- | + | | |
- | | + | |
end | end | ||
</ | </ | ||
Example of usage: | Example of usage: | ||
<code lua - Getter> | <code lua - Getter> | ||
- | include " | + | include " |
function main (userId) | function main (userId) | ||
- | + | local SAFE_VALUE = 10 | |
- | local t = os.date(" | + | local curHour |
- | | + | |
- | | + | |
- | | + | |
+ | if (not valueOutOfRange) then | ||
+ | W("value_for_curHour", y) -- WriteReg | ||
+ | | ||
+ | W(" | ||
+ | end | ||
end | end | ||
</ | </ |
curves.1596113417.txt.gz · Last modified: 2020/07/30 12:50 by atolstov