-- init code for LW timetable env -- stop, scheduled departure every -- d_int: Departure every n seconds (epoch modulo) -- d_off: Departure time offset function F.stop_sd(st_name, doors, departcommand, minstoptime, d_int, d_off) if event.train then local timenow = os.time() local timerdy = timenow + minstoptime local wait = d_int - ((timerdy-d_off) % d_int) local waitcorr = math.floor(wait*0.66) digiline_send("monitor", "Departure scheduled for: | "..os.date("%H:%M:%S", timenow+wait)) atc_send("B0 W O"..doors.." D"..waitcorr.." OCD1"..departcommand) else local timenow = os.time() digiline_send("monitor", "Time: "..os.date("%H:%M:%S", timenow)) end end function F.stop_sd_sched(st_name, doors, departcommand, minstoptime, d_int, d_off) depart = false if event.train then local time_now = rwt.now() local next_dep_time = rwt.next_rpt(rwt.add(time_now, minstoptime), d_int, d_off) digiline_send("monitor", "Departure scheduled for: | "..rwt.to_string(next_dep_time, true)) atc_set_text_inside(st_name.."\nDeparture: "..rwt.to_string(next_dep_time, true)) atc_send("B0 W O"..doors) schedule(next_dep_time, "depart") elseif event.schedule then atc_send("OCD1"..departcommand) digiline_send("monitor", "Last Departure: | "..rwt.to_string(rwt.now(), true)) atc_set_text_inside("") depart = true end end function F.timedisplay() digiline_send("time", "Time: | "..rwt.to_string(rwt.now(),true).." | "..os.date("%H:%M:%S")) schedule(rwt.next_rpt(rwt.now(),5,0), "") end -- Stat counter and timetaking utilities -- Stat from subway F.stat=function(line, init) --statistics -- init if init then reftrain = atc_id a_tbt = 30 a_tbtmax = 30 a_rtt = 500 a_not = 0 c_not = 0 c_tbtmax = 0 time_lt = os.time() time_rt=os.time() end if not a_tbtmax then a_tbtmax = 30 end if not c_tbtmax then c_tbtmax = 0 end --real code if event.train then local time = os.time() c_not = c_not + 1 a_tbt = (a_tbt + (time - time_lt)) / 2 c_tbtmax = math.max(c_tbtmax, (time - time_lt)) if atc_id == reftrain then a_rtt = (a_rtt*0.2 + (time - time_rt)*0.8) a_not = c_not c_not = 0 a_tbtmax = (a_tbtmax + c_tbtmax) / 2 c_tbtmax = 0 end digiline_send("stats", "Stat: "..line.. " NoT:"..a_not.."("..c_not..")".. " TbT:"..math.floor(a_tbt).."("..(time-time_lt)..")".. " Tmx:"..math.floor(a_tbtmax).."("..c_tbtmax..")".. " R:"..math.floor(a_rtt).."("..(time - time_rt)..")" ) time_lt = time if atc_id == reftrain then time_rt = time end end end S.timetake = {} function F.timetake_start(ttname) if not atc_id then return end local nouw = rwt.to_secs(rwt.now()) if not S.timetake[ttname] then S.timetake[ttname] = {} end S.timetake[ttname][atc_id] = nouw end --L100 function F.timetake_end(ttname) if not atc_id then return end if not S.timetake[ttname] or not S.timetake[ttname][atc_id] then digiline_send("timetake", "No start time for "..atc_id) return end local first = S.timetake[ttname][atc_id] local nouw = rwt.to_secs(rwt.now()) local tdiff = nouw - first local cavg = S.timetake[ttname].avg local cmax = S.timetake[ttname].max local cmin = S.timetake[ttname].min if cavg and cmax and cmin then S.timetake[ttname].avg = tdiff*0.1 + cavg*0.9 S.timetake[ttname].min = math.min(tdiff, cmin) S.timetake[ttname].max = math.max(tdiff, cmax) else S.timetake[ttname].avg = tdiff S.timetake[ttname].min = tdiff S.timetake[ttname].max = tdiff end digiline_send("timetake", ttname.. " this:"..tdiff.. " min:"..math.floor(S.timetake[ttname].min).. " avg:"..math.floor(S.timetake[ttname].avg).. " max:"..math.floor(S.timetake[ttname].max) ) end --== Timetable prototype (TTP) === --[[ table structures: F.ttp - static timetable data - see below S.ttp[tt_name] = { - dynamic tt data recording_train = travel_times = { =