It is currently May 4th, 2024, 3:47 am

Lua, bar graph, lua, and a database.

Get help with creating, editing & fixing problems with skins
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

Lua, bar graph, lua, and a database.

Post by syngod »

Hey guys... I am new to trying to create skins..

I was wondering if it would be possible to have reainmeter show info in a bar graph, or speedometer of information grabbed from a database... From looking at lua i don't think it would be directly possible. But if i saved the information to a file using php or some other way from the database i could have lua read the file whenever it is saved.

If this is possible can anyone give me a general direction of which meter, and measures need to be used.

Thanks for any help.
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

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

Post by syngod »

I have been looking at this for a while and though to do something and wanted to get an opinion.

What i can do is use php to create the file as a self describing data set. so have the data saved by php like this.

Code: Select all

MachineBuilds {
    target = "100,000"
    actual = "65,00"
    projected = "250,000"
}
I could have lua read that file with something along the lines of

Code: Select all

 local authors = {}     
    function MachineBuilds (b) target[b.target] = true end
    dofile("data")
    for name in pairs(authors) do print(name) end
I got this striaght from the programinig in lua book that i am trying to read to learn a good way to do all this. But this leads to some questions how can i get this to corispond to a graph within rainmeter.

I am going through the lua tutorial but since i don't know much about lua yet it is still not clicking all the way.

Anyone got any pointers on this.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

Don't do it that way. The implementation of Lua in Rainmeter does not support .dofile. It would be better if you wrote the file in an XML looking format like:

<target>100000</target>
<actual>6500</actual>
<projected>250000</projected>

Then open the file in Lua, read in the lines and put the values into variables (if there are only a few) or a table (if there are lots or more than one "target", "actual" etc.)

Then you can use those values to drive meters in Rainmeter. I don't know what kind of "graph" you are looking to do in the skin, but you can use the values you read in Lua to !SetVariable some variables in Rainmeter that could be used by a Histogram, Line Meter, or Bar Meter as you like.
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

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

Post by syngod »

thanks for the response... Ok that will work i will look into that here... and the graph choice i am still a little up in the air on... i think it will come down to aesthetics what is easiest to read in a glance here and there..

I am still learning LUA is there a direct approach to the xml...

something like

Code: Select all

for lines in io.lines(filename)
      table.insert(lines, line)
    end
for i = 1 , (lines < 4) do 
   then the rainmeter bang connection for variables here correct.
That would need to be done for each type... target, actual, prjocted, and machine builds.

Just seeing if i am headed in the right way now that dofile is not supported.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

syngod wrote:thanks for the response... Ok that will work i will look into that here... and the graph choice i am still a little up in the air on... i think it will come down to aesthetics what is easiest to read in a glance here and there..

I am still learning LUA is there a direct approach to the xml...

something like

Code: Select all

for lines in io.lines(filename)
      table.insert(lines, line)
    end
for i = 1 , (lines < 4) do 
   then the rainmeter bang connection for variables here correct.
That would need to be done for each type... target, actual, prjocted, and machine builds.

Just seeing if i am headed in the right way now that dofile is not supported.
Yes, I would do something like that. It will depend some on how much "data" you are reading, but you could use string.match to do a regular expression (more or less) search / capture on the lines of data, then either just assign them to variables or stick them in table(s). Then right, use SKIN:Bang('!SetOption TargetCalc1 Formula '..targetsTable[1]) to set the value of a Calc measure in the skin.

[Target1Calc]
Measure=Calc
Formula=0
MinValue=0
MaxValue=xxxxx
DynamicVariables=1

Then the Bar meter

[Target1Bar]
Meter=Bar
MeasureName=Target1Calc
...
syngod
Posts: 13
Joined: May 3rd, 2012, 2:10 pm

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

Post by syngod »

Im still not understanding this and i am not sure why.

I got assitance creating the lua script in that board this is now what i have.
function Initialize()
sFileName = SELF:GetOption('FileName')
end -- Initialize

function Update()
hFile = io.open(sFileName)
if not io.type(hFile)=='file' then
print('File error')
return 'File error'
else
sale = {}
local text=io.read('*all')
io.close(hFile)
for tag,contents in string.gmatch(text,'<([^%s>]+)(.-)%/>') do
sale[string.lower(tag)]=Keys(contents,{target=0,actual=0,projected=0})
end
end
return #sale
end --update
Now i figured i would use the round line to do the graphing as i can then put an image under that in a speedometer or non at all and people will see what the sales are.

so this is my .ini
[Rainmeter]
Update=1000


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

[MsCript]
Measure=Script
ScriptFile="#CURRENTPATH#sales.lua"
FileName=#CURRENTPATH#number.txt

[mring]
Measure=Calc
Formula=360

[msales]
MeasuerName=MsCript
Meter=ROUNDLINE
x=-10
y=50
w=200
h=10
LineLength=#sales.machinesales.projected#
LineStart=#sales.machinesales.target#
But i realized i am doing this all wrong i need to have something in lua script that runs the bang to update the roundline meter. but i am not sure what exactly i need to do i think it's something like this

Code: Select all

SKIN:Bang('!SetOption  LineLength=sales.machinesales.projected)
But when i tried that it gave me an error in the debugger to say that msales is unbound.
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 »

I need a bit more information on what you are wishing to accomplish.

What value to you wish to display, and which value do you wish to compare it to?

Roundlines require that they are passed a value between 0 and 1. That is why need need a number to compare the original value to.
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 i thought if you have the max and min value set it would work... The values that i need to show run anywhere from 0 up too 500000 what i want to do with it is to show sales projection and actual sales.. I was thinking that a round line could be used as it could be a simple graph then.

I may not be going at it right... I mean this is really the first time i have had to design anything so im confused at how to make it work.
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 »

If you set MaxValue=5000 on the measure that you use to drive the Roundline Rainmeter actually just does the math for us.

Currently the information you are returning to Rainmeter from the Lua script is the number of <tags> found and not the actual value you want to use.

There are a couple methods we can use to drive a Roundline from Lua. The question is, do you wish to use more than one Roundline?
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 »

The hope was to use more then one roundline yes. Or really i could create a seperate skin for each one if that is easier. Then i would only have to use what that person needs so aftermarket would only see after market..

But one skin with multiple roundlines would be best i believe.