Initial and hopefully last commit
I should put up some more public repos so this one is not such an eyesore
This commit is contained in:
commit
76593d1483
2 changed files with 90 additions and 0 deletions
48
README.org
Normal file
48
README.org
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#+OPTIONS: toc:nil
|
||||||
|
* Sleep calc
|
||||||
|
|
||||||
|
Silly script in Lua to help me with sleep planing. Should work well in termux.
|
||||||
|
Developed with Lua5.3 should work in any Lua5
|
||||||
|
|
||||||
|
** What it does:
|
||||||
|
|
||||||
|
It prints what are the best times to wake up and duration of sleep when presented wake up times are used.
|
||||||
|
Like this:
|
||||||
|
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
$ # now it's 01:23; we expect to fall asleep in 5 minutes
|
||||||
|
$ ./sleepCalc.lua 5
|
||||||
|
If gonna fall sleep at: 01:25
|
||||||
|
Wake up | to sleep
|
||||||
|
------------------
|
||||||
|
02:20 | 01h00m
|
||||||
|
03:20 | 02h00m
|
||||||
|
04:20 | 03h00m
|
||||||
|
05:20 | 04h00m
|
||||||
|
06:20 | 05h00m
|
||||||
|
07:20 | 06h00m
|
||||||
|
08:20 | 07h00m
|
||||||
|
09:20 | 08h00m
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Usage
|
||||||
|
|
||||||
|
- Two (optional) positional arguments
|
||||||
|
1) Number of minutes you estimate it will take you to fall asleep
|
||||||
|
- Default is 40 because I'm the only expected audience and I always to pray to Luna & Celestia before sleep
|
||||||
|
2) How many minutes one sleep cycle takes
|
||||||
|
- Default is 90minutes
|
||||||
|
|
||||||
|
** Notice
|
||||||
|
|
||||||
|
- Don't quote me on this I haven't actually done any research in this area
|
||||||
|
- This is just summarized knowledge I collected from randoms on the internet
|
||||||
|
- Most of it is probably wrong or oversimplified
|
||||||
|
- Total amount of research that went into this is < 5
|
||||||
|
- I just did it a few times and felt it actually worked (could be placebo)
|
||||||
|
|
||||||
|
** Basic ideas
|
||||||
|
|
||||||
|
- Ideal power nap is 20min
|
||||||
|
- Light sleep part of sleep is every 1h30m
|
||||||
|
- if you wake up in some multiple of 90 minutes, you should feel fresh a well rested
|
42
sleepCalc.lua
Executable file
42
sleepCalc.lua
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env lua
|
||||||
|
|
||||||
|
-- Everything is in minutes
|
||||||
|
local DEFAULT_SLEEP_CYCLE = 90;
|
||||||
|
local DEFAULT_TIME_TO_FALL_ASLEEP = 40;
|
||||||
|
local DEFAULT_TIME_TO_SLEEP_POWERNAP = 5;
|
||||||
|
|
||||||
|
local gonnaFallAsleepIn, actualSleepCycle;
|
||||||
|
|
||||||
|
-- Returns text representation of hh:mm
|
||||||
|
-- calculated from [now] seconds
|
||||||
|
-- We cant use os.date because of time zones
|
||||||
|
local function getHoursAndMinsString(mins)
|
||||||
|
local hours = mins // 60;
|
||||||
|
local minutes = mins % 60;
|
||||||
|
return (hours > 9 and hours or "0" .. hours) .. "h" .. (minutes > 9 and minutes or "0" .. minutes) .. "m";
|
||||||
|
end
|
||||||
|
|
||||||
|
local args = { ... };
|
||||||
|
|
||||||
|
if (#args == 2) then
|
||||||
|
gonnaFallAsleepIn = tonumber(args[1]);
|
||||||
|
actualSleepCycle = tonumber(args[2]);
|
||||||
|
elseif (#args == 1) then
|
||||||
|
gonnaFallAsleepIn = tonumber(args[1]);
|
||||||
|
actualSleepCycle = DEFAULT_SLEEP_CYCLE;
|
||||||
|
else
|
||||||
|
gonnaFallAsleepIn = DEFAULT_TIME_TO_FALL_ASLEEP;
|
||||||
|
actualSleepCycle = DEFAULT_SLEEP_CYCLE;
|
||||||
|
end
|
||||||
|
|
||||||
|
local now = os.time();
|
||||||
|
|
||||||
|
print("If gonna fall sleep at: " .. os.date("%H:%M", now + (gonnaFallAsleepIn * 60)));
|
||||||
|
print("Wake up | to sleep\n------------------");
|
||||||
|
|
||||||
|
local sleepLen = actualSleepCycle;
|
||||||
|
for i = 0, 7, 1 do
|
||||||
|
print(os.date("%H:%M", now + (actualSleepCycle * 60)) .. " | " .. getHoursAndMinsString(sleepLen));
|
||||||
|
sleepLen = sleepLen + actualSleepCycle;
|
||||||
|
now = now + (actualSleepCycle * 60);
|
||||||
|
end
|
Loading…
Reference in a new issue