Skip to content

Instantly share code, notes, and snippets.

@KitWallace
Created August 31, 2012 13:08
Show Gist options
  • Save KitWallace/3552467 to your computer and use it in GitHub Desktop.
Save KitWallace/3552467 to your computer and use it in GitHub Desktop.
Creating a simple forecast
"""
This forecast method comes from
http://www.sciencecompany.com/-W135.aspx
input is the current baro (in hPa) and the trend over 3 hours
"""
forecast1_table = \
(
(1022, ( (-0.1 , "Continued fair"),
(-1.55 , "Fair") ,
(-99 , "Cloudy, Warmer")
)
),
(1009, ( (-0.1 , "Same as present"),
(-1.55 , "Little change"),
(-99 , "Precipitation likely")
)
),
(0 , ( (-0.1 , "Clearing, cooler"),
(-1.55 , "Precipitation"),
(-99 , "Storm")
)
)
)
def find(table,myval) :
""" lookup up myval in the ordered values in the table.
Entries in the table are tuples:
the first value is a float
the second an obj
return the first obj whose value is >= myval
"""
for threshold,value in table :
if myval >= threshold :
return value
def forecast1 (baro, trend) :
return find(find(forecast1_table,baro),trend)
"""
e.g. print forecast1(1012,2.3)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment