It is currently May 18th, 2024, 5:05 am

Lua, bar graph, lua, and a database.

Get help with creating, editing & fixing problems with skins
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua, bar graph, lua, and a database.

Post by smurfier »

First off we have the source file.

Sales.txt

Code: Select all

<machinesales target="100000" actual="6500" projected="250000"/>

<aftermarketsales target="50000" actual="10000" projected="60000"/>

<repairsales target="50000" actual="10000" projected="60000"/>
Then the Lua.lua file.

Code: Select all

function Initialize()
	sFileName = SKIN:MakePathAbsolute(SELF:GetOption('FileName'))
	mtPrefix = SELF:GetOption('MeterPrefix','mt')
end -- Initialize

function Update()
	hFile = io.open(sFileName)
	if not io.type(hFile)=='file' then
		print('File error')
		return 'File error'
	else
		local text=io.read('*all')
		io.close(hFile)
		for tag,contents in string.gmatch(text,'<([^%s>]+)(.-)%/>') do
			local tbl={target=0,actual=0,projected=1}
			for key,value in string.gmatch(contents,'(%a+)=(%b"")') do
				local strip=string.match(value,'"(.+)"')
				tbl[string.lower(strip)]=tonumber(strip) or strip
			end
			local mHandle=SKIN:GetMeter(mtPrefix..string.lower(tag))
			local MeasureName=mHandle:GetOption('MeasureName')
			if SKIN:GetMeasure(MeasureName) then
				SKIN:Bang('!SetOption',MeasureName,'Formula',tbl.actual)
			end
		end
	end
end -- Update
Now for the skin portion. We will start with the script measure.

Code: Select all

[Lua]
Measure=Script
ScriptFile=Lua.lua
FileName=Sales.Txt
Update=-1
The Update=-1 part just makes it so that we don't read the file completely during every update.

Now, to get this to work we need to set up our meters with their measure pairs.

Code: Select all

[msOne]
Measure=Calc
Formula=0
MaxValue=500000

[mtmachinesales]
Meter=Roundline
MeasureName=msOne
Blah...
Blah...
You Know The Rest
The important bits are the measure (just create a simple Calc measure, don't forget the MaxValue) the meter name (name of the info you want to display as set in the text file prepended by 'mt') and of course the MeasureName (the script finds the measure from the MeasureName that you set in the meter).

What the measures are currently being set to is the actual sales figure present in the text file.

NOTE: I am not able to test this as the moment.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Re: Lua, bar graph, lua, and a database.

Post by syngod »

Ok sorry to bug with this issue again... but i have been trying to fix it all weekend and not sure what the issue is.

When i have setup what you gave me i get an error when running it

Code: Select all

Script:lua.lua:14:bad argument#1 to 'gmatch(string expected, not nil
I have looked this up and tried to see what was wrong but for some reason lua is just over my head at the moment. I am trying to learn it but there seems to be too much i guess.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua, bar graph, lua, and a database.

Post by smurfier »

Try this lua file:

Code: Select all

function Initialize()
	sFileName = SKIN:MakePathAbsolute(SELF:GetOption('FileName'))
	mtPrefix = SELF:GetOption('MeterPrefix','mt')
end -- Initialize

function Update()
	hFile = io.input(sFileName,'r')
	if not io.type(hFile)=='file' then
		print('File error')
		return 'File error'
	else
		local text=io.read('*all')
		io.close(hFile)
		for tag,contents in string.gmatch(text,'<([^%s>]+)(.-)%/>') do
			local tbl={target=0,actual=0,projected=1}
			for key,value in string.gmatch(contents,'(%a+)=(%b"")') do
				local strip=string.match(value,'"(.+)"')
				tbl[string.lower(strip)]=tonumber(strip) or strip
			end
			local mHandle=SKIN:GetMeter(mtPrefix..string.lower(tag))
			local MeasureName=mHandle:GetOption('MeasureName')
			if SKIN:GetMeasure(MeasureName) then
				SKIN:Bang('!SetOption',MeasureName,'Formula',tbl.actual)
			end
		end
	end
end -- Update
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Re: Lua, bar graph, lua, and a database.

Post by syngod »

Well it was that but i must of typed something wrong or copied it wrong cuz i recopied it just now and the only thing it is saying is that the bang has incorrect number of arguments looking at how to fix that now searching the forum and stuff.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua, bar graph, lua, and a database.

Post by smurfier »

Could you please zip up your whole skin so that I can properly test things.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Re: Lua, bar graph, lua, and a database.

Post by syngod »

Oh yes np... i zipped the whole folder... with all three files in.
You do not have the required permissions to view the files attached to this post.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua, bar graph, lua, and a database.

Post by smurfier »

Silly me and my small typos. I did add an option, with some error checking. Right now the script returns the actual value. If you want to change that just add ReturnValue=Projected (or Target) to the Lua measure.

Also, be sure you are running the most current Rainmeter 2.3 beta.

Lua.lua

Code: Select all

function Initialize()
   sFileName = SKIN:MakePathAbsolute(SELF:GetOption('FileName'))
   mtPrefix = SELF:GetOption('MeterPrefix','mt')
   rValue = string.lower(SELF:GetOption('ReturnValue','actual'))
   local check={target=true,actual=true,projected=true,}
   assert(check[rValue],'Error: Invalid ReturnValue in ['..SELF:GetName()..']')
end -- Initialize

function Update()
   hFile = io.input(sFileName,'r')
   if not io.type(hFile)=='file' then
      print('File error')
      return 'File error'
   else
      local text=io.read('*all')
      io.close(hFile)
      for tag,contents in string.gmatch(text,'<([^%s>]+)(.-)%/>') do
         local tbl={target=0,actual=0,projected=1}
         for key,value in string.gmatch(contents,'(%a+)=(%b"")') do
            local strip=string.match(value,'"(.+)"')
            tbl[string.lower(key)]=tonumber(strip) or strip
         end
         local mHandle=SKIN:GetMeter(mtPrefix..string.lower(tag))
         local MeasureName=mHandle:GetOption('MeasureName')
         if SKIN:GetMeasure(MeasureName) then
            SKIN:Bang('!SetOption',MeasureName,'Formula',tbl[rValue])
         end
      end
   end
end -- Update
dashboard.ini

Code: Select all

[Rainmeter]
Update=1000

[Metadata]
Name=
License=
Version=

[Variables]
bcolor=30,255,120,30
tcolor=0,0,0,255
lcolor=20,200,10,255

[Lua]
Measure=Script
ScriptFile=lua.lua
FileName=sales.Txt
Update=-1

[msOne]
Measure=Calc
Formula=0
MaxValue=500000

[msTwo]
Measure=Calc
Formula=0
MaxValue=500000

[msThree]
Measure=Calc
Formula=0
MaxValue=500000

[mtmachinesales]
Meter=Roundline
MeasureName=msOne
X=-50
Y=135
W=150
H=45
LineLength=50
LineStart=47
StartAngle=-6.28159265
RotationAngle=-1.95 ;.14159265
LineColor=#lcolor#
Solid=1
AntiAlias=1
SolidColor=255,0,0

[mtaftermarketsales]
Meter=Roundline
MeasureName=msTwo
X=-50
Y=135
W=150
H=45
LineLength=50
LineStart=47
StartAngle=-6.28159265
RotationAngle=-1.95
LineColor=#lcolor#
Solid=1
AntiAlias=1

[mtrepairsales]
Meter=Roundline
MeasureName=msThree
X=-50
Y=135
W=150
H=45
LineLength=50
LineStart=47
StartAngle=-6.28159265
RotationAngle=-1.95
LineColor=#lcolor#
Solid=1
AntiAlias=1
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Re: Lua, bar graph, lua, and a database.

Post by syngod »

Ok i hate to bee a pain... i have tried this again to change the background image and other things.

But now all the sudden the skin shows up as a red block with a green dot.

All i did was add the

Code: Select all

BackgroundMode=1
under the rainmeter tag and now i can't seem to fix it.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Lua, bar graph, lua, and a database.

Post by smurfier »

Under mtmachinesales remove the SolidColor line. That will take care of the red block.

The fact that you can't see anything is that since we're comparing such low numbers to 500,000 most figures are currently 2% or less.

Also, you have a RotationAngle of 1.95 which will only fill 31% of a complete circle.

If you switch out lua.lua with the code below, you can specify which figure to compare the ReturnValue to with the CompareValue option. CompareValue defaults to target.

Code: Select all

function Initialize()
	sFileName = SKIN:MakePathAbsolute(SELF:GetOption('FileName'))
	mtPrefix = SELF:GetOption('MeterPrefix','mt')
	rValue = string.lower(SELF:GetOption('ReturnValue','actual'))
	cValue = string.lower(SELF:GetOption('CompareValue','target'))
	local check={target=true,actual=true,projected=true,}
	assert(check[rValue],'Error: Invalid ReturnValue in ['..SELF:GetName()..']')
	assert(cValue~=rValue and check[cValue],'Error: Invalid CompareValue in ['..SELF:GetName()..']')
end -- Initialize

function Update()
	hFile = io.input(sFileName,'r')
	if not io.type(hFile)=='file' then
		print('File error')
		return 'File error'
	else
		local text=io.read('*all')
		io.close(hFile)
		for tag,contents in string.gmatch(text,'<([^%s>]+)(.-)%/>') do
			local tbl={target=0,actual=0,projected=1}
			for key,value in string.gmatch(contents,'(%a+)=(%b"")') do
				tbl[string.lower(key)]=tonumber(string.match(value,'"(.+)"'))
			end
			local mHandle=SKIN:GetMeter(mtPrefix..string.lower(tag))
			local MeasureName=mHandle:GetOption('MeasureName')
			if SKIN:GetMeasure(MeasureName) then
				for k,v in pairs({
					Formula=tbl[rValue],
					MaxValue=tbl[cValue],
				}) do SKIN:Bang('!SetOption',MeasureName,k,v) end
			end
		end
	end
end -- Update
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Re: Lua, bar graph, lua, and a database.

Post by syngod »

Thanks guys for your help it's working perfectly so far... created and doing what i wanted.

I wanted to ask another question though. I looked for this but i couldn't find anything that gives me an answer... I wanted to show a percentage of how much actual is away from target.

I know how to do this and use the code. But i don't know if using a variable in LUA for a math equation will clear the data they store.

so on the code i have i was thinking of putting

Code: Select all

percentage = tbl[rValue] / tbl[cValue] * 100
Before the if SKIN:GetMeasure line in the code. I did try it but it seemed to not process the rest.

I did even after that add the line for a measure update..

Code: Select all

do SKIN:Bang('!SetOption',textPercent,percentage)
I added that at the very end but it didn't update the skin... WHere i had a string measure... I think i am missing something obvious and for some reason can't find it.