forked from s444426/AIProjekt
97 lines
2.5 KiB
Python
97 lines
2.5 KiB
Python
from ID3 import predict_data
|
|
from dataset import create_data_soil
|
|
from plant_upgrade import Plant
|
|
import pandas as pd
|
|
|
|
|
|
def decide_to_plant(soil):
|
|
"""
|
|
Z tej funkcji będzie korzystał traktor, aby podjąć decyzję o sadzeniu rośliny.
|
|
Kluczowym punktem w tym działaniu jest sprawdzenie, czy w danej ziemi nie rośnie już jakaś roślina,
|
|
dopiero po roztrzygnięciu tej kwestii następuje poszukiwanie odpowiedniej rośliny w drzewie decyzyjnym.
|
|
"""
|
|
|
|
if soil.have_plant():
|
|
plant = soil.get_plant()
|
|
if plant.collect() == 'True':
|
|
info = get_info(soil)
|
|
plant.leave_soil()
|
|
else:
|
|
return [['none']]
|
|
else:
|
|
info = get_info(soil)
|
|
|
|
data = []
|
|
data.append(info)
|
|
|
|
# Roślina jest gotowa do zbioru lub ziemia jest wolna
|
|
predicted = predict_data(data)
|
|
grow_a_plant(soil, predicted[0][0])
|
|
|
|
return predicted
|
|
|
|
|
|
def grow_a_plant(soil, plant_name):
|
|
plant = Plant(plant_name)
|
|
soil.add_plant(plant)
|
|
|
|
|
|
def get_info(soil):
|
|
|
|
previous = 'none'
|
|
|
|
if soil.have_plant():
|
|
plant = soil.get_plant()
|
|
previous = plant.get_name()
|
|
|
|
info = [previous, categorize_pH(soil.get_pH()), categorize_dry_level(soil.get_dry_level()), '']
|
|
|
|
return info
|
|
|
|
|
|
def categorize_pH(pH):
|
|
if pH <= 4.5:
|
|
return 'strongly acidic'
|
|
if 4.5 < pH <= 5.5:
|
|
return 'acidic'
|
|
if 5.5 < pH <= 6.5:
|
|
return 'slightly acidic'
|
|
if 6.5 < pH <= 7.2:
|
|
return 'neutral'
|
|
if 7.2 < pH:
|
|
return 'alkaline'
|
|
|
|
|
|
def categorize_dry_level(dry_level):
|
|
if dry_level <= 0.1:
|
|
return 'soaking wet'
|
|
if 0.1 < dry_level <= 0.4:
|
|
return 'wet'
|
|
if 0.4 < dry_level <= 0.6:
|
|
return 'medium wet'
|
|
if 0.6 < dry_level <= 0.8:
|
|
return 'dry'
|
|
if 0.8 < dry_level:
|
|
return 'very dry'
|
|
|
|
|
|
"""
|
|
Testowanie działania dla argumentów obiektu Soil
|
|
"""
|
|
|
|
all_soil = create_data_soil()
|
|
result = []
|
|
|
|
for soil in all_soil:
|
|
predicted = decide_to_plant(soil)
|
|
for p in predicted:
|
|
if soil.have_plant():
|
|
plant = soil.get_plant().get_name()
|
|
collect = soil.get_plant().get_collect()
|
|
else:
|
|
plant = 'none'
|
|
collect = '-'
|
|
result.append([soil.get_pH(), soil.get_dry_level(), plant, collect, p[0]])
|
|
|
|
result = pd.DataFrame(data=result, columns=['pH', 'dry level', 'plant', 'ripe', 'prediction'])
|
|
#print(result) |