1998-01-16 15:13:05 +03:00
|
|
|
#!/usr/local/bin/ruby
|
|
|
|
#
|
2011-05-15 15:55:52 +04:00
|
|
|
# biorhythm.rb -
|
1998-01-16 15:13:05 +03:00
|
|
|
# $Release Version: $
|
|
|
|
# $Revision$
|
|
|
|
# by Yasuo OHBA(STAFS Development Room)
|
|
|
|
#
|
|
|
|
# --
|
|
|
|
#
|
2011-05-15 15:55:52 +04:00
|
|
|
#
|
1998-01-16 15:13:05 +03:00
|
|
|
#
|
|
|
|
|
2000-07-10 08:49:24 +04:00
|
|
|
# probably based on:
|
|
|
|
#
|
|
|
|
# Newsgroups: comp.sources.misc,de.comp.sources.os9
|
|
|
|
# From: fkk@stasys.sta.sub.org (Frank Kaefer)
|
|
|
|
# Subject: v41i126: br - Biorhythm v3.0, Part01/01
|
|
|
|
# Message-ID: <1994Feb1.070616.15982@sparky.sterling.com>
|
|
|
|
# Sender: kent@sparky.sterling.com (Kent Landfield)
|
|
|
|
# Organization: Sterling Software
|
|
|
|
# Date: Tue, 1 Feb 1994 07:06:16 GMT
|
|
|
|
#
|
|
|
|
# Posting-number: Volume 41, Issue 126
|
|
|
|
# Archive-name: br/part01
|
|
|
|
# Environment: basic, dos, os9
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
include Math
|
|
|
|
require "date.rb"
|
2007-12-25 00:21:16 +03:00
|
|
|
require "optparse"
|
|
|
|
require "optparse/date"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-03-05 23:25:08 +03:00
|
|
|
def print_header(y, m, d, p, w)
|
1998-01-16 15:13:05 +03:00
|
|
|
print "\n>>> Biorhythm <<<\n"
|
|
|
|
printf "The birthday %04d.%02d.%02d is a %s\n", y, m, d, w
|
|
|
|
printf "Age in days: [%d]\n\n", p
|
|
|
|
end
|
|
|
|
|
2011-03-05 23:25:08 +03:00
|
|
|
def get_position(z)
|
2000-07-31 13:21:25 +04:00
|
|
|
pi = Math::PI
|
2002-06-11 11:02:23 +04:00
|
|
|
z = Integer(z)
|
1998-01-16 15:13:05 +03:00
|
|
|
phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i
|
|
|
|
emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i
|
|
|
|
geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i
|
|
|
|
return phys, emot, geist
|
|
|
|
end
|
|
|
|
|
2007-12-25 00:21:16 +03:00
|
|
|
def prompt(msg)
|
|
|
|
$stderr.print msg
|
|
|
|
return gets.chomp
|
2000-07-25 11:21:54 +04:00
|
|
|
end
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#
|
|
|
|
# main program
|
|
|
|
#
|
2007-12-25 00:21:16 +03:00
|
|
|
options = {
|
|
|
|
:graph => true,
|
|
|
|
:date => Date.today,
|
|
|
|
:days => 9,
|
|
|
|
}
|
|
|
|
ARGV.options do |opts|
|
|
|
|
opts.on("-b", "--birthday=DATE", Date, "specify your birthday"){|v|
|
|
|
|
options[:birthday] = v
|
|
|
|
}
|
|
|
|
opts.on("--date=DATE", Date, "specify date to show"){|v|
|
|
|
|
options[:date] = v
|
|
|
|
}
|
|
|
|
opts.on("-g", "--show-graph", TrueClass, "show graph (default)"){|v|
|
|
|
|
options[:graph] = v
|
|
|
|
}
|
|
|
|
opts.on("-v", "--show-values", TrueClass, "show values"){|v|
|
|
|
|
options[:graph] = !v
|
|
|
|
}
|
|
|
|
opts.on("--days=DAYS", Integer, "graph range (only in effect for graph)"){|v|
|
|
|
|
options[:days] = v - 1
|
|
|
|
}
|
|
|
|
opts.on_tail("-h", "--help", "show this message"){puts opts; exit}
|
|
|
|
begin
|
|
|
|
opts.parse!
|
|
|
|
rescue => ex
|
|
|
|
puts "Error: #{ex.message}"
|
|
|
|
puts opts
|
|
|
|
exit
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2007-12-25 00:21:16 +03:00
|
|
|
end
|
2002-12-19 23:26:16 +03:00
|
|
|
|
2007-12-25 00:21:16 +03:00
|
|
|
bd = options[:birthday] || Date.parse(prompt("Your birthday (YYYYMMDD): "))
|
|
|
|
dd = options[:date] || Date.today
|
|
|
|
ausgabeart = options[:graph] ? "g" : "v"
|
|
|
|
display_period = options[:days]
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-12-19 23:26:16 +03:00
|
|
|
if ausgabeart == "v"
|
2011-03-05 23:25:08 +03:00
|
|
|
print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a"))
|
1998-01-16 15:13:05 +03:00
|
|
|
print "\n"
|
2011-05-15 15:55:52 +04:00
|
|
|
|
2011-03-05 23:25:08 +03:00
|
|
|
phys, emot, geist = get_position(dd - bd)
|
1998-01-16 15:13:05 +03:00
|
|
|
printf "Biorhythm: %04d.%02d.%02d\n", dd.year, dd.month, dd.day
|
|
|
|
printf "Physical: %d%%\n", phys
|
|
|
|
printf "Emotional: %d%%\n", emot
|
|
|
|
printf "Mental: %d%%\n", geist
|
|
|
|
print "\n"
|
|
|
|
else
|
2011-03-05 23:25:08 +03:00
|
|
|
print_header(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a"))
|
1998-01-16 15:13:05 +03:00
|
|
|
print " P=physical, E=emotional, M=mental\n"
|
|
|
|
print " -------------------------+-------------------------\n"
|
|
|
|
print " Bad Condition | Good Condition\n"
|
|
|
|
print " -------------------------+-------------------------\n"
|
2011-05-15 15:55:52 +04:00
|
|
|
|
2002-06-06 15:14:04 +04:00
|
|
|
(dd - bd).step(dd - bd + display_period) do |z|
|
2011-03-05 23:25:08 +03:00
|
|
|
phys, emot, geist = get_position(z)
|
2011-05-15 15:55:52 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
printf "%04d.%02d.%02d : ", dd.year, dd.month, dd.day
|
|
|
|
p = (phys / 2.0 + 0.5).to_i
|
|
|
|
e = (emot / 2.0 + 0.5).to_i
|
|
|
|
g = (geist / 2.0 + 0.5).to_i
|
|
|
|
graph = "." * 51
|
|
|
|
graph[25] = ?|
|
|
|
|
graph[p] = ?P
|
|
|
|
graph[e] = ?E
|
|
|
|
graph[g] = ?M
|
|
|
|
print graph, "\n"
|
|
|
|
dd = dd + 1
|
|
|
|
end
|
|
|
|
print " -------------------------+-------------------------\n\n"
|
|
|
|
end
|