Ejemplo n.º 1
0
def main():
    ''' Example code for inserting data into PostgresQL database '''
    # Feedback time; dtype = Timestamp w/o timezone
    ins_time = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Current model recommendation; dtype = Boolean
    ins_rec = 'false'

    # User accuracy selection; dtype = Text
    ins_user_rec = 'TEST'

    # User feedback; dtype = Text
    ins_feedback = '''May 4 CHAR TEST2 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ CHAR TEST'''

    ins_newcol = 'ajksdh'

    insert_user_feedback(table='feedback_test',
                         columns=('rec_time', 'rec', 'user_rec', 'feedback'),
                         values=(ins_time, ins_rec, ins_user_rec,
                                 ins_feedback),
                         ini_section='non-social-parks-db')

    print(
        db_to_df(sql='SELECT * FROM feedback;',
                 ini_section='non-social-parks-db'))
Ejemplo n.º 2
0
def pop_time():
    ''' Saves the popular times data to the db
    '''
    tz_offset = -14400

    cols = ['local_time', 'place_name', 'current_pop', 'data_json']

    data = populartimes.get_id(google_api, 'ChIJQwRohxBbwokRmHrfAMb3ixc')
    t = time.time() + tz_offset
    data_json = json.dumps(data)

    vals = [
        int(t),
        data['name'],
        data['current_popularity'],
        data_json
    ]

    insert_user_feedback(
        table='popular_times',
        columns=cols,
        values=vals,
        ini_section='non-social-parks-db'
    )
Ejemplo n.º 3
0
    # User accuracy selection; dtype = Text
    ins_user_rec = correct

    # User feedback; dtype = Text
    ins_feedback = re.sub('\'', '', user_input)

    # Send feedback to back end model
    src_dir = os.path.join(os.getcwd(), '..')
    root_dir = os.path.join(os.getcwd(), '..', '..')
    sys.path.append(root_dir)
    sys.path.append(src_dir)

    from d00_utils.db_funcs import insert_user_feedback

    insert_user_feedback(table='feedback',
                         values=(ins_time, ins_rec, ins_user_rec,
                                 ins_feedback),
                         ini_section='non-social-parks-db')

    st.markdown(
        "*Thank you for submitting your response! We will incorporate your feedback.*"
    )

## SURVEY
#st.header("Survey")
#st.markdown('[_Click Here_](https://docs.google.com/forms/d/e/1FAIpQLSdlczlOJ0s5eM01-HqQhekwlQlbihiW8yqPtsVQbQqNsyB-JQ/viewform) _to help us collect more data!_')

## SIMPLE SUMMARY GRAPHS

# Load our data
st.header("Past 24 Hours & Average Risk Levels")
df = pd.read_pickle("../d01_data/03_SQL_data_for_frontend_ee.pkl")
Ejemplo n.º 4
0
def weather_current():
    ''' Gets current weather data and commits to postgres db
    '''

    weather_columns = [
        'park_name', 'reception_time', 'reference_time', 'sunrise_time',
        'sunset_time', 'clouds', 'rain_1h', 'snow_1h', 'wind_speed',
        'humidity', 'press', 'temp', 'temp_feels', 'temp_max', 'temp_min',
        'status', 'detailed_status', 'wind_deg'
    ]

    owm = pyowm.OWM(OWM_api_key)

    park_name = 'Prospect Park'
    park_lat = 40.662551
    park_long = -73.969256
    tz_offset = -14400

    w_m = owm.weather_manager()
    # obs = w_m.weather_at_place('London,GB')
    obs = w_m.weather_at_coords(lat=park_lat, lon=park_long)
    # owm.weather_around_coords(,)

    w = obs.weather

    w_rain = 0
    if w.rain:
        w_rain = w.rain['1h']

    w_snow = 0
    if w.snow:
        w_snow = w.snow['1h']

    wind_deg = 0
    null_wind_deg = True
    if 'deg' in w.wind():
        null_wind_deg = False
        w.wind()['deg']

    weather_values = [
        park_name,
        obs.reception_time() + tz_offset,
        w.reference_time() + tz_offset,
        w.sunrise_time() + tz_offset,
        w.sunset_time() + tz_offset, w.clouds, w_rain, w_snow,
        w.wind()['speed'], w.humidity, w.pressure['press'],
        w.temperature(unit='fahrenheit')['temp'],
        w.temperature(unit='fahrenheit')['feels_like'],
        w.temperature(unit='fahrenheit')['temp_max'],
        w.temperature(unit='fahrenheit')['temp_min'], w.status,
        w.detailed_status, wind_deg
    ]

    if null_wind_deg:
        commit_cols = weather_columns[:-1]
        commit_vals = weather_values[:-1]
    else:
        commit_cols = weather_columns
        commit_vals = weather_values

    insert_user_feedback(table='weather',
                         columns=commit_cols,
                         values=commit_vals,
                         ini_section='non-social-parks-db')