Commit 15376b52 authored by Jorge Visca's avatar Jorge Visca

cleaned up logging

parent cbd4138f
......@@ -10,12 +10,6 @@ G.load('in/nodes.csv', 'in/edges.csv')
local mobility = require('mobility')
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
end
M.people = nil
-- Creates a new person, assigning processess
......@@ -44,13 +38,13 @@ M.create_exposed = function ( zone, exposed_from )
new_exposed.mobility_model = mobility_model
lib.esim.launch(mobility.process[mobility_model](new_exposed))
w_log(t, ' new_exposed id: ', new_exposed.id,
conf.w_log(t, ' new_exposed id: ', new_exposed.id,
' mobility: ', new_exposed.mobility_model,
' from: ', (exposed_from and exposed_from.id) or 'none',
' zone: ', zone.id, ' ', zone.dpto .. '-'..zone.localidad
)
if zone.Exposed==0 then
w_log(t, ' firstzone_exposed id: ', new_exposed.id,
conf.w_log(t, ' firstzone_exposed id: ', new_exposed.id,
' mobility: ', new_exposed.mobility_model,
' from: ', (exposed_from and exposed_from.id) or 'none',
' zone: ', zone.id, ' ', zone.dpto .. '-'..zone.localidad
......@@ -87,7 +81,6 @@ M.initialize = function ( c )
mobility.initialize( conf )
M.people = {}
if not conf.f_log then w_log = function() end end
end
return M
\ No newline at end of file
......@@ -5,12 +5,6 @@ local mathutil = require('lib.mathutil')
local conf
local lib
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
end
M.models = {}
M.models.forward1 = function ( case )
......@@ -21,7 +15,7 @@ M.models.forward1 = function ( case )
if (not contact.disease.quarantined)
and (math.random()<conf.ca_p)
and (math.random()<conf.ca_coop) then
w_log(t, ' app case: ', case.id, ' contact: ', contact.id )
conf.w_log(t, ' app case: ', case.id, ' contact: ', contact.id )
contact.disease.quarantined = true
end
end
......@@ -42,7 +36,7 @@ M.models.recursive = function ( case )
if (not contact.disease.quarantined)
and (math.random()<conf.ca_p)
and (math.random()<conf.ca_coop) then
w_log(t, ' app case: ', c.id, ' contact: ', contact.id )
conf.w_log(t, ' app case: ', c.id, ' contact: ', contact.id )
contact.disease.quarantined = true
end
end
......@@ -64,7 +58,6 @@ M.initialize = function ( c )
M.new_case = assert(M.models[conf.ca_model],
'unknown ca model: '..tostring(conf.ca_model))
if not conf.f_log then w_log = function() end end
end
......
......@@ -9,12 +9,6 @@ local lib
M.cases = nil --queue
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
end
local function tracer_process ( tracer_id )
local t = lib.esim.now
while true do
......@@ -24,7 +18,7 @@ local function tracer_process ( tracer_id )
end
local case = M.cases:popleft()
w_log(t, ' trace_start tid: ', tracer_id, ' id: ', case.id )
conf.w_log(t, ' trace_start tid: ', tracer_id, ' id: ', case.id )
local t_end = t + conf.ct_trace_t
local i = 1
while t<t_end do
......@@ -32,7 +26,7 @@ local function tracer_process ( tracer_id )
if i<=#case.exposed_to then
local contact = case.exposed_to[i]
if (not contact.disease.quarantined) and (math.random()<conf.ct_coop) then
w_log(t, ' traced tid: ', tracer_id, ' case: ', case.id, ' contact: ', contact.id )
conf.w_log(t, ' traced tid: ', tracer_id, ' case: ', case.id, ' contact: ', contact.id )
contact.disease.quarantined = true
end
i = i + 1
......@@ -51,8 +45,6 @@ end
M.initialize = function ( c )
conf = assert(c)
lib = conf.lib
if not conf.f_log then w_log = function() end end
M.cases = queue:new()
for i = 1, c.ct_count or 0 do
......
......@@ -9,16 +9,10 @@ local conf
local lib
local ds_model
local function w_states ()
local t = lib.esim.now
--w_eir('t E I Q R')
local function w_states ( t )
-- w_states('t', 'E', 'I', 'R', 'quarantined')
conf.f_states:write(t, ' ', M.state_count.E, ' ', M.state_count.I, ' ',
M.state_count.R, ' ', M.state_count.quarantined, '\n')
end
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
M.state_count.R, ' ', M.state_count.quarantined)
end
local states_mt = {
......@@ -38,13 +32,13 @@ local states_mt = {
if v=='R' and t._quarantined then
M.state_count.quarantined = M.state_count.quarantined - 1
end
w_states()
w_states( lib.esim.now )
elseif k=='quarantined' then
if v then
assert(not t._quarantined)
M.state_count.quarantined = M.state_count.quarantined + 1
t._quarantined = v
w_states()
w_states( lib.esim.now )
else
error('unquarantine not supported')
end
......@@ -84,7 +78,7 @@ local selfQuarantineProcess = function ( person )
lib.esim.sleep_to(tq)
if not d.quarantined then
d.quarantined = true
w_log(t, ' selfquarantined id:', person.id)
conf.w_log(t, ' selfquarantined id:', person.id)
end
lib.contacttracer.cases:pushright(person)
lib.contactapp.new_case(person)
......@@ -130,9 +124,7 @@ M.initialize = function ( c )
lib = conf.lib
M.state_count = {E=0, I=0, R=0, quarantined=0}
if not conf.f_states then w_states = function() end end
if not conf.f_log then w_log = function() end end
if conf.f_states then conf.f_states:write('t L P I R quarantined\n') end
w_states('t', 'E', 'I', 'R', 'quarantined')
end
return M
\ No newline at end of file
......@@ -9,17 +9,10 @@ local conf
local lib
local ds_model
local function w_states ()
local t = lib.esim.now
--w_slir('t L P I Q R')
conf.f_states:write(t, ' ', M.state_count.L, ' ', M.state_count.P, ' ',
M.state_count.I, ' ', M.state_count.R, ' ', M.state_count.quarantined, '\n')
conf.f_states:flush()
end
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
local function w_states ( t )
--w_states('t', 'L', 'P', 'I', 'R', 'quarantined')
conf.w_states(t, ' ', M.state_count.L, ' ', M.state_count.P, ' ',
M.state_count.I, ' ', M.state_count.R, ' ', M.state_count.quarantined)
end
local states_mt = {
......@@ -39,13 +32,13 @@ local states_mt = {
if v=='R' and t._quarantined then
M.state_count.quarantined = M.state_count.quarantined - 1
end
w_states()
w_states( lib.esim.now )
elseif k=='quarantined' then
if v then
assert(not t._quarantined)
M.state_count.quarantined = M.state_count.quarantined + 1
t._quarantined = v
w_states()
w_states( lib.esim.now )
else
error('unquarantine not supported')
end
......@@ -109,7 +102,7 @@ local selfQuarantineProcess = function ( person )
lib.esim.sleep_to(tq)
if not d.quarantined then
d.quarantined = true
w_log(t, ' selfquarantined id:', person.id)
conf.w_log(t, ' selfquarantined id:', person.id)
end
lib.contacttracer.cases:pushright(person)
lib.contactapp.new_case(person)
......@@ -170,9 +163,7 @@ M.initialize = function ( c )
lib = conf.lib
M.state_count = {L=0, P=0, I=0, R=0, quarantined=0}
if not conf.f_states then w_states = function() end end
if not conf.f_log then w_log = function() end end
if conf.f_states then conf.f_states:write('t L P I R quarantined\n') end
w_states('t', 'L', 'P', 'I', 'R', 'quarantined')
end
return M
\ No newline at end of file
......@@ -13,28 +13,34 @@ M.run = function ( conf )
local sim_status_count = {outbreak=0, extinction=0, runout=0}
local function w_log (t, ...)
conf.f_log:write(t, ...)
conf.f_log:write('\n')
--conf.f_log:flush()
local R_e_A = {}
local function get_logger ( f )
return function (t, ...)
f:write(t, ...)
f:write('\n')
end
end
local R_e_A = {}
--os.execute('rm out/*.log out/*.txt')
for i = 1, conf.NRUNS do
-- Log files
local f_log, f_states
if conf.out_path then
conf.f_states = io.open(conf.out_path..'states'..i..'.log', 'w')
conf.f_log = io.open(conf.out_path..'epitrace'..i..'.log', 'w')
f_states = io.open(conf.out_path..'states'..i..'.log', 'w')
f_log = io.open(conf.out_path..'epitrace'..i..'.log', 'w')
conf.w_log = get_logger(f_log)
conf.w_states = get_logger(f_states)
else
w_log = function () end
conf.w_log = function () end
conf.w_states = conf.w_log
end
-- Seed the random generator independetly per run
math.randomseed(i) --os.time())
w_log(0, ' randomseed ', i)
conf.w_log(0, ' randomseed ', i)
lib.esim.initialize( conf.TMAX )
lib.agents.initialize( conf )
......@@ -59,12 +65,12 @@ M.run = function ( conf )
end
until sim_status
w_log(t_now, ' finished ',sim_status,' R: ', lib.disease.state_count.R)
conf.w_log(t_now, ' finished ',sim_status,' R: ', lib.disease.state_count.R)
print (i, 'finished at t: '..t_now..' events: '
..event_count..' ('..sim_status ..')')
if conf.f_states then conf.f_states:close() end
if conf.f_log then conf.f_log:close() end
if f_log then f_log:close() end
if f_states then f_states:close() end
sim_status_count[sim_status] = (sim_status_count[sim_status] or 0) + 1
......@@ -90,7 +96,6 @@ M.run = function ( conf )
R_e_std = R_e_std,
}
return sim_result
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment