Agonostis
January 30th, 2006, 01:56 PM
Hi,
I'm really liking using AJAX + Girder to make my interfaces. I've got the web-page --> girder event triggering working great - it's super-responsive over my home network, and not half bad over the 'net.
Now I'm ready to make more progress on the girder--->web direction. I've pored through the examples that ship with Girder and I think I understand how it works.
I'd really like to write a function whose argument is a Lua table (for example, a weather.Local.cc object) that will return XML, comma-separated text, or anything else useful to pass back to the XMLhttpRequest object for use in my webpage.
Kind of like a combination of the GetField() (in the ajax_req.lhtml example) and table.print() functions.
I'm not a web (or any kind of) developer, so be gentle. This seems like the kind of thing AJAX is meant to handle with ease, so I was wondering if anyone has any advice before I go reinventing the wheel.
Thanks very much!
Ron
January 30th, 2006, 02:45 PM
Well, how hard this would be would really depend on exactly what you want it to do. I am not sure if we have code that converts a table to XML.. Anyone?
Agonostis
January 30th, 2006, 03:03 PM
My immediate goal is to click a "weather" button on a webpage, have it asynchronously query the Lua Global table to retrieve the weather.Local.cc table for parsing and display on the webpage.
More broadly, while the G examples have a robust solution for retrieving the data/type of a single variable, I'd like to be able to pass data back and forth in bigger chunks.
It doesn't necessarily have to be XML, check out this article (http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=AJAXWithoutXML) about forming the server response as JavaScript code.
Thanks for looking at/thinking about this Ron.
Ron
January 30th, 2006, 03:06 PM
That would be cool. I don't have too much time right now. Maybe some other day, but don't hold your breath.
Agonostis
February 6th, 2006, 09:03 PM
I kludged a solution to this to fit my specific weather needs. I think it would be pretty easy to adapt this to fit whatever somebody else needed to do.
i added the following code to the ajaxreq.lhtml file:
if ( t.Weather ) then
local tempString=""
for key,value in pairs(weather.Local.cc) do
tempString=tempString.."var "..key.."=".."'"..tostring(value).."'"..";"
end
for key,value in pairs(weather.Local.Location) do
tempString=tempString.."var "..key.."=".."'"..tostring(value).."'"..";"
end
for key,value in pairs(weather.Local.cc.TimeStamp) do
tempString=tempString.."var "..key.."=".."'"..tostring(value).."'"..";"
end
for i=1,7 do
for key,value in pairs(weather.Local.fc[i]) do
tempString=tempString.."var "..key..i.."=".."'"..tostring(value).."'"..";"
end
end
--print(tempString)
webserver:print(tempString)
end
and then use the javascript eval() function on the .responseText in the actual web page. Then all the weather info is available to use in conveniently named variables.
Ron
February 7th, 2006, 07:01 AM
Hmm, I think there are some issues with threading here. I'll get Mike's opinion on this.
Agonostis
February 7th, 2006, 07:34 AM
It seems to be working ok for the time being...perhaps not quite as fast as I might have liked, but hasn't crashed or anything.
Ron
February 7th, 2006, 08:13 AM
If the weather object updates right in the middle of you pushing the info to the webbrowser you might get unexpected results. Not a crash probably but just bad data.
Promixis
February 7th, 2006, 09:32 AM
These functions are for getting data.
Usage...
Weather.XXX:Get...
XXX = location
Use Local for default location
GetCWSmallIcon = function (self,iconnumber)
return win.GetDirectory('GIRDERDIR').."\\CWIcons\\Small\\"..(iconnumber or "")..".gif"
end,
GetCWLargeIcon = function (self,iconnumber)
return win.GetDirectory('GIRDERDIR').."\\CWIcons\\Large\\"..(iconnumber or "")..".gif"
end,
GetCWAnimSmallIcon = function (self,iconnumber)
return win.GetDirectory('GIRDERDIR').."\\CWIcons\\AnimatedSmall\\"..(iconnumber or "")..".gif"
end,
GetCWAnimLargeIcon = function (self,iconnumber)
return win.GetDirectory('GIRDERDIR').."\\CWIcons\\AnimatedSmall\\"..(iconnumber or "")..".gif"
end,
GetCurrentConditions = function (self) -- always returns a value so no need to check for nils..
local w = self:GetCC ()
if w and w.Observations and w.Observations [1]then
local xxx = w.Observations [1]
return {
BarometricPressure = xxx.baro_pressure or "?",
BarometricTendency = xxx.baro_tendency or "?",
DewPoint = xxx.dew_point or "?",
Humidity = xxx.humidity or "?",
Icon = xxx.icon or "",
IconName = xxx.icon_name or "?",
IconSmallFilename = self:GetCWSmallIcon (xxx.icon),
IconAnimSmallFilename = self:GetCWAnimSmallIcon (xxx.icon),
IconLargeFilename = self:GetCWLargeIcon (xxx.icon),
IconAnimLargeFilename = self:GetCWAnimLargeIcon (xxx.icon),
Precipitation = xxx.precip or "?",
PrecipitationDescription = xxx.precip_desc or "?",
Temperature = xxx.temperature or "?",
TemperatureDescription = xxx.temp or "?",
Visibility = xxx.visibility or "?",
WindDirectionDegrees = xxx.wind_dir or "?",
WindDirectionLong = xxx.wind_long or "?",
WindDirectionShort = xxx.wind_short or "?",
WindSpeed = xxx.wind_speed or "?",
SkyDescription = xxx.sky or "?",
Description = xxx.desc or "?",
TimeStamp = w.TimeStamp or "?",
Location = self.Location or "?",
Metric = self.Metric,
}
else
return nil
end
end,
GetForecastConditions = function (self)
local w = self:GetFC ()
if w and w.Forecast and w.Forecast [1] then
local Days = {}
for i in ipairs (w.Forecast) do
local xxx = w.Forecast [i]
Days [i] = {
Date = xxx.date or "?",
DayofWeek = xxx.day_of_week or "?",
DayofForecast = xxx.day_sequence or "?",
WeekDay = xxx.weekday or "?",
Description = xxx.description or "?",
DewPoint = dewpoint or "?",
Humidity = xxx.humidity or "?",
Icon = xxx.icon or "",
IconNam = xxx.icon_name or "?",
IconSmallFilename = self:GetCWSmallIcon (xxx.icon),
IconAnimSmallFilename = self:GetCWAnimSmallIcon (xxx.icon),
IconLargeFilename = self:GetCWLargeIcon (xxx.icon),
IconAnimLargeFilename = self:GetCWAnimLargeIcon (xxx.icon),
Beaufort = xxx.beaufort or "?",
BeaufortDescription = xxx.beaufort_desc or "?",
HighTemp = xxx.high_temp or "?",
LowTemp = xxx.low_temp or "?",
Precip = xxx.precip or "?",
PrecipDescription = xxx.precip_desc or "?",
PrecipProbability = xxx.precip_prob or "?",
Rainfall = xxx.rainfall or "?",
Sky = xxx.sky or "?",
SkyDescription = sky_desc or "?",
Snowfall = xxx.snowfall or "?",
Temp= xxx.temp or "?",
TempDescription = xxx.temp_desc or "?",
UV =xxx.uv or "?",
WindDirectionDegrees = xxx.wind_dir or "?",
WindDirectionLong = xxx.wind_long or "?",
WindDirectionShort = xxx.wind_short or "?",
WindSpeed = xxx.wind_speed or "?",
}
end
Days.TimeStamp = w.TimeStamp or "?"
Days.Location = self.Location or "?"
Days.Metric = self.Metric
return Days
else
return nil
end
end,
GetDetailedForecastConditions = function (self)
local w = self:GetDFC ()
if w and w.Forecast and w.Forecast [1] then
local Days = {}
for i in ipairs (w.Forecast) do
local xxx = w.Forecast [i]
Days [i] = {
Air = xxx.air or "?",
Comfort = xxx.comfort or "?",
DayofWeek = xxx.day_of_week or "?",
DaySegment = xxx.day_seqment or "?",
WeekDay = xxx.weekday or "?",
Description = xxx.description or "?",
DewPoint = dewpoint or "?",
Humidity = xxx.humidity or "?",
Icon = xxx.icon or "",
IconNam = xxx.icon_name or "?",
IconSmallFilename = self:GetCWSmallIcon (xxx.icon),
IconAnimSmallFilename = self:GetCWAnimSmallIcon (xxx.icon),
IconLargeFilename = self:GetCWLargeIcon (xxx.icon),
IconAnimLargeFilename = self:GetCWAnimLargeIcon (xxx.icon),
Beaufort = xxx.beaufort or "?",
BeaufortDescription = xxx.beaufort_desc or "?",
HighTemp = xxx.high_temp or "?",
LowTemp = xxx.low_temp or "?",
Precip = xxx.precip or "?",
PrecipDescription = xxx.precip_desc or "?",
PrecipProbability = xxx.precip_prob or "?",
Rainfall = xxx.rainfall or "?",
Sky = xxx.sky or "?",
SkyDescription = sky_desc or "?",
Snowfall = xxx.snowfall or "?",
Temp= xxx.temp or "?",
Temperature = xxx.temperature or "?",
TempDescription = xxx.temp_desc or "?",
UV =xxx.uv or "?",
WindDirectionDegrees = xxx.wind_dir or "?",
WindDirectionLong = xxx.wind_long or "?",
WindDirectionShort = xxx.wind_short or "?",
WindSpeed = xxx.wind_speed or "?",
Visibility = xxx.visibility or "?",
}
end
Days.TimeStamp = w.TimeStamp or "?"
Days.Location = self.Location or "?"
Days.Metric = self.Metric
return Days
else
return nil
end
end,
GetSatelliteMapFilename = function (self)
return self:GetSatMapFilename ()
end,
GetAnimatedSatelliteMapFilename = function (self)
return self:GetSatMapAnimFilename ()
end,
harleydude
March 21st, 2006, 06:43 AM
I am attempting to use the above methods of retreiving the weather data, but am not sure of the actual calls to make. Can some one provide me with a working code sample for GetCurrentConditions?
Thanks
Powered by vBulletin® Version 4.1.8 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.