def test_readSC():
    """Test the readSC function."""
    df, plot_names = readSC()
    assert isinstance(df, pd.DataFrame)
    assert isinstance(plot_names, list)
    for name in plot_names:
        assert isinstance(name, str)
Beispiel #2
0
def inventory_plot_filter():
    field = request.args.get('field')
    value = request.args.get('value')
    # print(", ".join((field, value)))
    df, columns = readSC()
    filterdf = df[df[str(field)] == value]
    # filterdfs = filterdf.sort_values('impound_no', ascending=False)  # [:50]  # TODO: Remove the slicing!
    return plot_page_inventory(filterdf, columns, request, field=field, value=value)
Beispiel #3
0
def los_plot():
    """Plot inventory over time"""
    df, columns = readSC()
    dfs = df.sort_values('animal_id', ascending=False)
    # cols = ['animal_id','animal_type','impound_no','intake_type','intake_subtype','intake_cond','outcome_type','outcome_subtype','outcome_cond','weight','intake_date','outcome_date','dob','primary_bree','secondary_','kennel_no','s_n_date','weight_1_week','due_out_date','location_1','location_1_date','location_2','location_2_date','los','days_old','los_1','los_2','age_s_n_date','weight_difference','in_to_due_out_date_diff','due_out_to_outcome_date_diff']
    decimals = dict.fromkeys(columns, 2)
    dfs = dfs.round(decimals=decimals)
    dfs = dfs.to_dict('records')
    return plot_page_los(df, columns, request, rows=dfs)
def test_readSC_with_nrows():
    """Test shortened readSC function."""
    for nrows in [2, 5]:
        df, plot_names = readSC(nrows=nrows)
        assert isinstance(df, pd.DataFrame)
        assert isinstance(plot_names, list)
        for name in plot_names:
            assert isinstance(name, str)
        assert len(df) == nrows
Beispiel #5
0
def counts_plot_filter():
    field = request.args.get('field')
    value = request.args.get('value')
    df, columns = readSC()
    filterdf = df[df[str(field)] == value]
    dfs = filterdf.sort_values('animal_id', ascending=False)
    decimals = dict.fromkeys(columns, 2)
    dfs = dfs.round(decimals=decimals)
    dfs = dfs.to_dict('records')
    return plot_page_counts(filterdf, columns, request, field=field, value=value, rows=dfs)
Beispiel #6
0
def los_plot_filter():
    field = request.args.get('field')
    value = request.args.get('value')
    df, columns = readSC()
    filterdf = df[df[str(field)] == value]
    dfs = filterdf.sort_values('animal_id', ascending=False)
    # columns = ['animal_id','animal_type','impound_no','intake_type','intake_subtype','intake_cond','outcome_type','outcome_subtype','outcome_cond','weight','intake_date','outcome_date','dob','primary_bree','secondary_','kennel_no','s_n_date','weight_1_week','due_out_date','location_1','location_1_date','location_2','location_2_date','los','days_old','los_1','los_2','age_s_n_date','weight_difference','in_to_due_out_date_diff','due_out_to_outcome_date_diff']
    decimals = dict.fromkeys(columns, 2)
    dfs = dfs.round(decimals=decimals)
    dfs = dfs.to_dict('records')
    return plot_page_los(filterdf, columns, request, field=field, value=value, rows=dfs)
Beispiel #7
0
def filter():
    field = request.args.get('field')
    value = request.args.get('value')
    df, cols = readSC()
    filterdf = df[df[str(field)] == value]
    filterdfs = filterdf.sort_values('animal_id', ascending=False)  # [:50]  # TODO: Remove the slicing!
    # cols = ['animal_id','animal_type','impound_no','intake_type','intake_subtype','intake_cond','outcome_type','outcome_subtype','outcome_cond','weight','intake_date','outcome_date','dob','primary_bree','secondary_','kennel_no','s_n_date','weight_1_week','due_out_date','location_1','location_1_date','location_2','location_2_date']
    decimals = dict.fromkeys(cols, 2)
    filterdfs = filterdfs.round(decimals=decimals)
    # df = df[(df['intake_type']!="DEAD")&(df['intake_subtype']!="DEAD")&(df['intake_cond']!="DEAD")&(df['intake_type']!="DISPOSAL")&(df['intake_subtype']!="DISPOSAL")&(df['intake_cond']!="DISPOSAL")&(df['intake_type']!="DECEASED")&(df['intake_subtype']!="DECEASED")&(df['intake_cond']!="DECEASED")]
    filterdfs = filterdfs.to_dict('records')
    return render_template('main.html', rows=filterdfs)
Beispiel #8
0
def homepage():
    """Home page for SWEETer-Cat with updated table"""
    df, _ = readSC()
    df['alink'] = list(map(author_html, df['Author'], df['link']))
    dfs = df.sort_values('updated', ascending=False)  # [:50]  # TODO: Remove the slicing!
    dfs.drop(['Author', 'link'], axis=1, inplace=True)
    cols = ['par', 'parerr', 'logg', 'loggerr', 'logglc', 'logglcerr', 'vterr',
            'mass', 'masserr', 'Vmag', 'Vmagerr', 'feh', 'feherr']
    decimals = dict.fromkeys(cols, 2)
    dfs = dfs.round(decimals=decimals)
    dfs['HD'].fillna('...', inplace=True)
    dfs['Comment'].fillna('...', inplace=True)
    dfs['source'].fillna('...', inplace=True)
    dfs = dfs.to_dict('records')
    return render_template('main.html', rows=dfs)
def test_hz():
    """Test the hz function."""
    df, _ = readSC()
    for (teff, logg, mass) in df.loc[:, ['teff', 'logg', 'mass']].values:
        lum = (teff / 5777)**4 * (mass / ((10**logg) / (10**4.44)))**2
        assert isinstance(hz(teff, lum, model=2), float)
        assert isinstance(hz(teff, lum, model=4), float)

    teff = 5777
    lum = 1
    invalids = [{teff: lum}, [teff, lum], (teff, lum), "..."]
    for model in range(1, 6):
        assert isinstance(hz(teff, lum, model), float)
    results = [0.75, 0.98, 0.99, 1.71, 1.77]
    for model, result in enumerate(results, start=1):
        assert round(hz(teff, lum, model), 2) == result
        for invalid in invalids:
            assert np.isnan(hz(invalid, lum, model))
            assert np.isnan(hz(teff, invalid, model))
    assert hz(teff, lum, 2) < hz(teff, lum, 4)  # hz1 < hz2
Beispiel #10
0
def animal_iddetail(animal_id=None):
    """Page with details on the individual animal"""
    if animal_id:
        df, cols = readSC()
        # t1, t2 = min(df['intake_date']), max(df['outcome_date'])
        t1, t2 = min(df['los']), max(df['los'])
        index = df['animal_id'] == animal_id
        d = df.loc[index, :].copy()
        if len(d):
            show_intake = bool(~d['los'].isnull().values[0])
            if len(d) == sum(d['datetime'].isnull()):
                plot = None
            else:
                plot = detail_plot(d, t1, t2)
            d.fillna('...', inplace=True)
            info = d.to_dict('records')

            dfs = d.sort_values('animal_id', ascending=False)
            # cols = ['animal_id','animal_type','impound_no','intake_type','intake_subtype','intake_cond','outcome_type','outcome_subtype','outcome_cond','weight','intake_date','outcome_date','dob','primary_bree','secondary_','kennel_no','s_n_date','weight_1_week','due_out_date','location_1','location_1_date','location_2','location_2_date','los','days_old','los_1','los_2','age_s_n_date','weight_difference','in_to_due_out_date_diff','due_out_to_outcome_date_diff']
            decimals = dict.fromkeys(cols, 2)
            dfs = dfs.round(decimals=decimals)
            dfs = dfs.to_dict('records')
            return render_template('detail.html', info=info, show_intake=show_intake, plot=plot, rows=dfs)
    return redirect(url_for('homepage'))
Beispiel #11
0
def SCdata():
    """SWEET-Cat database fixture."""
    return readSC()
Beispiel #12
0
def inventory_plot():
    """Plot inventory over time"""
    df, columns = readSC()
    return plot_page_inventory(df, columns, request)
Beispiel #13
0
def linked_plot_filter():
    field = request.args.get('field')
    value = request.args.get('value')
    df, columns = readSC()
    filterdf = df[df[str(field)] == value]
    return plot_page_mpld3(filterdf, columns, request, field=field, value=value)
Beispiel #14
0
def linked_plot():
    """Plot inventory over time"""
    df, columns = readSC()
    # print(", ".join(((df, columns))))
    return plot_page_mpld3(df, columns, request)
Beispiel #15
0
def plot():
    """Plot stellar parameters"""
    df, columns = readSC()
    return plot_page(df, columns, request, page="plot")