Back to index

freevial  1.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
common.database.Database Class Reference

List of all members.

Public Member Functions

def __init__
def __len__
def addQuestion
def question
def currentQuestionNumber

Public Attributes

 num
 name
 language
 description
 players
 authors
 time
 image
 sound
 shuffled

Private Member Functions

def _shuffle
def _get_question

Private Attributes

 _questions
 _old_questions
 _shuffled

Detailed Description

Definition at line 29 of file database.py.


Constructor & Destructor Documentation

def common.database.Database.__init__ (   self,
  num,
  name,
  language,
  description,
  players,
  authors,
  time,
  image,
  sound 
)

Definition at line 31 of file database.py.

00031 
00032        def __init__( self, num, name, language, description, players, authors, time, image, sound ):
00033               
00034               # General Database Data
00035               self.num = num       # provisional, should be removed soon
00036               self.name = unicode(name)
00037               self.language = unicode(language)
00038               self.description = unicode(description)
00039               self.players = unicode(players)
00040               self.authors = unicode(authors)
00041               self.time = [ time[0], time[1] ]
00042               self.image = image
00043               self.sound = sound
00044               
00045               # Questions
00046               self._questions = []
00047               self._old_questions = []
00048               
00049               # Internal Variables
00050               self._shuffled = False
       

Member Function Documentation

Returns the total amount of questions in this database. 

Definition at line 51 of file database.py.

00051 
00052        def __len__( self ):
00053               """ Returns the total amount of questions in this database. """
00054               
00055               return len( self._questions ) + len( self._old_questions )
       
def common.database.Database._get_question (   self) [private]
Returns the next question in a list, where the first answer
    is the correct one. 

Definition at line 62 of file database.py.

00062 
00063        def _get_question( self ):
00064               """ Returns the next question in a list, where the first answer
00065                   is the correct one. """
00066               
00067               if len(self._questions) == 0:
00068                      print _(u'All questions in category «%s» have been answered. Reshuffling...') %  self.name
00069                      self._questions = deepcopy(self._old_questions)
00070                      self._old_questions = []
00071                      self.shuffled = False
00072               
00073               if not self._shuffled:
00074                      self._shuffle()
00075               
00076               self._old_questions.append( self._questions.pop() )
00077               
00078               return self._old_questions[-1]
       

Here is the caller graph for this function:

def common.database.Database._shuffle (   self) [private]
Shuffles the question list. 

Definition at line 56 of file database.py.

00056 
00057        def _shuffle( self ):
00058               """ Shuffles the question list. """
00059               
00060               shuffle(self._questions)
00061               self._shuffled = True
       
def common.database.Database.addQuestion (   self,
  question,
  answ1,
  answ2,
  answ3,
  author,
  comment 
)

Definition at line 79 of file database.py.

00079 
00080        def addQuestion( self, question, answ1, answ2, answ3, author, comment):
00081               
00082               self._questions.append( [question, answ1, answ2, answ3, 1, author, comment] )
       

Definition at line 101 of file database.py.

00101 
00102        def currentQuestionNumber( self ):
00103               
00104               return len(self._old_questions)
Returns the next question in a dictionary (with the answers
    in a random position). 

Definition at line 83 of file database.py.

00083 
00084        def question( self ):
00085               """ Returns the next question in a dictionary (with the answers
00086                   in a random position). """
00087               
00088               data = self._get_question()
00089               answer_order = sample(xrange(1, 4), 3)
00090               
00091               question = {}
00092               question['text'] = data[0]
00093               question['opt1'] = data[answer_order[0]]
00094               question['opt2'] = data[answer_order[1]]
00095               question['opt3'] = data[answer_order[2]]
00096               question['answer'] = answer_order.index(1) + 1
00097               question['author'] = data[5]
00098               question['comment'] = data[6]
00099               
00100               return question
       

Here is the call graph for this function:


Member Data Documentation

Definition at line 46 of file database.py.

Definition at line 45 of file database.py.

Definition at line 49 of file database.py.

Definition at line 39 of file database.py.

Definition at line 37 of file database.py.

Definition at line 41 of file database.py.

Definition at line 36 of file database.py.

Definition at line 35 of file database.py.

Definition at line 34 of file database.py.

Definition at line 38 of file database.py.

Definition at line 70 of file database.py.

Definition at line 42 of file database.py.

Definition at line 40 of file database.py.


The documentation for this class was generated from the following file: