A randomized process adjusts pricing for a list of items, while maintaining a previous 24 hour Price Tracking log directly in each record. The 24 Hour Price Tracking column for the current hour UTC is highlighted in green. The column highlighted in red represents the trailing edge of the previous 24 hours, and holds the value that is used to calculate the 24 Hour % Change. Any column highlighted in yellow represents the last recorded Heartbeat Pricing Change hour, only when it doesn't overlap with the other highlighted columns.
This page uses Conditional Range Loops to implement the following Gap Correction logic: When the last recorded Heartbeat Pricing Change was not done in the current hour, or the hour directly before the current hour, the price recorded for that last change will be applied to every hour up until the current hour.
Item Name | Current Price | 24 Hour % Change | 24 Hour Price Tracking | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | |||
Item 1 | 23.86 | - 0.50 % | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.92 | 23.86 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 | 23.98 |
Item 2 | 24.90 | - 0.24 % | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.90 | 24.90 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 | 24.96 |
Item 3 | 26.03 | + 0.22 % | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 26.00 | 26.03 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 | 25.97 |
Item 4 | 26.93 | - 0.26 % | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 26.93 | 26.93 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 |
Item 5 | 27.89 | + 0.00 % | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.96 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 | 27.89 |
Item 6 | 28.86 | - 0.25 % | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.86 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 | 28.93 |
Item 7 | 29.94 | - 0.10 % | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.94 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 | 29.97 |
Item 8 | 31.05 | + 0.00 % | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.02 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 | 31.05 |
Item 9 | 32.00 | + 0.00 % | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 | 32.00 |
Item 10 | 32.79 | + 0.10 % | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.79 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 | 32.76 |
<# // load the last record for Heartbeat Time, then apply any overrides apply heartbeat_time as "heartbeat" or redirect to "/heartbeat/purge"; if("<#[url.override_hour]#>"!="") { set heartbeat.hour to "<#[url.override_hour as integer]#>"; } if("<#[url.override_date]#>"!="") { set heartbeat.date to "<#[url.override_date as date "Y-M-D"]#>"; } // set time based values for % Change calculations and Gap Correction set this_hour to <#[system.timestamp as date "H"]#>; set prev_hour to (<#[this_hour]#> - 1) % 24; set next_hour to (<#[this_hour]#> + 1) % 24; set gap_days to <#[system.date as timestamp]#> - <#[heartbeat.date as timestamp]#> as timespan "d"; // set classes for highlighted columns set hour_<#[heartbeat.hour]#>_background to "bg-warning"; set hour_<#[this_hour]#>_background to "bg-success"; set hour_<#[next_hour]#>_background to "bg-danger"; // process all Heartbeat Items to update all pricing values start list for heartbeat_items; sort by price as numeric; #> <# start header #> <div class="table-responsive"> <table class="table table-hover table-striped table-condensed small" id="heartbeat"> <thead> <tr> <th rowspan="2">Item Name</th> <th rowspan="2" class="text-right">Current Price</th> <th rowspan="2" class="text-center">24 Hour <span class="text-nowrap">% Change</span></th> <th colspan="24">24 Hour Price Tracking</th> </tr> <tr> <th class="text-right <#[hour_0_background]#>">0</th> <th class="text-right <#[hour_1_background]#>">1</th> <th class="text-right <#[hour_2_background]#>">2</th> <th class="text-right <#[hour_3_background]#>">3</th> <th class="text-right <#[hour_4_background]#>">4</th> <th class="text-right <#[hour_5_background]#>">5</th> <th class="text-right <#[hour_6_background]#>">6</th> <th class="text-right <#[hour_7_background]#>">7</th> <th class="text-right <#[hour_8_background]#>">8</th> <th class="text-right <#[hour_9_background]#>">9</th> <th class="text-right <#[hour_10_background]#>">10</th> <th class="text-right <#[hour_11_background]#>">11</th> <th class="text-right <#[hour_12_background]#>">12</th> <th class="text-right <#[hour_13_background]#>">13</th> <th class="text-right <#[hour_14_background]#>">14</th> <th class="text-right <#[hour_15_background]#>">15</th> <th class="text-right <#[hour_16_background]#>">16</th> <th class="text-right <#[hour_17_background]#>">17</th> <th class="text-right <#[hour_18_background]#>">18</th> <th class="text-right <#[hour_19_background]#>">19</th> <th class="text-right <#[hour_20_background]#>">20</th> <th class="text-right <#[hour_21_background]#>">21</th> <th class="text-right <#[hour_22_background]#>">22</th> <th class="text-right <#[hour_23_background]#>">23</th> </tr> </thead> <tbody> <# end header #> <# start row #> <#: Gap Correction Logic :#> <# if "<#[gap_days]#>"="0" and "<#[heartbeat.hour]#>" < "<#[prev_hour]#>" #> <# start loop <#[heartbeat.hour]#>+1..<#[prev_hour]#>; #> <# update record for "<# id #>"; set hour_<#value#>_price to "<# hour_<#[heartbeat.hour]#>_price #>"; #> <# end loop #> <# elseif "<#[gap_days]#>"="1" and not("<#[heartbeat.hour]#>"="23" and "<#[this_hour]#>"="0") #> <# start loop <#[heartbeat.hour]#>+1..23; #> <# update record for "<# id #>"; set hour_<#value#>_price to "<# hour_<#[heartbeat.hour]#>_price #>"; #> <# end loop #> <# start loop 0..<#[prev_hour]#>; #> <# update record for "<# id #>"; set hour_<#value#>_price to "<# hour_<#[heartbeat.hour]#>_price #>"; #> <# end loop #> <# elseif "<#[gap_days]#>" > "1" #> <# start loop <#[next_hour]#>..23; #> <# update record for "<# id #>"; set hour_<#value#>_price to "<# hour_<#[heartbeat.hour]#>_price #>"; #> <# end loop #> <# start loop 0..<#[prev_hour]#>; #> <# update record for "<# id #>"; set hour_<#value#>_price to "<# hour_<#[heartbeat.hour]#>_price #>"; #> <# end loop #> <# end if #> <# // randomly adjust pricing set new_price to "<# price #>"; set change to random 0..100; if("<# change #>" < "3") { increment new_price by <# new_price #> * (.5 / 100); } elseif("<# change #>" < "6") { decrement new_price by <# new_price #> * (.5 / 100); } elseif("<# change #>" < "15") { increment new_price by <# new_price #> * (.25 / 100); } elseif("<# change #>" < "24") { decrement new_price by <# new_price #> * (.25 / 100); } elseif("<# change #>" < "49") { increment new_price by <# new_price #> * (.1 / 100); } elseif("<# change #>" < "74") { decrement new_price by <# new_price #> * (.1 / 100); } // never allow zero pricing if("<# new_price as cents #>"="0.00") { set new_price to "0.01"; } // save new pricing update record for "<# id #>"; set price to "<# new_price as cents #>"; set hour_<#[this_hour]#>_price to "<# new_price as cents #>"; set price_percent_change to ( (<#new_price#> - <#hour_<#[next_hour]#>_price#>) / <#hour_<#[next_hour]#>_price#> ) * 100 as cents; #> <tr> <td class="text-nowrap"><# name as html #></td> <td class="text-right"><# price as cents #></td> <td class="text-nowrap"><# price_percent_change as changepercent #></td> <td class="text-right <#[hour_0_background]#>"><# hour_0_price #></td> <td class="text-right <#[hour_1_background]#>"><# hour_1_price #></td> <td class="text-right <#[hour_2_background]#>"><# hour_2_price #></td> <td class="text-right <#[hour_3_background]#>"><# hour_3_price #></td> <td class="text-right <#[hour_4_background]#>"><# hour_4_price #></td> <td class="text-right <#[hour_5_background]#>"><# hour_5_price #></td> <td class="text-right <#[hour_6_background]#>"><# hour_6_price #></td> <td class="text-right <#[hour_7_background]#>"><# hour_7_price #></td> <td class="text-right <#[hour_8_background]#>"><# hour_8_price #></td> <td class="text-right <#[hour_9_background]#>"><# hour_9_price #></td> <td class="text-right <#[hour_10_background]#>"><# hour_10_price #></td> <td class="text-right <#[hour_11_background]#>"><# hour_11_price #></td> <td class="text-right <#[hour_12_background]#>"><# hour_12_price #></td> <td class="text-right <#[hour_13_background]#>"><# hour_13_price #></td> <td class="text-right <#[hour_14_background]#>"><# hour_14_price #></td> <td class="text-right <#[hour_15_background]#>"><# hour_15_price #></td> <td class="text-right <#[hour_16_background]#>"><# hour_16_price #></td> <td class="text-right <#[hour_17_background]#>"><# hour_17_price #></td> <td class="text-right <#[hour_18_background]#>"><# hour_18_price #></td> <td class="text-right <#[hour_19_background]#>"><# hour_19_price #></td> <td class="text-right <#[hour_20_background]#>"><# hour_20_price #></td> <td class="text-right <#[hour_21_background]#>"><# hour_21_price #></td> <td class="text-right <#[hour_22_background]#>"><# hour_22_price #></td> <td class="text-right <#[hour_23_background]#>"><# hour_23_price #></td> </tr> <# end row #> <# start footer #> </tbody> </table> </div> <# update record for "heartbeat_time.<#[heartbeat.id]#>"; set hour to "<#[this_hour]#>"; set date to "<#[system.date]#>"; #> <# end footer #> <# end list #>
This Form is provided to override the latest Pricing Change Heartbeat Time, allowing testing of the Gap Correction Logic.