It is currently April 24th, 2024, 3:35 am

LUA and WebParser seems a bit slow...

Discuss the use of Lua in Script measures.
Sven2157
Posts: 4
Joined: March 17th, 2013, 5:51 pm

LUA and WebParser seems a bit slow...

Post by Sven2157 »

Hello Everyone! :welcome:

I have recently discovered Rainmeter, and love it! However, I have been unable to find very many Skins that display what I would like to see; so naturally I started to create my own. I have a pretty good grasp of many programming languages, but I am new to LUA. Seems pretty straight forward, from what I can tell so far.

-- Basic Skin description --
I have created a Skin that pulls METAR data from the Aviation Digital Data Service( ADDS ). This is a Weather Skin( like there aren't enough ;-) ), but for pilots. METARs update ~approximately every hour, give or take, and provide precise, detailed weather information to Aviators in a coded text string( see link above ).

My Skin 'fetches' an XML file, returns some values, and then I use LUA to set FontColor and perform a basic conversion of a measurement.

-- Technical and Problem( possibly ) --
My problem right now( I have many of them, but will keep the post on a single topic ), is that my skin retrieves the requested information relatively fast( ~1 - 2s ), but the parts sent to LUA seem extremely slow( ~5s ). Being new to LUA, I may have some programmatic issues. I even downloaded JSMorley's LuaTutorial_1.1.rmskin. However I can't help but feel this should be faster.

I have attached the .RMSKIN, as apposed to typing a bunch of code, and then eventually having to do so anyway.

The starting METAR is for Chicago O'Hare International Airport( KORD ). To see another airport METAR just click the 'SET ICAO' in the lower left. Then type the 4 character identifier.

For those that are unfamiliar with international airport identifiers, you must enter the ICAO Identifier( 4 chars ); not the IATA identifier( 3 chars ). Here are some quick examples you can try:
  • KATL - Hartsfield - Jackson Atlanta International Airport
  • KJFK - John F Kennedy International Airport
  • KLAX - Los Angeles International Airport
  • EGLL - London Heathrow Airport
  • CYYC - Calgary International Airport
Any help would be greatly appreciated! :bow:
Last edited by Sven2157 on April 21st, 2013, 6:03 pm, edited 2 times in total.
Regards,

Sven2157
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: LUA and WebParser seems a bit slow...

Post by smurfier »

It's the UpdateDivider that's you're using that is getting in the way.

aeroWeather.ini

Code: Select all

;;===============================;;
;;																;;
;;			 Aviation Weather Powered				;;
;;					    	 by								;;
;;	   Aviation Digital Data Service( ADDS )	;;
;;																;;
;;			 Rainmeter Skin developed				;;
;;					    	 by								;;
;;			  			Sven2157							;;
;;																;;
;;				   Copyright © 2013					;;
;;				  dynamic FX group					;;
;;		  support@dynamicfxgroup.com			;;
;;																;;
;;			 NOT FOR REAL WORLD				;;
;;					AVIATION USE!						;;
;;																;;
;;===============================;;

[Rainmeter]
Update=1000
@include="#@#variables.inc"

[Metadata]
Name=Aviation Weather
Author=Sven2157
Information=NOT FOR REAL WORLD AVIATION! | Powered by Aviation Digital Data Service( ADDS ) | ADDS is a free public service produced by the National Center for Atmospheric Research( NCAR ) under sponsorship of the Federal Aviation Administration( FAA ). | Additional ADDS Sponsorship by: | The National Weather Service( NWS ) | The National Oceanic and Atmospheric Administration( NOAA ) | The National Science Foundation( NSF )
Version=1.0 Beta
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Background]
Meter=Image
W=200
H=180
SolidColor=63,63,65,125


;;=====================;;
;;==		Begin  Measure		==;;
;;=====================;;

[MeasureMETAR]
Measure=Plugin
Plugin=WebParser
URL=#METARURL#
RegExp=#METARREGEX#
UpdateRate=#uRATE#
FinishAction=!CommandMeasure MeasureLuaScript Update() #CURRENTCONFIG#

[MeasureData]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMETAR]
StringIndex=1
UpdateRate=#uRATE#

[MeasureStation]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMETAR]
StringIndex=2

[MeasureOBStime]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMETAR]
StringIndex=3
UpdateRate=#uRATE#

[MeasurePressureInHg]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMETAR]
StringIndex=11
UpdateRate=#uRATE#
StringStyle=Bold

[MeasureFlightRules]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMETAR]
StringIndex=12
UpdateRate=#uRATE#

[MeasureLuaScript]
Measure=Script
ScriptFile=adds.lua
UpdateDivider=-1

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=100,100,100,255
MeterStyle=ADDSstyle
X=#METX#
Y=164
FontColor=F8F8F8FF
X=#METX#
Y=148
H=14
W=55
DefaultValue=#ICAO#
Command1=!WriteKeyValue Variables ICAO "$UserInput$" "#@#variables.inc"
Command2=!Refresh #CURRENTCONFIG#

;;===================;;
;;==		Begin Meter		==;;
;;===================;;

[MeterStation]
Meter=String
MeasureName=MeasureStation
MeterStyle=ADDSstyle
X=3
Y=5
FontSize=12
FontColor=2,126,250,255
StringStyle=Bold
ToolTipTitle=%1 Airport Information
ToolTipType=0
ToolTipIcon=#@#\images\airnav_favicon.ico
ToolTipText=Click here for additional#CRLF#information provided by Airnav.com.
LeftMouseUpAction=["#ANURL#"]
Text= %1


;;=========================================;;
;; With FontSize of 8, each line of text is ~approx 12 tall: 	;;
;; 2 padding top & 2 bottom, and character height of 8		;;
;;=========================================;;
[MeterData]
Meter=String
MeasureName=MeasureData
MeterStyle=ADDSstyle
X=5
Y=#METY#
W=#METW#
H=#CLIPH#
Clipstring=1
DynamicVariables=1
Text= %1
ToolTipTitle=METAR Translation
ToolTipType=0
ToolTipIcon=#@#\images\aviation_weather_favicon.ico
ToolTipText=Click here for translated#CRLF#METAR information. Provided#CRLF#by AviationWeather.com.
LeftMouseUpAction=["#TRANSURL#"]

[MeterOBStime]
Meter=String
MeasureName=MeasureOBStime
MeterStyle=ADDSstyle
X=75
Y=7
W=#METW#
H=#METH#
DynamicVariables=1
Text= %1

[MeterCondition]
Meter=String
MeterStyle=ADDSstyle
X=#METX#
Y=88
Text=Conditions:

[MeterFlightRules]
Meter=String
MeterStyle=ADDSstyle
X=60
Y=88
DynamicVariables=1

[MeterPressureInHgText]
Meter=String
MeterStyle=ADDSstyle
X=#METX#
Y=#METY#
Text=Alt Pressure:

[MeterPressureInHg]
Meter=String
MeterStyle=ADDSstyle
X=70
Y=106
DynamicVariables=1

[MeterWriteKeyValue]
Meter=String
MeterStyle=ADDSstyle
FontColor=2,126,250,255
X=#METX#
Y=164
AntiAlias=1
StringStyle=Bold
Text=SET ICAO
LeftMouseUpAction=!CommandMeasure "MeasureInput" "ExecuteBatch 1-2"


;;=====================;;
;;==	Powered by Footer		==;;
;;=====================;;
[MeterPowered]
Meter=String
MeasureName=MeasureADDSlogo
X=91
Y=166
FontColor=2,126,250,255
FontSize=7
StringStyle=BoldItalic
LeftMouseUpAction=["#ADDSURL#"]
Text= Powered by


[MeterADDSlogo]
Meter=IMAGE
ImageName=logo-adds.png
Path=#@#\images
ImageTint=136,137,141,255
X=150
Y=166
W=45
PreserveAspectRatio=1
LeftMouseUpAction=["#ADDSURL#"]
adds.lua

Code: Select all

function Initialize()
	msMeasureFlightRules = SKIN:GetMeasure( "MeasureFlightRules" )
	msMeasurePressureInHg = SKIN:GetMeasure( "MeasurePressureInHg" )
end  -- funciton Initialize

function Update()
	sFlightRules = msMeasureFlightRules:GetStringValue()
	sPressureInHg = tonumber(msMeasurePressureInHg:GetStringValue())

	local color = {VFR = '0,255,0,255', IFR = '255,102,0,255', MVFR = '255,255,0,255', LIFR = '255,0,0,255',}

	SKIN:Bang('!SetOption', 'MeterFlightRules', 'Text', sFlightRules)
	SKIN:Bang('!SetOption', 'MeterFlightRules', 'FontColor', color[sFlightRules])
	SKIN:Bang('!SetOption', 'MeterPressureInHg', 'Text', ('%d in (%d mb)'):format(Round(sPressureInHg, 2), Round(sPressureInHg * 33.8637526, 1)))
	SKIN:Bang('!UpdateMeter', '*')
	SKIN:Bang('!Redraw')
end -- function Update

Round = function(num, idp)
	assert( type(num) == 'number', type(num))--'Round expects a number.')	
	local mult = 10 ^ (idp or 0)
	if num >= 0 then
		return math.floor( num * mult + 0.5 ) / mult
	else
		return math.ceil( num * mult - 0.5 ) / mult
	end
end -->Round
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 . . .
Sven2157
Posts: 4
Joined: March 17th, 2013, 5:51 pm

Re: LUA and WebParser seems a bit slow...

Post by Sven2157 »

Holy cow! :o

That is what I thought! Much faster. Although I am not quite sure that I fully understand what is happening.

I compared yours to the original, and noticed these changes.
  1. Cleaned up some of the PATHS to files.
  2. You added the FinishAction to the base Measure.
    • This is 'waiting' for the URL to load, then sending a command to the LuaScript Measure to update it with the newly retrieved information, correct?
  3. Removed 'TableName', 'StringIndexReturn', and the variable being passed to the LUA script, in the LUA Script Measure.
    • Which I see now is not necessary.
  4. Also set the UpdateDivider to -1.
    • Though I am not understanding why this Measure does not need to be updated?
METAR information is suppose to update around 10 minutes to the hour, but that is not always the case. So this will still update every five minutes? I would assume so, but not getting my head around the LuaScript not updating.

Is this because the FinishAction is using the !CommandMeasure to update the script from MeasureMETAR? What is the difference between that and the UpdateDivider?

Thank you for the help, thus far. The speed is what I thought it should be now!
Regards,

Sven2157
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: LUA and WebParser seems a bit slow...

Post by smurfier »

The Lua Script only needs to Update every time the data retrieved by WebParser changes. That is why the script has UpdateDivider=-1. The FinishAction is forcing an update of the script when it's loading and parsing is complete.
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 . . .