Added house stats, removed hud display

This commit is contained in:
Magdalena Wilczyńska 2019-03-27 10:20:22 +01:00
parent 5454710e15
commit 04ee4fc1da
8 changed files with 78 additions and 30 deletions

13
game.py
View File

@ -25,7 +25,7 @@ interactables = {
##GAMEWINDOW########################## ##GAMEWINDOW##########################
WINDOW_WIDTH = PLAY_WIDTH WINDOW_WIDTH = PLAY_WIDTH
WINDOW_HEIGHT = PLAY_HEIGHT + HUD_HEIGHT WINDOW_HEIGHT = PLAY_HEIGHT #+ HUD_HEIGHT
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW) hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW)
display.set_caption('Smieciarz WMI') display.set_caption('Smieciarz WMI')
@ -46,14 +46,7 @@ hud_break = 0
####################################### #######################################
##INIT CSV FILE######################## ##INIT CSV FILE########################
currentDT = datetime.datetime.now() csv_name, houses_csv_name = utils.init_csv()
csv_name = "logs/stats_" + currentDT.strftime("%Y%m%d%H%M%S") + ".csv"
with open(csv_name, 'w', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
row = ['Plastic left', "Glass left", "Metal left", "GC plastic", "GC glass", "GC metal", "Total collected"]
filewriter.writerow(row)
csvfile.close()
####################################### #######################################
##GAME LOOP####################################################################### ##GAME LOOP#######################################################################
@ -86,7 +79,7 @@ while(1):
if(hud_break == 0): if(hud_break == 0):
################################### ###################################
hud.get_statistics(all_sprites, csv_name) hud.get_statistics(all_sprites, csv_name, houses_csv_name)
display.flip() display.flip()
fps_clock.tick(FPS) fps_clock.tick(FPS)
################################################################################## ##################################################################################

View File

@ -0,0 +1,12 @@
House 1 plastic,House 1 glass,House 1 metal,House 2 plastic,House 2 glass,House 2 metal,House 3 plastic,House 3 glass,House 3 metal,House 4 plastic,House 4 glass,House 4 metal
5,7,7,5,9,3,7,4,3,8,4,9
6,7,7,5,9,3,8,4,3,8,8,9
7,7,8,6,9,3,9,4,4,9,8,10
7,9,9,7,9,3,10,4,4,9,9,10
7,9,9,7,10,3,0,1,0,10,5,5
8,9,9,7,10,4,1,1,0,10,6,5
8,9,10,7,10,6,2,1,1,10,6,5
5,10,6,0,0,1,3,1,1,10,7,5
6,10,7,1,0,1,3,2,1,10,7,5
9,10,8,2,0,1,4,2,2,10,9,5
9,10,8,3,0,1,5,4,3,10,9,5
1 House 1 plastic House 1 glass House 1 metal House 2 plastic House 2 glass House 2 metal House 3 plastic House 3 glass House 3 metal House 4 plastic House 4 glass House 4 metal
2 5 7 7 5 9 3 7 4 3 8 4 9
3 6 7 7 5 9 3 8 4 3 8 8 9
4 7 7 8 6 9 3 9 4 4 9 8 10
5 7 9 9 7 9 3 10 4 4 9 9 10
6 7 9 9 7 10 3 0 1 0 10 5 5
7 8 9 9 7 10 4 1 1 0 10 6 5
8 8 9 10 7 10 6 2 1 1 10 6 5
9 5 10 6 0 0 1 3 1 1 10 7 5
10 6 10 7 1 0 1 3 2 1 10 7 5
11 9 10 8 2 0 1 4 2 2 10 9 5
12 9 10 8 3 0 1 5 4 3 10 9 5

View File

@ -0,0 +1,5 @@
House 1 plastic,House 1 glass,House 1 metal,House 2 plastic,House 2 glass,House 2 metal,House 3 plastic,House 3 glass,House 3 metal,House 4 plastic,House 4 glass,House 4 metal
10,10,3,10,9,0,8,0,10,3,3,7
10,10,4,10,10,0,9,1,10,3,3,7
0,1,0,10,10,0,9,1,10,4,4,7
1,2,0,10,10,2,9,1,10,5,5,7
1 House 1 plastic House 1 glass House 1 metal House 2 plastic House 2 glass House 2 metal House 3 plastic House 3 glass House 3 metal House 4 plastic House 4 glass House 4 metal
2 10 10 3 10 9 0 8 0 10 3 3 7
3 10 10 4 10 10 0 9 1 10 3 3 7
4 0 1 0 10 10 0 9 1 10 4 4 7
5 1 2 0 10 10 2 9 1 10 5 5 7

View File

@ -1,18 +0,0 @@
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
27,21,18,0/10,0/10,0/10,0
30,21,20,0/10,0/10,0/10,0
31,23,21,0/10,0/10,0/10,0
33,25,23,0/10,0/10,0/10,0
34,26,24,0/10,0/10,0/10,0
34,32,26,0/10,0/10,0/10,0
34,32,26,0/10,0/10,0/10,0
35,32,28,0/10,0/10,0/10,0
38,36,33,0/10,0/10,0/10,0
29,26,24,10/10,10/10,10/10,30
30,26,25,0/10,10/10,10/10,30
30,27,27,0/10,0/10,0/10,30
23,18,18,10/10,10/10,10/10,60
13,10,19,10/10,10/10,10/10,80
13,11,22,1/10,1/10,10/10,82
14,13,13,2/10,3/10,10/10,95
14,14,15,0/10,0/10,0/10,95
1 Plastic left Glass left Metal left GC plastic GC glass GC metal Total collected
2 27 21 18 0/10 0/10 0/10 0
3 30 21 20 0/10 0/10 0/10 0
4 31 23 21 0/10 0/10 0/10 0
5 33 25 23 0/10 0/10 0/10 0
6 34 26 24 0/10 0/10 0/10 0
7 34 32 26 0/10 0/10 0/10 0
8 34 32 26 0/10 0/10 0/10 0
9 35 32 28 0/10 0/10 0/10 0
10 38 36 33 0/10 0/10 0/10 0
11 29 26 24 10/10 10/10 10/10 30
12 30 26 25 0/10 10/10 10/10 30
13 30 27 27 0/10 0/10 0/10 30
14 23 18 18 10/10 10/10 10/10 60
15 13 10 19 10/10 10/10 10/10 80
16 13 11 22 1/10 1/10 10/10 82
17 14 13 13 2/10 3/10 10/10 95
18 14 14 15 0/10 0/10 0/10 95

View File

@ -0,0 +1,12 @@
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
25,24,22,0/10,0/10,0/10,0
27,28,22,0/10,0/10,0/10,0
31,28,25,0/10,0/10,0/10,0
33,31,26,0/10,0/10,0/10,0
24,25,17,10/10,10/10,10/10,30
26,26,18,0/10,0/10,10/10,30
27,26,22,0/10,0/10,0/10,30
18,18,13,10/10,10/10,10/10,60
20,19,14,10/10,10/10,10/10,60
25,21,16,10/10,0/10,0/10,60
27,23,17,0/10,0/10,0/10,60
1 Plastic left Glass left Metal left GC plastic GC glass GC metal Total collected
2 25 24 22 0/10 0/10 0/10 0
3 27 28 22 0/10 0/10 0/10 0
4 31 28 25 0/10 0/10 0/10 0
5 33 31 26 0/10 0/10 0/10 0
6 24 25 17 10/10 10/10 10/10 30
7 26 26 18 0/10 0/10 10/10 30
8 27 26 22 0/10 0/10 0/10 30
9 18 18 13 10/10 10/10 10/10 60
10 20 19 14 10/10 10/10 10/10 60
11 25 21 16 10/10 0/10 0/10 60
12 27 23 17 0/10 0/10 0/10 60

View File

@ -0,0 +1,5 @@
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
31,22,20,0/10,0/10,0/10,0
32,24,21,0/10,0/10,0/10,0
23,16,17,10/10,10/10,4/10,24
25,18,19,10/10,0/10,0/10,24
1 Plastic left Glass left Metal left GC plastic GC glass GC metal Total collected
2 31 22 20 0/10 0/10 0/10 0
3 32 24 21 0/10 0/10 0/10 0
4 23 16 17 10/10 10/10 4/10 24
5 25 18 19 10/10 0/10 0/10 24

View File

@ -26,7 +26,7 @@ class Hud():
overall_text = font.render("Garbage thrown away: 0",True,WHITE) overall_text = font.render("Garbage thrown away: 0",True,WHITE)
GAMEWINDOW.blit(overall_text,(20, 20)) GAMEWINDOW.blit(overall_text,(20, 20))
def get_statistics(self, all_sprites, csv_name): def get_statistics(self, all_sprites, csv_name, houses_csv_name):
###Garbage collector stats### ###Garbage collector stats###
gc_taken_space_plastic = 0 gc_taken_space_plastic = 0
gc_taken_space_metal = 0 gc_taken_space_metal = 0
@ -39,12 +39,17 @@ class Hud():
glass_left = 0 glass_left = 0
total_gathered = 0 total_gathered = 0
houses_data = []
for item in all_sprites: for item in all_sprites:
if(type(item) == House): if(type(item) == House):
rubbish = item.get_rubbish_data() rubbish = item.get_rubbish_data()
plastic_left += rubbish[0] plastic_left += rubbish[0]
glass_left += rubbish[1] glass_left += rubbish[1]
metal_left += rubbish[2] metal_left += rubbish[2]
houses_data.append(str(rubbish[0]))
houses_data.append(str(rubbish[1]))
houses_data.append(str(rubbish[2]))
if(type(item) == Garbage_collector): if(type(item) == Garbage_collector):
space_taken = item.get_space_data() space_taken = item.get_space_data()
gc_taken_space_plastic += space_taken.get("plastic") gc_taken_space_plastic += space_taken.get("plastic")
@ -61,3 +66,8 @@ class Hud():
row = [str(plastic_left), str(glass_left), str(metal_left), str(gc_taken_space_plastic)+"/"+str(gc_trash_space), str(gc_taken_space_glass)+"/"+str(gc_trash_space), str(gc_taken_space_metal)+"/"+str(gc_trash_space), str(total_gathered)] row = [str(plastic_left), str(glass_left), str(metal_left), str(gc_taken_space_plastic)+"/"+str(gc_trash_space), str(gc_taken_space_glass)+"/"+str(gc_trash_space), str(gc_taken_space_metal)+"/"+str(gc_trash_space), str(total_gathered)]
filewriter.writerow(row) filewriter.writerow(row)
csvfile.close() csvfile.close()
with open(houses_csv_name, 'a', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(houses_data)
csvfile.close()

View File

@ -1,6 +1,8 @@
import sys import sys
import getopt import getopt
import random import random
import csv
import datetime
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
from sprites.cell import CELL_SIZE from sprites.cell import CELL_SIZE
from sprites.grass import Grass from sprites.grass import Grass
@ -69,3 +71,30 @@ def generate_garbage_collector(all_sprites, obstacles_coords):
all_sprites.add(gc) all_sprites.add(gc)
return gc return gc
################################################################################## ##################################################################################
##INIT CSV FILES#######################
def init_csv():
currentDT = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
stats_csv_name = "logs/stats_" + currentDT + ".csv"
with open(stats_csv_name, 'w', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
row = ["Plastic left", "Glass left", "Metal left", "GC plastic", "GC glass", "GC metal", "Total collected"]
filewriter.writerow(row)
csvfile.close()
houses_csv_name = "logs/houses_stats_" + currentDT + ".csv"
with open(houses_csv_name, 'w', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
row = []
for i in range(home_amount):
row.append("House "+str(i+1)+" plastic")
row.append("House "+str(i+1)+" glass")
row.append("House "+str(i+1)+" metal")
filewriter.writerow(row)
csvfile.close()
return stats_csv_name, houses_csv_name
#######################################