1998-01-16 15:13:05 +03:00
|
|
|
#!/usr/local/bin/ruby
|
|
|
|
#
|
|
|
|
# biorhythm.rb -
|
|
|
|
# $Release Version: $
|
|
|
|
# $Revision$
|
|
|
|
# $Date$
|
|
|
|
# by Yasuo OHBA(STAFS Development Room)
|
|
|
|
#
|
|
|
|
# --
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
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"
|
|
|
|
require "parsearg.rb"
|
2000-07-25 11:21:54 +04:00
|
|
|
require "parsedate.rb"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
def usage()
|
|
|
|
print "Usage:\n"
|
|
|
|
print "biorhythm.rb [options]\n"
|
|
|
|
print " options...\n"
|
1999-08-13 09:45:20 +04:00
|
|
|
print " -D YYYYMMDD(birthday) : use default values.\n"
|
|
|
|
print " --sdate | --date YYYYMMDD : use system date; use specified date.\n"
|
|
|
|
print " --birthday YYYYMMDD : specifies your birthday.\n"
|
|
|
|
print " -v | -g : show values or graph.\n"
|
|
|
|
print " --days DAYS : graph range (only in effect for graphs).\n"
|
1998-01-16 15:13:05 +03:00
|
|
|
print " --help : help\n"
|
|
|
|
end
|
|
|
|
$USAGE = 'usage'
|
|
|
|
|
|
|
|
def printHeader(y, m, d, p, w)
|
|
|
|
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
|
|
|
|
|
|
|
|
def getPosition(z)
|
2000-07-31 13:21:25 +04:00
|
|
|
pi = Math::PI
|
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
|
|
|
|
|
2000-07-25 11:21:54 +04:00
|
|
|
def parsedate(s)
|
|
|
|
ParseDate::parsedate(s).indexes(0, 1, 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
def name_of_week(date)
|
2000-07-31 13:21:25 +04:00
|
|
|
Date::DAYNAMES[date.wday]
|
2000-07-25 11:21:54 +04:00
|
|
|
end
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#
|
|
|
|
# main program
|
|
|
|
#
|
|
|
|
parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:")
|
|
|
|
|
|
|
|
if $OPT_D
|
2000-07-31 13:21:25 +04:00
|
|
|
dd = Date.today
|
2000-07-25 11:21:54 +04:00
|
|
|
bd = Date.new(*parsedate($OPT_D))
|
1998-01-16 15:13:05 +03:00
|
|
|
ausgabeart = "g"
|
|
|
|
else
|
|
|
|
if $OPT_birthday
|
2000-07-25 11:21:54 +04:00
|
|
|
bd = Date.new(*parsedate($OPT_birthday))
|
1998-01-16 15:13:05 +03:00
|
|
|
else
|
|
|
|
printf(STDERR, "Birthday (YYYYMMDD) : ")
|
|
|
|
if (si = STDIN.gets.chop) != ""
|
2000-07-25 11:21:54 +04:00
|
|
|
bd = Date.new(*parsedate(si))
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if !bd
|
|
|
|
printf STDERR, "BAD Input Birthday!!\n"
|
|
|
|
exit()
|
|
|
|
end
|
|
|
|
|
|
|
|
if $OPT_sdate
|
2000-07-31 13:21:25 +04:00
|
|
|
dd = Date.today
|
1998-01-16 15:13:05 +03:00
|
|
|
elsif $OPT_date
|
2000-07-25 11:21:54 +04:00
|
|
|
dd = Date.new(*parsedate($OPT_date))
|
1998-01-16 15:13:05 +03:00
|
|
|
else
|
|
|
|
printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
|
|
|
|
if (si = STDIN.gets.chop) != ""
|
2000-07-25 11:21:54 +04:00
|
|
|
dd = Date.new(*parsedate(si))
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if !dd
|
2000-07-31 13:21:25 +04:00
|
|
|
dd = Date.today
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
if $OPT_v
|
|
|
|
ausgabeart = "v"
|
|
|
|
elsif $OPT_g
|
|
|
|
ausgabeart = "g"
|
|
|
|
else
|
|
|
|
printf(STDERR, "Values for today or Graph (v/g) [default g] : ")
|
|
|
|
ausgabeart = STDIN.gets.chop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (ausgabeart == "v")
|
2000-07-31 13:21:25 +04:00
|
|
|
printHeader(bd.year, bd.month, bd.day, dd - bd, name_of_week(bd))
|
1998-01-16 15:13:05 +03:00
|
|
|
print "\n"
|
|
|
|
|
2000-07-31 13:21:25 +04:00
|
|
|
phys, emot, geist = getPosition(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
|
|
|
|
if $OPT_days
|
|
|
|
display_period = $OPT_days.to_i
|
|
|
|
elsif $OPT_D
|
|
|
|
display_period = 9
|
|
|
|
else
|
|
|
|
printf(STDERR, "Graph for how many days [default 10] : ")
|
|
|
|
display_period = STDIN.gets.chop
|
|
|
|
if (display_period == "")
|
|
|
|
display_period = 9
|
|
|
|
else
|
|
|
|
display_period = display_period.to_i - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-07-31 13:21:25 +04:00
|
|
|
printHeader(bd.year, bd.month, bd.day, dd - bd, name_of_week(bd))
|
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"
|
|
|
|
|
2000-07-31 13:21:25 +04:00
|
|
|
for z in (dd - bd)..(dd - bd + display_period)
|
1998-01-16 15:13:05 +03:00
|
|
|
phys, emot, geist = getPosition(z)
|
|
|
|
|
|
|
|
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
|