codeforboston / flagging

Flagging website for CRWA
MIT License
4 stars 12 forks source link

Overhauls! #154

Closed dwreeves closed 3 years ago

dwreeves commented 3 years ago

Model outputs page overhaul

Preview:

image

Preview of tooltip makeover + its responsiveness. When I hover over it, it doesn't trail off the screen.

image

Jinja2 updates

Data stuff

I'm honestly still a bit torn on the whole ORM thing for our purposes. In a professional large enterprise setting it's 100% the right thing to do. And it makes the code a lot prettier when you write it properly. For us, the case is less convincing notwithstanding the huge upside of Flask-Admin. I still think for frontend stuff we should totally use it though for general purpose things.

The way I think of it is like this as a TLDR:

More detailed thoughts:

The one issue I am struggling with is figuring out how to connect the Boathouse class and the predictive model outputs in a sane way, since the latter doesn't have a model for it. Still working on making it sane, but this is what I have so far:

def get_flags(df: pd.DataFrame) -> Dict[str, bool]:
    """
    Get a dict of boolean values indicating whether each boathouse is considered
    safe. True means it is considered safe-- otherwise it is false.
    Args:
        df: (pd.DataFrame) Pandas Dataframe containing predictive model outputs.
    Returns:
        Dict of booleans.
    """
    # sql equivalent: SELECT * FROM boathouses ORDER BY boathouse
    all_boathouses = (
        Boathouse.query
        .order_by(Boathouse.boathouse)
        .all()
    )

    def _reach_is_safe(r: int) -> bool:
        return df.loc[df['reach'] == r, 'safe'].iloc[0]

    flag_statuses = {}

    for row in all_boathouses:
        # Check to see if the reach is safe AND the row has not been overridden.
        # If both are true, then the boathouse gets a blue flag.
        # Otherwise, give it a red flag.
        flag_statuses[row.boathouse] = \
             _reach_is_safe(row.reach) and (not row.overridden)

    return flag_statuses

Other stuff