From: NilsForssen Date: Mon, 7 Mar 2022 07:55:58 +0000 (+0100) Subject: update X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=14295e7a094feb67ed6bcd89ab97be468b0bef04;p=TDDE44.git update --- diff --git a/laboration4/adventure.py b/laboration4/adventure.py index 21c5932..29157dd 100644 --- a/laboration4/adventure.py +++ b/laboration4/adventure.py @@ -55,7 +55,7 @@ def main(): print_desc(current_state) current_state = get_next_state(current_state) - +# Non-refractored code def main_old(): current_state = "Start" succ_states = ADVENTURE_TREE[current_state] diff --git a/laboration4/gamedata.py b/laboration4/gamedata.py index 6e632ef..85503d9 100644 --- a/laboration4/gamedata.py +++ b/laboration4/gamedata.py @@ -27,7 +27,7 @@ PICTURES = { "Sneak_left": print_ded, "Die": print_game_over, "Talk": print_guard, - "Red": print_dragon, + "Red": print_dragon, "Chest": print_treasure, "Talk_not_noice": print_ded, "Win": print_win diff --git a/laboration4/uppgift_1.py b/laboration4/uppgift_1.py index 6fe0806..aed2142 100644 --- a/laboration4/uppgift_1.py +++ b/laboration4/uppgift_1.py @@ -1,26 +1,34 @@ +#!/usr/bin/env python3 + import matplotlib import numpy as np import matplotlib.pyplot as plt import sys import common - +# Mainloop def main(): + + # Matplotlib setup matplotlib.use('AGG') plt.figure() + try: csv_file_path = sys.argv[1] except IndexError: raise ValueError("Need csv file argument") + + d1 = common.load_csv(csv_file_path) x, y = prepare_data(d1) draw_diagram1(x, y) + plt.ylabel("Cups of coffee") plt.xlabel("Time of day") plt.savefig("uppgift_1.png") - return +# Format the data into relevant axis def prepare_data(data): new_list = [] x_values = [] @@ -28,23 +36,26 @@ def prepare_data(data): for rader in data: new_list.append(rader.split(";")) + # Ignore day tag new_list = new_list[1:] + # Convert data from str to int for i, rad in enumerate(new_list): for j, s in enumerate(rad): new_list[i][j] = int(s.strip()) - # [int(s.strip()) for rad in new_list[1:] for s in rad] + # Sum up y values for rad in new_list: x_values.append(rad[0]) y_values.append(sum(rad[1:])) + return (x_values, y_values) +# Uses data as arguments and draws it onto axis def draw_diagram1(x_values, y_values): plt.plot(x_values, y_values) - if __name__ == "__main__": main()