AI2020_Project/models/dumpster.py

127 lines
3.8 KiB
Python
Raw Normal View History

2020-05-02 17:10:49 +02:00
import numpy as np
import random
import os
2020-05-02 17:10:49 +02:00
class trash():
def __init__(self):
self.id = 0
self.plastic = 0
self.paper = 0
self.metal = 0
self.cardboard = 0
2020-05-02 17:10:49 +02:00
self.glass = 0
self.color = 0
self.xy = 0
self.value = 1
self.numberx = 0
self.numbery = 0
self.trashPaths = []
self.trash = 0
self.kind = ""
2020-05-02 17:10:49 +02:00
def giveID(self,id):
self.id = id
#puts garbage locations into a list
def createTrash(self, x, type):
trashPaths=[]
for i in range(x):
kind = random.choice(type)
path = "Garbage classification\\testset\\" + kind
file = random.choice(os.listdir(path))
path = "Garbage classification\\testset\\" + kind + "\\" + file
trashPaths.append(path)
return trashPaths
2020-05-02 17:10:49 +02:00
def throwAway(self):
trash = np.random.randint(1,6)
if trash == 1:
#plastic YELLOW
tra = self.createTrash(random.randint(1,3), ["plastic"])
sh = self.createTrash((random.randint(0,2)), ["cardboard", "glass", "metal", "paper", "plastic"])
self.trash = tra + sh
self.kind = "plastic"
self.plastic += len(self.trash)
2020-05-02 17:10:49 +02:00
return True
elif trash == 2:
#paper GREEN
tra = self.createTrash(random.randint(1,3), ["paper"])
sh = self.createTrash((random.randint(0,2)), ["cardboard", "glass", "metal", "paper", "plastic"])
self.trash = tra + sh
self.kind = "paper"
self.paper += len(self.trash)
2020-05-02 17:10:49 +02:00
return True
elif trash == 3:
#glass RED
tra = self.createTrash(random.randint(1,3), ["glass"])
sh = self.createTrash((random.randint(0,2)), ["cardboard", "glass", "metal", "paper", "plastic"])
self.trash = tra + sh
self.kind = "glass"
self.glass += len(self.trash)
2020-05-02 17:10:49 +02:00
return True
elif trash == 4:
#cardboard BLUE
tra = self.createTrash(random.randint(1,3), ["cardboard"])
sh = self.createTrash((random.randint(0,2)), ["cardboard", "glass", "metal", "paper", "plastic"])
self.trash = tra + sh
self.kind = "cardboard"
self.cardboard += len(self.trash)
2020-05-02 17:10:49 +02:00
return True
elif trash == 5:
#metal BLACK
tra = self.createTrash(random.randint(1,3), ["metal"])
sh = self.createTrash((random.randint(0,2)), ["cardboard", "glass", "metal", "paper", "plastic"])
self.trash = tra + sh
self.kind = "metal"
self.metal += len(self.trash)
2020-05-02 17:10:49 +02:00
return True
else:
return False
def empty(self, i):
if i == "plastic":
2020-05-02 17:10:49 +02:00
self.plastic -= 1
#print("taking plastic")
2020-05-02 17:10:49 +02:00
return True
elif i == "paper":
2020-05-02 17:10:49 +02:00
self.paper -= 1
#print("taking paper")
2020-05-02 17:10:49 +02:00
return True
elif i == "glass":
2020-05-02 17:10:49 +02:00
self.glass -= 1
#print("taking glass")
2020-05-02 17:10:49 +02:00
return True
elif i == "cardboard":
self.cardboard -= 1
#print("taking cardboard")
2020-05-02 17:10:49 +02:00
return True
elif i == "metal":
self.metal -= 1
#print("taking metal")
2020-05-02 17:10:49 +02:00
return True
else:
return False
def colour(self):
if self.plastic > 0:
self.color = 1
return True
elif self.paper > 0:
self.color = 2
return True
elif self.glass > 0:
self.color = 3
return True
elif self.cardboard > 0:
2020-05-02 17:10:49 +02:00
self.color = 4
return True
elif self.metal > 0:
2020-05-02 17:10:49 +02:00
self.color = 5
return True
else:
return False