curves
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
curves [2020/08/03 13:33] – atolstov | curves [2024/06/03 08:45] (current) – emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{ network: | ||
======Curves====== | ======Curves====== | ||
=====Introduction===== | =====Introduction===== | ||
Line 88: | Line 89: | ||
{{ : | {{ : | ||
- | =====Get value from the curve===== | + | =====Get value from the curve via Lua ===== |
To get the **OUTPUT y value** from existing(pre-created) curve, you need: | To get the **OUTPUT y value** from existing(pre-created) curve, you need: | ||
Line 98: | Line 99: | ||
<code lua - curves.lib> | <code lua - curves.lib> | ||
- | function | + | --[[ |
- | --[[ | + | The function |
- | --Curve handler | + | Example of a curve, having multiple ranges of kx + b, set in a register of a String type with Json |
- | | + | [{" |
- | Put curve register as first argument and X coordinate as second. | + | --]] |
- | | + | function getCurveValue (curveReg, v) |
- | Get as result status if it is inside curve range of outside(false) and the Y value as second output argument | + | |
+ | | ||
+ | local tab = cjson.decode(R(curveReg)) | ||
| | ||
- | | + | |
- | | + | |
- | --]] | + | |
- | | + | |
- | -- inRangeCurve( table, x_to_find_y ) | + | |
- | for _, value in ipairs( | + | end |
- | if ( value.range[1] <= x_to_find_y | + | |
- | | + | for _, sub_ in ipairs(tab) do |
- | in_range_status, | + | if ( (sub_.range[start] <= v) and (v < sub_.range[end_]) ) then |
- | return in_range_status, y | + | |
end | end | ||
end | end | ||
- | if x_to_find_y < table[1].range[1] then -- behaivior for outside left-sided | ||
- | -- in_range_status, | ||
- | in_range_status, | ||
- | return in_range_status, | ||
- | elseif x_to_find_y > table[# | ||
- | -- in_range_status, | ||
- | in_range_status, | ||
- | return in_range_status, | ||
- | end | ||
- | |||
- | return in_range_status, | ||
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.1596461628.txt.gz · Last modified: 2020/08/03 13:33 by atolstov