Esmaeilkiani commited on
Commit
a9f7c2e
1 Parent(s): 1bfa558

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Load the data files
6
+ cleaned_data = pd.read_csv('cleaned_data.csv')
7
+ veg_index_data = pd.read_csv('SentinelTimeSeries_Sugarcane (2) (3).csv')
8
+ weather_data = pd.read_csv('weather_data.csv') # Replace with your weather data file
9
+ performance_estimation_data = pd.read_csv('تخمین تناژ.csv') # Replace with your yield estimation file
10
+
11
+ # Function to search for farm performance
12
+ def search_farm(farm_name):
13
+ # Filter the farm's data for recent years (1392-1402)
14
+ farm_data = cleaned_data[cleaned_data['مزرعه'] == farm_name]
15
+ farm_performance = farm_data[(farm_data['year'] >= 1392) & (farm_data['year'] <= 1402)]
16
+
17
+ # Create a time-series chart for the vegetation index (mean_VH, mean_VV)
18
+ veg_data = veg_index_data[veg_index_data['مزرعه'] == farm_name]
19
+
20
+ # Plotting vegetation index trends
21
+ fig, ax = plt.subplots(figsize=(10,5))
22
+ ax.plot(veg_data['date'], veg_data['mean_VH'], label='mean_VH')
23
+ ax.plot(veg_data['date'], veg_data['mean_VV'], label='mean_VV')
24
+ ax.set_xlabel('Date')
25
+ ax.set_ylabel('Vegetation Index')
26
+ ax.set_title(f'Vegetation Index Trends for {farm_name}')
27
+ ax.legend()
28
+ plt.xticks(rotation=45)
29
+
30
+ return farm_performance, fig
31
+
32
+ # Function to display weather data
33
+ def show_weather_data():
34
+ st.dataframe(weather_data)
35
+
36
+ # Function to predict farm performance (yield and tonnage)
37
+ def predict_performance(farm_name):
38
+ prediction_data = performance_estimation_data[performance_estimation_data['مزرعه'] == farm_name]
39
+
40
+ if prediction_data.empty:
41
+ st.write("مزرعه مورد نظر پیدا نشد.")
42
+ else:
43
+ yield_value = prediction_data['yield'].values[0]
44
+ tonnage = prediction_data['tonnage'].values[0] # Adjust based on your actual column name
45
+ st.write(f"تن در هکتار: {yield_value}")
46
+ st.write(f"تناژ: {tonnage}")
47
+
48
+ # Streamlit app
49
+ st.title("Farm Performance Dashboard")
50
+
51
+ # Sidebar menu
52
+ menu = st.sidebar.selectbox("انتخاب منو", ["Farm Search", "دیتابیس هواشناسی", "پیش بینی عملکرد"])
53
+
54
+ # Farm Search section
55
+ if menu == "Farm Search":
56
+ st.header("Search for Farm Performance")
57
+ farm_name = st.text_input("نام مزرعه را وارد کنید")
58
+
59
+ if st.button("Search"):
60
+ farm_performance, veg_chart = search_farm(farm_name)
61
+ st.write("Farm Performance (1392-1402):")
62
+ st.dataframe(farm_performance)
63
+ st.write("Vegetation Index Time Series:")
64
+ st.pyplot(veg_chart)
65
+
66
+ # Weather Database section
67
+ elif menu == "دیتابیس هواشناسی":
68
+ st.header("Weather Data")
69
+ st.write("مشاهده داده‌های هواشناسی:")
70
+ show_weather_data()
71
+
72
+ # Performance Prediction section
73
+ elif menu == "پیش بینی عملکرد":
74
+ st.header("Predict Farm Performance")
75
+ farm_name_prediction = st.text_input("نام مزرعه برای پیش بینی")
76
+
77
+ if st.button("پیش بینی"):
78
+ predict_performance(farm_name_prediction)