2021-05-19 04:01:26 +02:00
|
|
|
from itertools import product
|
|
|
|
import csv
|
2021-05-19 15:04:10 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2021-05-19 04:01:26 +02:00
|
|
|
|
|
|
|
field_states = ['toPlow', 'toWater', 'toSeed', 'toFertilize', 'toCut']
|
2021-05-19 15:04:10 +02:00
|
|
|
day_time = ['Day', 'Night']
|
|
|
|
weather = ['Clear Sky', 'Cloudy', 'Rainy', 'Hail']
|
|
|
|
temperature = ['Freezing', 'Cold', 'Mild', 'Hot']
|
|
|
|
wind = ['Windless', 'Strong Wind', 'Gale']
|
|
|
|
humidy = ['Low', 'High']
|
2021-05-19 04:01:26 +02:00
|
|
|
|
2021-05-19 15:04:10 +02:00
|
|
|
output = list(product(field_states, day_time, weather, temperature, wind, humidy))
|
2021-05-19 04:01:26 +02:00
|
|
|
|
|
|
|
dict = []
|
|
|
|
|
|
|
|
for x in range(len(output)):
|
2021-05-19 15:04:10 +02:00
|
|
|
if x % 3 == 0:
|
|
|
|
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 == 'Clear Sky' 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"
|
|
|
|
|
|
|
|
#Special conditions
|
|
|
|
if mDay_time == 'Night' and (mField == 'toWater' or mField == 'toCut'):
|
|
|
|
mDecision = "Make Action"
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
mDecision = "Wait"
|
|
|
|
|
|
|
|
if mWeather == 'Rainy' and (mField == 'toPlow' or mField == 'toSeed'):
|
|
|
|
mDecision = "Make Action"
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
mDecision = 'Wait'
|
|
|
|
|
|
|
|
if mWeather == 'Hail':
|
|
|
|
mDecision = 'Wait'
|
|
|
|
break
|
|
|
|
|
|
|
|
if mTemperature == 'Freezing':
|
|
|
|
mDecision = 'Wait'
|
|
|
|
break
|
|
|
|
|
|
|
|
if mWind == 'Gale':
|
|
|
|
mDecision = 'Wait'
|
|
|
|
break
|
|
|
|
|
|
|
|
if mHumidy == 'High' and mField == 'toCut':
|
|
|
|
mDecision = "Wait"
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
mDecision = "Make Action"
|
|
|
|
|
|
|
|
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"
|
2021-05-19 04:01:26 +02:00
|
|
|
|
|
|
|
with open(filename, 'w') as csvfile:
|
|
|
|
writer = csv.DictWriter(csvfile, fieldnames=fields)
|
|
|
|
writer.writeheader()
|
2021-05-31 21:05:42 +02:00
|
|
|
writer.writerows(dict)
|