Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lang = mw.language.new('en')
- local p = {}
- --Cycles in the last 10 hours:
- --07 December 2018 22:00:00 (UTC): Chinchompa, Dragon, Zygomite
- --08 December 2018 00:30:00 (UTC): Chinchompa
- --08 December 2018 03:00:00 (UTC): Chinchompa
- --08 December 2018 05:30:00 (UTC): Chinchompa
- --08 December 2018 06:20:00 (UTC): Zygomite
- --Cycles in the next 10 hours:
- --08 December 2018 08:00:00 (UTC): Chinchompa
- --08 December 2018 10:30:00 (UTC): Chinchompa
- --08 December 2018 13:00:00 (UTC): Chinchompa
- --08 December 2018 14:40:00 (UTC): Dragon, Zygomite
- --08 December 2018 15:30:00 (UTC): Chinchompa
- function p.test()
- return p.pof({'Chinchompa', 'Zygomite', 'Dragon'}, 10);
- end
- function p.pof(animals, timespan_hours)
- local timesPast = {};
- local timesFuture = {};
- for _,a in ipairs(animals) do
- local g = p.pof_generate(a, timespan_hours);
- for _,t in ipairs(g.past) do
- if timesPast[t] == nil then
- timesPast[t] = {};
- end
- table.insert(timesPast[t], a);
- end
- for _,t in ipairs(g.future) do
- if timesFuture[t] == nil then
- timesFuture[t] = {};
- end
- table.insert(timesFuture[t], a);
- end
- end
- local r = 'Cycles in the last ' .. timespan_hours .. (timespan_hours == 1 and ' hour:\n' or ' hours:\n');
- local times = {};
- for k in pairs(timesPast) do table.insert(times, k); end
- table.sort(times);
- for _,t in ipairs(times) do
- local a = timesPast[t];
- table.sort(a);
- r = r .. lang:formatDate('d F Y H:i:s', '@' .. t, nil) .. ' (UTC): ' .. table.concat(a, ', ') .. '\n';
- end
- r = r .. 'Cycles in the next ' .. timespan_hours .. (timespan_hours == 1 and ' hour:\n' or ' hours:\n');
- times = {};
- for k in pairs(timesFuture) do table.insert(times, k) end
- table.sort(times);
- for _,t in ipairs(times) do
- local a = timesFuture[t];
- table.sort(a);
- r = r .. lang:formatDate('d F Y H:i:s', '@' .. t, nil) .. ' (UTC): ' .. table.concat(a, ', ') .. '\n';
- end
- return r;
- end
- function p.pof_generate(animal, timespan_hours)
- local a = p.pof_animals()[animal];
- local cycleInS = a.cycleLength * 60;
- local lastCycleTime = math.floor(os.time() / cycleInS) * cycleInS;
- local timesPast = {};
- local pastCutoff = os.time() - (timespan_hours * 3600);
- local cycleTime = lastCycleTime;
- while cycleTime >= pastCutoff do
- table.insert(timesPast, cycleTime);
- cycleTime = cycleTime - cycleInS;
- end
- local timesFuture = {};
- local futureCutoff = os.time() + (timespan_hours * 3600);
- cycleTime = lastCycleTime + cycleInS;
- while cycleTime <= futureCutoff do
- table.insert(timesFuture, cycleTime);
- cycleTime = cycleTime + cycleInS;
- end
- return {past = timesPast, future = timesFuture};
- end
- function p.pof_animals()
- return {
- ['Rabbit'] = {cycleLength = 5},
- ['Chicken'] = {cycleLength = 50},
- ['Chinchompa'] = {cycleLength = 150},
- ['Sheep'] = {cycleLength = 100},
- ['Spider'] = {cycleLength = 180},
- ['Zygomite'] = {cycleLength = 500},
- ['Cow'] = {cycleLength = 300},
- ['Yak'] = {cycleLength = 400},
- ['Dragon'] = {cycleLength = 1000},
- };
- end
- return p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement