Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-04-20 22:33:09 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-04-20 22:33:09 (GMT)
commited90ac4d7a676251732c783fe47c9d24ce47d6af (patch)
tree665e0390d6bbd56cd4215b44829604c782375002
parent2c9f84baf82de7d7bab14a5b4289f86d4bebfd20 (diff)
using myplate instead of food pyramid
-rw-r--r--NutritionActivity.py9
-rw-r--r--game.py101
-rw-r--r--icons/pyramid-game.svg30
3 files changed, 85 insertions, 55 deletions
diff --git a/NutritionActivity.py b/NutritionActivity.py
index 9330ec2..4838de4 100644
--- a/NutritionActivity.py
+++ b/NutritionActivity.py
@@ -25,7 +25,7 @@ from sugar import mime
from gettext import gettext as _
-from game import Game, GAME_DEFS
+from game import Game, FOOD
from toolbar_utils import separator_factory, radio_factory, label_factory, \
button_factory, entry_factory, combo_factory
@@ -39,7 +39,8 @@ LABELS = [_('Match the food to its name.'),
_('How many calories are there?'),
_('How much should you eat?'),
_('Is this a well-balanced meal?')]
-PYRAMID = [_('sweets'), _('meat and dairy'), _('fruits and grains')]
+PYRAMID = [_('sweets'), _('dairy'), _('fruits'), _('meat'), _('grains'),
+ _('vegetables')]
class NutritionActivity(activity.Activity):
""" Simple nutrition game based on GCompris ImageID """
@@ -75,7 +76,7 @@ class NutritionActivity(activity.Activity):
pyramid = int(self.metadata['pyramid-%d' % (i)])
jobject = datastore.get(self.metadata['jobject-%d' % (i)])
_logger.debug(jobject.file_path)
- GAME_DEFS.append([name, calories, pyramid, 'apple.png'])
+ FOOD.append([name, calories, pyramid, 'apple.png'])
self._game.word_card_append()
self._game.picture_append(jobject.file_path)
self._game.small_picture_append(jobject.file_path)
@@ -263,7 +264,7 @@ item.')
return
_logger.debug(self._custom_food_jobject.file_path)
- GAME_DEFS.append([name, calories, pyramid, 'apple.png'])
+ FOOD.append([name, calories, pyramid, 'apple.png'])
self._game.word_card_append()
self._game.picture_append(self._custom_food_jobject.file_path)
self._game.small_picture_append(self._custom_food_jobject.file_path)
diff --git a/game.py b/game.py
index ad5d817..642adba 100644
--- a/game.py
+++ b/game.py
@@ -30,30 +30,34 @@ except ImportError:
from sprites import Sprites, Sprite
-# Food Pyramid
-LEVELS = [_('minimum'), _('moderate'), _('most'), _('unlimited')]
-# Food name; calories; food pyramid level, image file name
-GAME_DEFS = [[_('banana'), 105, 2, 'banana.png'],
+# ChooseMyPlate.gov
+LEVELS = [_('minimum'), _('moderate'), _('more'), _('most'), _('unlimited')]
+MYPLATE = [[_('sweets'), 0], [_('dairy'), 1], [_('fruits'), 2],
+ [_('meat'), 2], [_('grains'), 3], [_('vegetables'), 3],
+ [_('water'), 4]]
+
+# Food name; calories; myplate category, image file name
+FOOD = [[_('banana'), 105, 2, 'banana.png'],
[_('apple'), 72, 2, 'apple.png'],
- [_('fish'), 58, 1, 'fish.png'],
- [_('corn'), 96, 2, 'corn.png'],
- [_('broccoli'), 55, 2, 'broccoli.png'],
- [_('chicken'), 262, 1, 'chicken.png'],
+ [_('fish'), 58, 3, 'fish.png'],
+ [_('corn'), 96, 4, 'corn.png'],
+ [_('broccoli'), 55, 5, 'broccoli.png'],
+ [_('chicken'), 262, 3, 'chicken.png'],
[_('cheese'), 114, 1, 'cheese.png'],
[_('orange'), 62, 2, 'orange.png'],
- [_('potato'), 159, 2, 'potato.png'],
- [_('water'), 0, 3, 'water.png'],
- [_('tomato'), 150, 2, 'tomato.png'],
+ [_('potato'), 159, 5, 'potato.png'],
+ [_('water'), 0, 6, 'water.png'],
+ [_('tomato'), 150, 5, 'tomato.png'],
[_('cookie'), 68, 0, 'cookie.png'],
- [_('beef'), 284, 1, 'beef.png'],
- [_('egg'), 77, 1, 'egg.png'],
- [_('sweetpotato'), 169, 2, 'sweetpotato.png'],
- [_('tamale'), 126, 2, 'nacatamal.png'],
- [_('bread'), 69, 2, 'bread.png'],
- [_('rice and beans'), 411, 2, 'rice-and-beans.png'],
+ [_('beef'), 284, 3, 'beef.png'],
+ [_('egg'), 77, 3, 'egg.png'],
+ [_('sweetpotato'), 169, 5, 'sweetpotato.png'],
+ [_('tamale'), 126, 5, 'nacatamal.png'],
+ [_('bread'), 69, 4, 'bread.png'],
+ [_('rice and beans'), 411, 4, 'rice-and-beans.png'],
[_('cake'), 387, 0, 'cake.png']]
GAME4 = [_('balanced'), _('unbalanced')]
-NCARDS = 4
+NCARDS = 5
class Game():
@@ -89,18 +93,18 @@ class Game():
self._backgrounds[-1].hide()
self._picture_cards = []
- for i in GAME_DEFS:
+ for i in FOOD:
self.picture_append(os.path.join(self._path, 'images', i[-1]))
self._small_picture_cards = []
- for i in GAME_DEFS:
+ for i in FOOD:
self.small_picture_append(os.path.join(self._path, 'images', i[-1]))
self._word_cards = []
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
os.path.join(self._path, 'images', 'word-box.png'),
int(350 * self._scale), int(100 * self._scale))
- for i in GAME_DEFS:
+ for i in FOOD:
self.word_card_append(pixbuf=pixbuf)
self._smile = Sprite(self._sprites,
@@ -166,7 +170,7 @@ class Game():
for i, w in enumerate(self._word_cards):
w.set_label_color('black')
if self.level in [0, 1]:
- w.set_label(GAME_DEFS[i][self.level])
+ w.set_label(FOOD[i][self.level])
else:
w.set_label('')
w.hide()
@@ -193,9 +197,9 @@ class Game():
# Select N cards
self._list = []
for i in range(NCARDS):
- j = int(uniform(0, len(GAME_DEFS)))
+ j = int(uniform(0, len(FOOD)))
while j in self._list:
- j = int(uniform(0, len(GAME_DEFS)))
+ j = int(uniform(0, len(FOOD)))
self._list.append(j)
# Show the word cards from the list
@@ -215,9 +219,9 @@ class Game():
def _games_4(self):
''' A well-balanced meal '''
# Fill the Food Pyramid
- self._food_pyramid = [[], [], [], []]
- for i, f in enumerate(GAME_DEFS):
- self._food_pyramid[f[2]].append(i)
+ self._my_plate = [[], [], [], [], []]
+ for i, f in enumerate(FOOD):
+ self._my_plate[MYPLATE[f[2]][1]].append(i)
x = 10 # some small offset from the left edge
y = 10 # some small offset from the top edge
@@ -230,22 +234,26 @@ class Game():
self._word_cards[i].set_label(GAME4[i])
y += int(dy * 1.25)
- n = [0, 0, 0]
- n[0] = int(uniform(0, 5))
- n[1] = int(uniform(0, 6 - n[0]))
- n[2] = 6 - n[0] - n[1]
+ n = [0, 0, 0, 0]
+ n[0] = int(uniform(0, 2.5))
+ n[1] = int(uniform(0, 3 - n[0]))
+ n[2] = 3 - n[0] - n[1]
+ n[3] = 6 - n[0] - n[1] - n[2]
self._list = []
for i in range(n[0]): # Sweets
- self._list.append(self._food_pyramid[0][
- int(uniform(0, len(self._food_pyramid[0])))])
- for i in range(n[1]): # Meats and dairy
- self._list.append(self._food_pyramid[1][
- int(uniform(0, len(self._food_pyramid[1])))])
- for i in range(n[2]): # Veggies and fruits
- self._list.append(self._food_pyramid[2][
- int(uniform(0, len(self._food_pyramid[2])))])
-
- if n[0] < n[1] and n[1] < n[2]: # Balanced meal
+ self._list.append(self._my_plate[0][
+ int(uniform(0, len(self._my_plate[0])))])
+ for i in range(n[1]): # Dairy
+ self._list.append(self._my_plate[1][
+ int(uniform(0, len(self._my_plate[1])))])
+ for i in range(n[2]): # Protein and Fruits
+ self._list.append(self._my_plate[2][
+ int(uniform(0, len(self._my_plate[2])))])
+ for i in range(n[3]): # Veggies and Grains
+ self._list.append(self._my_plate[3][
+ int(uniform(0, len(self._my_plate[3])))])
+
+ if n[0] < 2 and n[1] < 2 and n[2] < n[3]: # Balanced meal
self._target = True
else:
self._target = False
@@ -271,7 +279,7 @@ class Game():
i = self._word_cards.index(spr)
self._word_cards[i].set_label_color('red')
if self.level in [0, 1]:
- self._word_cards[i].set_label(GAME_DEFS[i][self.level])
+ self._word_cards[i].set_label(FOOD[i][self.level])
elif self.level == 2:
j = self._list.index(i)
self._word_cards[i].set_label(LEVELS[j])
@@ -284,20 +292,19 @@ class Game():
self._smile.set_layer(200)
if self.level == 0:
self._smile.set_label(_('%d calories') % (
- GAME_DEFS[self._list[self._target]][1]))
+ FOOD[self._list[self._target]][1]))
else:
self._frown.set_layer(200)
self._frown.set_label(
- GAME_DEFS[self._list[self._target]][self.level])
+ FOOD[self._list[self._target]][self.level])
elif self.level == 2:
- if j == GAME_DEFS[self._list[self._target]][2]:
+ if j == MYPLATE[FOOD[self._list[self._target]][2]][1]:
self._smile.set_layer(200)
else:
self._frown.set_layer(200)
self._frown.set_label(
- LEVELS[GAME_DEFS[self._list[self._target]][2]])
+ LEVELS[MYPLATE[FOOD[self._list[self._target]][2]][1]])
else:
- _logger.debug('%s, %d' % (str(self._target), i))
if self._target and i == 0:
self._smile.set_layer(200)
elif not self._target and i == 1:
diff --git a/icons/pyramid-game.svg b/icons/pyramid-game.svg
index 64ae964..4fdc660 100644
--- a/icons/pyramid-game.svg
+++ b/icons/pyramid-game.svg
@@ -72,8 +72,30 @@
id="path3852"
style="fill:#a0a0a0;fill-opacity:1;stroke:none" />
</g>
- <path
- d="m 7.4659057,37.85432 33.0664883,0 L 24.121617,8.3918316 z"
- id="path4692"
- style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.25785267px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <g
+ transform="matrix(0.18712321,0,0,0.18710157,19.089796,31.786893)"
+ id="g3901"
+ style="stroke-width:5.34438133;stroke-miterlimit:4;stroke-dasharray:none">
+ <path
+ d="m 162.46154,-13.538462 a 83.307693,81.46154 0 1 1 -166.6153867,0 83.307693,81.46154 0 1 1 166.6153867,0 z"
+ transform="matrix(1.0203139,0,0,1.0434372,-38.761772,-7.8734669)"
+ id="path3131"
+ style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:5.17961407;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 39.692308,-31.307692 -67.384616,-0.461539 c 0,0 5.896026,-28.689145 22.6153849,-44.076923 C 10.618599,-90.291637 39.078262,-92.5398 38.769231,-92.230769 z"
+ id="path3068"
+ style="fill:none;stroke:#000000;stroke-width:5.34438133;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 44.769231,-13.320778 67.384619,0.46154 c 0,0 -5.89603,28.689142 -22.615388,44.07692 -15.695522,14.44548 -44.155185,16.69365 -43.846154,16.38461 z"
+ id="path3068-4"
+ style="fill:none;stroke:#000000;stroke-width:5.34438133;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 46.153844,-18.371525 67.384616,-0.461539 c 0,0 -3.56539,-37.021813 -20.307694,-52.384615 C 72.458323,-90.278547 45.383279,-92.065171 45.692309,-91.75614 z"
+ id="path3068-6"
+ style="fill:none;stroke:#000000;stroke-width:5.34438133;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ d="m 40.383306,-25.09178 -67.384616,0.46154 c 0,0 -1.049995,32.4064294 17.5384694,52.384616 C 9.7413787,48.394353 41.153876,48.601872 40.844846,48.292832 z"
+ id="path3068-6-0"
+ style="fill:none;stroke:#000000;stroke-width:5.34438133;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ </g>
</svg>