-
-
Save thomasjslone/17fbc93532ce75ac5c221c112656a42d to your computer and use it in GitHub Desktop.
schedual progress estimate display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32/sound' | |
include Win32 | |
Time.class.class.class_eval{ | |
def parse_seconds(s) | |
s = s.to_s.to_f | |
if s.to_f < 60.0 | |
[0,0,s.to_i] | |
elsif s.to_f < 3600.0 and s.to_f >= 60.0 | |
minutes = s.to_f / 60.0 | |
sec = ("." + minutes.to_s.split(".")[-1].to_s).to_f * 60 ## the period is because the expression is converting integers to strings to floats | |
[0,minutes.to_i, sec.round] | |
elsif s.to_f < 86400.0 and s.to_f >= 3600.0 | |
hours = s.to_f / 60.0 / 60.0 | |
minutes = ("." + hours.to_s.split(".")[-1].to_s).to_f * 60 | |
sec = ("." + minutes.to_s.split(".")[-1].to_s).to_f * 60 | |
[hours.to_i, minutes.to_i ,sec.to_i] | |
elsif s.to_f >= 86400.0 | |
days = s.to_f / 60.0 / 60.0 / 24.0 | |
hours = ("."+ days.to_s.split(".")[-1]).to_f * 24 | |
minutes = ("." + hours.to_s.split(".")[-1]).to_s.to_i*60 | |
sec = (s/60.0).to_s.split(".")[-1].to_i*60 | |
[days,hours.to_i,minutes] | |
end | |
end | |
def stamp *args | |
if args[0] == nil ; t = Time.now ; y = t.year.to_s ; mo = t.month.to_s ; d = t.day.to_s ; h = t.hour.to_s ; mi = t.min.to_s ; s = t.sec.to_s ; if y.length < 4 ; until y.length == 4 ; y = "0" + y ; end ; end ; y = y[0..3] ; if mo.length < 2 ; mo = "0" + mo end ; mo = mo[0..1] ; if d.length < 2 ; d = "0" + d ; end ; d = d[0..1] ; if h.length < 2 ; h = "0" + h ; end ; h = h[0..1] ; if mi.length < 2 ; mi = "0" + mi ; end ; mi = mi[0..1] ; if s.length < 2 ; s = "0" + s ; end ; s = s[0..1] ; [y,mo,d,h,mi,s].join(".") | |
elsif args[0].is_a? Time ; t = args[0] ; y = t.year.to_s ; mo = t.month.to_s ; da = t.day.to_s ; hr = t.hour.to_s ; mi = t.min.to_s ; se = t.sec.to_s ; if mo.length == 1 ; mo = "0" + mo.to_s ; end ; if da.length == 1 ; da = "0" + da.to_s ; end ; if hr.length == 1 ; hr = "0" + hr.to_s ; end ; if mi.length == 1 ; mi = "0" + mi.to_s ; end ; if se.length == 1 ; se = "0" + se.to_s ; end ; return y.to_s + "." + mo.to_s + "." + da.to_s + "." + hr.to_s + "." + mi.to_s + "." + se.to_s | |
elsif args[0].is_a? String ; t = args[0].split(".") ; return Time.new(t[0],t[1],t[2],t[3],t[4],t[5]) | |
end | |
end | |
} | |
class Display | |
def initialize | |
@list = ["1:25;Wake Up."] | |
self.main_loop | |
end | |
def main_loop | |
nlv=nil | |
loop do | |
ampm=nil | |
if Time.stamp.to_s.split(".")[3].to_i>=12;ampm="PM";else;ampm="AM";end | |
dayname=Time.now.wday.to_s | |
if dayname=="1";dayname="Monday";elsif dayname=="2";dayname="Tuesday";elsif dayname=="3";dayname="Wednesday";elsif dayname=="4";dayname="Thursday";elsif dayname=="5";dayname="Friday";elsif dayname=="6";dayname="Saturday";elsif dayname=="7";dayname="Sunday";end | |
num=Time.now.day.to_s | |
if num=="11";num="11th" | |
elsif num=="12";num="12th" | |
elsif num=="13";num="13th" | |
elsif num[-1].to_s=="1";num=num+"st" | |
elsif num[-1].to_s=="2";num=num+"nd" | |
elsif num[-1].to_s=="3";num=num+"rd" | |
else;num=num+"th" | |
end | |
month=Time.now.month.to_s | |
if month=="1";month="Janurary";elsif month == "2";month="Februrary";elsif month == "3";month="March";elsif month == "4";month="April";elsif month == "5";month="May";elsif month == "6";month="June";elsif month == "7";month="July";elsif month == "8";month="August";elsif month == "9";month="September";elsif month == "10";month="October";elsif month == "11";month="November";elsif month == "12";month="December";end | |
date=Time.stamp.to_s.split(".")[0..2] | |
date = date[1..2].join("-")+" "+date[0].to_s | |
timeformat=Time.stamp.to_s.split(".")[3..-1] | |
if timeformat[0].to_i<=12 and timeformat[0].to_i>0 | |
timeformat = timeformat.join(":") | |
#####bug here undefined t | |
else | |
tt=nil | |
if timeformat[0].to_s=="13";tt="1"; | |
elsif timeformat[0].to_s=="14";tt="2"; | |
elsif timeformat[0].to_s=="15";tt="3"; | |
elsif timeformat[0].to_s=="16";tt="4"; | |
elsif timeformat[0].to_s=="17";tt="5"; | |
elsif timeformat[0].to_s=="18";tt="6"; | |
elsif timeformat[0].to_s=="19";tt="7"; | |
elsif timeformat[0].to_s=="20";tt="8"; | |
elsif timeformat[0].to_s=="21";tt="9"; | |
elsif timeformat[0].to_s=="22";tt="10"; | |
elsif timeformat[0].to_s=="23";tt="11"; | |
elsif timeformat[0].to_i.to_s=="0";tt="12"; | |
end | |
timeformat = tt+":"+timeformat[1..2].join(":") | |
end | |
t=Time.stamp.split(".") | |
bt=Time.new(t[0],t[1],t[2],"16","0","0") | |
rt=bt-Time.now | |
if rt.to_i>0 | |
rt=Time.parse_seconds(rt).join(":") | |
if rt.split(":")[0].to_s=="0";rt=rt.split(":")[1..2].join(":");end | |
else | |
rt=rt.to_s[1..-1].to_s | |
rt=Time.parse_seconds(rt).join(":") | |
if rt.split(":")[0].to_s=="0";rt=rt.split(":")[1..2].join(":");end | |
rt="-"+rt | |
end | |
wt=Time.new(t[0],t[1],t[2],"1","30","0") | |
wt=Time.now-wt | |
wt=Time.parse_seconds(wt).join(":") | |
tt=Time.now+24*60*60 | |
tt=Time.stamp(tt).split(".")[0..2] | |
tt=Time.new(tt[0],tt[1],tt[2],"1","30","0") | |
tbw=tt-Time.now | |
tbw=Time.parse_seconds(tbw).join(":") | |
lt=[] | |
ll=[] | |
@list.each do |l| | |
lt<<l.to_s.split(";")[0].to_s | |
ll<<l.to_s.split(";")[1].to_s | |
end | |
lto=[] | |
lt.each do |ttt| | |
h=ttt.split(":")[0].to_s | |
m=ttt.split(":")[1].to_s | |
lto<<Time.new(Time.now.year,Time.now.month,Time.now.day,h,m,"0") | |
end | |
now=[] | |
lt.each do |l| | |
t=l.split(":") | |
if Time.now.hour == t[0].to_i | |
if Time.now.min>=t[1].to_i | |
now<< lt.index(l) | |
end | |
end | |
end | |
if now.length>0 | |
now=ll[now[-1].to_i].to_s | |
if nlv!=now | |
3.times{Sound.beep(700,100);sleep 0.10} | |
nlv=now | |
end | |
nowt=lt[ll.index(now)] | |
nowtn=lt[ll.index(now)+1] | |
nowtr=Time.new(Time.now.year,Time.now.month,Time.now.day,nowtn.split(":")[0],nowtn.split(":")[1],"0")-Time.now | |
nowtr=Time.parse_seconds(nowtr) | |
if nowtr[0].to_i==0 | |
nowtr=nowtr[1..-1] | |
end | |
nowtr=nowtr.join(":") | |
nowt=self.from_military(nowt) | |
nowtn=self.from_military(nowtn) | |
viewlist=[] | |
ll.reverse.each do |lll| | |
if lll==now | |
break | |
end | |
viewlist<<self.from_military(lt[ll.index(lll)])+" "+lll.to_s | |
end | |
unless viewlist.length<=1 | |
viewlist.insert(1,"\n") | |
end | |
viewlist=viewlist.reverse | |
nextt=viewlist[0] | |
else ##nothing schedualed right now | |
now = "" # blank | |
nowt="" # blank | |
nowtr="" #this can still work | |
viewlist=[] | |
lto.each do |t| | |
if t>Time.now | |
viewlist<<ll[lto.index(t)] | |
end | |
end | |
nowtn ="" | |
nextt = "" | |
nowtn="" | |
end | |
viewlist.delete("\n") | |
system("CLS") | |
puts "#############################################" | |
puts "## "+dayname[0..2].to_s + ", " + month[0..2].to_s + " "+ num.to_s + " " + date.to_s + " " + Time.stamp.split(".")[3..-1].join(":") | |
puts "#############################################" | |
puts "## Awake: " + wt.to_s | |
puts "## Bedtime: " + rt.to_s | |
puts "## Morning: " + tbw.to_s | |
puts "#############################################" | |
puts "### NOW ## "+timeformat + " " + ampm.to_s+"########################" | |
puts "## "+now.to_s | |
puts "## "+nowt.to_s+"-"+nowtn.to_s | |
puts "## Time left: "+nowtr.to_s | |
puts "## NEXT: " +nextt.to_s | |
puts "#############################################" | |
puts "#############################################" | |
puts "## Rest of day:" | |
puts "## " | |
puts "## "+viewlist[0..12].join("\n## ") | |
puts "## " | |
puts "#############################################" | |
puts "" | |
begin | |
file=File.open(Dir.getwd.to_s+"/dlog.txt","w");file.write(Time.stamp);file.close | |
rescue | |
end | |
sleep 1.0 | |
end | |
end | |
def from_military(s) # 00:00 | |
h=s.to_s.split(":")[0] | |
m=s.to_s.split(":")[1] | |
c="" | |
if h=="00";h="12";c="AM" | |
elsif h=="01";h="1";c="A" | |
elsif h=="02";h="2";c="A" | |
elsif h=="03";h="3";c="A" | |
elsif h=="04";h="4";c="A" | |
elsif h=="05";h="5";c="A" | |
elsif h=="06";h="6";c="A" | |
elsif h=="07";h="7";c="A" | |
elsif h=="08";h="8";c="A" | |
elsif h=="09";h="9";c="A" | |
elsif h=="10";h="10";c="A" | |
elsif h=="11";h="11";c="A" | |
elsif h=="12";h="12";c="P" | |
elsif h=="13";h="1";c="P" | |
elsif h=="14";h="2";c="P" | |
elsif h=="15";h="3";c="P" | |
elsif h=="16";h="4";c="P" | |
elsif h=="17";h="5";c="P" | |
elsif h=="18";h="6";c="P" | |
elsif h=="19";h="7";c="P" | |
elsif h=="20";h="8";c="P" | |
elsif h=="21";h="9";c="P" | |
elsif h=="22";h="10";c="P" | |
elsif h=="23";h="11";c="P" | |
end | |
h+":"+m+""+c | |
end | |
end | |
$d=Display.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment