Spaces:
Sleeping
Sleeping
File size: 5,161 Bytes
2edf7af d697c35 e8219cc d697c35 e8219cc d697c35 2178497 d697c35 2178497 d697c35 2178497 d697c35 2178497 d697c35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
import streamlit as st
import pandas as pd
import numpy as np
from datetime import datetime
import plotly.express as px
import sqlite3
from pathlib import Path
# تنظیمات اولیه
st.set_page_config(page_title="سامانه مدیریت مزارع نیشکر", layout="wide", direction="rtl")
# ایجاد دیتابیس
def init_db():
conn = sqlite3.connect('sugarcane_farms.db')
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS farm_data (
id INTEGER PRIMARY KEY AUTOINCREMENT,
row_number INTEGER,
representative TEXT,
channel INTEGER,
department INTEGER,
production INTEGER,
cultivation_area REAL,
sub_area REAL,
variety TEXT,
age TEXT,
station1 REAL,
station2 REAL,
station3 REAL,
station4 REAL,
station5 REAL,
current_height REAL,
previous_height REAL,
current_growth REAL,
previous_growth REAL,
current_nitrogen REAL,
current_nitrogen_std REAL,
previous_nitrogen REAL,
previous_nitrogen_std REAL,
current_moisture REAL,
current_moisture_std REAL,
previous_moisture REAL,
previous_moisture_std REAL,
well1_depth REAL,
well2_depth REAL,
reading_date DATE
)
''')
conn.commit()
conn.close()
# فرم ورود داده
def data_entry_form():
st.header("فرم ورود دادههای مزارع نیشکر")
col1, col2, col3 = st.columns(3)
with col1:
row_number = st.number_input("ردیف", min_value=1, max_value=99)
representative = st.text_input("نماینده (مثال: 01-22)")
channel = st.selectbox("کانال", options=[i for i in range(1, 31) if i != 28])
department = st.selectbox("اداره", options=[1, 2, 3, 4])
production = st.selectbox("تولید", options=[1, 2])
with col2:
cultivation_area = st.number_input("مساحت داشت", min_value=0.0)
sub_area = st.number_input("مساحت زیرمجموعه", min_value=0.0)
variety = st.selectbox("واریته", options=["CP69", "CP48", "CP57"])
age = st.selectbox("سن", options=["R1", "R2", "P"])
with col3:
reading_date = st.date_input("تاریخ قرائت")
# ایستگاههای اندازهگیری
st.subheader("ایستگاههای اندازهگیری")
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
station1 = st.number_input("ایستگاه 1", min_value=0.0)
with col2:
station2 = st.number_input("ایستگاه 2", min_value=0.0)
with col3:
station3 = st.number_input("ایستگاه 3", min_value=0.0)
with col4:
station4 = st.number_input("ایستگاه 4", min_value=0.0)
with col5:
station5 = st.number_input("ایستگاه 5", min_value=0.0)
# محاسبه خودکار ارتفاع هفته جاری
current_height = np.mean([station1, station2, station3, station4, station5])
st.info(f"ارتفاع هفته جاری مزرعه (محاسبه شده): {current_height:.2f}")
# ادامه فرم...
col1, col2 = st.columns(2)
with col1:
previous_height = st.number_input("ارتفاع هفته گذشته مزرعه", min_value=0.0)
current_growth = current_height - previous_height
st.info(f"رشد هفته جاری (محاسبه شده): {current_growth:.2f}")
previous_growth = st.number_input("رشد هفته گذشته", min_value=0.0)
# دکمه ذخیره
if st.button("ذخیره اطلاعات"):
save_data(locals())
st.success("اطلاعات با موفقیت ذخیره شد!")
# تابع ذخیرهسازی دادهها
def save_data(data):
conn = sqlite3.connect('sugarcane_farms.db')
c = conn.cursor()
# ایجاد query برای ذخیره دادهها
query = """
INSERT INTO farm_data (
row_number, representative, channel, department, production,
cultivation_area, sub_area, variety, age, station1, station2,
station3, station4, station5, current_height, previous_height,
current_growth, previous_growth, reading_date
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
values = (
data['row_number'], data['representative'], data['channel'],
data['department'], data['production'], data['cultivation_area'],
data['sub_area'], data['variety'], data['age'], data['station1'],
data['station2'], data['station3'], data['station4'], data['station5'],
data['current_height'], data['previous_height'], data['current_growth'],
data['previous_growth'], data['reading_date']
)
c.execute(query, values)
conn.commit()
conn.close()
# اجرای برنامه
if __name__ == "__main__":
init_db()
data_entry_form() |