Informatik10/quiz/neuesquiz_data.py

70 lines
2.1 KiB
Python

from random import sample, choice
DEBUG = True
class Quizdata():
""" Data Model
"""
def __init__(self, controller):
self.con = controller
# TODO: full list of presidents
self.D = {1: "George Washington",
2: "John Adams",
3: "Thomas Jefferson",
4: "James Madison",
5: "James Monroe",
6: "John Quincy Adams",
7: "Andrew Jackson",
8: "Martin Van Buren",
9: "William Henry Harrison",
10: "John Tyler",
11: "James K. Polk",
12: "Zachary Tayler",
13: "Millard Fillmore",
14: "Franklin Pierce",
15: "James Buchanan",
16: "Abraham Lincoln",
17: "Andrew Johnson",
18: "Ulysses S. Grant",
19: "Rutherford B. Hayes",
20: "James A. Garfield",
21: "Chester A. Arthur"
}
self.list_of_names = list(self.D.values())
def get_random_sample_dict(self, number: int = 4):
# get list of selected keys
selection = sample(sorted(self.D), number)
# construct dictionary of selected elements
selection_D = dict()
for key in selection:
selection_D[key] = self.D[key]
return selection_D
def get_single_from_sample_dict(self, selection_D):
# get random single element from dict
chosen = choice(sorted(selection_D)) # int (key)
# construct dictionary of chosen element
chosen_D = dict()
chosen_D[chosen] = self.D[chosen]
return chosen_D
def test_get_random_sample(self):
s = self.get_random_sample_dict()
print("Quizdata.test: {}".format(s))
# TODO: implement loading of data from file
def load_from_file(self, filename: str = None):
pass
# TODO: saving to file + editor of data
def save_to_file(self, filename: str = None):
pass