Example #1
0
def compute_predictions(session):
    """compute and cache predictions for all runs

    Args:
        session: (Session) database connection

    Returns:
        True: if observations were successfully retrieved and inserted
        False: otherwise
    """
    try:
        arima = Arima(session)
        repo = Repository(session)

        runs = repo.get_all_runs_as_list()
        for run in runs:
            try:
                predictions = arima.arima_model(run.run_id)

                to_add = [
                    Prediction(run_id=run.run_id,
                               timestamp=pd.to_datetime(d),
                               fr_lb=round(float(p), 1),
                               fr=round(float(p), 1),
                               fr_ub=round(float(p), 1)) for p, d in
                    zip(predictions.values, predictions.index.values)
                ]

                repo.clear_predictions(run.run_id)
                repo.put_predictions(to_add)
                log(f'predictions for {run.run_id}-{run.run_name} added to db')

            except SQLAlchemyError as e:
                log(f'{run.run_id}-{run.run_name} failed - {[str(a) for a in e.args]}'
                    )
                session.rollback()

            except Exception as e:
                log(f'predictions for {run.run_id}-{run.run_name} failed - {[str(a) for a in e.args]}'
                    )

        return True

    except Exception as e:
        log(f'failed to compute daily predictions - {str(e.args)}')
        return False
Example #2
0
from riverrunner import settings

# IP address for running application
HOST_IP = '192.168.80.13'

# enable for application debugging features
DEBUG = False

# mapping from river's predicted status to a color code
COLOR_MAP = dict(unknown='#41434C',
                 optimal='#4254CC',
                 fair='#8F8A18',
                 not_recommended='#A63617')

repo = Repository()
runs = repo.get_all_runs_as_list()
runs = [run for run in runs if run.todays_runability != -2]
options = [r.select_option for r in runs]
options.sort(key=lambda r: r['label'])

# create a new Dash app adding custom fonts and CSS
app = dash.Dash()
font_url = 'https://fonts.googleapis.com/css?family=Montserrat|Permanent+Marker'
app.css.append_css({'external_url': font_url})


def color_scale(x):
    """prediction binning

    method bins river predictions into discrete categories for color coding