Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefanie Nobel <stefanie.nobel@googlemail.com>2011-08-28 12:40:54 (GMT)
committer Stefanie Nobel <stefanie.nobel@googlemail.com>2011-08-28 12:40:54 (GMT)
commit09589d4ac67fea7fdca56673aa66eb4e94f19ec0 (patch)
tree3a9521c96ead3d0453719dd9fe9fb79a6579de8a
parentfea038ff741a2b8a5da670fc5dc710426be9ba2e (diff)
parentb1db04eb335745ba1261e18bbf0602ab9740ab4f (diff)
merge databasesolutions
-rw-r--r--DATABASEbin12288 -> 0 bytes
-rw-r--r--DATABASE2bin6144 -> 0 bytes
-rwxr-xr-xactivity/activity.info4
-rw-r--r--config.ini8
-rwxr-xr-xfiles/dbinput.txt27
-rwxr-xr-xfiles/dbinputsparetime.txt5
-rw-r--r--lib/server/_server.py7
-rw-r--r--lib/server/flask/_app.py10
-rw-r--r--lib/server/tools/storage.py20
-rw-r--r--nutrinoweb/activity.py56
-rw-r--r--nutrinoweb/controllers/Avatar.py170
-rw-r--r--nutrinoweb/controllers/database_manager.py103
-rw-r--r--nutrinoweb/controllers/eating.py10
-rw-r--r--nutrinoweb/controllers/main.py8
-rw-r--r--nutrinoweb/controllers/sparetime.py4
-rw-r--r--nutrinoweb/ui/toolbar.py17
-rw-r--r--run.py2
-rwxr-xr-xsample/dbinput.txt28
-rw-r--r--sample/schema1.sql29
-rw-r--r--schema/schema1.sql29
-rw-r--r--schema/schema2.sql30
-rw-r--r--templates/layout.html1
22 files changed, 439 insertions, 129 deletions
diff --git a/DATABASE b/DATABASE
deleted file mode 100644
index 04bff30..0000000
--- a/DATABASE
+++ /dev/null
Binary files differ
diff --git a/DATABASE2 b/DATABASE2
deleted file mode 100644
index 60f0676..0000000
--- a/DATABASE2
+++ /dev/null
Binary files differ
diff --git a/activity/activity.info b/activity/activity.info
index 539a853..3ffc4c1 100755
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -2,6 +2,10 @@
name = NutrinoWeb
activity_version = 1
service_name = org.laptop.NutrinoWebActivity
+<<<<<<< HEAD
icon = activity-NutriWeb
+=======
+icon = activity-nutrinoweb
+>>>>>>> b1db04eb335745ba1261e18bbf0602ab9740ab4f
class = nutrinoweb.activity.NutrinoWebActivity
license = gplv3
diff --git a/config.ini b/config.ini
index 1b1c094..971e2aa 100644
--- a/config.ini
+++ b/config.ini
@@ -1,2 +1,10 @@
[activity]
name = nutriweb
+# ...
+debug = True
+# ...
+use-toolbar = True
+
+[server]
+# ...
+port = 8008
diff --git a/files/dbinput.txt b/files/dbinput.txt
new file mode 100755
index 0000000..1e53b29
--- /dev/null
+++ b/files/dbinput.txt
@@ -0,0 +1,27 @@
+BUTTER WITH SALT|15.87|0.06|24|0.02|2|24|24|714|0.09|0|0|0.005|0.034|0.042|0.11|0.003|3|0.17|684|2.32|1.5|0.85|0|rack
+CHEESE CHEDDAR|36.75|0.52|721|0.68|28|512|98|621|3.11|0.031|0|0.027|0.375|0.08|0.413|0.074|18|0.83|265|0.29|0.6|24.9|0|rack
+CREAM|80.57|0.16|105|0.07|10|95|130|41|0.51|0.01|0.9|0.035|0.149|0.078|0.289|0.039|3|0.33|97|0.33|0.2|2.96|0|fridge
+MILK|87.67|0|128|0.05|13|97|139|57|0.36|0.01|0.9|0.03|0.123|0.087|0.301|0.04|5|0.34|2|0|0|3.33|0|fridge
+YOGURT|87.9|4.66|121|0.05|12|95|155|46|0.59|0.009|0.5|0.029|0.142|0.075|0.389|0.032|7|0.37|27|0.06|0.1|3.47|0|fridge
+OMELET|76.13|0.31|48|1.48|11|167|117|155|1.09|0.063|0|0.034|0.386|0.064|1.289|0.143|39|0.76|172|1.29|1.7|10.57|0|fridge
+SALAD DRSNG. FRENCH|54.28|16.86|11|0.73|8|16|107|838|0.2|0.16|4.8|0.024|0.052|0.467|0|0.055|2|0|27|1|0|0.58|0|rack
+OIL|0|0|1|0.56|0|0|1|2|0|0|0|0|0|0|0|0|0|0|0|14.35|0|0|0|rack
+CHICKEN|52.41|0|17|1.38|25|191|234|84|2.04|0.075|0|0.087|0.193|8.992|1.079|0.41|9|0.31|27|0.63|0.1|28.56|0|meatcounter
+TURKEY|70.61|0|15|1.69|22|180|269|67|2.31|0.114|0.2|0.065|0.203|4.148|0.953|0.41|23|1.62|102|0|0|20.37|0|meatcounter
+SOUP TURKEY NOODLES|86.37|0.41|9|0.75|4|38|60|650|0.46|0.1|0.1|0.059|0.051|1.112|0.14|0.03|15|0.13|13|0.14|0|3.11|0|rack
+SAUSAGE PORK|56.11|0.11|57|0.73|13|178|206|848|2.25|0.07|0|0.249|0.16|2.9|0.76|0.13|3|1.73|0|0|0.3|12.89|0|meatcounter
+KELLOGG'S CORN FLAKES|3.76|10.5|4|29|9|37|79|723|0.18|0.108|22|2.13|2.64|24.4|0.079|3.44|480|9.47|456|0.13|3.6|6.61|0|rack
+MELONS HONEY|89.82|8.12|6|0.17|10|11|228|18|0.09|0.024|18|0.038|0.012|0.418|0.155|0.088|19|0|3|0.02|0|0.54|0|fruits
+ORANGES|86.75|9.35|40|0.1|10|14|181|0|0.07|0.045|53.2|0.087|0.04|0.282|0.25|0.06|30|0|11|0.18|0|0.94|0|fruits
+BLUEBERRIES|70.63|19.28|19|2.2|6|14|46|1|0.12|0|0.3|0.033|0.313|0.469|0.041|0.035|8|0|0|0|0|0.56|0|fruits
+PINEAPPLE|83.51|14.26|16|0.28|15|7|124|1|0.1|0.107|9.4|0.102|0.021|0.284|0|0.075|5|0|3|0.02|0|0.51|0|fruits
+APRICOTS|77.56|18.65|10|0.3|7|13|143|4|0.11|0.097|3.1|0.021|0.024|0.376|0|0.055|2|0|146|0.89|0|0.64|0|fruits
+CHERRIES|77.61|16.18|10|0.35|9|20|148|3|0.1|0.176|3.6|0.022|0.043|0.396|0.06|0.022|5|0|12|0.17|0|0.73|0|fruits
+PEACHES|80.62|14.66|3|0.27|5|12|94|6|0.09|0.063|0.7|0.02|0.02|0.625|0.024|0.013|9|0|31|1.19|0|0.52|0|fruits
+PORK|74.31|0|14|1.2|22|202|339|65|3.36|0.102|0|0.558|0.384|4.387|1.567|0.521|0|0.91|0|0.24|0.6|18.73|0|meatcounter
+POTATO PANCAKES|47.77|1.79|32|1.67|36|128|622|764|0.7|0.18|27.6|0.158|0.173|1.672|0.757|0.448|41|0.29|32|0.23|0.3|6.08|0|fridge
+ARTICHOKES|84.08|0.99|21|0.61|42|73|286|60|0.4|0.127|7.4|0.05|0.089|1.11|0.24|0.081|89|0|1|0.19|0|2.89|0|fruits
+COCONUT MEAT|46.99|6.23|14|2.43|32|113|356|20|1.1|0.435|3.3|0.066|0.02|0.54|0.3|0.054|26|0|0|0.24|0|3.33|0|fruits
+BEEF|58.1|0|11|2.7|19|168|429|1439|3.98|0.034|0|0.08|0.19|5.27|0.59|0.34|11|2.57|0|0|0.1|28.11|0|meatcounter
+BREAD|64.9|3.92|26|0.94|13|34|62|455|0.23|0.069|0.8|0.117|0.092|1.247|0.06|0.038|97|0.01|78|0.85|0|2.9|0|rack
+WATER|640.9|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|rack \ No newline at end of file
diff --git a/files/dbinputsparetime.txt b/files/dbinputsparetime.txt
new file mode 100755
index 0000000..35ebfe5
--- /dev/null
+++ b/files/dbinputsparetime.txt
@@ -0,0 +1,5 @@
+Swimming|3.3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
+COOKING|3.3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
+READING|3.3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
+SOCCER|3.3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
+SLEEPING|3.3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
diff --git a/lib/server/_server.py b/lib/server/_server.py
index eb7f94c..cdc9164 100644
--- a/lib/server/_server.py
+++ b/lib/server/_server.py
@@ -1,13 +1,14 @@
-# python import
-import atexit, multiprocessing
# server import
from server import config
-from server.flask import app, run_app
class Server(object):
def __init__(self):
+ # python import
+ import atexit, multiprocessing
+ # ..
+ from server.flask import run_app
# start the server
self._server = multiprocessing.Process(target=run_app)
self._server.start()
diff --git a/lib/server/flask/_app.py b/lib/server/flask/_app.py
index bc6f3b3..89d9cb4 100644
--- a/lib/server/flask/_app.py
+++ b/lib/server/flask/_app.py
@@ -14,6 +14,7 @@ APP_NAME = 'my_activity' if APP_NAME is None else APP_NAME
# get app config values
_debug = config.Config().get('server>debug')
_key = config.Config().get('server>secret_key')
+_port = config.Config().get('server>port', type_=int)
# flask import
import flask
@@ -22,10 +23,11 @@ import flask
try:
from sugar.activity import activity
BUNDLE = activity.get_bundle_path()
- ROOT = activity.get_bundle_path()
+ ROOT = activity.get_activity_root()
except Exception, e:
- BUNDLE = '.'
- ROOT = '.'
+ BUNDLE = os.path.abspath(os.path.join(
+ os.path.dirname(__file__), '..', '..', '..'))
+ ROOT = BUNDLE
# init app
app = flask.Flask(__name__)
@@ -53,7 +55,7 @@ except Exception:
def run_app():
"""run method to trigger at from python class.
"""
- app.run()
+ app.run(port=_port)
def render(template, **context):
diff --git a/lib/server/tools/storage.py b/lib/server/tools/storage.py
index 535eb66..1c2455e 100644
--- a/lib/server/tools/storage.py
+++ b/lib/server/tools/storage.py
@@ -12,14 +12,30 @@ ACTIVITY_NAMES = {
}
+def check_dir(path):
+ if os.path.exists(path):
+ pass
+ else:
+ os.mkdir(path)
+
+
+def check_file(path):
+ if os.path.exists(path):
+ pass
+ else:
+ _f = open(path, 'wb')
+ _f.write('')
+ _f.close()
+
+
def get_path(path=None, bundle=True):
# ..
- path = 'static' if path is None else os.path.join('static', path)
+ path = 'static' if path is None else path
# ..
if bundle is True:
return os.path.join(BUNDLE, path)
else:
- return os.path.join(ROOT, 'data', path)
+ return os.path.join(ROOT, path)
def list_dir(path=None, bundle=True):
diff --git a/nutrinoweb/activity.py b/nutrinoweb/activity.py
index 7722908..f02b619 100644
--- a/nutrinoweb/activity.py
+++ b/nutrinoweb/activity.py
@@ -1,5 +1,5 @@
# python import
-import logging
+import os, sys, threading, time
# gettext import
from gettext import gettext as _
@@ -8,15 +8,45 @@ from sugar.activity import activity
# hulahop import
from hulahop.webview import WebView
-# atoideweb import - first to update lib path
-import run
+# add lib path to current python path
+sys.path.append(os.path.join(activity.get_bundle_path(), 'lib'))
# server import
from server import config
-from server.flask import logger
+from server.flask import app, run_app as __run, logger
+# nutriweb import
+from nutrinoweb.controllers import app
-URL_BASE = 'http://localhost:5000/'
+
+# get port from config
+_port = config.Config().get('server>port', type_=int)
+_port = '5000' if _port is None or _port == '' else _port
+# ..
+URL_BASE = 'http://localhost:%s' % _port
+
+
+class ThreadServer(threading.Thread):
+
+ def __init__(self, activity_):
+ # init parent
+ threading.Thread.__init__(self)
+ # main flag
+ self._die = False
+ # start right now
+ self.start()
+
+ def kill(self):
+ self._die = True
+
+ def run(self):
+ # do run
+ __run()
+ # ...
+ while self._die is False:
+ continue
+ # ..
+ del app
def _toolbar_changed(toolbox, page, activity_):
@@ -25,22 +55,24 @@ def _toolbar_changed(toolbox, page, activity_):
# is the activity tab?
if page == 0:
# show the activity screen
- activity_.change_screen('activity')
+ activity_.change_screen('main')
else:
pass
# propagate it
return True
-class NutrinoWebActivity(run.Server, activity.Activity):
+class NutrinoWebActivity(activity.Activity):
def __init__(self, handle):
+ # init thread server
+ self._thread = ThreadServer(self)
+ # ..
+ time.sleep(5)
# init parents
activity.Activity.__init__(self, handle)
self.max_participants = 1
# ..
- run.Server.__init__(self)
- # ..
if config.Config().get('activity>use-toolbar', type_=bool):
self.__init_toolbar()
else:
@@ -56,7 +88,7 @@ class NutrinoWebActivity(run.Server, activity.Activity):
return self._toolbox
def change_screen(self, name):
- self.web_view.load_uri(URL_BASE + name)
+ self.web_view.load_uri('%s/%s' % (URL_BASE, name))
def __init_toolbar(self):
"""Keep an example of how to manage toolbar in our webapp ...
@@ -93,5 +125,7 @@ class NutrinoWebActivity(run.Server, activity.Activity):
pass
def close(self, skip_save=False):
- run.Server.close(self)
+ # stop the thread
+ self._thread.kill()
+ # ..
activity.Activity.close(self, skip_save=True)
diff --git a/nutrinoweb/controllers/Avatar.py b/nutrinoweb/controllers/Avatar.py
index 3eaab37..a804218 100644
--- a/nutrinoweb/controllers/Avatar.py
+++ b/nutrinoweb/controllers/Avatar.py
@@ -1,51 +1,99 @@
-import os
-import json
+#import os
+#import json
-path_to_this_file = os.path.abspath( __file__ )
-temp_json = os.path.join(os.path.dirname(path_to_this_file), "../../sample/status.json")
+#path_to_this_file = os.path.abspath( __file__ )
+#temp_json = os.path.join(os.path.dirname(path_to_this_file), "../../sample/status.json")
+# python import
+import os, json
+
+# server import
+from server.tools import storage
+DATA = storage.get_path(path='data', bundle=False)
+
+# ensure path
+storage.check_dir(DATA)
+
+# status path
+DATA_STATUS = os.path.join(DATA, 'status.json')
+# ..
+storage.check_file(DATA_STATUS)
class Character:
-
+
def __init__(self):
-
- self.water = 0.0
- self.energie = 0.0
- self.calcium = 0.0
- self.iron = 0.0
- self.magnesium = 0.0
- self.phosphorus = 0.0
- self.potassium = 0.0
- self.sodium = 0.0
- self.zinc = 0.0
- self.copper = 0.0
- self.vit_c = 0.0
- self.thiamin = 0.0
- self.riboflavin = 0.0
- self.niacin = 0.0
- self.panto_acid = 0.0
- self.vit_b6 = 0.0
- self.folate_tot = 0.0
- self.vit_b12 = 0.0
- self.vit_a = 0.0
- self.vit_e = 0.0
- self.vit_d = 0.0
- self.vit_total = 0.0
- self.construction = 0.0
+ self.water = 0.0
+ self.energie = 0.0
+ self.calcium = 0.0
+ self.iron = 0.0
+ self.magnesium = 0.0
+ self.phosphorus = 0.0
+ self.potassium = 0.0
+ self.sodium = 0.0
+ self.zinc = 0.0
+ self.copper = 0.0
+ self.vit_c = 0.0
+ self.thiamin = 0.0
+ self.riboflavin = 0.0
+ self.niacin = 0.0
+ self.panto_acid = 0.0
+ self.vit_b6 = 0.0
+ self.folate_tot = 0.0
+ self.vit_b12 = 0.0
+ self.vit_a = 0.0
+ self.vit_e = 0.0
+ self.vit_d = 0.0
+ self.vit_total = 0.0
+ self.construction = 0.0
def load_status(self):
- fh = open(temp_json,'r')
+ fh = open(DATA_STATUS,'r')
status = json.load(fh)
fh.close()
return status
+ def load_status1(self):
+
+ fobj = open(DATA_STATUS)
+
+ zuordnung = fobj.read().split("|")
+
+ # little check - TODO nicer check
+ if len(zuordnung) < 23:
+ pass
+ else:
+ # OK!
+ self.water = zuordnung[1]
+ self.energie = zuordnung[2]
+ self.calcium = zuordnung[3]
+ self.iron =zuordnung[4]
+ self.magnesium = zuordnung[5]
+ self.phosphorus = zuordnung[6]
+ self.potassium = zuordnung[7]
+ self.sodium = zuordnung[8]
+ self.zinc = zuordnung[9]
+ self.copper = zuordnung[10]
+ self.vit_c = zuordnung[11]
+ self.thiamin = zuordnung[12]
+ self.riboflavin = zuordnung[13]
+ self.niacin =zuordnung[14]
+ self.panto_acid = zuordnung[15]
+ self.vit_b6 = zuordnung[16]
+ self.folate_tot = zuordnung[17]
+ self.vit_b12 = zuordnung[18]
+ self.vit_a = zuordnung[19]
+ self.vit_e = zuordnung[20]
+ self.vit_d = zuordnung[21]
+ self.vit_total = zuordnung[22]
+ self.construction = zuordnung[23]
+
def save_status(self, status):
- fh = open(temp_json,'w')
+ fh = open(DATA_STATUS,'w')
json.dump(status,fh)
fh.close()
- def reset_status(self):
+ def reset_status2(self):
status = {
"water": 0,
"energie": 0,
@@ -75,5 +123,63 @@ class Character:
json.dump(status,fh)
fh.close()
+ status = {
+ "water": self.water,
+ "energie": self.energie,
+ "calcium": self.calcium,
+ "iron" : self.iron,
+ "magnesium": self.magnesium,
+ "phosphorus": self.phosphorus,
+ "potassium": self.potassium,
+ "sodium": self.sodium,
+ "zinc": self.zinc,
+ "copper": self.copper,
+ "vit_c": self.vit_c,
+ "thiamin": self.thiamin,
+ "riboflavin": self.riboflavin,
+ "niacin": self.niacin,
+ "panto_acid": self.panto_acid,
+ "vit_b6": self.vit_b6,
+ "folate_tot": self.folate_tot,
+ "vit_b12": self.vit_b12,
+ "vit_a": self.vit_a,
+ "vit_e": self.vit_e,
+ "vit_d": self.vit_d,
+ "vit_total": self.vit_total,
+ "construction": self.construction
+ }
+ return status
+ def save_status1(self, water, energie, calcium, iron, magnesium, phosphorus,
+ potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin,
+ niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e,
+ vit_d, vit_total, construction):
+ fobj = open(DATA_STATUS, 'wb')
+ fobj.truncate()
+ fobj.write(
+ '|' + water
+ + '|' + energie
+ + '|' + calcium
+ + '|' + iron
+ + '|' + magnesium
+ + '|' + phosphorus
+ + '|' + potassium
+ + '|' + sodium
+ + '|' + zinc
+ + '|' + copper
+ + '|' + vit_c
+ + '|' + thiamin
+ + '|' + riboflavin
+ + '|' + niacin
+ + '|' + panto_acid
+ + '|' + vit_b6
+ + '|' + folate_tot
+ + '|' + vit_b12
+ + '|' + vit_a
+ + '|' + vit_e
+ + '|' + vit_d
+ + '|' + vit_total
+ + '|' + construction
+ )
+ fobj.close()
diff --git a/nutrinoweb/controllers/database_manager.py b/nutrinoweb/controllers/database_manager.py
index ca33419..c2e7618 100644
--- a/nutrinoweb/controllers/database_manager.py
+++ b/nutrinoweb/controllers/database_manager.py
@@ -3,12 +3,45 @@ from sqlite3 import dbapi2 as sqlite3
from contextlib import closing
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
-import re
+
+# python import
+import os, re
+
+# server import
+from server.tools import storage
+DATA = storage.get_path(path='data', bundle=False)
+SCHEMA = storage.get_path(path='schema', bundle=True)
+FILES = storage.get_path(path='files', bundle=True)
+
+# ensure paths
+storage.check_dir(DATA)
+storage.check_dir(SCHEMA)
+storage.check_dir(FILES)
+
+# DB paths
+DATABASE1 = os.path.join(DATA, 'nutrition.db')
+DATABASE2 = os.path.join(DATA, 'sparetime.db')
+DATABASE3 = os.path.join(DATA, 'aliments.db')
+
+# SCHEMA paths
+SCHEMA1 = os.path.join(SCHEMA, 'schema1.sql')
+SCHEMA2 = os.path.join(SCHEMA, 'schema2.sql')
+
+# FILE paths
+FILE_DINPUT = os.path.join(FILES, 'dbinput.txt')
+FILE_SPARTI = os.path.join(FILES, 'dbinputsparetime.txt')
+# ..
+DATA_ALIMTS = os.path.join(DATA, 'aliments.txt')
+DATA_STATUS = os.path.join(DATA, 'status.txt')
+
+# ensure FILES
+storage.check_file(FILE_DINPUT)
+storage.check_file(FILE_SPARTI)
+# ..
+storage.check_file(DATA_ALIMTS)
+storage.check_file(DATA_STATUS)
# configuration
-DATABASE = '/tmp/nutrition.db'
-DATABASE2 = '/tmp/sparetime.db'
-DATABASE3 = '/tmp/aliments.db'
DEBUG = True
SECRET_KEY = '12345'
@@ -18,58 +51,68 @@ app.config.from_envvar('NUTRINOWEB_SETTINGS', silent=True)
def connect_db(database):
"""Returns a new connection to the database."""
try:
- if database == 'nutrition':
- return sqlite3.connect('DATABASE')
- elif database == 'activity':
- return sqlite3.connect('DATABASE2')
+ print DATABASE1
+ print DATABASE2
+ print DATABASE3
+ if database == 'nutrition':
+ return sqlite3.connect(DATABASE1)
+ elif database == 'activity':
+ return sqlite3.connect(DATABASE2)
except:
- return redirect(url_for('addentry'))
+ return redirect(url_for('addentry'))
def connect_db3():
"""Returns a new connection to the database."""
- return sqlite3.connect('DATABASE3')
+ return sqlite3.connect(DATABASE3)
def init_db3():
"""Creates the database tables."""
with closing(connect_db3()) as db:
- with app.open_resource('../../sample/schema2.sql') as f:
+ with app.open_resource(SCHEMA2) as f:
db.cursor().executescript(f.read())
db.commit()
-def init_db():
+def init_db(database):
"""Creates the database tables."""
- with closing(connect_db()) as db:
- with app.open_resource('../../sample/schema.sql') as f:
- db.cursor().executescript(f.read())
- db.commit()
+ if database == 'nutrition':
+ with closing(connect_db('nutrition')) as db:
+ with app.open_resource(SCHEMA1) as f:
+ db.cursor().executescript(f.read())
+ db.commit()
+ elif database == 'activity':
+ with closing(connect_db('activity')) as db:
+ with app.open_resource(SCHEMA1) as f:
+ db.cursor().executescript(f.read())
+ db.commit()
-def load_inputfilenutrition():
+
+def load_inputfileactivities():
g.db = connect_db('activity')
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/dbinput.txt')
-
+ fobj = open(FILE_SPARTI)
+
for line in fobj:
zuordnung = line.split("|")
g.db.execute('insert into entries (title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [zuordnung[0], zuordnung[1], zuordnung[2], zuordnung[3], zuordnung[4], zuordnung[5], zuordnung[6], zuordnung[7], zuordnung[8], zuordnung[9], zuordnung[10], zuordnung[11], zuordnung[12], zuordnung[13], zuordnung[14], zuordnung[15], zuordnung[16], zuordnung[17], zuordnung[18], zuordnung[19], zuordnung[20], zuordnung[21], zuordnung[22]])
g.db.commit()
fobj.close()
-def load_inputfile():
+def load_inputfilenutrition():
g.db = connect_db('nutrition')
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/dbinputsparetime.txt')
+ fobj = open(FILE_DINPUT)
for line in fobj:
zuordnung = line.split("|")
- g.db.execute('insert into entries (title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein, path, sceanrio) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [zuordnung[0], zuordnung[1], zuordnung[2], zuordnung[3], zuordnung[4], zuordnung[5], zuordnung[6], zuordnung[7], zuordnung[8], zuordnung[9], zuordnung[10], zuordnung[11], zuordnung[12], zuordnung[13], zuordnung[14], zuordnung[15], zuordnung[16], zuordnung[17], zuordnung[18], zuordnung[19], zuordnung[20], zuordnung[21], zuordnung[22], 0, 0])
+ g.db.execute('insert into entries (title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein, path, scenario) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [zuordnung[0], zuordnung[1], zuordnung[2], zuordnung[3], zuordnung[4], zuordnung[5], zuordnung[6], zuordnung[7], zuordnung[8], zuordnung[9], zuordnung[10], zuordnung[11], zuordnung[12], zuordnung[13], zuordnung[14], zuordnung[15], zuordnung[16], zuordnung[17], zuordnung[18], zuordnung[19], zuordnung[20], zuordnung[21], zuordnung[22], zuordnung[23], zuordnung[24]])
g.db.commit()
fobj.close()
def entries():
"""Make sure we are connected to the database."""
g.db = connect_db('nutrition')
-
+ # TODO - check the table exist or create it
cur = g.db.execute('select title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein, scenario from entries order by id desc')
entries = [dict(title=row[0], water=row[1], energie=row[2], calcium=row[3], iron=row[4], magnesium=row[5], phosphorus=row[6], potassium=row[7], sodium=row[8], zinc=row[9], copper=row[10], vit_c=row[11], thiamin=row[12], riboflavin=row[13], niacin=row[14], panto_acid=row[15], vit_b6=row[16], folate_tot=row[17], vit_b12=row[18], vit_a=row[19], vit_e=row[20], vit_d=row[21], protein=row[22], scenario=row[23] ) for row in cur.fetchall()]
return entries
@@ -77,7 +120,7 @@ def entries():
def entriessparetime():
"""Make sure we are connected to the database."""
g.db = connect_db('activity')
-
+ # TODO - check the table exist or create it
cur = g.db.execute('select title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein from entries order by id desc')
entries = [dict(title=row[0], water=row[1], energie=row[2], calcium=row[3], iron=row[4], magnesium=row[5], phosphorus=row[6], potassium=row[7], sodium=row[8], zinc=row[9], copper=row[10], vit_c=row[11], thiamin=row[12], riboflavin=row[13], niacin=row[14], panto_acid=row[15], vit_b6=row[16], folate_tot=row[17], vit_b12=row[18], vit_a=row[19], vit_e=row[20], vit_d=row[21], protein=row[22]) for row in cur.fetchall()]
return entries
@@ -108,7 +151,7 @@ def delete_entry(database):
def show_entry(database):
g.db = connect_db(database)
-
+ # TODO - check the table exist or create it
if database == 'nutrition':
entry = g.db.execute('select title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein, scenario from entries where title=?', [request.form['title'].upper()]).fetchone()
elif database == 'activity':
@@ -130,30 +173,30 @@ def return_entry():
return entry
def reset_status():
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/status.txt', 'w')
+ fobj = open(DATA_STATUS, 'wb')
fobj.truncate()
fobj.write('|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0') + '|' + str('0'))
fobj.close()
def add_entry_tolist(aliment, path, quantity, unit):
g.db = connect_db('nutrition')
-
+ # TODO - check the table exist or create it
entry = g.db.execute('select title, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein from entries where title=?', [aliment]).fetchone()
-
g.db = connect_db3()
+ # TODO - check the table exist or create it
g.db.execute('insert into aliments (title, path, quantity, unit, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [aliment.lower(), path, quantity, unit, entry[1], entry[2], entry[3], entry[4], entry[5], entry[6], entry[7], entry[8], entry[9], entry[10], entry[11], entry[12], entry[13], entry[14], entry[15], entry[16], entry[17], entry[18], entry[19], entry[20], entry[21], entry[22]])
g.db.commit()
def aliments():
"""Make sure we are connected to the database."""
g.db = connect_db3()
-
+ # TODO - check the table exist or create it
cur = g.db.execute('select title, path, quantity, unit, water, energie, calcium, iron, magnesium, phosphorus, potassium, sodium, zinc, copper, vit_c, thiamin, riboflavin, niacin, panto_acid, vit_b6, folate_tot, vit_b12, vit_a, vit_e, vit_d, protein from aliments')
aliments = [dict(title=row[0], path=row[1], quantity=row[2], unit=row[3], water=row[4], energie=row[5], calcium=row[6], iron=row[7], magnesium=row[8], phosphorus=row[9], potassium=row[10], sodium=row[11], zinc=row[12], copper=row[13], vit_c=row[14], thiamin=row[15], riboflavin=row[16], niacin=row[17], panto_acid=row[18], vit_b6=row[19], folate_tot=row[20], vit_b12=row[21], vit_a=row[22], vit_e=row[23], vit_d=row[24], protein=row[25]) for row in cur.fetchall()]
return aliments
def save_aliments(aliments):
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/aliments.txt', 'w')
+ fobj = open(DATA_ALIMTS, 'wb')
fobj.truncate()
for aliment in aliments:
fobj.write('|' + str(aliment['quantity']) + ',' + aliment['title'])
diff --git a/nutrinoweb/controllers/eating.py b/nutrinoweb/controllers/eating.py
index 0fb2238..b8a9b31 100644
--- a/nutrinoweb/controllers/eating.py
+++ b/nutrinoweb/controllers/eating.py
@@ -16,8 +16,8 @@ IM_PATH = ['../static/images/journal/jauge-energie.png']
@app.route('/eating', methods=['GET', 'POST'])
def eating():
- #database_manager.init_db()
- #database_manager.load_inputfilenutrition()
+ database_manager.init_db('nutrition')
+ database_manager.load_inputfilenutrition()
entries = database_manager.entries()
IM_PATH = None
path = '../../static/images/journal/backgroundeating.png'
@@ -69,7 +69,7 @@ def eating():
_text = 'How much do you want?'
_visibilitytextbox2 = 'visible'
else:
- _text = 'Sorry, I do not have ' + request.form['title'] + '. Maybe you should ask somebody else!'
+ _text = 'Sorry, I do not have ' + request.form['title'] + '. Maybe you should ask somewhere else!'
else:
_text = 'Sorry, I do not have ' + request.form['title'] + '. Do you want something else?'
_visibilitytextbox = 'visible'
@@ -170,7 +170,7 @@ def calculateDimension(result, entries):
else:
pass
else:
- #part water
+ #part water
water = 100.0 - float(eng['water'])
#part energie
@@ -179,7 +179,7 @@ def calculateDimension(result, entries):
#part vitamine
vitamine = 100.0 - float(eng['vit_total'])
- #part construction
+ #part construction
construction = 100.0 - float(eng['construction'])
_result = [water, energie, vitamine, construction, calculateHeight(float(eng['water'])), calculateHeight(float(eng['energie'])), calculateHeight(float(eng['vit_total'])), calculateHeight(float(eng['construction']))]
diff --git a/nutrinoweb/controllers/main.py b/nutrinoweb/controllers/main.py
index 2dcbc76..3d7045a 100644
--- a/nutrinoweb/controllers/main.py
+++ b/nutrinoweb/controllers/main.py
@@ -8,7 +8,7 @@ from gettext import gettext as _
from server.flask import app, logger, render, request, jsonify
#eating import for the status
-import eating, Avatar
+import eating, Avatar, database_manager
IM_PATH = ['../static/images/journal/jauge-energie.png']
@@ -22,9 +22,9 @@ def main():
if request.method == 'POST':
if 'reset' in request.form:
- instance = Avatar.Character()
-
- instance.reset_status()
+ #instance = Avatar.Character()
+ database_manager.reset_status()
+ #instance.reset_status()
_result[0] = 100.0
_result[1] = 100.0
_result[2] = 100.0
diff --git a/nutrinoweb/controllers/sparetime.py b/nutrinoweb/controllers/sparetime.py
index 31e8752..f122767 100644
--- a/nutrinoweb/controllers/sparetime.py
+++ b/nutrinoweb/controllers/sparetime.py
@@ -14,8 +14,8 @@ IM_PATH = ['../static/images/journal/jauge-energie.png']
@app.route('/sparetime', methods=['GET', 'POST'])
def sparetime():
- #database_manager.init_db()
- #database_manager.load_inputfile()
+ database_manager.init_db('activity')
+ database_manager.load_inputfileactivities()
entries = database_manager.entriessparetime()
content = [ ]
# POST
diff --git a/nutrinoweb/ui/toolbar.py b/nutrinoweb/ui/toolbar.py
index 9266606..f0811c8 100644
--- a/nutrinoweb/ui/toolbar.py
+++ b/nutrinoweb/ui/toolbar.py
@@ -24,26 +24,27 @@ def _cb_next(widget, toolbar, next_):
BUTTONS = {
- 'post' : ['document-generic', _cb_next],
- 'ajax' : ['document-generic', _cb_next],
- 'gallery' : ['document-generic', _cb_next],
- 'separator' : [None, None]
+ 'main' : ['document-generic', _cb_next],
+ 'eating' : ['document-generic', _cb_next],
+ 'sparetime': ['document-generic', _cb_next],
+ 'separator': [None, None]
}
TOOLBARS = {
'menu' : [
- ['post', 'ajax'],
+ ['main', 'eating', 'sparetime'],
[]
],
}
TITLES = {
'menu' : {
- 'toolbox': _('Menu'),
+ 'toolbox': _('Debug'),
'buttons': {
- 'post': _('Post'),
- 'ajax': _('Ajax')
+ 'main' : _('Activity'),
+ 'eating' : _('Eating'),
+ 'sparetime': _('Sparetime')
}
}
}
diff --git a/run.py b/run.py
index cce0c65..3709078 100644
--- a/run.py
+++ b/run.py
@@ -6,7 +6,7 @@ try:
from sugar.activity import activity
BUNDLE = activity.get_bundle_path()
except Exception, e:
- BUNDLE = '.'
+ BUNDLE = os.path.dirname(__file__)
# add lib path to current python path
sys.path.append(os.path.join(BUNDLE, 'lib'))
diff --git a/sample/dbinput.txt b/sample/dbinput.txt
index b9d4a11..52d5803 100755
--- a/sample/dbinput.txt
+++ b/sample/dbinput.txt
@@ -1,27 +1 @@
-BUTTER WITH SALT|15.87|0.06|24|0.02|2|24|24|714|0.09|0|0|0.005|0.034|0.042|0.11|0.003|3|0.17|684|2.32|1.5|0.85
-CHEESE CHEDDAR|36.75|0.52|721|0.68|28|512|98|621|3.11|0.031|0|0.027|0.375|0.08|0.413|0.074|18|0.83|265|0.29|0.6|24.9
-CREAM|80.57|0.16|105|0.07|10|95|130|41|0.51|0.01|0.9|0.035|0.149|0.078|0.289|0.039|3|0.33|97|0.33|0.2|2.96
-MILK|87.67|0|128|0.05|13|97|139|57|0.36|0.01|0.9|0.03|0.123|0.087|0.301|0.04|5|0.34|2|0|0|3.33
-YOGURT|87.9|4.66|121|0.05|12|95|155|46|0.59|0.009|0.5|0.029|0.142|0.075|0.389|0.032|7|0.37|27|0.06|0.1|3.47
-OMELET|76.13|0.31|48|1.48|11|167|117|155|1.09|0.063|0|0.034|0.386|0.064|1.289|0.143|39|0.76|172|1.29|1.7|10.57
-SALAD DRSNG. FRENCH|54.28|16.86|11|0.73|8|16|107|838|0.2|0.16|4.8|0.024|0.052|0.467|0|0.055|2|0|27|1|0|0.58
-OIL|0|0|1|0.56|0|0|1|2|0|0|0|0|0|0|0|0|0|0|0|14.35|0|0
-CHICKEN|52.41|0|17|1.38|25|191|234|84|2.04|0.075|0|0.087|0.193|8.992|1.079|0.41|9|0.31|27|0.63|0.1|28.56
-TURKEY|70.61|0|15|1.69|22|180|269|67|2.31|0.114|0.2|0.065|0.203|4.148|0.953|0.41|23|1.62|102|0|0|20.37
-SOUP TURKEY NOODLES|86.37|0.41|9|0.75|4|38|60|650|0.46|0.1|0.1|0.059|0.051|1.112|0.14|0.03|15|0.13|13|0.14|0|3.11
-SAUSAGE PORK|56.11|0.11|57|0.73|13|178|206|848|2.25|0.07|0|0.249|0.16|2.9|0.76|0.13|3|1.73|0|0|0.3|12.89
-KELLOGG'S CORN FLAKES|3.76|10.5|4|29|9|37|79|723|0.18|0.108|22|2.13|2.64|24.4|0.079|3.44|480|9.47|456|0.13|3.6|6.61
-MELONS HONEY|89.82|8.12|6|0.17|10|11|228|18|0.09|0.024|18|0.038|0.012|0.418|0.155|0.088|19|0|3|0.02|0|0.54
-ORANGES|86.75|9.35|40|0.1|10|14|181|0|0.07|0.045|53.2|0.087|0.04|0.282|0.25|0.06|30|0|11|0.18|0|0.94
-BLUEBERRIES|70.63|19.28|19|2.2|6|14|46|1|0.12|0|0.3|0.033|0.313|0.469|0.041|0.035|8|0|0|0|0|0.56
-PINEAPPLE|83.51|14.26|16|0.28|15|7|124|1|0.1|0.107|9.4|0.102|0.021|0.284|0|0.075|5|0|3|0.02|0|0.51
-APRICOTS|77.56|18.65|10|0.3|7|13|143|4|0.11|0.097|3.1|0.021|0.024|0.376|0|0.055|2|0|146|0.89|0|0.64
-CHERRIES|77.61|16.18|10|0.35|9|20|148|3|0.1|0.176|3.6|0.022|0.043|0.396|0.06|0.022|5|0|12|0.17|0|0.73
-PEACHES|80.62|14.66|3|0.27|5|12|94|6|0.09|0.063|0.7|0.02|0.02|0.625|0.024|0.013|9|0|31|1.19|0|0.52
-PORK|74.31|0|14|1.2|22|202|339|65|3.36|0.102|0|0.558|0.384|4.387|1.567|0.521|0|0.91|0|0.24|0.6|18.73
-POTATO PANCAKES|47.77|1.79|32|1.67|36|128|622|764|0.7|0.18|27.6|0.158|0.173|1.672|0.757|0.448|41|0.29|32|0.23|0.3|6.08
-ARTICHOKES|84.08|0.99|21|0.61|42|73|286|60|0.4|0.127|7.4|0.05|0.089|1.11|0.24|0.081|89|0|1|0.19|0|2.89
-COCONUT MEAT|46.99|6.23|14|2.43|32|113|356|20|1.1|0.435|3.3|0.066|0.02|0.54|0.3|0.054|26|0|0|0.24|0|3.33
-BEEF|58.1|0|11|2.7|19|168|429|1439|3.98|0.034|0|0.08|0.19|5.27|0.59|0.34|11|2.57|0|0|0.1|28.11
-BREAD|64.9|3.92|26|0.94|13|34|62|455|0.23|0.069|0.8|0.117|0.092|1.247|0.06|0.038|97|0.01|78|0.85|0|2.9
-WATER|640.9|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0 \ No newline at end of file
+BUTTER WITH SALT|15.87|0.06|24|0.02|2|24|24|714|0.09|0|0|0.005|0.034|0.042|0.11|0.003|3|0.17|684|2.32|1.5|0.85|0|0|0 \ No newline at end of file
diff --git a/sample/schema1.sql b/sample/schema1.sql
new file mode 100644
index 0000000..fab8d9a
--- /dev/null
+++ b/sample/schema1.sql
@@ -0,0 +1,29 @@
+drop table if exists entries;
+create table entries(
+ id integer primary key autoincrement,
+ title string not null,
+ water string not null,
+ energie string not null,
+ calcium string not null,
+ iron string not null,
+ magnesium string not null,
+ phosphorus string not null,
+ potassium string not null,
+ sodium string not null,
+ zinc string not null,
+ copper string not null,
+ vit_c string not null,
+ thiamin string not null,
+ riboflavin string not null,
+ niacin string not null,
+ panto_acid string not null,
+ vit_b6 string not null,
+ folate_tot string not null,
+ vit_b12 string not null,
+ vit_a string not null,
+ vit_e string not null,
+ vit_d string not null,
+ protein string not null,
+ path string,
+ scenario string
+);
diff --git a/schema/schema1.sql b/schema/schema1.sql
new file mode 100644
index 0000000..fab8d9a
--- /dev/null
+++ b/schema/schema1.sql
@@ -0,0 +1,29 @@
+drop table if exists entries;
+create table entries(
+ id integer primary key autoincrement,
+ title string not null,
+ water string not null,
+ energie string not null,
+ calcium string not null,
+ iron string not null,
+ magnesium string not null,
+ phosphorus string not null,
+ potassium string not null,
+ sodium string not null,
+ zinc string not null,
+ copper string not null,
+ vit_c string not null,
+ thiamin string not null,
+ riboflavin string not null,
+ niacin string not null,
+ panto_acid string not null,
+ vit_b6 string not null,
+ folate_tot string not null,
+ vit_b12 string not null,
+ vit_a string not null,
+ vit_e string not null,
+ vit_d string not null,
+ protein string not null,
+ path string,
+ scenario string
+);
diff --git a/schema/schema2.sql b/schema/schema2.sql
new file mode 100644
index 0000000..17bb3c7
--- /dev/null
+++ b/schema/schema2.sql
@@ -0,0 +1,30 @@
+drop table if exists aliments;
+create table aliments(
+ id integer primary key autoincrement,
+ title string not null,
+ path string not null,
+ quantity string not null,
+ unit string not null,
+ water string not null,
+ energie string not null,
+ calcium string not null,
+ iron string not null,
+ magnesium string not null,
+ phosphorus string not null,
+ potassium string not null,
+ sodium string not null,
+ zinc string not null,
+ copper string not null,
+ vit_c string not null,
+ thiamin string not null,
+ riboflavin string not null,
+ niacin string not null,
+ panto_acid string not null,
+ vit_b6 string not null,
+ folate_tot string not null,
+ vit_b12 string not null,
+ vit_a string not null,
+ vit_e string not null,
+ vit_d string not null,
+ protein string not null
+);
diff --git a/templates/layout.html b/templates/layout.html
index 3f540bd..400f857 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -13,6 +13,7 @@
<a href="/main">activity</a>
<a href="/eating">eating</a>
<a href="/sparetime">sparetime</a>
+ <a href="/addentry">add entry</a>
</div>
{% block content %}{% endblock %}