minor changes

This commit is contained in:
secret_dude 2021-05-31 20:34:09 +02:00
parent e10fbe4e48
commit 66fe537f7a
3 changed files with 18 additions and 117 deletions

View File

@ -1,101 +0,0 @@
from itertools import product
import numpy as np
import pandas as pd
import csv
import id3test
import pprint
import sys
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
import matplotlib.image as pltimg
# stan pola: toCut, toPlow, toWater, toSeed, toFertilize
# pora dnia: dzień, noc
# pogoda: sunny, cloudy, rainy, hail
# temperatura: freezing, cold, mild, hot
# wiatr: windless, strong wind, gale
# humidy: low, high
field_states = ['toPlow', 'toWater', 'toSeed', 'toFertilize', 'toCut']
day_time = ['Day', 'Night']
weather = ['Clear Sky', 'Cloudy', 'Rainy', 'Hail']
temperature = ['Freezing', 'Cold', 'Mild', 'Hot']
wind = ['Windless', 'Strong Wind', 'Gale']
humidy = ['Low', 'High']
output = list(product(field_states, day_time, weather, temperature, wind, humidy))
dict = []
for x in range(len(output)):
while True:
mField = output[x][0]
mDay_time = output[x][1]
mWeather = output[x][2]
mTemperature = output[x][3]
mWind = output[x][4]
mHumidy = output[x][5]
mDecision = 'null'
# pora dnia: dzień 2, noc -2
# pogoda: sunny+3, cloudy+3, rainy-2, hail-5
# temperatura: freezing -3, cold-1, mild+4, hot+2
# wiatr: windless +2, strong wind-1, gale-3
# humidy: low+2, high-3
if mDay_time == 'Day':
valDay_time = 2
else:
valDay_time = -3
if mWeather == 'Sunny' or 'Cloudy':
valWeather = 3
elif mWeather == 'Rainy':
valWeather = -2
else:
valWeather = -5
if mTemperature == 'Freezing':
valTemperature = -3
elif mTemperature == 'Cold':
valTemperature = -1
elif mTemperature == 'Mild':
valTemperature = 4
else:
valTemperature = 2
if mWind == 'Windless':
valWind = +2
elif mWind == 'Strong Wind':
valWind = -1
else:
valWind = -3
if humidy == 'Low':
valHumidy = 2
else:
valHumidy = -2
result = valDay_time + valWeather + valTemperature + valWind + valHumidy
if result >= 0:
mDecision = "Make Action"
else:
mDecision = "Wait"
break
dict.append({'Field': mField, 'Day Time': mDay_time, 'Weather': mWeather,
'Temperature': mTemperature, 'Wind': mWind, 'Humidy': mHumidy, 'Decision': mDecision})
fields = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy', 'Decision']
filename = "treedata\\data.csv"
with open(filename, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fields)
writer.writeheader()
writer.writerows(dict)

View File

@ -53,13 +53,14 @@ while working:
field = board[tractor.horizontal_index][tractor.vertical_index] field = board[tractor.horizontal_index][tractor.vertical_index]
if weatherTimer == 30: if weatherTimer == 2:
weatherTimer = 0 weatherTimer = 0
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions() weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)] question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)]
decision = dtree.predict(question) decision = dtree.predict(question)
if tractor.autodrive:
if not move_list and decision == 1: if not move_list and decision == 1:
field.state = TractorAction.changeFieldState(field, tractor) field.state = TractorAction.changeFieldState(field, tractor)
istate = graph.Istate(tractor.direction, tractor.horizontal_index, tractor.vertical_index) istate = graph.Istate(tractor.direction, tractor.horizontal_index, tractor.vertical_index)
@ -73,7 +74,8 @@ while working:
if field.horizontal_index == 0 and field.vertical_index == 0 and not move_list: if field.horizontal_index == 0 and field.vertical_index == 0 and not move_list:
tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter) tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter)
drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time, temperature, wind, humidy, decision) drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time,
temperature, wind, humidy, decision)
clock.tick(FPS) clock.tick(FPS)
weatherTimer = weatherTimer + 1 weatherTimer = weatherTimer + 1

View File

@ -53,10 +53,10 @@ def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadC
def manualTurning(event, tractor): def manualTurning(event, tractor):
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and tractor.horizontal_index > 0: if event.key == pygame.K_LEFT and tractor.horizontal_index > 0:
tractor.direction = TRACTOR_DIRECTION_LEFT tractor.direction = "LEFT"
elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1: elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
tractor.direction = TRACTOR_DIRECTION_RIGHT tractor.direction = "RIGHT"
elif event.key == pygame.K_UP and tractor.vertical_index > 0: elif event.key == pygame.K_UP and tractor.vertical_index > 0:
tractor.direction = TRACTOR_DIRECTION_UP tractor.direction = "UP"
elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1: elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1:
tractor.direction = TRACTOR_DIRECTION_DOWN tractor.direction = "DOWN"