[gcompris] lang-activity, normalize the number of triplets to 12.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] lang-activity, normalize the number of triplets to 12.
- Date: Fri, 10 May 2013 08:55:33 +0000 (UTC)
commit 5e1f20a484cb961f35efe3e33b12ce5f553fef2f
Author: Bruno Coudoin <bcoudoin rcsmobility com>
Date: Tue May 7 01:02:08 2013 +0200
lang-activity, normalize the number of triplets to 12.
src/lang-activity/langLib.py | 56 +++++++++++++++++++++++++++++++++---------
1 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/src/lang-activity/langLib.py b/src/lang-activity/langLib.py
index c8ef019..465dab5 100644
--- a/src/lang-activity/langLib.py
+++ b/src/lang-activity/langLib.py
@@ -65,30 +65,60 @@ class Triplet:
+ " / " + str(self.type)
class Lesson:
- def __init__(self, elem):
+
+ def __init__(self, lesson):
self.name = None
self.description = None
self.triplets = []
+ if lesson:
+ self.name = lesson.name
+ self.description = lesson.description
+
+ def getTriplets(self):
+ return self.triplets
+
+ def dump(self):
+ print " Lesson "+ self.name + " / " + str(self.description)
+ for triplet in self.triplets:
+ triplet.dump()
+
+
+class LessonCreator:
+
+ MAX_TRIPLETS = 12
+
+ def __init__(self, elem):
+ self.lessons = []
self.parse(elem)
def parse(self, elem):
+ lesson = Lesson(None)
for e in elem.childNodes:
if isNode(e, "name"):
- self.name = e.firstChild.nodeValue
+ lesson.name = e.firstChild.nodeValue
elif isNode(e, "description"):
- self.description = e.firstChild.nodeValue if e.firstChild else None
+ lesson.description = e.firstChild.nodeValue if e.firstChild else None
elif isNode(e, "Triplet"):
triplet = Triplet(e)
if triplet.isValid():
- self.triplets.append( triplet )
+ if len(lesson.triplets) < self.MAX_TRIPLETS:
+ lesson.triplets.append( triplet )
+ else:
+ self.lessons.append(lesson)
+ lesson = Lesson(lesson)
+
+
+ if len(lesson.triplets) < self.MAX_TRIPLETS:
+ # There is no enough triplet for this level, add the first
+ # of the first lesson
+ if len(self.lessons):
+ for triplet in self.lessons[0].getTriplets()[0:self.MAX_TRIPLETS-len(lesson.triplets)]:
+ lesson.triplets.append(triplet)
+ self.lessons.append(lesson)
- def getTriplets(self):
- return self.triplets
- def dump(self):
- print " Lesson "+ self.name + " / " + str(self.description)
- for triplet in self.triplets:
- triplet.dump()
+ def getLessons(self):
+ return self.lessons
class Chapter:
@@ -105,7 +135,9 @@ class Chapter:
elif isNode(e, "description"):
self.description = e.firstChild.nodeValue if e.firstChild else None
elif isNode(e, "Lesson"):
- self.lessons.append( Lesson(e) )
+ lessonCreator = LessonCreator(e)
+ for lesson in lessonCreator.getLessons():
+ self.lessons.append( lesson )
def getLessons(self):
return self.lessons
@@ -130,7 +162,7 @@ class Chapters:
def dump(self):
print "Dump"
- for chapter in self.chapters:
+ for k, chapter in self.chapters.iteritems():
chapter.dump()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]