Created
November 20, 2021 20:53
-
-
Save thomasjslone/383fb5d91ffc8507f5e611145e2a5c43 to your computer and use it in GitHub Desktop.
schedual display rev 1
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) ## get an array for timer displays of number of seconds [days:hours:minutes:seconds] | |
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 # get a time stamp like this 1996.11.11.23.13.02, works with strings and time objects and interchanges them if used as arguements, returns the current time as a string if no arguements | |
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=[] | |
if File.exist?(Dir.getwd+"/schedual.txt") | |
f=File.open(Dir.getwd+"/schedual.txt","r");@list=eval(f.read.to_s);f.close ##just type an array of the schedual ["hr:min;description"] | |
end | |
self.main_loop | |
end | |
def main_loop ## do some computations then refresh the screen by printing the results over the old ones | |
loop do | |
################################## | |
###### time date formatting ###### | |
################################## | |
## get light cycle am/pm | |
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 | |
## format st th nd and rd to numbers for the date display | |
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 ## convert month number to name | |
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] | |
dateformat = date[1..2].join("-")+" "+date[0].to_s | |
timeformat=Time.stamp.to_s.split(".")[3..-1].join(":") | |
timeformat=self.from_military(timeformat) | |
########################### | |
###### time math ########## | |
########################### | |
##bed time today | |
bed_time_today=Time.new(Time.now.year,Time.now.month,Time.now.day,"16","0","0") | |
##number of seconds positive or negitave of bedtime today minus now | |
bed_time_today_remain=bed_time_today-Time.now ##integer of seconds until bed time | |
##wake time today | |
wake_time_today=Time.new(Time.now.year,Time.now.month,Time.now.day,"1","30","0") | |
##number of seconds positive or netigave of waketimetoday minus now | |
wake_time_today_remain=wake_time_today-Time.now | |
##parse wake time tomorrow | |
tt=Time.stamp((Time.now+24*60*60)).split(".")[0..2] ## make a time object and add one day | |
wake_time_tomorrow=Time.new(tt[0],tt[1],tt[2],"1","30","0") ##create time object wake time tomorrow | |
##number of seconds positive or negative of waketimetomorrow | |
wake_time_tomorrow_remain=wake_time_tomorrow-Time.now | |
lt=[] ## list times | |
ll=[] ##list descriptions | |
@list.each do |l| ##seperate times and description into their own lists | |
lt<<l.to_s.split(";")[0].to_s | |
ll<<l.to_s.split(";")[1].to_s | |
end | |
##make list of time objects for todays date using the list times | |
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 | |
## search for list times that are the current time falls with in, each entry ends where the next begins | |
## parse time remaining until next list entry | |
## parse list of days remaining entries | |
## | |
## printed refreshed display data | |
## | |
system("CLS") ##make the console clean for printing | |
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 ##wake time today passed ##fuck actualy we need to adjust this for wake times of 11pm i.e. | |
puts "## Bedtime: "# + rt.to_s ##bed today remaining time | |
puts "## Morning: "# + tbw.to_s ##wake tomorrow remaining time | |
puts "#############################################" | |
puts "### NOW ## "+timeformat + " " + ampm.to_s+" #######################" | |
puts "## "#+now.to_s | |
puts "## "#+nowlisttime.to_s+"-"+nestlisttime.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 "" | |
## | |
## | |
## | |
## wait one second before reparsing times and updating display | |
sleep 1.0 | |
## write the current time to a file, for debugging to see when crashed about to remove its just for time math exceptions | |
begin;file=File.open(Dir.getwd.to_s+"/dlog.txt","w");file.write(Time.stamp);file.close;rescue;end | |
end | |
end | |
def from_military(s) # 00:00 | |
h=s.to_s.split(":")[0];m=s.to_s.split(":")[1] | |
if s.split(":").length>2;sec=s.to_s.split(":")[2];else;sec=nil;end | |
c="";if h=="00";h="12";c="AM";elsif h=="01";h="1";c="AM";elsif h=="02";h="2";c="AM";elsif h=="03";h="3";c="AM";elsif h=="04";h="4";c="AM";elsif h=="05";h="5";c="AM";elsif h=="06";h="6";c="AM";elsif h=="07";h="7";c="AM";elsif h=="08";h="8";c="AM";elsif h=="09";h="9";c="AM";elsif h=="10";h="10";c="AM";elsif h=="11";h="11";c="AM";elsif h=="12";h="12";c="PM";elsif h=="13";h="1";c="PM";elsif h=="14";h="2";c="PM";elsif h=="15";h="3";c="PM";elsif h=="16";h="4";c="PM";elsif h=="17";h="5";c="PM";elsif h=="18";h="6";c="PM";elsif h=="19";h="7";c="PM";elsif h=="20";h="8";c="PM";elsif h=="21";h="9";c="PM";elsif h=="22";h="10";c="PM";elsif h=="23";h="11";c="PM";end | |
if sec==nil;val=h+":"+m+" "+c ##parse with out seconds | |
else;val=h+":"+m+":"+sec+" "+c ##parse with seconds | |
end | |
return val | |
end | |
end | |
$d=Display.new | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment