Spaces:
Runtime error
Runtime error
Commit
·
2c4b129
1
Parent(s):
b7ae033
Update Homepage.py
Browse files- Homepage.py +11 -11
Homepage.py
CHANGED
@@ -76,7 +76,7 @@ if authentication_status:
|
|
76 |
ketoan_end_time = col2.date_input(
|
77 |
"Select end date", value=DEFAULT_END_DATE)
|
78 |
submit_button = st.form_submit_button(
|
79 |
-
label='Filter'
|
80 |
|
81 |
# the duration between 2 dates exclude Sunday
|
82 |
duration = sum(1 for i in range((ketoan_end_time - ketoan_start_time).days)
|
@@ -89,17 +89,17 @@ if authentication_status:
|
|
89 |
days_excluding_sundays = days_in_month - sundays_in_month
|
90 |
#----------------------#
|
91 |
|
92 |
-
@st.
|
93 |
def collect_data(link):
|
94 |
return(pd.DataFrame((requests.get(link).json())))
|
95 |
|
96 |
-
@st.
|
97 |
def rename_lop(dataframe, column_name):
|
98 |
dataframe[column_name] = dataframe[column_name].replace(
|
99 |
{1: "Hoa Cúc", 2: "Gò Dầu", 3: "Lê Quang Định", 5: "Lê Hồng Phong"})
|
100 |
return dataframe
|
101 |
|
102 |
-
@st.
|
103 |
def grand_total(dataframe, column):
|
104 |
# create a new row with the sum of each numerical column
|
105 |
totals = dataframe.select_dtypes(include=[float, int]).sum()
|
@@ -171,7 +171,7 @@ if authentication_status:
|
|
171 |
ca6 = pd.to_datetime('2000-01-01 19:30:00').time()
|
172 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
173 |
|
174 |
-
@st.
|
175 |
def time_of_day(time):
|
176 |
if (time >= start_time) & (time < end_time):
|
177 |
return "Sáng"
|
@@ -179,7 +179,7 @@ if authentication_status:
|
|
179 |
return "Tối"
|
180 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
181 |
|
182 |
-
@st.
|
183 |
def day_of_week(day):
|
184 |
if (day == 5) | (day == 6):
|
185 |
return "weekend"
|
@@ -187,7 +187,7 @@ if authentication_status:
|
|
187 |
return "weekdays"
|
188 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
189 |
|
190 |
-
@st.
|
191 |
def cahoc_converter(ca):
|
192 |
if (ca >= ca1) & (ca < ca2):
|
193 |
return 1
|
@@ -369,14 +369,14 @@ if authentication_status:
|
|
369 |
# "------------------"
|
370 |
|
371 |
# Define a function
|
372 |
-
@st.
|
373 |
def csv_reader(file):
|
374 |
df = pd.read_csv(file)
|
375 |
df = df.query("phanloai == 1") # Filter lop chính
|
376 |
df['date_created'] = pd.to_datetime(df['date_created'])
|
377 |
return df
|
378 |
|
379 |
-
@st.
|
380 |
def collect_filtered_data(table, date_column='', start_time='', end_time=''):
|
381 |
link = f"https://vietop.tech/api/get_data/{table}?column={date_column}&date_start={start_time}&date_end={end_time}"
|
382 |
df = pd.DataFrame((requests.get(link).json()))
|
@@ -425,7 +425,7 @@ if authentication_status:
|
|
425 |
['id', 'fullname', 'lop_cn'], as_index=False)['thucthu'].sum()
|
426 |
# "_______________"
|
427 |
|
428 |
-
@st.
|
429 |
def thucthu_time(dataframe, column):
|
430 |
df = dataframe.groupby(['lop_cn', column], as_index=False)[
|
431 |
'thucthu'].sum()
|
@@ -656,7 +656,7 @@ if authentication_status:
|
|
656 |
lambda x: '{:.2%}'.format(x/100))
|
657 |
|
658 |
# define a function
|
659 |
-
@ st.
|
660 |
def thousands_divider(df, col):
|
661 |
df[col] = df[col].apply(
|
662 |
lambda x: '{:,.0f}'.format(x))
|
|
|
76 |
ketoan_end_time = col2.date_input(
|
77 |
"Select end date", value=DEFAULT_END_DATE)
|
78 |
submit_button = st.form_submit_button(
|
79 |
+
label='Filter')
|
80 |
|
81 |
# the duration between 2 dates exclude Sunday
|
82 |
duration = sum(1 for i in range((ketoan_end_time - ketoan_start_time).days)
|
|
|
89 |
days_excluding_sundays = days_in_month - sundays_in_month
|
90 |
#----------------------#
|
91 |
|
92 |
+
@st.cache
|
93 |
def collect_data(link):
|
94 |
return(pd.DataFrame((requests.get(link).json())))
|
95 |
|
96 |
+
@st.cache
|
97 |
def rename_lop(dataframe, column_name):
|
98 |
dataframe[column_name] = dataframe[column_name].replace(
|
99 |
{1: "Hoa Cúc", 2: "Gò Dầu", 3: "Lê Quang Định", 5: "Lê Hồng Phong"})
|
100 |
return dataframe
|
101 |
|
102 |
+
@st.cache
|
103 |
def grand_total(dataframe, column):
|
104 |
# create a new row with the sum of each numerical column
|
105 |
totals = dataframe.select_dtypes(include=[float, int]).sum()
|
|
|
171 |
ca6 = pd.to_datetime('2000-01-01 19:30:00').time()
|
172 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
173 |
|
174 |
+
@st.cache
|
175 |
def time_of_day(time):
|
176 |
if (time >= start_time) & (time < end_time):
|
177 |
return "Sáng"
|
|
|
179 |
return "Tối"
|
180 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
181 |
|
182 |
+
@st.cache
|
183 |
def day_of_week(day):
|
184 |
if (day == 5) | (day == 6):
|
185 |
return "weekend"
|
|
|
187 |
return "weekdays"
|
188 |
# Create a function that takes a time and returns "Morning" or "Evening" depending on whether the time falls within the specified range
|
189 |
|
190 |
+
@st.cache
|
191 |
def cahoc_converter(ca):
|
192 |
if (ca >= ca1) & (ca < ca2):
|
193 |
return 1
|
|
|
369 |
# "------------------"
|
370 |
|
371 |
# Define a function
|
372 |
+
@st.cache
|
373 |
def csv_reader(file):
|
374 |
df = pd.read_csv(file)
|
375 |
df = df.query("phanloai == 1") # Filter lop chính
|
376 |
df['date_created'] = pd.to_datetime(df['date_created'])
|
377 |
return df
|
378 |
|
379 |
+
@st.cache
|
380 |
def collect_filtered_data(table, date_column='', start_time='', end_time=''):
|
381 |
link = f"https://vietop.tech/api/get_data/{table}?column={date_column}&date_start={start_time}&date_end={end_time}"
|
382 |
df = pd.DataFrame((requests.get(link).json()))
|
|
|
425 |
['id', 'fullname', 'lop_cn'], as_index=False)['thucthu'].sum()
|
426 |
# "_______________"
|
427 |
|
428 |
+
@st.cache
|
429 |
def thucthu_time(dataframe, column):
|
430 |
df = dataframe.groupby(['lop_cn', column], as_index=False)[
|
431 |
'thucthu'].sum()
|
|
|
656 |
lambda x: '{:.2%}'.format(x/100))
|
657 |
|
658 |
# define a function
|
659 |
+
@ st.cache
|
660 |
def thousands_divider(df, col):
|
661 |
df[col] = df[col].apply(
|
662 |
lambda x: '{:,.0f}'.format(x))
|