4from pprint
import pprint
14PROBLEM_REQUEST_REVIEW = 0x01
18 """A problem in the Pafera Learning System is defined as a
19 collection of cards. The two required cards are a problem card and
20 an answer card, but cards can also be added to explain how to do the
21 problem
or explicitly define choices
for multiple choice challenges.
23 Like cards, a problem also has owners
and editors,
and will be
24 copied
if someone does
not have permission to change the original card.
28 'rid': (
'INTEGER PRIMARY KEY',
'NOT NULL',),
29 'problemid': (
'INT',
'NOT NULL'),
30 'answerid': (
'INT',
'NOT NULL'),
31 'explanationid': (
'INT',
'NOT NULL DEFAULT 0'),
32 'choice1id': (
'INT',
'NOT NULL DEFAULT 0'),
33 'choice2id': (
'INT',
'NOT NULL DEFAULT 0'),
34 'choice3id': (
'INT',
'NOT NULL DEFAULT 0'),
35 'choice4id': (
'INT',
'NOT NULL DEFAULT 0'),
36 'choice5id': (
'INT',
'NOT NULL DEFAULT 0'),
37 'choice6id': (
'INT',
'NOT NULL DEFAULT 0'),
38 'choice7id': (
'INT',
'NOT NULL DEFAULT 0'),
39 'timelimit': (
'INT16',
'NOT NULL DEFAULT 0'),
40 'points': (
'INT16',
'NOT NULL DEFAULT 0'),
41 'ownerid': (
'INT',
'NOT NULL',),
42 'editors': (
'NEWLINELIST',
"NOT NULL DEFAULT ''",),
43 'flags': (
'INT',
'NOT NULL DEFAULT 0'),
46 _dblinks = [
'learn_card']
47 _dbdisplay = [
'problemid',
'answerid']
58 problemtype = CARD_LINK_PROBLEM,
61 """This function returns a list of problems as dicts given lesson ids
62 or explicit problem ids.
68 if not isinstance(cardids, list):
71 cardids = list(set(cardids))
73 for cardid
in cardids:
74 c = g.db.Load(learn_card, cardid,
'rid')
79 extraproblemids = list(set(extraproblemids))
81 for r
in g.db.LoadMany(
83 [x
for x
in extraproblemids],
93 problemcardids.append(r.problemid)
94 problemcardids.append(r.answerid)
98 if len(problemcardids) == 0:
101 problemcardids = list(set(problemcardids))
103 for r
in g.db.LoadMany(
106 'rid, content, image, sound, video',
108 o = r.ToJSON(
'content, image, sound, video')
112 cards[o[
'idcode']] = o
117 if p[
'problemidcode']
not in cards
or p[
'answeridcode']
not in cards
or not cards[p[
'problemidcode']]
or not cards[p[
'answeridcode']]:
118 print(f
'''GetAllProblems():\tSkipping incomplete problem with ID {p['idcode']}''')
121 p[
'problem'] = cards[p[
'problemidcode']]
122 p[
'answer'] = cards[p[
'answeridcode']]
124 intactproblems.append(p)
126 return intactproblems
130 """A helper function for GetAllProblems() to iterate through
133 for r
in g.db.Linked(card, learn_card, CARD_CHILD, fields =
'rid'):
136 for r
in g.db.Linked(card, learn_problem, problemtype, fields =
'rid, problemid, answerid'):
145 problemcardids.append(r.problemid)
146 problemcardids.append(r.answerid)
A problem in the Pafera Learning System is defined as a collection of cards.
def __init__(self)
Initialize all fields at creation like a good programmer should.
Base class for all database models.
def GetAllProblems(g, cardids, problemtype=CARD_LINK_PROBLEM, extraproblemids=[])
This function returns a list of problems as dicts given lesson ids or explicit problem ids.
def GetChildProblems(g, card, problems, problemcardids, problemtype)
A helper function for GetAllProblems() to iterate through lesson trees.
def ToShortCode(val, chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_')
Turns a 32-bit value into a six character alphanumeric code.