Commit a6586d0a authored by sinthu's avatar sinthu

50 % done until water time prediction

parent 11d62d0f
Add Your Custom Modules Here.
If you have a module named module_name.py in
libs/applibs dir. You can call it directly in your
uix dir via:
`import module_name` instead of `from libs.applibs import module`
\ No newline at end of file
import os
from main_imports import Builder
def load_kv(file_name, file_path=os.path.join("ProjectFiles", "uix", "kv")):
"""
`load_kv` func is used to load a .kv file.
args that you can pass:
* `file_name`: Name of the kv file.
* `file_path`: Path to the kv file, it defaults
to `project_name/libs/kv`.
Q: Why a custom `load_kv`?
A: To avoid some encoding errors.
"""
with open(os.path.join(file_path, file_name), encoding="utf-8") as kv:
Builder.load_string(kv.read())
from main_imports import MDScreen
from ProjectFiles.applibs import utils
import warnings
import pandas as pd
from sklearn import metrics
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from six import StringIO
import pydotplus
from sklearn.tree import DecisionTreeClassifier
warnings.filterwarnings('ignore')
utils.load_kv("Water_filling.kv")
class Water_filling_Screen(MDScreen):
def btnA(self):
import pandas as pd
import warnings
from tqdm import tqdm
from time import sleep
warnings.filterwarnings('ignore')
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
import seaborn as sns
WaterData_Load = pd.read_csv("WaterData/DataSet.csv")
WaterData_Load = WaterData_Load.head()
print(WaterData_Load)
X = WaterData_Load[['Temperature', 'Humidity', 'Rainfall_Forcasting', 'Water_level', 'Light']]
y = WaterData_Load['Filling_Time_Minutes']
# Train Test split DataSet for ML
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)
# Fitting RandomForestClassifier
rf = RandomForestClassifier()
rf.fit(X_train, y_train)
# Dataload
for i in tqdm(range(5)):
sleep(0.4)
Rainfall_Forcasting = WaterData_Load["Rainfall_Forcasting"].mean()
Water_level = WaterData_Load["Water_level"].mean()
Light = WaterData_Load["Light"].mean()
# ML prediction
Temperature = self.txt3.text
Humidity = self.txt4.text
new_input = [[Temperature, Humidity, Rainfall_Forcasting, Water_level, Light]]
pred = rf.predict(new_input)
print(int(pred))
feature_imp = pd.Series(rf.feature_importances_, index=WaterData_Load['Filling_Time_Minutes']).sort_values(
ascending=False)
sns.barplot(x=feature_imp, y=feature_imp.index)
# Add labels to your graph
plt.xlabel('Feature Importance')
plt.ylabel('Features')
plt.title("Visualizing Important Features")
plt.legend()
# Accurac Level
Y_pred_rf = rf.predict(X_test)
current_accuracy = round(accuracy_score(Y_pred_rf, y_test) * 100, 2)
print(current_accuracy)
self.l1.text = str(pred[0]) + str(" ") + str("Minutes")
pass
from main_imports import MDScreen
from ProjectFiles.applibs import utils
utils.load_kv("login.kv")
import mysql.connector
class Login_Screen(MDScreen):
def LoginButton(self):
email = format(self.txt1.text)
password = format(self.txt2.text)
try:
connection = mysql.connector.connect(host='localhost',
database='SystemUser',
user='root',
password='')
cursor = connection.cursor()
sql_select_query = "SELECT * FROM People WHERE email = '" + email + "' AND password = '" + password + "'"
cursor.execute(sql_select_query)
cursor.fetchall()
rowcount = cursor.rowcount
if rowcount > 0:
self.parent.current = "Water_filling"
else:
self.l1.text = "Login Invalid"
finally:
if connection.is_connected():
connection.close()
def ClearButton(self):
self.txt1.text = ""
self.txt2.text = ""
self.l1.text = ""
pass
from kivy.core.window import Window
from main_imports import ScreenManager
from ProjectFiles.applibs import utils
utils.load_kv("root.kv")
class Root(ScreenManager):
def __init__(self, **kwargs):
super(Root, self).__init__(**kwargs)
Window.bind(on_keyboard=self._key_handler)
self.screen_list = list() #this list have all screen that user switched
def _key_handler(self, instance, key, *args):
if key is 27:
#in Desktop this key 27 is Esc and in Phone it's Back btn
self.previous_screen()
return True
def previous_screen(self):
"""
Switch to previous screen last screen in screen_list
"""
last_screen=self.screen_list.pop()
if last_screen == "home" or last_screen == "login":
exit()
print(self.screen_list)
self.transition.direction = "left"
self.current = self.screen_list[len(self.screen_list)-1]
def change_screen(self,name):
"""
Switch Screen using screen name and
"""
self.current = name
if name not in self.screen_list:
self.screen_list.append(self.current)
else:
self.screen_list.remove(name)
self.screen_list.append(self.current)
print(self.screen_list)
# if name == "home":
# MDBottomNavigation not resize there tabs when app stat in android
# to resize when switch to home screen
# self.get_screen(name).ids.android_tabs.on_resize()
\ No newline at end of file
from main_imports import BoxLayout
from ProjectFiles.applibs import utils
utils.load_kv("ui_class.kv")
class OneLineTextDialog(BoxLayout):
def input_text(self):
return self.ids.dialog_text.text
from main_imports import MDScreen
from ProjectFiles.applibs import utils
utils.load_kv("verification.kv")
class Verification_Screen(MDScreen):
pass
\ No newline at end of file
<Water_filling_Screen>:
name: "Water_filling"
txt3:txt3
txt4:txt4
l1:l1
l2:l2
l3:l3
MDToolbar:
title: "FILLING TIME PREDICTION"
size_hint: 1,.08
elevation: 5
pos_hint: {"center_y": .95}
MDToolbar:
title: app.APP_NAME
size_hint: 1,.08
elevation: 5
font_size: 20
color: 0,100,0
pos_hint: {"center_y": .95}
MDToolbar:
size_hint: 1,.08
elevation: 5
canvas.before:
Color:
rgba: (1, 1, 1, 1)
Rectangle:
source:'assets//img//bk.jpg'
size: 500, 500
pos: self.pos
Image:
source: "assets//img//2022.png"
id: avatar_image
size_hint: 1, 1
pos_hint: {"center_x":0.5, "center_y":0.78}
MDIconButton:
icon: "home"
text_color: "white"
theme_text_color: "Custom"
pos_hint: {"center_x": 0.1}
pos_hint: {"center_x": 0.50}
user_font_size: "35sp"
on_release: app.screen_manager.change_screen("login")
GridLayout:
cols: 2
padding : 30,30
spacing: 20, 20
row_default_height: '30dp'
MDLabel:
text: "WATER FILLING TIME PREDICTION"
halign: "center"
pos_hint: {"center_x":0.5, "center_y":0.58}
font_style: "H6"
color: 223, 55, 19
background_color: (1.0, 0.0, 0.0, 1.0)
MDTextField:
hint_text: "Enter Temperature"
id: txt3
pos_hint: {"center_x":0.5, "center_y":0.50}
size_hint: .75,0.08
# mode: "rectangle"
MDTextField:
hint_text: "Enter Humidity"
id: txt4
pos_hint: {"center_x":0.5, "center_y":0.41}
size_hint: .75,0.08
# mode: "rectangle"
MDFillRoundFlatButton:
text: "PREDICT TIME"
pos_hint: {"center_x": 0.5, "center_y":0.33}
size_hint: .7,0.05
on_release:
root.btnA()
MDLabel:
text: ""
halign: "center"
pos_hint: {"center_y":.20}
font_style: "Subtitle2"
id: l1
color: 223, 55, 19
background_color: (1.0, 0.0, 0.0, 1.0)
MDLabel:
text: ""
halign: "center"
pos_hint: {"center_y":.0}
font_style: "Subtitle2"
id: l2
color: 223, 55, 19
background_color: (1.0, 0.0, 0.0, 1.0)
MDLabel:
text: ""
halign: "center"
pos_hint: {"center_y":.0}
font_style: "Subtitle2"
id: l3
color: 223, 55, 19
background_color: (1.0, 0.0, 0.0, 1.0)
<Login_Screen>:
name: "login"
txt1:txt1
txt2:txt2
l1:l1
l2:l2
MDToolbar:
title: app.APP_NAME
size_hint: 1,.08
elevation: 5
font_size: 20
color: 0,100,0
pos_hint: {"center_y": .95}
MDToolbar:
size_hint: 1,.08
elevation: 5
canvas.before:
Color:
rgba: (1, 1, 1, 1)
Rectangle:
source:'assets//img//bk.jpg'
size: 500, 500
pos: self.pos
Image:
source: "assets//img//2022.png"
id: avatar_image
size_hint: 1, 1
pos_hint: {"center_x":0.5, "center_y":0.78}
MDLabel:
text: "USER LOGIN"
halign: "center"
pos_hint: {"center_y":.55}
font_style: "Subtitle2"
font_size: 20
color: 0,100,0
MDTextField:
hint_text: "Username"
id: txt1
pos_hint: {"center_x": 0.5, "center_y": 0.46}
size_hint: .75,0.085
# mode: "rectangle"
MDTextField:
hint_text: "Password"
id: txt2
pos_hint: {"center_x":0.5, "center_y":0.38}
size_hint: .75,0.085
password: True
# mode: "rectangle"
MDLabel:
text: ""
halign: "center"
pos_hint: {"center_y":.30}
font_style: "Subtitle2"
id: l1
color: 1,0,1,1
MDLabel:
text: ""
halign: "center"
pos_hint: {"center_y":.35}
font_style: "Subtitle2"
id: l2
color: 1,0,1,1
MDFillRoundFlatButton:
text: "LOGIN"
pos_hint: {"center_x": 0.2, "center_y":0.24}
size_hint: .11,0.05
on_release:
root.LoginButton()
MDFillRoundFlatButton:
text: "Clear"
pos_hint: {"center_x": 0.8, "center_y":0.24}
size_hint: .11,0.05
on_release:
root.ClearButton()
<Root>:
\ No newline at end of file
<OneLineTextDialog>
orientation: "vertical"
spacing: "6dp"
size_hint_y: None
height: "60dp"
MDTextField:
id:dialog_text
# Enter text in textfiled
\ No newline at end of file
<Verification_Screen>:
name: "verification"
MDLabel:
text: app.APP_NAME
halign: "center"
pos_hint: {"center_y": .8}
font_style: "H3"
MDLabel:
text: "Account verification"
halign: "center"
pos_hint: {"center_y":.73}
font_style: "Subtitle2"
MDLabel:
text: "We've sent a verification code to your email."
halign: "center"
pos_hint: {"center_y":.67}
font_style: "Body2"
MDTextField:
hint_text: "Enter your verification Code"
pos_hint: {"center_x": 0.5, "center_y": 0.6}
size_hint: .75,0.08
max_text_length: 6
# mode: "rectangle"
MDRaisedButton:
text: "Submit"
pos_hint: {"center_x": 0.5, "center_y":0.52}
size_hint: .7,0.05
MDTextButton:
text: "Resend code"
pos_hint: {"center_x": 0.5, "center_y":0.45}
on_release: app.screen_manager.change_screen("verification")
MDLabel:
text: "Never share your verification code to anyone."
halign: "center"
pos_hint: {"center_y":.4}
font_style: "Caption"
MDLabel:
text: f"[font=Icons] {md_icons['copyright']}[/font] [font=Roboto]{app.COMPANY_NAME} [/font]"
markup: True
halign: "center"
pos_hint: {"center_y":0.05}
\ No newline at end of file
Temperature,Humidity,Rainfall_Forcasting,Water_level,Light,Filling_Time_Minutes
28,29,27,0.5,26,60
28,29,27,0.5,26,60
28,29,27,0.5,26,60
32,28,29,0.7,31,45
32,28,29,0.7,31,45
32,28,29,0.7,31,45
32,28,29,0.7,31,45
33,28,28,0.9,32,15
33,28,28,0.9,32,15
33,28,28,0.9,32,15
import pandas as pd
import warnings
from tqdm import tqdm
from time import sleep
warnings.filterwarnings('ignore')
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
import seaborn as sns
WaterData_Load = pd.read_csv("WaterData/DataSet.csv")
WaterData_Load = WaterData_Load.head()
print(WaterData_Load)
X = WaterData_Load[['Temperature', 'Humidity', 'Rainfall_Forcasting', 'Water_level', 'Light']]
y = WaterData_Load['Filling_Time_Minutes']
# Train Test split DataSet for ML
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)
# Fitting RandomForestClassifier
rf = RandomForestClassifier()
rf.fit(X_train, y_train)
# Dataload
for i in tqdm(range(5)):
sleep(0.4)
# ML prediction
Rainfall_Forcasting = WaterData_Load["Rainfall_Forcasting"].mean()
Water_level = WaterData_Load["Water_level"].mean()
Light = WaterData_Load["Light"].mean()
new_input = [[28, 29, Rainfall_Forcasting, Water_level, Light]]
pred = rf.predict(new_input)
print(int(pred))
feature_imp = pd.Series(rf.feature_importances_,index= WaterData_Load['Filling_Time_Minutes']).sort_values(ascending=False)
sns.barplot(x=feature_imp, y=feature_imp.index)
# Add labels to your graph
plt.xlabel('Feature Importance')
plt.ylabel('Features')
plt.title("Visualizing Important Features")
plt.legend()
# Accurac Level
Y_pred_rf = rf.predict(X_test)
current_accuracy = round(accuracy_score(Y_pred_rf, y_test) * 100, 2)
print(current_accuracy)
This diff is collapsed.
#--[Start platform specific code]
"""This code to detect it's Android or not
if it's not android than app window size change in android phone size"""
from kivy.utils import platform
if platform != 'android':
from kivy.config import Config
Config.set("graphics","width",360)
Config.set("graphics","height",740)
Config.set('graphics', 'borderless', 'True')
#--[End platform specific code]
#--[Start Soft_Keyboard code ]Config
"""code for android keyboard. when in android keyboard show textbox
automatic go to top of keyboard so user can see when he type msg"""
from kivy.core.window import Window
Window.keyboard_anim_args = {"d":.2,"t":"linear"}
Window.softinput_mode = "below_target"
#--[End Soft_Keyboard code ]
from ProjectFiles.uix.baseclass.login import Login_Screen
from ProjectFiles.uix.baseclass.root import Root
from ProjectFiles.uix.baseclass.Water_filling import Water_filling_Screen
from ProjectFiles.uix.baseclass.verification import Verification_Screen
from main_imports import ImageLeftWidget, MDApp, TwoLineAvatarListItem
class HamsterApp(MDApp):
"""
Hamster App start from here this class is root of app.
in kivy (.kv) file when use app.method_name app is start from here
"""
def __init__(self, **kwargs):
super(HamsterApp, self).__init__(**kwargs)
self.APP_NAME = "SMART FARMING"
self.COMPANY_NAME = "2022"
def all_chats(self):
# self.change_screen("profile")
twolineW= TwoLineAvatarListItem(text=f"DIABETES IDENTIFICATION WITH ML",
secondary_text="@username",
on_touch_up=self.chat_room)
twolineW.add_widget(ImageLeftWidget(source="assets//img//hamster_icon.png"))
self.screen_manager.get_screen("login").ids.chat_tab.add_widget(twolineW)
def build(self):
self.theme_cls.primary_palette = "LightGreen"
self.theme_cls.primary_hue = "500"
self.theme_cls.accent_palette = "LightGreen"
self.theme_cls.accent_hue = "500"
self.theme_cls.theme_style = "Light"
self.screen_manager = Root()
self.screen_manager.add_widget(Login_Screen())
self.screen_manager.add_widget(Water_filling_Screen())
self.screen_manager.add_widget(Verification_Screen())
return self.screen_manager
def on_start(self):
self.screen_manager.change_screen("Water_filling")
if __name__ == "__main__":
HamsterApp().run()
"""
IMPORT all modules here that use in this app.
"""
#--[Start UI Imports]
"""All imports for UI here Kivy,KivyMD or etc that help in UI"""
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager
from kivymd.app import MDApp
from kivymd.uix.bottomsheet import MDGridBottomSheet
from kivymd.uix.button import MDFlatButton
from kivymd.uix.card import MDCard, MDSeparator
from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel
from kivymd.uix.list import ImageLeftWidget, TwoLineAvatarListItem
from kivymd.uix.screen import MDScreen
from kivymd.uix.tab import MDTabsBase
from kivymd.uix.textfield import MDTextField
from ProjectFiles.uix.baseclass.ui_class import OneLineTextDialog
#--[End UI Imports]
#--[Start Non UI Imports]
"""All imports that use in application """
#--[End Non UI Imports]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment