Coverage for src/frontend/main_frontend.py: 93%

29 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-05 14:25 +0000

1import numpy as np 

2import pandas as pd 

3import streamlit as st 

4 

5 

6def dummy_function_front_end(x: str) -> str: 

7 """A sample docstring using pep-0257 (https://peps.python.org/pep-0257/) formatting 

8 

9 :param x: a dummy string 

10 :type x: str 

11 

12 :return: a dummy string 

13 :rtype: str 

14 """ 

15 return x 

16 

17st.title('Uber pickups in NYC') 

18 

19DATE_COLUMN = 'date/time' 

20DATA_URL = ('https://s3-us-west-2.amazonaws.com/' 

21 'streamlit-demo-data/uber-raw-data-sep14.csv.gz') 

22 

23def to_lower(x: str) -> str: 

24 return str(x).lower() 

25 

26@st.cache_data 

27def load_data(nrows): 

28 data = pd.read_csv(DATA_URL, nrows=nrows) 

29 data.rename(to_lower, axis='columns', inplace=True) 

30 data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN]) 

31 return data 

32 

33data_load_state = st.text('Loading data...') 

34data = load_data(10000) 

35data_load_state.text("Done! (using st.cache_data)") 

36 

37if st.checkbox('Show raw data'): 

38 st.subheader('Raw data') 

39 st.write(data) 

40 

41st.subheader('Number of pickups by hour') 

42hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0] 

43st.bar_chart(hist_values) 

44 

45# Some number in the range 0-23 

46hour_to_filter = st.slider('hour', 0, 23, 17) 

47filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter] 

48 

49st.subheader('Map of all pickups at %s:00' % hour_to_filter) 

50st.map(filtered_data)