diff --git a/tools/questions2json.py b/tools/questions2json.py index a14dabc..7224215 100755 --- a/tools/questions2json.py +++ b/tools/questions2json.py @@ -40,11 +40,24 @@ class Question(yaml.YAMLObject): """ yaml_tag = u"!Question" web_root = "data" - media_path = "" # {round_no1: [tier1, tier2, ...], round_no2: [tier1, ...]} registered_questions = {} - points = { + points_fixed = { + 1: 100, + 2: 150, + 3: 225, + 4: 337, + 5: 506, + 6: 759, + 7: 1139, + 8: 1709, + 9: 2563, + 10: 3844, + 11: 5555, + 12: 7531, + } + points_rnd_by_round = { 1: 100, 2: 150, 3: 225, @@ -59,8 +72,11 @@ class Question(yaml.YAMLObject): 12: 7531, } + # kinda a symlink to the points generating dict + points = points_rnd_by_round + def __init__(self, question=u"", tier=0, answers=[], game_round=0, - media=("", "", ""), source="", media_path="", web_root="data"): + media=("", "", ""), media_path="data", web_root="data"): """docstring for __init__ @question - the Question @rank - number of the question in the game @@ -68,14 +84,12 @@ class Question(yaml.YAMLObject): @answers - list of answers, assumed are 4 @media - (media show at question time, media shown at answer time, media shown at resolution time) - @media_path - src path to the media files - @web_root - path to media files on the web server + @media_path - path to the media files """ self.question = question self.answers = answers self.tier = tier self.game_round = game_round - self.source = source self.media = media self.media_path = media_path self.web_root = web_root @@ -108,11 +122,11 @@ class Question(yaml.YAMLObject): data = {} data['text'] = self.question + data['tier'] = self.points.get(int(self.tier), 0) try: data['source'] = self.source except AttributeError: - data['source'] = "" - data['tier'] = self.points.get(int(self.tier), 0) + data['source'] = False data['answers'] = [ {'text': answer[False]} if answer.has_key(False) \ else {'text': answer[True], 'right': True} \ @@ -122,14 +136,9 @@ class Question(yaml.YAMLObject): def gen_questions(): q_data = {} for f in self.media['question']: - try: - q_data[self.__type_by_extension( - os.path.sep.join(os.path.join([self.media_path, f]) - ) - )] = os.sep.join([self.web_root, f]) - except AttributeError, e: - raise AttributeError, \ - "Question {0} cannot be generated: {1}".format(self.question, e) + q_data[self.__type_by_extension( + os.path.sep.join(os.path.join([self.media_path, f])) + )] = os.sep.join([self.web_root, f]) return q_data def gen_explanation(): return {'explanation': [os.sep.join([self.web_root, expl]) \