[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squirrelmail-plugins
Subject:    [SM-PLUGINS] TWC_Weather 1.1 Beta 2C is available
From:       "Starkey, Jamuel, NLNS" <jamuel () att ! com>
Date:       2003-02-28 21:46:18
[Download RAW message or body]

Hi,

TWC Weather v1.1 Beta 2c can be found on the SM.org site.  This ought to be the final \
beta2 release.  The major feature in 1.1 Beta 2 is fairly good support for SI/Metric \
conversion of the weather forecast (narrative) text.  

If you are an everyday SI user please give it a shot and let me know what you think!  \


A patch has been included here as well from 1.1-beta-2b (see below).

Cheers,

JPS


From the README:

============================================================================
Features in 1.1 Beta 2c
--------------------------

-- Cleaned up twc_support quite a bit.  Added lots of comments and restructured
   some of the lines of code to stay within 80 columns.

-- Also fixed the output of the weather box to so that the column position
   of the weather values doesn't fluctuate.  They sort of floated ever since
   the option to display a wide (vs narrow) forecast/narrative text.
   (Thanks to Stephen Brown for coming up with the patch for that.)

-- Made a couple of random fixes to the support code to help handle random
   preg_replace problems/bugs in my search-patterns.  What comes to mind
   are a fix for trapping "than" vs "an" (was getting a hit on a phrase
   that had "than") and was dropping a period on an end of a sentence that
   contained an inches conversion.  Both are fixed.

# # #


Patch to go from Beta 2b to Beta 2c (below the vvvvvvv's):

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

cvs diff: Diffing .
Index: README
===================================================================
RCS file: /usr/local/src/CVSROOT/twc_weather/README,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -B -b -p -r1.19 -r1.20
--- README      2003/02/26 07:43:32     1.19
+++ README      2003/02/27 23:30:20     1.20
@@ -22,6 +22,23 @@ Additionally this plug-in is based on Da
 Weather 3.0.0 code base.  I only mangled it for the purpose described herein.
 
 
+Features in 1.1 Beta 2c
+--------------------------
+
+-- Cleaned up twc_support quite a bit.  Added lots of comments and restructured
+   some of the lines of code to stay within 80 columns.  
+
+-- Also fixed the output of the weather box to so that the column position 
+   of the weather values doesn't fluctuate.  They sort of floated ever since 
+   the option to display a wide (vs narrow) forecast/narrative text.  
+   (Thanks to Stephen Brown for coming up with the patch for that.)
+
+-- Made a couple of random fixes to the support code to help handle random
+   preg_replace problems/bugs in my search-patterns.  What comes to mind
+   are a fix for trapping "than" vs "an" (was getting a hit on a phrase 
+   that had "than") and was dropping a period on an end of a sentence that 
+   contained an inches conversion.  Both are fixed.
+
 Features in 1.1 Beta 2b
 --------------------------
 
@@ -126,21 +143,26 @@ Requirements
 The only tested configuration that is supported is as follows:
 
 -- Need feedback for the following:  Squirrelmail 1.2.x, 1.3.x, 1.4.x
-   but (known to work with SM 1.4.0-rc2a, 1.2.10 both with PHP 4.3.0)
+   but (known to work with SM 1.4.0-rc2a, 1.2.11 both with PHP 4.3.0)
 
--- PHP register_globals = Off (or On) 
+-- PHP register_globals = Off (or On).  PHP should also support Perl Regular
+   Expressions (PCRE) as well as Regular Expressions (EREG). 
 
 Caveats
 --------
 * rg = Off supported in SM 1.2.x if user_prefs are *file* based as opposed to 
-  MySQL/database-based.  Seems like other portions of SM code prevent correct \
                operation
-  when user preferences are stored in a database as oppoed to being stored in the
-  data directory.
-
--- Have received a report that the Squid Proxy can interfere with the gathering of \
                the
-   twc data feed.  The user was able to create an appropriate rule to enable the 
-   correct operation.  Send me email and we can discuss debugging options if you 
-   aren't able to get this plug-in working.
+   MySQL/database-based.  Seems like other portions of SM code prevent correct 
+   operation when user preferences are stored in a database as oppoed to being 
+   stored in the data directory.
+
+-- Have received a report that the Squid Proxy can interfere with the 
+   gathering of the twc data feed.  The user was able to create an appropriate 
+   rule to enable the correct operation.  Send me email and we can discuss 
+   debugging options if you aren't able to get this plug-in working.
+
+-- Heard that Netscape 4.x browsers can only display the weather box and can NOT
+   edit the TWC Options.  A blank page is displayed.  Will try and resolve for
+   by the final 1.1 release.
 
 
 Installation
Index: twc_support.php
===================================================================
RCS file: /usr/local/src/CVSROOT/twc_weather/twc_support.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -B -b -p -r1.9 -r1.10
--- twc_support.php     2003/02/26 07:30:30     1.9
+++ twc_support.php     2003/02/27 23:17:40     1.10
@@ -35,9 +35,7 @@ function SI_Pressure ($Pressure_InchesHg
 
         return (round($Pressure_KPa,1));
 
-//     return (round($Pressure_MB, 2));
 
-
 }
 
 function SI_Distance ($Distance_Miles) {
@@ -120,10 +118,15 @@ function fixBallParkTemps($temperature_p
 
        /* this is where some work on the adjectives would be nice */
        /* this could get ugly! */
-               preg_replace("/(single\ digits)/", round(SI_Temperature("5"), \
                -1)."s", $temperature_phrase[0]);
-               preg_replace("/(teens)/", round(SI_Temperature("15"), -1)."s", \
$temperature_phrase[0]); +               preg_replace("/(single\ digits)/", 
+                            round(SI_Temperature("5"), -1)."s", 
+                            $temperature_phrase[0]);
+               preg_replace("/(teens)/", round(SI_Temperature("15"), -1)."s", 
+                            $temperature_phrase[0]);
                preg_match("/\-*[0-9]+/", $temperature_phrase[0], $value);
-               $temperature_phrase[0] =  preg_replace("/\-*[0-9]+/", \
round(SI_Temperature($value[0]), -1), $temperature_phrase[0]); +               \
$temperature_phrase[0] =  preg_replace("/\-*[0-9]+/",  +                              \
round(SI_Temperature($value[0]),  +                                         -1), \
$temperature_phrase[0]);  
 
        if (preg_match("/(\ \-*0s){1}/", $temperature_phrase[0]))
@@ -159,8 +162,10 @@ function fixWind($wind_speed_phrase)
        return ($wind_speed_phrase[0]);
 }
 
-// The TWC narratives don't include the degree symbol they are just valueF (like \
                45F)
-// Parse and fix up to include the html tag for degrees (&deg;)
+/*
+   The TWC narratives don't include the degree symbol they are just valueF 
+   (like 45F).  Parse and fix up to include the html tag for degrees (&deg;)
+*/
 
 function fixFahrenheit ($temperature_phrase)
 {
@@ -181,18 +186,25 @@ function fixEnglishNarrative ($narrative
 {
         $start_pos = 0;
         $chop_pos = 0;
-        $phrase_num = 0;
         $new_narrative ="";
         while ($chop_pos !== false)
         {
-                $phrase_num = $phrase_num + 1;
+/*
+   This little trick keeps from getting a null phrase after the last valid
+   phrase.
+*/
                 if (!(1 && $chop_pos = strpos($narrative, ".", $start_pos)))
                         {break;}
 
-                $phrase = substr($narrative, $start_pos, $chop_pos + 1 - \
$start_pos); +                $phrase = substr($narrative, $start_pos, 
+                       $chop_pos + 1 - $start_pos);
 
-                /* Find Temperature */
-                $phrase = preg_replace_callback ("/\-?[0-9]+[F]{1}/", fixFahrenheit, \
$phrase); +/* 
+   Annoyingly the fahrenheit temps in the narratives don't have the little 
+   degree symbol.  So trap them here for fixFahrenheit to fix up.
+*/
+                $phrase = preg_replace_callback ("/\-?[0-9]+[F]{1}/", 
+                               fixFahrenheit, $phrase);
 
                 $start_pos = $chop_pos + 1;
                 $new_narrative .= $phrase;
@@ -214,76 +226,25 @@ function fixInches ($inches_phrase)
         $inches_text = explode (" ",$inches_phrase[0]);
        foreach ($inches_text as $key => $value)
         {
-               switch ($value)
-               {
-                       case 'one' :
-                               $value = 1.0;
-                               break;
-                       case 'two' :
-                               $value = 2.0;
-                               break;
-                       case 'three' :
-                               $value = 3.0;
-                               break;
-                       case 'four' :
-                               $value = 4.0;
-                               break;
-                       case 'five' : 
-                               $value = 5.0;
-                               break;
-                       case 'six' :
-                               $value = 6.0;
-                               break;
-                       case 'seven' :
-                               $value = 7.0;
-                               break;
-                       case 'eight' :
-                               $value = 8.0;
-                               break;
-                       case 'nine' :
-                               $value = 9.0;
-                               break;
-                       case 'ten' :
-                               $ten = 10.0;
-                               break;
-                       case 'eigth' :
-                               $value = 0.125;
-                               break;
-                       case 'quarter' :
-                               $value = 0.25;
-                               break;
-                       case 'half' :
-                               $value = 0.50;
-                               break;
-                       case 'three-quarters' :
-                               $value = 0.75;
-                               break;
 
-               } 
-
 /* 
    This gets really ugly because they all use a's, an's, of an's to make the english \
words  read correctly.
 */
-               if (ereg("[0-9]+(\.+[0-9]+)*", $value))
-               {
-                       $inches_text[$key]  = SI_Length($value);
-               }
-                if ( ereg("(inches|inch)+\.*", $value))
-                {
-                        $inches_text[$key] = "cm";
-               /*      if ( ereg("(\.)+", $value))
-                       {
-                               $inches_text[$key] .= ".";
-                       }
-               */
-               }
+
                if ( ereg("(^a|^an|^of)+", $value))
                {
                        $inches_text[$key] ="";
                }
+
+               $inches_text[$key] = preg_replace ( "/[0-9]+(\.+[0-9]+)*/", 
+                                       SI_Length($value), $inches_text[$key]);
+
+               $inches_text[$key] = preg_replace("/(inches|inch)+/", "cm", 
+                                       $inches_text[$key]);
        }
        $inches_phrase[0] = implode (" ", $inches_text);
+
        return ($inches_phrase[0]);
 }
 
@@ -292,53 +253,6 @@ function fixTemperatureRange ($temperatu
         $temperature_text = explode (" ",$temperature_phrase[0]);
         foreach ($temperature_text as $key => $value)
         {
-               switch ($value)
-                {
-                        case 'one' :
-                                $value = 1.0;
-                                break;
-                        case 'two' :
-                                $value = 2.0;
-                                break;
-                        case 'three' :
-                                $value = 3.0;
-                                break;
-                        case 'four' :
-                                $value = 4.0;
-                                break;
-                        case 'five' :
-                                $value = 5.0;
-                                break;
-                        case 'six' :
-                                $value = 6.0;
-                                break;
-                        case 'seven' :
-                                $value = 7.0;
-                                break;
-                        case 'eight' :
-                                $value = 8.0;
-                                break;
-                        case 'nine' :
-                                $value = 9.0;
-                                break;
-                        case 'ten' :
-                                $ten = 10.0;
-                                break;
-                        case 'eigth' :
-                                $value = 0.125;
-                                break;
-                        case 'quarter' :
-                                $value = 0.25;
-                                break;
-                        case 'half' :
-                                $value = 0.50;
-                                break;
-                        case 'three-quarters' :
-                                $value = 0.75;
-                                break;
-
-                }
-
                 if (ereg("[0-9]+F?", $value))
                 {
                         $temperature_text[$key]  = SI_Temperature($value);
@@ -360,7 +275,8 @@ function fixTemperatureRange ($temperatu
 
 function fixWordstoNumbers ($phrase)
 {
-       $phrase[0] = preg_replace ("/(three(\-|\ )+quarters)+(\ of\ an)+/", "0.75", \
$phrase[0]); +       $phrase[0] = preg_replace ("/(three(\-|\ )+quarters)+(\ of\ \
an)+/" +                       , "0.75", $phrase[0]);
        $phrase[0] = preg_replace ("/(one)+/", "1.0", $phrase[0]);
         $phrase[0] = preg_replace ("/(two)+/", "2.0", $phrase[0]);
         $phrase[0] = preg_replace ("/(three)+/", "3.0", $phrase[0]);
@@ -373,7 +289,8 @@ function fixWordstoNumbers ($phrase)
         $phrase[0] = preg_replace ("/(ten)+/", "10.0", $phrase[0]);
         $phrase[0] = preg_replace ("/(a* half)+/", "0.5", $phrase[0]);
        $phrase[0] = preg_replace ("/(an inch)+/", "1.0 inches", $phrase[0]);
-return ($phrase[0]);
+
+       return ($phrase[0]);
 }
 
 
@@ -383,55 +300,10 @@ function fixInchesRange ($inches_phrase)
        $inches_text = explode (" ",$inches_phrase[0]);
         foreach ($inches_text as $key => $value)
         {
-               switch ($value)
-                {
-                        case 'one' :
-                                $value = 1.0;
-                                break;
-                        case 'two' :
-                                $value = 2.0;
-                                break;
-                        case 'three' :
-                                $value = 3.0;
-                                break;
-                        case 'four' :
-                                $value = 4.0;
-                                break;
-                        case 'five' :
-                                $value = 5.0;
-                                break;
-                        case 'six' :
-                                $value = 6.0;
-                                break;
-                        case 'seven' :
-                                $value = 7.0;
-                                break;
-                        case 'eight' :
-                                $value = 8.0;
-                                break;
-                        case 'nine' :
-                                $value = 9.0;
-                                break;
-                        case 'ten' :
-                                $ten = 10.0;
-                                break;
-                        case 'eigth' :
-                                $value = 0.125;
-                                break;
-                        case 'quarter' :
-                                $value = 0.25;
-                                break;
-                        case 'half' :
-                                $value = 0.50;
-                                break;
-                        case 'three-quarters' :
-                                $value = 0.75;
-                                break;
-
-                }
-
-                $inches_text[$key] = preg_replace ( "/[0-9]+(\.+[0-9]+)*/", \
                SI_Length($value), $inches_text[$key]);
-                $inches_text[$key] = preg_replace("/(inches|inch)+/", "cm", \
$inches_text[$key]); +                $inches_text[$key] = preg_replace ( \
"/[0-9]+(\.+[0-9]+)*/",  +                                       SI_Length($value), \
$inches_text[$key]); +                $inches_text[$key] = \
preg_replace("/(inches|inch)+/", "cm",  +                                       \
$inches_text[$key]);  }
         $inches_phrase[0] = implode (" ", $inches_text);
 
@@ -451,33 +323,93 @@ function SI_Narrative($narrative)
 {
        $start_pos = 0;
        $chop_pos = 0;
-       $phrase_num = 0;
        $new_narrative ="";
+
+/* 
+   Chop up the complete narrative into phrases that are delimited with "."s
+   Then iterate over the phrases and convert based on the contextual
+   searches below.
+*/
        while ($chop_pos !== false)
        {
-               $phrase_num = $phrase_num + 1;
+
+/* 
+   This little trick keeps from getting a null phrase after the last valid 
+   phrase.  
+*/
                if (!(1 && $chop_pos = strpos($narrative, ".", $start_pos)))
-                       {break;}
+               {
+                       break;
+               }
 
-               $phrase = substr($narrative, $start_pos, $chop_pos + 1 - $start_pos);
+               $phrase = substr($narrative, $start_pos, 
+                         $chop_pos + 1 - $start_pos);
 
-               // Find wind speed range
-               $search = "/([0-9]+\ to\ {1}[0-9]+\ {1}mph{1}\.*)|(to\ {1}[0-9]+\ \
{1}mph{1}\.*)|([0-9]+\ mph\.*)/"; +
+
+/* First let's do our best to convert words to numbers */
+
+                $search = "/((three(\-|\ )+quarters)(\ of\ an)*".
+                          "|one|two|three|four|five|six|seven|eight|nine|ten".
+                          "|quarter|half|eighth|an\ inch(\.*))/";
+                $phrase = preg_replace_callback ($search, fixWordstoNumbers, 
+                          $phrase);
+
+/* Find wind speed range:  XX to YY mph or just XX mph  */
+
+               $search = "/([0-9]+\ to\ {1}[0-9]+\ {1}mph{1}\.*)".
+                         "|(to\ {1}[0-9]+\ {1}mph{1}\.*)|([0-9]+\ mph\.*)/";
                $phrase = preg_replace_callback ($search, fixWind, $phrase);
+                
+/* Find Temperature (Fahrenheit Variants  */
                 
-               // Find Temperature
+/* Handle a range of temps from XX to YYF */
+
                $search = "/[0-9]+\ to\ {1}\-?[0-9]+F{1}\.*/";
-               $phrase = preg_replace_callback ($search, fixTemperatureRange, \
                $phrase);
-               $phrase = preg_replace_callback ("/\-?[0-9]+[F]{1}/", fixTemps, \
                $phrase);
-$search = "/(in\ the\ )*((High|high|Low|low|Upper|upper|Lower|lower|Mid|mid)\ \
                {1}+(\-*[0-9]+[s]{1}|single\ digits|teens)){1}/";
-               $phrase = preg_replace_callback ($search, fixBallParkTemps, $phrase);
-
-               // Find Inches
-               $search = "/((three(\-|\ )+quarters)(\ of\ \
an)*|one|two|three|four|five|six|seven|eight|nine|ten|quarter|half|eighth|an\ \
                inch)/";
-               $phrase = preg_replace_callback ($search, fixWordstoNumbers, \
                $phrase);
-               $search = "/(to\ {1}[0-9]+\ {1}(inches|inch){1}\.*)|([0-9]+\.+[0-9]+\ \
                to\ {1}[0-9]+\.+[0-9]+\ {1}(inches|inch){1}\.*)/";
-               $phrase = preg_replace_callback ($search, fixInchesRange, $phrase);
-               $phrase = preg_replace_callback ("/(an\ |a\ \
)*([0-9](\.+[0-9]+)|one|two|three|four|five|six|seven|eight|nine|ten|quarter|half|eighth)+\ \
{1}(an\ |of\ an\ |a\ )*(inches|inch){1}\.*/", fixInches, $phrase); +               \
$phrase = preg_replace_callback ($search, fixTemperatureRange,  +                     \
$phrase); +
+/* Handle a single temp:  XXF  */
+
+               $phrase = preg_replace_callback ("/\-?[0-9]+[F]{1}/", fixTemps, 
+                         $phrase);
+
+/* TWC likes to use words for numerical values when expressing temperature 
+   forecasts usually the forecast is: XXs or WORD-VALUEs  */
+
+
+               $search = "/(in\ the\ )*((High|high|Low|low|Upper|upper|Lower". 
+                         "|lower|Mid|mid)\ {1}+(\-*[0-9]+[s]{1}".
+                         "|single\ digits|teens)){1}/";
+               $phrase = preg_replace_callback ($search, fixBallParkTemps, 
+                         $phrase);
+
+/* Convert Precipitaion (Inches variants) */
+
+/* First let's do our best to convert words to numbers 
+
+               $search = "/((three(\-|\ )+quarters)(\ of\ an)*".
+                         "|one|two|three|four|five|six|seven|eight|nine|ten".
+                         "|quarter|half|eighth|an\ inch(\.*))/";
+               $phrase = preg_replace_callback ($search, fixWordstoNumbers, 
+                         $phrase);
+*/
+/* Handle ranges of precipitation: to XX inch(es) or XX to YY inch(es) */
+
+               $search = "/(to\ {1}([0-9](\.[0-9])+)*\ {1}(inches|inch){1}".
+                         "\.*)|([0-9]+(\.[0-9]+)*\ to\ {1}[0-9]+(\.+[0-9]+)*".
+                          "\ {1}(inches|inch){1}\.*)/";
+               $phrase = preg_replace_callback ($search, fixInchesRange, 
+                         $phrase);
+
+/* Handle single instance of precip:  an XX inch(es) */
+
+               $search = "/(!(than)&an\ |a\ )*([0-9]".
+                          "(\.+[0-9]+)|one|two|three|four|five|six|seven".
+                          "|eight|nine|ten|quarter|half|eighth)+\ {1}(an\ ".
+                          "|of\ an\ |a\ )*(inches|inch){1}\.*/";
+
+               $phrase = preg_replace_callback ($search, fixInches, $phrase);
 
                $start_pos = $chop_pos + 1;
                $new_narrative .= $phrase;
Index: version
===================================================================
RCS file: /usr/local/src/CVSROOT/twc_weather/version,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -B -b -p -r1.6 -r1.7
--- version     2003/02/26 07:30:30     1.6
+++ version     2003/02/27 23:30:21     1.7
@@ -1,2 +1,2 @@
 TWC Weather
-1.1 Beta 2b
+1.1 Beta 2c
Index: weather.php
===================================================================
RCS file: /usr/local/src/CVSROOT/twc_weather/weather.php,v
retrieving revision 1.36
retrieving revision 1.38
diff -u -B -b -p -r1.36 -r1.38
--- weather.php 2003/02/26 07:36:04     1.36
+++ weather.php 2003/02/27 23:21:08     1.38
@@ -3,6 +3,26 @@
 /*******************************************************************************
 
 $Log: weather.php,v $
+Revision 1.38  2003/02/27 23:21:08  jamuel
+
+Turn debugging off darn it!
+
+Revision 1.37  2003/02/27 23:17:40  jamuel
+
+Cleaned up twc_support quite a bit.  Added lots of comments and restructured
+some of the lines of code to stay within 80 columns.
+
+Also fixed the output of the weather box to so that the column position
+of the weather values doesn't fluctuate.  They sort of floated ever since
+the option to display a wide (vs narrow) forecast/narrative text.
+(Thanks to Stephen Brown for coming up with the patch for that.)
+
+Made a couple of random fixes to the support code to help handle random
+preg_replace problems/bugs in my search-patterns.  What comes to mind
+are a fix for trapping "than" vs "an" (was getting a hit on a phrase
+that had "than") and was dropping a period on an end of a sentence that
+contained an inches conversion.  Both are fixed.
+
 Revision 1.36  2003/02/26 07:36:04  jamuel
 
 Forgot to turn off debugging again!
@@ -805,7 +825,7 @@ function weather_display ($location, $th
        print "<table style=\"margin-left: " . $table_margin_left . "px; \
margin-right: " . $table_margin_right . "px; margin-top: " . $table_margin_top . "px; \
margin-bottom: " . $table_margin_bottom . "px;\" cellpadding=1 cellspacing=0 border=0 \
                bgcolor=" . $table_color_background . " width=" . $table_width . ">";
        print "<tr><td><table cellpadding=0 cellspacing=0 border=0  width=" . \
$table_width2 . " bgcolor=" . $table_color_foreground . ">";  
-        print "<tr><td align=left style=\"padding-left: 6px\">";
+         print "<tr><td align=left width=20% style=\"padding-left: 6px\">";
        if ($location['view-icon'])
        {
                print $icon;
@@ -815,7 +835,7 @@ function weather_display ($location, $th
                print "</td>";
        }
        if ($location['view-place'])
-               print "<td align=left><b><font face=\"helvetica\" style=\"font-size: \
10pt;\">" . $citytitle . "</font></b></td></tr>"; +                print "<td \
align=left width=80%><b><font face=\"helvetica\" style=\"font-size:10pt;\">" . \
$citytitle . "</font></b></td></tr>";  
         if ($location['view-alias'])
                 print "<td align=left><b><font face=\"helvetica\" style=\"font-size: \
10pt;\">" . $location['alias'] . "</font></b></td></tr>";


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
--
squirrelmail-plugins mailing list
List Address: squirrelmail-plugins@lists.sourceforge.net
List Info: https://lists.sourceforge.net/lists/listinfo/squirrelmail-plugins
http://squirrelmail.org/cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic