Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clément Foucher
SEIR DEVS Simulator
Commits
59d4a334
Commit
59d4a334
authored
Jun 08, 2022
by
Clément Foucher
Browse files
Add CSV export.
parent
07f6ec64
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
59d4a334
.vscode
__pycache__
*.csv
config.py
View file @
59d4a334
# Default values
DEFAULT_WIDHT
=
30
0
DEFAULT_HEIGHT
=
30
0
DEFAULT_WIDHT
=
25
0
DEFAULT_HEIGHT
=
25
0
DEFAULT_AGENT_COUNT
=
10000
DEFAULT_AGENT_INFECTED_RATIO
=
0.1
...
...
gui/gui.py
View file @
59d4a334
# 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
(
"1
500x100
0+200+
10
0"
)
self
.
gui
.
geometry
(
"1
450x96
0+200+
5
0"
)
# 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
'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment