How to find the percent between two values of a list

14 views
Skip to first unread message

Skadomersmtl

unread,
Mar 19, 2020, 10:17:48 PM3/19/20
to Warp 10 users
Hi,

I'm a new warpscript user and I would like to know if there is a mapper function to calculate the percent between two values of a list:

For example I found the mapper.delta with a sliding window of 1 to find the delta between two values of the list, but I would like to have the increasing or decreasing percentage between each values
[
  [
    NEWGTS "GTS1" RENAME 
    10 NaN NaN NaN 5.0 ADDVALUE
    20 NaN NaN NaN 120.0 ADDVALUE 
    30 NaN NaN NaN 140.0 ADDVALUE

    NEWGTS "GTS2" RENAME 
    10 NaN NaN NaN 8.0 ADDVALUE
    20 NaN NaN NaN 42.0 ADDVALUE 
  ]
  mapper.delta 
  1
  0
  0
MAP

Thanks for your help and have a nice day

Mic

Jean-Charles Vialatte

unread,
Mar 20, 2020, 5:00:48 AM3/20/20
to Warp 10 users
Hi Mic,

You can use a macro as a mapper. In this case, the macro expects as input a subgts containing the sliding windows ticks.
You can use this macro:

<%
  'gts' STORE
  $gts SIZE 2 <
  <% [ 0.0 ] %>
  <%
    $gts 0 ATINDEX 4 GET 'a' STORE
    $gts 1 ATINDEX 4 GET 'b' STORE
    [  $b $a - $a / 100.0 * ]
  %>
  IFTE
%>
'mapper' STORE

This macro returns 0.0% if it's the first tick, or the increasing percent if the sliding window has 2 values.

Skadomersmtl

unread,
Mar 20, 2020, 7:46:41 AM3/20/20
to Warp 10 users
Hi,

Thanks Jean-Charles for your help, I didn't know I can create a specific macro (I'm a warpscript beginner). Your solution is working like a charm, I will study every part to improve my warpscript skills ;)

Have a nice day

Mic
Reply all
Reply to author
Forward
0 new messages