<commit_before>from flask import Flask, render_template, request, url_for, redirect, session
import numpy as np
import pandas as pd
from PyAstronomy import pyasl
from bokeh.embed import components
from bokeh.resources import INLINE
from bokeh.palettes import Viridis11
from bokeh.util.string import encode_utf8
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool, ColorBar, LinearColorMapper, LabelSet

COLORS = Viridis11

colors = {
    'Blue': '#1f77b4',
    'Orange': '#ff7f0e',
    'Green': '#2ca02c',
    'Red': '#d62728',
    'Purple': '#9467bd',
}


def absolute_magnitude(parallax, m):
    d = 1 / parallax
    mu = 5 * np.log10(d) - 5
    M = m - mu
    return M


def readSC():
    names = ['Star', 'HD', 'RA', 'dec', 'Vmag', 'Vmagerr', 'par', 'parerr', 'source',
             'teff', 'tefferr', 'logg', 'loggerr', 'logglc', 'logglcerr',
             'vt', 'vterr', 'feh', 'feherr', 'mass', 'masserr', 'Author', 'flag', 'updated', 'Comment']
    df = pd.read_table('sc.txt', names=names, na_values=['~'])
    df['flag'] = df['flag'] == 1
    df['Vabs'] = [absolute_magnitude(p, m) for p, m in df[['par', 'Vmag']].values]

    plots = ['Vmag', 'Vmagerr', 'Vabs', 'par', 'parerr', 'teff', 'tefferr',
             'logg', 'loggerr', 'logglc', 'logglcerr', 'vt', 'vterr',
             'feh', 'feherr', 'mass', 'masserr']
    return df, plots


def planetAndStar():
    deu = pd.DataFrame(pyasl.ExoplanetEU().data)
    cols = ['stName', 'plMass', 'plRadius', 'period', 'sma', 'eccentricity',
            'inclination', 'discovered', 'dist',
            'mag_v', 'mag_i', 'mag_j', 'mag_h', 'mag_k']
    deu = deu[cols]
    df, columns = readSC()
    d = pd.merge(df, deu, left_on='Star', right_on='stName')

    return d, columns+cols


# Setup Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = '<KEY>'
df, columns = readSC()


@app.route('/')
def homepage():
    dfs = df.sort_values('updated', ascending=False)[:50]  # TODO: Remove the slicing!
    for col in ('teff', 'tefferr'):  # These should be integers
        idx = dfs[col].isnull()
        dfs[col] = dfs[col].astype(str)
        dfs.loc[~idx, col] = list(map(lambda s: s[:-2], dfs.loc[~idx, col]))
    dfs.fillna('...', inplace=True)
    columns = dfs.columns
    dfs = dfs.loc[:, columns]
    dfs = dfs.to_dict('records')
    return render_template('main.html', rows=dfs, columns=columns[1:])

<commit_msg>Convert bytes to str for python3 compatible. Issue #10<commit_after>from flask import Flask, render_template, request, url_for, redirect, session
import numpy as np
import pandas as pd
from PyAstronomy import pyasl
from bokeh.embed import components
from bokeh.resources import INLINE
from bokeh.palettes import Viridis11
from bokeh.util.string import encode_utf8
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool, ColorBar, LinearColorMapper, LabelSet

COLORS = Viridis11

colors = {
    'Blue': '#1f77b4',
    'Orange': '#ff7f0e',
    'Green': '#2ca02c',
    'Red': '#d62728',
    'Purple': '#9467bd',
}


def absolute_magnitude(parallax, m):
    d = 1 / parallax
    mu = 5 * np.log10(d) - 5
    M = m - mu
    return M


def readSC():
    names = ['Star', 'HD', 'RA', 'dec', 'Vmag', 'Vmagerr', 'par', 'parerr', 'source',
             'teff', 'tefferr', 'logg', 'loggerr', 'logglc', 'logglcerr',
             'vt', 'vterr', 'feh', 'feherr', 'mass', 'masserr', 'Author', 'flag', 'updated', 'Comment']
    df = pd.read_table('sc.txt', names=names, na_values=['~'])
    df['flag'] = df['flag'] == 1
    df['Vabs'] = [absolute_magnitude(p, m) for p, m in df[['par', 'Vmag']].values]

    plots = ['Vmag', 'Vmagerr', 'Vabs', 'par', 'parerr', 'teff', 'tefferr',
             'logg', 'loggerr', 'logglc', 'logglcerr', 'vt', 'vterr',
             'feh', 'feherr', 'mass', 'masserr']
    return df, plots


def planetAndStar():
    deu = pd.DataFrame(pyasl.ExoplanetEU().data)
    cols = ['stName', 'plMass', 'plRadius', 'period', 'sma', 'eccentricity',
            'inclination', 'discovered', 'dist',
            'mag_v', 'mag_i', 'mag_j', 'mag_h', 'mag_k']
    deu = deu[cols]
    deu['stName'] = [s.decode() for s in deu['stName']]
    df, columns = readSC()
    d = pd.merge(df, deu, left_on='Star', right_on='stName')

    return d, columns+cols


# Setup Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = '<KEY>'
df, columns = readSC()


@app.route('/')
def homepage():
    dfs = df.sort_values('updated', ascending=False)[:50]  # TODO: Remove the slicing!
    for col in ('teff', 'tefferr'):  # These should be integers
        idx = dfs[col].isnull()
        dfs[col] = dfs[col].astype(str)
        dfs.loc[~idx, col] = list(map(lambda s: s[:-2], dfs.loc[~idx, col]))
    dfs.fillna('...', inplace=True)
    columns = dfs.columns
    dfs = dfs.loc[:, columns]
    dfs = dfs.to_dict('records')
    return render_template('main.html', rows=dfs, columns=columns[1:])


{'fraction_non_alphanumeric': 0.18728417631525493, 'fraction_numerical': 0.014015843997562462, 'mean_word_length': 3.593283582089552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '304160', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1848, 'n_words': 466}