Biorythm script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Biorythm script

Started by charlize, 05 December, 2004, 09:39:01

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

charlize

Hy all, I'm italian and i'm looking for a biorythm script (I think it's a script) that I saw some time ago in a hub.

What is Biorythm?
From the day we are born natural rythmns or cycles regulate our lives. There are three of these cycles; Physical, Emotional and Intellectual.
like You can see here:
http://www.astrology4free.com/AstBioR.html

Could someone help me?

NotRabidWombat

This just does the math. Someone else will have to do the Hub input and output.

iPhysicalCycle = 23;
iEmotionalCycle = 28;
iIntellectualCycle = 33;
fRadian = 2.0 * Pi;

-- GetBioRhythm
-- Desc: Gets the "BioRhythm" based on birthday
-- Input: Birthday Day (number), Birthday Month (number), Birthday Year (number)
-- Return: PhysicalIndex (number), IntellectualIndex (number), EmotionalIndex (number)
function GetBioRhythm( Day, Month, Year )
	local iCurDay, iCurMonth, iCurYear = tonumber(date("%m")), tonumber(date("%d")), tonumber(date("%Y"));

	local iDaysBetween = GetDaysBetween( Day, Month, Year, iCurDay, iCurMonth, iCurYear );

	local iPhysicalIndex = sin(iDaysBetween * fRadian / iPhysicalCycle)
	local iIntellectualIndex = SIN(iDaysBetween * fRadian / iIntellectualCycle)
	local iEmotionalIndex = SIN(iDaysBetween * fRadian / iEmotionalCycle)

	return iPhysicalIndex, iIntellectualIndex, iEmotionalIndex;
end

function GetDaysBetween( StartDay, StartMonth, StartYear, EndDay, EndMonth, EndYear )
	return JulianDate( EndDay, EndMonth, EndYear, 0, 0, 0 ) - JulianDate( StartDay, StartMonth, StartYear, 0, 0, 0 );
end

-- Convert Gregorian Date to Julian Date
function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- HOUR is 24hr format
	local jy, ja, jm;

	assert(YEAR ~= 0);
	assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15);
	--The dates 5 through 14 October, 1582, do not exist in the Gregorian system!");

	if(YEAR < 0 ) then
		YEAR = YEAR + 1;
	end

	if( MONTH > 2) then 
		jy = YEAR;
		jm = MONTH + 1;
	else
		jy = YEAR - 1;
		jm = MONTH + 13;
	end

	local intgr = floor( floor(365.25*jy) + floor(30.6001*jm) + DAY + 1720995 );

	--check for switch to Gregorian calendar
	local gregcal = 15 + 31*( 10 + 12*1582 );
	if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then
		ja = floor(0.01*jy);
		intgr = intgr + 2 - ja + floor(0.25*ja);
	end

	--correct for half-day offset

	local dayfrac = HOUR / 24 - 0.5;
	if( dayfrac < 0.0 ) then
		dayfrac = dayfrac + 1.0;
		intgr = intgr - 1;
	end

	--now set the fraction of a day
	local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0;

	--round to nearest second
	local jd0 = (intgr + frac)*100000;
	local  jd  = floor(jd0);
	if( jd0 - jd > 0.5 ) then jd = jd + 1 end
	return jd/100000;
end

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

charlize

Great, Not! I'll try it. Thks so much!

bastya_elvtars

#3
Done for PtokaX

It returns indices, maybe a graph would be more informative (like the FreeBSD brother)

But what I think of, the monthly prediction, not the graph itself. That would make sense.


-- Biorythm calculation bot
-- core written by RabidWombat
-- ported to PtokaX by bastya_elvtars
-- use !biorythm YYYY-MM-DD
-- where you enter your bithday




Bot="-Sybilla-"

-------------====================------------------

iPhysicalCycle = 23;
iEmotionalCycle = 28;
iIntellectualCycle = 33;
fRadian = 2.0 * PI;


-- GetBioRhythm
-- Desc: Gets the "BioRhythm" based on birthday
-- Input: Birthday Day (number), Birthday Month (number), Birthday Year (number)
-- Return: PhysicalIndex (number), IntellectualIndex (number), EmotionalIndex (number)
function GetBioRhythm( Day, Month, Year )
	local iCurDay, iCurMonth, iCurYear = tonumber(date("%m")), tonumber(date("%d")), tonumber(date("%Y"));


	local iDaysBetween = GetDaysBetween( Day, Month, Year, iCurDay, iCurMonth, iCurYear );


	local iPhysicalIndex = sin(iDaysBetween * fRadian / iPhysicalCycle)
	local iIntellectualIndex = sin(iDaysBetween * fRadian / iIntellectualCycle)
	local iEmotionalIndex = sin(iDaysBetween * fRadian / iEmotionalCycle)


	return iPhysicalIndex, iIntellectualIndex, iEmotionalIndex;
end


function GetDaysBetween( StartDay, StartMonth, StartYear, EndDay, EndMonth, EndYear )
	return JulianDate( EndDay, EndMonth, EndYear, 0, 0, 0 ) - JulianDate( StartDay, StartMonth, StartYear, 0, 0, 0 );
end


-- Convert Gregorian Date to Julian Date
function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- HOUR is 24hr format
	local jy, ja, jm;


	assert(YEAR ~= 0);
	assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15);
	--The dates 5 through 14 October, 1582, do not exist in the Gregorian system!");


	if(YEAR < 0 ) then
		YEAR = YEAR + 1;
	end


	if( MONTH > 2) then 
		jy = YEAR;
		jm = MONTH + 1;
	else
		jy = YEAR - 1;
		jm = MONTH + 13;
	end


	local intgr = floor( floor(365.25*jy) + floor(30.6001*jm) + DAY + 1720995 );


	--check for switch to Gregorian calendar
	local gregcal = 15 + 31*( 10 + 12*1582 );
	if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then
		ja = floor(0.01*jy);
		intgr = intgr + 2 - ja + floor(0.25*ja);
	end


	--correct for half-day offset


	local dayfrac = HOUR / 24 - 0.5;
	if( dayfrac < 0.0 ) then
		dayfrac = dayfrac + 1.0;
		intgr = intgr - 1;
	end


	--now set the fraction of a day
	local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0;


	--round to nearest second
	local jd0 = (intgr + frac)*100000;
	local  jd  = floor(jd0);
	if( jd0 - jd > 0.5 ) then jd = jd + 1 end
	return jd/100000;
end

function DataArrival(user,data)
	if strsub(data,1,1)=="<" then
		local msg
		local _,_,command,args=strfind(data,"%b<>%s+(%S+)%s+(.+)")
		if command=="!biorythm" then
			if args then
				local _,_,Y,M,D=strfind(args,"(%d%d%d%d)%D(%d%d)%D(%d%d)")
				if Y and M and D then
					user:SendData(D.."-"..M.."-"..Y)
					msg="\r\nBiorythm calculation started. Hold on! :)\r\n==================================\r\n"
					local Day,Month,Year=tonumber(D),tonumber(M),tonumber(Y)
					local Phys,Intell,Emot=GetBioRhythm( Day, Month, Year ) -- not Intel but Intell! :P (AMD)
					msg=msg.."\r\nPhysical index: "..Phys.."\r\nIntellectual index: "..Intell.."\r\nEmotional index: "..Emot.."\r\n\r\n=================================="
				else
					msg="Correct usage: !biorythm YYYY-MM-DD"
				end
			else
				msg="Correct usage: !biorythm YYYY-MM-DD"
			end
			user:SendData(Bot,msg)
		end
	end
end


*** EDIT ***

see how FreeBSD does:

Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk