My partner and I have developed a fair amount of knowledge about acquiring, parsing, and displaying weather data while developing a sailing website. San Francisco sailors and Drupalcon attendees can see a sample here:
http://www.raceonedesign.com/weather?lat=37.794&lon=-122.347&title=San%2...
The module we have developed and would like to contribute is similar in concept to the existing 'weather' module in that it uses a SOAP interface to request weather data from the National Weather Service. Our new module, however, compliments 'weather' by displaying forecast data instead of the 'weather' modules current weather conditions.
The link above will bring up weather data for San Francisco, CA. Clicking the '3 Day Forecast' gives a reasonable preview of what our proposed module will provide to the Drupal community.
Our new module requires 'SOAP' to be enabled on the host. It has not other dependencies.
We have included two methods to utilize our module. The simple method is a Drupal admin configurable 'single location' mode. The administrator defines a latitude/longitude and name along with a few details about how the data is displayed. Our module exposes a block that the administrator can place appropriately. This mode is obviously limited to just one location.
The second mode is to expose a function to a Drupal coder. A coder might need to get weather for multiple locations and this would allow him or her to make multiple function calls to assemble weather forecasts for multiple locations. This method also requires the coder to parse a rather obtusely arranged array to retrieve the weather data. The format of this array is dictated by the complexity and variability of weather data.
The theming is not fancy but uses standard Drupal theming practices so that it can be rethemed as appropriate.
Thanks
Dwaine
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | nws_weather.zip | 22.3 KB | dwaine |
| #11 | nws_weather.zip | 22.37 KB | dwaine |
| #8 | nws_weather.zip | 21.92 KB | dwaine |
| #4 | nws_weather.zip | 21.32 KB | dwaine |
| #1 | nws_weather.zip | 45.02 KB | dwaine |
Comments
Comment #1
dwaine commentedComment #2
dawehnerYou could use instead of the the preprocess and set the output for this there. Then other modules could hook in and display something else. Also theme templates should only contain the print.
Thats not needed.
Basically it all looks fine. I didn't tryed out the module yet. Additional i don't see a reason why this shouldn't be rtbc.
Suggestions:
Comment #3
avpadernoI am changing the status as per previous comment.
Comment #4
dwaine commentedThank you for you help so far.
The four issues mentioned by dereine have been corrected. His third suggestion, checking for PHP's SimpleXML module, has also been added.
I've zipped and uploaded. I believe it is ready for review.
Thanks
Dwaine
Comment #5
avpadernoThe implementation of
hook_requirements()is not correct; or it checks the parameter$phasepassed, or it usesget_t().The global variable doesn't use the correct name, which should prefixed by an underscore, and the module name (and should be in lower case).
Some strings used in the user interface are written as
Option Title, when they should be written as .Comment #6
dwaine commentedThe first issue description in kiamlaluno's comment isn't clear to me. I've gone back and made numerous changes to my implementation of hook_requirements() based on research I've done. But I'm not convinced I addressed the issue. I've pasted the new code below. Does it look correct now? If not, can you be more specific about how the implementation is not correct?
Thanks
Dwaine
Comment #7
avpadernoThe code reported in the previous comment is correct. The previous code was not corrected because used
t(), and it didn't check the value of$phase.You can use
t()insidehook_requirements(), but only when$phaseis equal to .Comment #8
dwaine commentedThe improved implementation of hood_requirements() has been added to the module. I've uploaded the latest version.
Thanks
Comment #9
avpadernoI am adding the review tags.
Comment #10
atheneus commentedLast posted version throws some PHP notice level warnings. Please check the syntax of your define declarations. i.e. use define('NWS_WEATHER_WSDL_URL', '...'). the constant needs to be quoted when first defined.
Ran through Coder and throws only 3 very minor coding standards problems (not a problem).
You do not need all the variable_set()'s in your _install() function. When using variable_get() always include the default setting as the second parameter.
I think the image mapping should not be stored in the variable table but stored in a database table. Your usage here really seems to be stretching the use of variable settings beyond what is intended. Just my opinion, others might disagree.
Hope this helps. Seems like a cool contribution.
Comment #11
dwaine commentedThe recommendation to remove image mapping out of variable table was a good one and has been completed. The image map (a serialized array) is now saved to the DB.
The 'define' declarations have been corrected.
I've looked at the variable_set()'s in the _install function versus using variable_get() with a default value. During development we tried both methods and had an issue with the latter. During testing I found a problem when using variable_get() and a default value. I found that, if the module is enabled but the admin page is never 'save configuration' submitted, the default values are not written to the 'variable'. Without these config values set the block does not function correctly. So we ended up with the current solution to guarantee the values are set. I was unable to find a more elegant solution.
I've uploaded the module again without any changes to the variable_set() vs 'variable_get() with defaults' issue. I'm not sure of the best solution for the extraneous variable_set()'s but was hoping to start that discussion with a more knowledgeable Drupaler.
Thanks for your help
Dwaine
Comment #12
atheneus commentedHi dwaine,
The changes look good. On the issue with the use of variable_set and variable_get methods. The function variable_set() writes the value to the variables database table, which means that it gets loaded into the global $conf variable when Drupal is bootstrapped. The correct use of variable_get is to supply your defaults as the second parameter to the function call. The function is there to allow users to override the default.
In your module block view I see you using:
This is why it doesn't display properly without those variable_set() in the install. You should be using:
By supplying the default in the places where you use it means you don't have to load up the global name space with a bunch of default values just for your application. Only those defaults that the user explicitly sets in your admin settings form will get loaded into global scope. That puts the control back in the hands of the user.
See: the code in http://api.drupal.org/api/function/variable_set/6 - how variable_set works and where the value gets stored (i.e. global $conf).
This is part of Drupal best practice and I don't think it should be ignored.
I also find how you are storing those image mappings in the database disturbing. It's good that it's in the database rather than in the global application space, but storing them as a serialized array means that if you need to add or remove a mapping in subsequent updates that you will have to initialize a new complete array in your update function, serialize and rewrite. You will need to do this for every update is any single value changes. If you can be 100% certain there is zero likelihood that these values will never have to be changed it isn't an issue - but that seems unlikely to me.
Alternatively you can simple have a schema:
url (this should always be unique and set as the primary key for indexing lookups)
file
Then you can just lookup the image you need from the URL key.
This is more maintainable and more efficient use of resources. In your nws_weather_override_image($image) function instead of loading in the record, deserializing into an array and then doing an array key lookup, you can simply query the database "SELECT file FROM {nws_weather} WHERE url = '%' " and use db_result() to get your result as a scalar value.
Also - since you are implementing a schema you should use drupal_write_record() instead of db_query() in your install file.
Hope that's helpful and constructive input!
Comment #13
avpadernoI am changing the status as per previous comment.
drupal_write_record()doesn't work inhook_install(), untilhook_install()is not completed and the table system doesn't report the module is enabled.[Edited by kiamlaluno to correct the last sentence]
Comment #14
atheneus commented@kiamlaluno: good catch on the drupal_write_record(). I always forget that, and always try to do it, duh!
Comment #15
dwaine commentedThanks for the explanation on the how and why variable_get()/variable_set() was being mis-used.
This upload include two updates.
The first is to correct the use of variable_get() so that we are supplying default values. The complication I saw was that variable_get() could be called from two different places for some values. My solution, to allow more convenient maintenance, was to create constants for those default values.
The second change is in regards to the DB structure for the image map. The 'url' value is defined by NWS and they could choose to change it at any time. So, yes, the values could change. I changed the DB structure as suggested. The url field is indexed.
Dwaine
Comment #16
dwaine commentedI forgot to update status on previous comment.
Dwaine
Comment #17
atheneus commentedLooks good to me. One thing you should do before releasing is to change the index in your schema to either 'primary key' or 'unique keys'. This isn't going to make a huge amount of difference in the short term, but it's important for maintaining data integrity. With a unique key index there cannot be any duplicate values. The way you are using this table demands that there are no duplicate urls. In general best practice every database table should have a primary key so just changing 'indexed' to 'primary key' should do fine.
At this point I'm happy with it. Good work!
Comment #18
avpadernoComment #21
avpaderno