It is currently May 2nd, 2024, 10:17 am

Using ValueRemainder to show progress through the year?

Get help with creating, editing & fixing problems with skins
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Using ValueRemainder to show progress through the year?

Post by FlyingHyrax »

Salutations,
I am having trouble getting a Roundline meter to correctly show progress through the current year. I have a configurable clock skin, where you can change what the Roundline meter shows - one minute, one hour, 12 hours, 24 hours, one week, one month, or one year. I am using a Lua script to read an integer (0-6) from my shared variables file, which determines the mode. The script then returns the correct value remainder for that mode, which I plug into my Roundline meter as a dynamic variable.

Modes 0-5 work just fine, only the year does not seem to display correctly:


You can see in the About dialog that the script seems to be returning the intended remainder (the approximate number of seconds in a year). Also, since the other remainders function as intended, it cannot be a problem with my usage of Dynamic Variables. However, you can see that in the screenshot that the Roundline meter shows year progress as sometime around September; so something must be wrong with the remainder value I am using?

Kaelri's explanation of ValueRemainder here was immensely helpful in increasing my understanding of how ValueRemainder works; but it still seems to me that the correct ValueRemainder would definitely be the number of seconds in a day times the number of days in the year, which is what my Lua script is consistently providing.

What am I missing?

Many thanks for any assistance.

Skin code:

Code: Select all

[Rainmeter]
Update=1000
Group=circa2

[Metadata]
Name=Circuitous |
Author=Flying Hyrax | flyinghyrax.deviantart.com
Information=
Version=beta
License=Creative Commons BY-NC-SA 3.0

@include1=#@#Settings.txt
@include2=#@#Appearance.txt

@include3="#@#Styles\common.inc"
@include4="#@#Styles\#orient#.inc"

[Variables]
radius=42

[mTimeString]
Measure=Time
Format=#timeFormat#

[mDateString]
Measure=Time
Format=#dateFormat#

[mTimeRoundline]
Measure=Time

[mRoundLineScript]
Measure=Script
ScriptFile="#@#Scripts\timeRemainder.lua"

@include5="#@#sharedMeters.inc"

[pie]
Meter=ROUNDLINE
MeterStyle=roundlineCommon | pieCommon
MeasureName=mTimeRoundline
ValueRemainder=[mRoundlineScript]
;ValueRemainder=31536000
DynamicVariables=1

[divider]
Meter=IMAGE
MeterStyle=dividerStyle | dividerCommon

[mainText]
Meter=STRING
MeterStyle=mainTextStyle | mainTextCommon
MeasureName=mTimeString
Text="%1"

[subText]
Meter=STRING
MeterStyle=subTextStyle | subTextCommon
MeasureName=mDateString
Text="%1"
Lua code:

Code: Select all

function Initialize()
	-- hour, half, day, week, month, year
	unit = tonumber(SKIN:GetVariable('timeRoundline', 1))
	
	if (unit > 6 or unit < 0) then
		print('invalid time skin roundline setting')
		unit = 1
	end
	
	daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
	
end

function Update()
	currentTime = os.date("!*t")
	
	if unit == 0 then
		return 60
	
	elseif unit == 1 then
		return 3600
	
	elseif unit == 2 then
		return 43200
	
	elseif unit == 3 then
		return 86400
	
	elseif unit == 4 then
		return 604800
	
	elseif unit == 5 then
		if isLeapYear(currentTime.year) then 
			daysInMonth[2] = 29
		end
		return (86400 * daysInMonth[currentTime.month])
	
	elseif unit == 6 then
		if isLeapYear(currentTime.year) then 
			return (86400 * 366)
		else 
			return (86400 * 365) 
		end
	
	else
		print('wth?')
		return 0
	end
	
end

function isLeapYear(year)
	return (year % 4 == 0) and ((year % 100 ~= 0) or (year % 400 == 0))
end
If you want to see the skin in context, here is the suite it is from:
http://flyinghyrax.deviantart.com/art/Circuitous-Two-beta-373198450
Note that mode 0 (seconds in a minute) is not included in the version from DeviantArt - just added that this morning.

Running Rainmeter 2.5.0 r1842 (x64) on Windows 7 (x64)
Flying Hyrax on DeviantArt