Commit 59d4a334 authored by Clément Foucher's avatar Clément Foucher
Browse files

Add CSV export.

parent 07f6ec64
.vscode
__pycache__
*.csv
# Default values
DEFAULT_WIDHT = 300
DEFAULT_HEIGHT = 300
DEFAULT_WIDHT = 250
DEFAULT_HEIGHT = 250
DEFAULT_AGENT_COUNT = 10000
DEFAULT_AGENT_INFECTED_RATIO = 0.1
......
# Tkinter
from tkinter import *
from tkinter import filedialog
# Matplotlib
import matplotlib.pyplot as plt
......@@ -46,6 +47,7 @@ class Gui():
self.label_i = Label(self.top_bar_results, text = "I: " + str(infected_agents) + "; ")
self.label_r = Label(self.top_bar_results, text = "R: 0")
self.button_results = Button(self.top_bar_results, text = "Draw results", command = self.draw_results)
self.button_export = Button(self.top_bar_results, text = "Export results", command = self.export_results)
# Build grid
self.display_area = Frame(self.main_frame)
......@@ -54,7 +56,7 @@ class Gui():
self.h_scroll = Scrollbar(self.display_area, command = self.grid.xview, orient=HORIZONTAL)
self.grid.configure(xscrollcommand=self.h_scroll.set, yscrollcommand=self.v_scroll.set, scrollregion=self.grid.bbox("all"))
self.gui.geometry("1500x1000+200+100")
self.gui.geometry("1450x960+200+50")
# Pack
self.main_frame.pack()
......@@ -74,6 +76,7 @@ class Gui():
self.label_i.grid(row = 0, column = 3)
self.label_r.grid(row = 0, column = 4)
self.button_results.grid(row = 0, column = 5)
self.button_export.grid(row = 0, column = 6)
self.grid.grid(row = 0, column = 0)
self.v_scroll.grid(row = 0, column = 1, sticky="ns")
......@@ -196,3 +199,21 @@ class Gui():
self.update_results()
self.update_gui()
def export_results(self):
savefile = filedialog.asksaveasfile(parent=self.gui, defaultextension=".csv")
(resS, resE, resI, resR) = self.normalize_results()
savefile.write("timestamp,S,E,I,R\n")
for i in range(0, len(self.results['t'])):
savefile.write(str(self.results['t'][i]))
savefile.write(',')
savefile.write(str(resS[i]))
savefile.write(',')
savefile.write(str(resE[i]))
savefile.write(',')
savefile.write(str(resI[i]))
savefile.write(',')
savefile.write(str(resR[i]))
savefile.write('\n')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment