Added importing stats to csv file
This commit is contained in:
parent
f5bc39f5ab
commit
adde0b2286
23
game.py
23
game.py
@ -6,6 +6,8 @@ from sprites.house import House
|
|||||||
from sprites.hud import Hud
|
from sprites.hud import Hud
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
import utils
|
import utils
|
||||||
|
import csv
|
||||||
|
import datetime
|
||||||
|
|
||||||
##INITIALIZE STATIC VARIABLES#########
|
##INITIALIZE STATIC VARIABLES#########
|
||||||
FPS = 20
|
FPS = 20
|
||||||
@ -39,9 +41,20 @@ utils.generate_houses(all_sprites, interactables)
|
|||||||
gc = utils.generate_garbage_collector(all_sprites, interactables)
|
gc = utils.generate_garbage_collector(all_sprites, interactables)
|
||||||
##
|
##
|
||||||
|
|
||||||
##REMOVE THAT#
|
##COUNTER FOR HUB BRAKE IN CONSOLE#####
|
||||||
hud_break = 0
|
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()
|
||||||
|
#######################################
|
||||||
|
|
||||||
##GAME LOOP#######################################################################
|
##GAME LOOP#######################################################################
|
||||||
while(1):
|
while(1):
|
||||||
@ -68,12 +81,12 @@ while(1):
|
|||||||
if(type(item) == House):
|
if(type(item) == House):
|
||||||
item.generate_rubbish()
|
item.generate_rubbish()
|
||||||
|
|
||||||
##REMOVE THAT#
|
##LIMIT LOGS TO 1 LOG EVERY 2s#####
|
||||||
hud_break = (hud_break + 1) % (FPS*2)
|
hud_break = (hud_break + 1) % (FPS*2)
|
||||||
|
|
||||||
if(hud_break == 0):
|
if(hud_break == 0):
|
||||||
##
|
###################################
|
||||||
hud.get_statistics(all_sprites)
|
hud.get_statistics(all_sprites, csv_name)
|
||||||
display.flip()
|
display.flip()
|
||||||
fps_clock.tick(FPS)
|
fps_clock.tick(FPS)
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
18
logs/stats_20190327083321.csv
Normal file
18
logs/stats_20190327083321.csv
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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
|
|
0
persons.csv
Normal file
0
persons.csv
Normal file
|
@ -2,6 +2,7 @@ import pygame
|
|||||||
from sprites.house import House
|
from sprites.house import House
|
||||||
from sprites.garbage_collector import Garbage_collector
|
from sprites.garbage_collector import Garbage_collector
|
||||||
from config import HUD_HEIGHT
|
from config import HUD_HEIGHT
|
||||||
|
import csv
|
||||||
HUD_COLOR = (51,21,4)
|
HUD_COLOR = (51,21,4)
|
||||||
WHITE = (255,255,255)
|
WHITE = (255,255,255)
|
||||||
class Hud():
|
class Hud():
|
||||||
@ -25,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):
|
def get_statistics(self, all_sprites, 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
|
||||||
@ -54,3 +55,9 @@ class Hud():
|
|||||||
print("plastic left: "+str(plastic_left)+" | glass left: "+str(glass_left)+" | metal left: "+str(metal_left))
|
print("plastic left: "+str(plastic_left)+" | glass left: "+str(glass_left)+" | metal left: "+str(metal_left))
|
||||||
print(" plastic: "+str(gc_taken_space_plastic)+"/"+str(gc_trash_space)+" | glass: "+str(gc_taken_space_glass)+"/"+str(gc_trash_space)+" | metal: "+str(gc_taken_space_metal)+"/"+str(gc_trash_space))
|
print(" plastic: "+str(gc_taken_space_plastic)+"/"+str(gc_trash_space)+" | glass: "+str(gc_taken_space_glass)+"/"+str(gc_trash_space)+" | metal: "+str(gc_taken_space_metal)+"/"+str(gc_trash_space))
|
||||||
print("### TOTAL COLLECTED: "+str(total_gathered)+" ###")
|
print("### TOTAL COLLECTED: "+str(total_gathered)+" ###")
|
||||||
|
|
||||||
|
with open(csv_name, 'a', newline='') as csvfile:
|
||||||
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user