home | news | discuss | issues | license LURE: spy |
|
---|---|
Watch over a stream, regularly reportingtim@menzies.us |
require "show"
local the=require "config"
local NUM=require "num"
|
Create a new watcher |
local function create(n) return {
reportEvery = n,
m = 0,
stats = NUM.create(),
all = {}
} end
|
Report |
local function report(i,x)
print{n=i.stats.n, mu=i.stats.mu, sd=i.stats.sd} end
|
Update watcher |
local function update(i,x)
if x~= the.ignore then
i.m = i.m + 1
NUM.update(i.stats,x)
if i.m % i.reportEvery == 0 then
i.all[#i.all + 1] = i.stats
report(i)
i.stats = NUM.create() end end
return i end
|
Handy short cut |
local function watch(n)
local i=create(n)
return i, function (x) return update(i,x) end end
|
Update a watcher
|
local function updates(lst,f,i)
i = i or create()
f = f or function (z) return z end
for _,one in pairs(lst) do
update(i, f(one)) end
return i end
|
Public interface |
return {create=create, update=update, updates=updates,
watch=watch, report=report}
|
LegalLURE, Copyright (c) 2017, Tim Menzies All rights reserved, BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|