Added source field to generated json input
- the key 'source' has as the value the url to the source of the question - If not source is specified it is set to 'false'
This commit is contained in:
parent
e8cc69ca12
commit
b143c4dbc1
|
@ -40,11 +40,24 @@ class Question(yaml.YAMLObject):
|
||||||
"""
|
"""
|
||||||
yaml_tag = u"!Question"
|
yaml_tag = u"!Question"
|
||||||
web_root = "data"
|
web_root = "data"
|
||||||
media_path = ""
|
|
||||||
|
|
||||||
# {round_no1: [tier1, tier2, ...], round_no2: [tier1, ...]}
|
# {round_no1: [tier1, tier2, ...], round_no2: [tier1, ...]}
|
||||||
registered_questions = {}
|
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,
|
1: 100,
|
||||||
2: 150,
|
2: 150,
|
||||||
3: 225,
|
3: 225,
|
||||||
|
@ -59,8 +72,11 @@ class Question(yaml.YAMLObject):
|
||||||
12: 7531,
|
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,
|
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__
|
"""docstring for __init__
|
||||||
@question - the Question
|
@question - the Question
|
||||||
@rank - number of the question in the game
|
@rank - number of the question in the game
|
||||||
|
@ -68,14 +84,12 @@ class Question(yaml.YAMLObject):
|
||||||
@answers - list of answers, assumed are 4
|
@answers - list of answers, assumed are 4
|
||||||
@media - (media show at question time, media shown at answer time,
|
@media - (media show at question time, media shown at answer time,
|
||||||
media shown at resolution time)
|
media shown at resolution time)
|
||||||
@media_path - src path to the media files
|
@media_path - path to the media files
|
||||||
@web_root - path to media files on the web server
|
|
||||||
"""
|
"""
|
||||||
self.question = question
|
self.question = question
|
||||||
self.answers = answers
|
self.answers = answers
|
||||||
self.tier = tier
|
self.tier = tier
|
||||||
self.game_round = game_round
|
self.game_round = game_round
|
||||||
self.source = source
|
|
||||||
self.media = media
|
self.media = media
|
||||||
self.media_path = media_path
|
self.media_path = media_path
|
||||||
self.web_root = web_root
|
self.web_root = web_root
|
||||||
|
@ -108,11 +122,11 @@ class Question(yaml.YAMLObject):
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data['text'] = self.question
|
data['text'] = self.question
|
||||||
|
data['tier'] = self.points.get(int(self.tier), 0)
|
||||||
try:
|
try:
|
||||||
data['source'] = self.source
|
data['source'] = self.source
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
data['source'] = ""
|
data['source'] = False
|
||||||
data['tier'] = self.points.get(int(self.tier), 0)
|
|
||||||
data['answers'] = [
|
data['answers'] = [
|
||||||
{'text': answer[False]} if answer.has_key(False) \
|
{'text': answer[False]} if answer.has_key(False) \
|
||||||
else {'text': answer[True], 'right': True} \
|
else {'text': answer[True], 'right': True} \
|
||||||
|
@ -122,14 +136,9 @@ class Question(yaml.YAMLObject):
|
||||||
def gen_questions():
|
def gen_questions():
|
||||||
q_data = {}
|
q_data = {}
|
||||||
for f in self.media['question']:
|
for f in self.media['question']:
|
||||||
try:
|
q_data[self.__type_by_extension(
|
||||||
q_data[self.__type_by_extension(
|
os.path.sep.join(os.path.join([self.media_path, f]))
|
||||||
os.path.sep.join(os.path.join([self.media_path, f])
|
)] = os.sep.join([self.web_root, f])
|
||||||
)
|
|
||||||
)] = os.sep.join([self.web_root, f])
|
|
||||||
except AttributeError, e:
|
|
||||||
raise AttributeError, \
|
|
||||||
"Question {0} cannot be generated: {1}".format(self.question, e)
|
|
||||||
return q_data
|
return q_data
|
||||||
def gen_explanation():
|
def gen_explanation():
|
||||||
return {'explanation': [os.sep.join([self.web_root, expl]) \
|
return {'explanation': [os.sep.join([self.web_root, expl]) \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user