Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,36 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
# توابع م
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
df
|
| 9 |
-
return df
|
| 10 |
|
| 11 |
def format_number(num):
|
| 12 |
return f"{num:,}"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
'category': [label, ''],
|
| 17 |
-
'value': [percentage, 100 - percentage]
|
| 18 |
-
})
|
| 19 |
-
chart = alt.Chart(data).mark_arc(innerRadius=50).encode(
|
| 20 |
-
theta='value',
|
| 21 |
-
color=alt.condition(
|
| 22 |
-
alt.datum.category == label,
|
| 23 |
-
alt.value(color),
|
| 24 |
-
alt.value('lightgray')
|
| 25 |
-
)
|
| 26 |
-
).properties(
|
| 27 |
-
width=200,
|
| 28 |
-
height=200
|
| 29 |
-
)
|
| 30 |
-
return chart
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
data = {
|
| 34 |
-
'states': ['State1', 'State2', 'State3', 'State4'],
|
| 35 |
-
'population': [100000, 200000, 150000, 250000],
|
| 36 |
-
'year': [2011, 2011, 2011, 2011]
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
df = pd.DataFrame(data)
|
| 40 |
-
|
| 41 |
-
# ایجاد داشبورد
|
| 42 |
st.title('داشبورد تجزیه و تحلیل مزارع نیشکر')
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
df_population_difference_sorted = calculate_population_difference(df, selected_year)
|
| 47 |
-
|
| 48 |
-
col1, col2 = st.columns(2)
|
| 49 |
-
|
| 50 |
-
with col1:
|
| 51 |
-
st.markdown('#### Gains/Losses')
|
| 52 |
-
|
| 53 |
-
if selected_year > 2010:
|
| 54 |
-
first_state_name = df_population_difference_sorted.states.iloc[0]
|
| 55 |
-
first_state_population = format_number(df_population_difference_sorted.population.iloc[0])
|
| 56 |
-
first_state_delta = format_number(df_population_difference_sorted.population_difference.iloc[0])
|
| 57 |
-
else:
|
| 58 |
-
first_state_name = '-'
|
| 59 |
-
first_state_population = '-'
|
| 60 |
-
first_state_delta = ''
|
| 61 |
-
st.metric(label=first_state_name, value=first_state_population, delta=first_state_delta)
|
| 62 |
-
|
| 63 |
-
if selected_year > 2010:
|
| 64 |
-
last_state_name = df_population_difference_sorted.states.iloc[-1]
|
| 65 |
-
last_state_population = format_number(df_population_difference_sorted.population.iloc[-1])
|
| 66 |
-
last_state_delta = format_number(df_population_difference_sorted.population_difference.iloc[-1])
|
| 67 |
-
else:
|
| 68 |
-
last_state_name = '-'
|
| 69 |
-
last_state_population = '-'
|
| 70 |
-
last_state_delta = ''
|
| 71 |
-
st.metric(label=last_state_name, value=last_state_population, delta=last_state_delta)
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
states_migration_greater = round((len(df_greater_50000)/df_population_difference_sorted.states.nunique())*100)
|
| 82 |
-
states_migration_less = round((len(df_less_50000)/df_population_difference_sorted.states.nunique())*100)
|
| 83 |
-
donut_chart_greater = make_donut(states_migration_greater, 'Inbound Migration', 'green')
|
| 84 |
-
donut_chart_less = make_donut(states_migration_less, 'Outbound Migration', 'red')
|
| 85 |
-
else:
|
| 86 |
-
states_migration_greater = 0
|
| 87 |
-
states_migration_less = 0
|
| 88 |
-
donut_chart_greater = make_donut(states_migration_greater, 'Inbound Migration', 'green')
|
| 89 |
-
donut_chart_less = make_donut(states_migration_less, 'Outbound Migration', 'red')
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
|
| 5 |
+
# توابع کمکی
|
| 6 |
+
def calculate_growth(df, week):
|
| 7 |
+
df['growth'] = df['ارتفاع هفته جاری مزرعه'] - df['ارتفاع هفته گذشته مزرعه']
|
| 8 |
+
df = df[df['هفته'] == week]
|
| 9 |
+
return df
|
| 10 |
|
| 11 |
def format_number(num):
|
| 12 |
return f"{num:,}"
|
| 13 |
|
| 14 |
+
# بارگذاری دادهها
|
| 15 |
+
df = pd.read_csv('path_to_your_csv_file.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# تنظیم داشبورد
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
st.title('داشبورد تجزیه و تحلیل مزارع نیشکر')
|
| 19 |
|
| 20 |
+
selected_week = st.slider('هفته را انتخاب کنید', min_value=df['هفته'].min(), max_value=df['هفته'].max(), value=df['هفته'].min(), step=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
df_growth = calculate_growth(df, selected_week)
|
| 23 |
|
| 24 |
+
# ایجاد نمودارهای سهبعدی
|
| 25 |
+
fig1 = px.scatter_3d(df_growth, x='ارتفاع هفته جاری مزرعه', y='رشد هفته جاری', z='نیتروژن فعلی', color='واریته', title='ارتفاع و رشد در مقابل نیتروژن')
|
| 26 |
+
fig2 = px.scatter_3d(df_growth, x='ارتفاع هفته جاری مزرعه', y='رشد هفته جاری', z='رطوبت غلاف فعلی', color='واریته', title='ارتفاع و رشد در مقابل رطوبت')
|
| 27 |
+
fig3 = px.scatter_3d(df_growth, x='ارتفاع هفته جاری مزرعه', y='رشد هفته گذشته', z='نیتروژن قبلی', color='واریته', title='ارتفاع و رشد گذشته در مقابل نیتروژن')
|
| 28 |
+
fig4 = px.scatter_3d(df_growth, x='ارتفاع هفته گذشته مزرعه', y='رشد هفته جاری', z='رطوبت غلاف قبلی', color='واریته', title='ارتفاع گذشته و رشد در مقابل رطوبت')
|
| 29 |
+
fig5 = px.scatter_3d(df_growth, x='نیتروژن فعلی', y='رطوبت غلاف فعلی', z='ارتفاع هفته جاری مزرعه', color='واریته', title='نیتروژن و رطوبت در مقابل ارتفاع')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# نمایش نمودارها
|
| 32 |
+
st.plotly_chart(fig1)
|
| 33 |
+
st.plotly_chart(fig2)
|
| 34 |
+
st.plotly_chart(fig3)
|
| 35 |
+
st.plotly_chart(fig4)
|
| 36 |
+
st.plotly_chart(fig5)
|