From 04ee4fc1dabf88ca8eea97b0fa0c50973686df18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Wilczy=C5=84ska?= Date: Wed, 27 Mar 2019 10:20:22 +0100 Subject: [PATCH] Added house stats, removed hud display --- game.py | 13 +++---------- logs/houses_stats_20190327101235.csv | 12 ++++++++++++ logs/houses_stats_20190327101837.csv | 5 +++++ logs/stats_20190327083321.csv | 18 ----------------- logs/stats_20190327101235.csv | 12 ++++++++++++ logs/stats_20190327101837.csv | 5 +++++ sprites/hud.py | 14 ++++++++++++-- utils.py | 29 ++++++++++++++++++++++++++++ 8 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 logs/houses_stats_20190327101235.csv create mode 100644 logs/houses_stats_20190327101837.csv delete mode 100644 logs/stats_20190327083321.csv create mode 100644 logs/stats_20190327101235.csv create mode 100644 logs/stats_20190327101837.csv diff --git a/game.py b/game.py index 67e47f3..9907e26 100644 --- a/game.py +++ b/game.py @@ -25,7 +25,7 @@ interactables = { ##GAMEWINDOW########################## 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) hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW) display.set_caption('Smieciarz WMI') @@ -46,14 +46,7 @@ hud_break = 0 ####################################### ##INIT CSV FILE######################## -currentDT = datetime.datetime.now() -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() +csv_name, houses_csv_name = utils.init_csv() ####################################### ##GAME LOOP####################################################################### @@ -86,7 +79,7 @@ while(1): if(hud_break == 0): ################################### - hud.get_statistics(all_sprites, csv_name) + hud.get_statistics(all_sprites, csv_name, houses_csv_name) display.flip() fps_clock.tick(FPS) ################################################################################## diff --git a/logs/houses_stats_20190327101235.csv b/logs/houses_stats_20190327101235.csv new file mode 100644 index 0000000..57f499f --- /dev/null +++ b/logs/houses_stats_20190327101235.csv @@ -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 diff --git a/logs/houses_stats_20190327101837.csv b/logs/houses_stats_20190327101837.csv new file mode 100644 index 0000000..1c1fab1 --- /dev/null +++ b/logs/houses_stats_20190327101837.csv @@ -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 diff --git a/logs/stats_20190327083321.csv b/logs/stats_20190327083321.csv deleted file mode 100644 index dbcd3e9..0000000 --- a/logs/stats_20190327083321.csv +++ /dev/null @@ -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 diff --git a/logs/stats_20190327101235.csv b/logs/stats_20190327101235.csv new file mode 100644 index 0000000..092009d --- /dev/null +++ b/logs/stats_20190327101235.csv @@ -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 diff --git a/logs/stats_20190327101837.csv b/logs/stats_20190327101837.csv new file mode 100644 index 0000000..ce35944 --- /dev/null +++ b/logs/stats_20190327101837.csv @@ -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 diff --git a/sprites/hud.py b/sprites/hud.py index eb5a83b..48e9fa0 100644 --- a/sprites/hud.py +++ b/sprites/hud.py @@ -26,7 +26,7 @@ class Hud(): overall_text = font.render("Garbage thrown away: 0",True,WHITE) 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### gc_taken_space_plastic = 0 gc_taken_space_metal = 0 @@ -39,12 +39,17 @@ class Hud(): glass_left = 0 total_gathered = 0 + houses_data = [] + for item in all_sprites: if(type(item) == House): rubbish = item.get_rubbish_data() plastic_left += rubbish[0] glass_left += rubbish[1] 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): space_taken = item.get_space_data() gc_taken_space_plastic += space_taken.get("plastic") @@ -60,4 +65,9 @@ class Hud(): filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) 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) - 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() diff --git a/utils.py b/utils.py index 25aaef9..d05ef20 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,8 @@ import sys import getopt import random +import csv +import datetime from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount from sprites.cell import CELL_SIZE from sprites.grass import Grass @@ -69,3 +71,30 @@ def generate_garbage_collector(all_sprites, obstacles_coords): all_sprites.add(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 +#######################################