def __init__(self): self.cmds = commands.Commands() self.fc = forecast.Forecast() self.timestamps = { '**:00:00': 'full_hour', '**:30:00': 'forecast', '09:30:00': 'standup', '10:00:00': 'standup' }
def __init__(self, applet): self.applet = applet self.weather_fail = [False, False, False] self.reset_weather_data() self.network_handler = self.NetworkHandler() self.notification = applet.notification.create( _("Network error in Weather"), network_error_message, "dialog-warning", 20) self.setup_context_menu() self.forecaster = forecast.Forecast(self) # Set default icons/titles/dialogs so the applet is informative without data self.set_icon() self.applet.tooltip.set( "%s %s..." % (_("Fetching conditions for"), self.applet.settings['location'])) # Overlays self.__temp_overlay = OverlayText() self.__temp_overlay.props.gravity = gtk.gdk.GRAVITY_SOUTH applet.add_overlay(self.__temp_overlay) disconnect_overlay = OverlayThemedIcon("gtk-disconnect") disconnect_overlay.props.alpha = 1.0 throbber_overlay = OverlayThrobber() for i in (disconnect_overlay, throbber_overlay): i.props.scale = 0.5 i.props.gravity = gtk.gdk.GRAVITY_SOUTH_EAST i.props.apply_effects = False applet.add_overlay(i) global overlay_fsm overlay_fsm = OverlayStateMachine(disconnect_overlay, throbber_overlay) def show_map(widget): if self.map_dialog is None: self.fetch_weather_map(show=True) applet.connect("middle-clicked", show_map) # Set up the timer which will refresh the conditions, forecast, and weather map applet.timing.register(self.activate_refresh_cb, update_interval * 60) applet.timing.delay(self.activate_refresh_cb, 1.0)
def __init__(self, station, run, model, startDate, nDays): self.startDate = startDate self.run = run self.model = model self.periods = [] self.checkRep() baseURL = 'https://mesonet.agron.iastate.edu/mos/csv.php' for i in range(nDays): forecastDate = startDate + datetime.timedelta(days=i) modelRun = datetime.datetime.combine( forecastDate - datetime.timedelta(days=1), self.run) runText = modelRun.strftime('%Y-%m-%d %H:%M') url = baseURL + '?station=' + station + '&runtime=' + runText + '&model=' + model f = util.getData(url) f.readline() y = 0 if self.run.hour == 0: offset = 8 if self.run.hour == 6: offset = 6 if self.run.hour == 12: offset = 4 if self.run.hour == 18: offset = 2 maxTemp = -200 minTemp = 200 maxWind = 0 precip = 0 for line in f: fields = line.split(',') fcDate = datetime.datetime.strptime(fields[3].split('+')[0], '%Y-%m-%d %H:%M:%S') fcTemp = None if fields[5] != '': fcTemp = int(fields[5]) fcWind = 0 if fields[9] != '': fcWind = float(fields[9]) fcPrecip = 0 if fields[12] != '': if fields[12] == '1': fcPrecip = 0.05 elif fields[12] == '2': fcPrecip = 0.17 elif fields[12] == '3': fcPrecip = 0.37 elif fields[12] == '4': fcPrecip = 0.75 elif fields[12] == '5': fcPrecip = 1 y += 1 if y > offset + 8: self.periods.append( forecast.Forecast(maxTemp, minTemp, float(maxWind), float(precip))) break if y > offset: if fcDate.hour % 6 == 0: precip += fcPrecip if fcTemp != None: if fcTemp > maxTemp: maxTemp = fcTemp if fcTemp < minTemp: minTemp = fcTemp if fcWind > maxWind: maxWind = fcWind f.close() return
PREDICTION_QUARTER = pd.date_range(start=datetime.now().date(), end=datetime(2060, 1, 1), freq='3MS', closed='right').date[:4] PREDICTION_QUARTER_BOUNDARIES = [(PREDICTION_QUARTER[i], PREDICTION_QUARTER[i + 1]) for i in range(len(PREDICTION_QUARTER) - 1)] df = prep.read_permits('currentPermits.csv') writer = pd.ExcelWriter(datetime.now().strftime('%d %m %y') + '_forecast.xls', datetime_format='mmm d yyyy') for occupancy in OCCUPANCY_GROUPS: predictor = forecast.Forecast(df, occupancy_group=occupancy[0], lower_value_limit=occupancy[1], regression_algorithm=RandomForestRegressor) current_data = pd.DataFrame( data={ 'numberPending': predictor.get_quarterly_pending(quarters=QUARTERS), 'valuePending': predictor.get_quarterly_pending_value(quarters=QUARTERS), 'waitTime': predictor.get_wait_time(), 'quarter': QUARTER_BEGINNINGS[:-1] }) current_data.to_excel(writer, sheet_name=occupancy[0][:2] + ' timeseries at ' + datetime.now().strftime('%d %m %y'))
# (c) 2017 kj/P1X # # external libs import os, slackclient, time, re, random # internal libs import filesystem, config, logger, display_fast, commands import whiteboard, forecast, psas fs = filesystem.Filesystem() cfg = config.Config() log = logger.Logger() cmds = commands.Commands() wb = whiteboard.Whiteboard() fc = forecast.Forecast() sc = slackclient.SlackClient(cfg.get_api_key('slack')) psa = psas.PublicServiceAnnaucments() disp = display_fast.Display() def get_mention(user): return '<@{user}>'.format(user=user) bot_slack_mention = get_mention(cfg.get_api_key('bot')) # The BRAIN def decode_message(message, user): if message: tokens = [re.sub('[^A-Za-z0-9]+', '', word.lower()) for word in message.strip().split()] # real commands
import os import argparse import forecast as fc # Parse arguments parser = argparse.ArgumentParser(description='Forecast command line') parser.add_argument('years', help='Number of years to project', type=int) parser.add_argument('--auto-open', help='Whether to open the HTML', action='store_true') parser.add_argument('--include-net', help='Whether to include net worth', action='store_true') args = parser.parse_args() # Build forecasts directory = os.path.join('.', 'configs') for filename in os.listdir(directory): extension = os.path.splitext(filename)[1][1:] if extension not in ['yml', 'yaml'] or filename == 'sample.yaml': continue filepath = os.path.join(directory, filename) forecast = fc.Forecast(filepath, args.years, args.include_net).project() fc.PlotBuilder(forecast).build(args.auto_open) fc.CsvBuilder(forecast).build()
def __init__(self, station, startDate, nDays): self.startDate = startDate self.periods = [] self.checkRep() baseURL = 'https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?data=tmpf&data=sknt&data=p01i&tz=Etc%2FUTC&format=onlycomma&latlon=no&missing=M&trace=T&direct=no&report_type=1&report_type=2' for i in range(nDays): forecastDate = startDate + datetime.timedelta(days=i) nextForecastDate = forecastDate + datetime.timedelta(days=2) url = baseURL + '&station=' + station + '&year1=' + str( forecastDate.year) + '&month1=' + str( forecastDate.month) + '&day1=' + str( forecastDate.day) + '&year2=' + str( nextForecastDate.year) + '&month2=' + str( nextForecastDate.month) + '&day2=' + str( nextForecastDate.day) f = util.getData(url) f.readline() y = 0 maxTemp = -200 minTemp = 200 maxWind = 0 precip = 0 offset = 81 for line in f: line = line.strip('\n') fields = line.split(',') fcDate = datetime.datetime.strptime(fields[1].split('+')[0], '%Y-%m-%d %H:%M') fcTemp = None if fields[2] != '' and fields[2] != 'M' and fields[2] != 'T': fcTemp = int(round(float(fields[2]))) fcWind = None if fields[3] != '' and fields[3] != 'M' and fields[3] != 'T': fcWind = float(fields[3]) fcPrecip = None if fields[4] != '' and fields[4] != 'M' and fields[4] != 'T': fcPrecip = float(fields[4]) y += 1 if y > offset + 314: self.periods.append( forecast.Forecast(maxTemp, minTemp, float(maxWind), float(precip))) break if y > offset: if fcDate.minute % 53 == 0: if fcPrecip != None: precip += fcPrecip if fcTemp != None: if fcTemp > maxTemp: maxTemp = fcTemp if fcTemp < minTemp: minTemp = fcTemp if fcWind != None: if fcWind > maxWind: maxWind = fcWind f.close() return