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 10:25:50 (GMT)
committer Stefanie Nobel <stefanie.nobel@googlemail.com>2011-08-28 10:25:50 (GMT)
commitb09f09ff7be8a64bb2f0a2ac3692941aaae5ea89 (patch)
treefdd609c74ec9eab6d56b52c76eff64b0c5c5e148
parent982993db385d8f56eb0d70fc52a3e63aa718852c (diff)
parent8e93250fd567dce82706242cedfa5d4bcbd9d5b9 (diff)
.json instead of .txt for status
-rw-r--r--.DS_Storebin6148 -> 0 bytes
-rw-r--r--.gitignore2
-rw-r--r--DATABASE3bin12288 -> 12288 bytes
-rw-r--r--activity/activity-nutriweb.svg232
-rw-r--r--docs/.DS_Storebin6148 -> 0 bytes
-rw-r--r--docs/source/.DS_Storebin6148 -> 0 bytes
-rw-r--r--lib/server/__init__.py2
-rw-r--r--lib/server/config.py2
-rw-r--r--lib/server/flask/__init__.py2
-rw-r--r--lib/server/flask/_app.py16
-rw-r--r--lib/server/tools/__init__.py1
-rw-r--r--lib/server/tools/_obj.py8
-rw-r--r--lib/server/tools/image.py110
-rw-r--r--lib/server/tools/registry.py48
-rw-r--r--lib/server/tools/sound.py111
-rw-r--r--lib/server/tools/storage.py135
-rw-r--r--nutrinoweb/.DS_Storebin6148 -> 0 bytes
-rw-r--r--nutrinoweb/controllers/.DS_Storebin12292 -> 0 bytes
-rw-r--r--nutrinoweb/controllers/Avatar.py111
-rw-r--r--nutrinoweb/controllers/database_manager.py14
-rw-r--r--nutrinoweb/controllers/eating.py31
-rw-r--r--nutrinoweb/controllers/main.py6
-rw-r--r--nutrinoweb/controllers/schema.sql29
-rw-r--r--nutrinoweb/controllers/schema2.sql30
-rw-r--r--nutrinoweb/controllers/sparetime.py29
-rw-r--r--po/.DS_Storebin6148 -> 0 bytes
-rw-r--r--sample/aliments.txt (renamed from nutrinoweb/controllers/aliments.txt)0
-rwxr-xr-xsample/dbinput.txt (renamed from nutrinoweb/controllers/dbinput.txt)0
-rwxr-xr-xsample/dbinputsparetime.txt (renamed from nutrinoweb/controllers/dbinputsparetime.txt)0
-rw-r--r--sample/status.txt (renamed from nutrinoweb/controllers/status.txt)0
-rw-r--r--sample/statusanfang.txt (renamed from nutrinoweb/controllers/statusanfang.txt)0
-rw-r--r--static/.DS_Storebin6148 -> 0 bytes
-rw-r--r--static/css/.DS_Storebin6148 -> 0 bytes
-rw-r--r--static/images/.DS_Storebin6148 -> 0 bytes
-rw-r--r--static/images/journal/.DS_Storebin6148 -> 0 bytes
-rw-r--r--static/images/journal/activities/SLEEPING.pngbin0 -> 7954 bytes
-rw-r--r--static/images/journal/aliments/.DS_Storebin15364 -> 0 bytes
-rw-r--r--templates/.DS_Storebin6148 -> 0 bytes
-rw-r--r--templates/nutrinoweb/.DS_Storebin6148 -> 0 bytes
-rw-r--r--templates/nutrinoweb/main.html2
40 files changed, 542 insertions, 379 deletions
diff --git a/.DS_Store b/.DS_Store
deleted file mode 100644
index 6068657..0000000
--- a/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/.gitignore b/.gitignore
index c7d20ce..eb6e0b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@ syntax: glob
*.new
dist
docs/build
+.DS_Store
+data/
diff --git a/DATABASE3 b/DATABASE3
index 0ce335c..8d8c913 100644
--- a/DATABASE3
+++ b/DATABASE3
Binary files differ
diff --git a/activity/activity-nutriweb.svg b/activity/activity-nutriweb.svg
deleted file mode 100644
index 0726484..0000000
--- a/activity/activity-nutriweb.svg
+++ /dev/null
@@ -1,232 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- version="1.0"
- id="svg2"
- sodipodi:version="0.32"
- inkscape:version="0.47 r22583"
- sodipodi:docname="activity-NutriWeb.svg"
- width="55"
- height="55"
- inkscape:output_extension="org.inkscape.output.svg.inkscape">
- <metadata
- id="metadata371">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- </cc:Work>
- </rdf:RDF>
- </metadata>
- <sodipodi:namedview
- inkscape:window-height="882"
- inkscape:window-width="1233"
- inkscape:pageshadow="2"
- inkscape:pageopacity="0.0"
- guidetolerance="10.0"
- gridtolerance="10.0"
- objecttolerance="10.0"
- borderopacity="1.0"
- bordercolor="#666666"
- pagecolor="#ffffff"
- id="base"
- inkscape:zoom="4.2923284"
- inkscape:cx="63.342591"
- inkscape:cy="51.710699"
- inkscape:window-x="168"
- inkscape:window-y="24"
- inkscape:current-layer="svg2"
- width="210mm"
- height="40mm"
- units="mm"
- showgrid="false"
- inkscape:window-maximized="0" />
- <defs
- id="defs4">
- <inkscape:perspective
- sodipodi:type="inkscape:persp3d"
- inkscape:vp_x="0 : 71.887497 : 1"
- inkscape:vp_y="0 : 1000 : 0"
- inkscape:vp_z="486.04999 : 71.887497 : 1"
- inkscape:persp3d-origin="243.02499 : 47.924998 : 1"
- id="perspective46" />
- <linearGradient
- id="linearGradient2795">
- <stop
- style="stop-color: rgb(184, 184, 184); stop-opacity: 0.498039;"
- offset="0"
- id="stop2797" />
- <stop
- style="stop-color: rgb(127, 127, 127); stop-opacity: 0;"
- offset="1"
- id="stop2799" />
- </linearGradient>
- <linearGradient
- id="linearGradient2787">
- <stop
- style="stop-color: rgb(127, 127, 127); stop-opacity: 0.5;"
- offset="0"
- id="stop2789" />
- <stop
- style="stop-color: rgb(127, 127, 127); stop-opacity: 0;"
- offset="1"
- id="stop2791" />
- </linearGradient>
- <linearGradient
- id="linearGradient3676">
- <stop
- style="stop-color: rgb(178, 178, 178); stop-opacity: 0.5;"
- offset="0"
- id="stop3678" />
- <stop
- style="stop-color: rgb(179, 179, 179); stop-opacity: 0;"
- offset="1"
- id="stop3680" />
- </linearGradient>
- <linearGradient
- id="linearGradient3236">
- <stop
- style="stop-color: rgb(244, 244, 244); stop-opacity: 1;"
- offset="0"
- id="stop3244" />
- <stop
- style="stop-color: white; stop-opacity: 1;"
- offset="1"
- id="stop3240" />
- </linearGradient>
- <linearGradient
- id="linearGradient4671">
- <stop
- style="stop-color: rgb(255, 212, 59); stop-opacity: 1;"
- offset="0"
- id="stop4673" />
- <stop
- style="stop-color: rgb(255, 232, 115); stop-opacity: 1;"
- offset="1"
- id="stop4675" />
- </linearGradient>
- <linearGradient
- id="linearGradient4689">
- <stop
- style="stop-color: rgb(90, 159, 212); stop-opacity: 1;"
- offset="0"
- id="stop4691" />
- <stop
- style="stop-color: rgb(48, 105, 152); stop-opacity: 1;"
- offset="1"
- id="stop4693" />
- </linearGradient>
- <linearGradient
- x1="224.23996"
- y1="144.75717"
- x2="-65.308502"
- y2="144.75717"
- id="linearGradient2987"
- xlink:href="#linearGradient4671"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)" />
- <linearGradient
- x1="172.94208"
- y1="77.475983"
- x2="26.670298"
- y2="76.313133"
- id="linearGradient2990"
- xlink:href="#linearGradient4689"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4689"
- id="linearGradient2587"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)"
- x1="172.94208"
- y1="77.475983"
- x2="26.670298"
- y2="76.313133" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4671"
- id="linearGradient2589"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)"
- x1="224.23996"
- y1="144.75717"
- x2="-65.308502"
- y2="144.75717" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4689"
- id="linearGradient2248"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)"
- x1="172.94208"
- y1="77.475983"
- x2="26.670298"
- y2="76.313133" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4671"
- id="linearGradient2250"
- gradientUnits="userSpaceOnUse"
- gradientTransform="translate(100.27,99.6112)"
- x1="224.23996"
- y1="144.75717"
- x2="-65.308502"
- y2="144.75717" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4671"
- id="linearGradient2255"
- gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.562541,0,0,0.567972,-11.5974,-7.60954)"
- x1="224.23996"
- y1="144.75717"
- x2="-65.308502"
- y2="144.75717" />
- <linearGradient
- inkscape:collect="always"
- xlink:href="#linearGradient4689"
- id="linearGradient2258"
- gradientUnits="userSpaceOnUse"
- gradientTransform="matrix(0.562541,0,0,0.567972,-11.5974,-7.60954)"
- x1="172.94208"
- y1="76.176224"
- x2="26.670298"
- y2="76.313133" />
- <radialGradient
- inkscape:collect="always"
- xlink:href="#linearGradient2795"
- id="radialGradient2801"
- cx="61.518883"
- cy="132.28575"
- fx="61.518883"
- fy="132.28575"
- r="29.036913"
- gradientTransform="matrix(1,0,0,0.177966,0,108.743)"
- gradientUnits="userSpaceOnUse" />
- </defs>
- <g
- id="g2847"
- transform="matrix(0.46766264,0,0,0.46766264,-1.1078811,-1.5517981)">
- <path
- id="path1948"
- d="m 60.510156,6.3979729 c -4.583653,0.021298 -8.960939,0.4122177 -12.8125,1.09375 C 36.35144,9.4962267 34.291407,13.691825 34.291406,21.429223 l 0,10.21875 26.8125,0 0,3.40625 -26.8125,0 -10.0625,0 c -7.792459,0 -14.6157592,4.683717 -16.7500002,13.59375 -2.46182,10.212966 -2.5710151,16.586023 0,27.25 1.9059283,7.937852 6.4575432,13.593748 14.2500002,13.59375 l 9.21875,0 0,-12.25 c 0,-8.849902 7.657144,-16.656248 16.75,-16.65625 l 26.78125,0 c 7.454951,0 13.406253,-6.138164 13.40625,-13.625 l 0,-25.53125 c 0,-7.266339 -6.12998,-12.7247775 -13.40625,-13.9375001 -4.605987,-0.7667253 -9.385097,-1.1150483 -13.96875,-1.09375 z m -14.5,8.2187501 c 2.769547,0 5.03125,2.298646 5.03125,5.125 -2e-6,2.816336 -2.261703,5.09375 -5.03125,5.09375 -2.779476,-1e-6 -5.03125,-2.277415 -5.03125,-5.09375 -1e-6,-2.826353 2.251774,-5.125 5.03125,-5.125 z"
- style="fill:#000000;fill-opacity:1" />
- <path
- id="path1950"
- d="m 91.228906,35.054223 0,11.90625 c 0,9.230755 -7.825895,16.999999 -16.75,17 l -26.78125,0 c -7.335833,0 -13.406249,6.278483 -13.40625,13.625 l 0,25.531247 c 0,7.26634 6.318588,11.54032 13.40625,13.625 8.487331,2.49561 16.626237,2.94663 26.78125,0 6.750155,-1.95439 13.406253,-5.88761 13.40625,-13.625 l 0,-10.218747 -26.78125,0 0,-3.40625 26.78125,0 13.406254,0 c 7.79246,0 10.69625,-5.435408 13.40624,-13.59375 2.79933,-8.398886 2.68022,-16.475776 0,-27.25 -1.92578,-7.757441 -5.60387,-13.59375 -13.40624,-13.59375 l -10.062504,0 z m -15.0625,64.65625 c 2.779478,3e-6 5.03125,2.277417 5.03125,5.093747 -2e-6,2.82635 -2.251775,5.125 -5.03125,5.125 -2.76955,0 -5.03125,-2.29865 -5.03125,-5.125 2e-6,-2.81633 2.261697,-5.093747 5.03125,-5.093747 z"
- style="fill:#000000;fill-opacity:1" />
- </g>
-</svg>
diff --git a/docs/.DS_Store b/docs/.DS_Store
deleted file mode 100644
index 226dc11..0000000
--- a/docs/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/docs/source/.DS_Store b/docs/source/.DS_Store
deleted file mode 100644
index e1a71de..0000000
--- a/docs/source/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/lib/server/__init__.py b/lib/server/__init__.py
index a779594..06b0b1d 100644
--- a/lib/server/__init__.py
+++ b/lib/server/__init__.py
@@ -1,2 +1,4 @@
# server import
from server._server import Server
+# ..
+from server.flask import BUNDLE, ROOT
diff --git a/lib/server/config.py b/lib/server/config.py
index 659ec18..9180e54 100644
--- a/lib/server/config.py
+++ b/lib/server/config.py
@@ -4,7 +4,7 @@ import logging
from ConfigParser import SafeConfigParser
# get application logger
-logger = logging.getLogger('nutriweb')
+logger = logging.getLogger('atoideweb')
class Config(object):
diff --git a/lib/server/flask/__init__.py b/lib/server/flask/__init__.py
index 7d75791..f079068 100644
--- a/lib/server/flask/__init__.py
+++ b/lib/server/flask/__init__.py
@@ -2,4 +2,4 @@
from flask import request, jsonify
# server import
-from server.flask._app import logger, app, render, run_app
+from server.flask._app import logger, app, render, run_app, BUNDLE, ROOT
diff --git a/lib/server/flask/_app.py b/lib/server/flask/_app.py
index cb2d4c3..bc6f3b3 100644
--- a/lib/server/flask/_app.py
+++ b/lib/server/flask/_app.py
@@ -15,23 +15,29 @@ APP_NAME = 'my_activity' if APP_NAME is None else APP_NAME
_debug = config.Config().get('server>debug')
_key = config.Config().get('server>secret_key')
-# our activity root directory relative to the current one
-PROJET_ROOT = os.path.join(os.path.dirname(__file__), '..', '..', '..')
-
# flask import
import flask
+# sugar or debug root path factory
+try:
+ from sugar.activity import activity
+ BUNDLE = activity.get_bundle_path()
+ ROOT = activity.get_bundle_path()
+except Exception, e:
+ BUNDLE = '.'
+ ROOT = '.'
+
# init app
app = flask.Flask(__name__)
app.debug = True if _debug is None else _debug
app.secret_key = 'NO_KEY_OOPS' if _key is None else _key
# override jinja template path
-app.jinja_loader.searchpath = [os.path.join(PROJET_ROOT, 'templates')]
+app.jinja_loader.searchpath = [os.path.join(BUNDLE, 'templates')]
# init static folder path
from werkzeug import SharedDataMiddleware
app.wsgi_app = SharedDataMiddleware(app.wsgi_app,
- {'/static': os.path.join(PROJET_ROOT, 'static')})
+ {'/static': os.path.join(BUNDLE, 'static')})
# set basic logging out of sugar
try:
diff --git a/lib/server/tools/__init__.py b/lib/server/tools/__init__.py
new file mode 100644
index 0000000..ec464ac
--- /dev/null
+++ b/lib/server/tools/__init__.py
@@ -0,0 +1 @@
+from server.tools._obj import obj
diff --git a/lib/server/tools/_obj.py b/lib/server/tools/_obj.py
new file mode 100644
index 0000000..c2c3383
--- /dev/null
+++ b/lib/server/tools/_obj.py
@@ -0,0 +1,8 @@
+
+class obj(object):
+ def __init__(self, d):
+ for a, b in d.items():
+ if isinstance(b, (list, tuple)):
+ setattr(self, a, [obj(x) if isinstance(x, dict) else x for x in b])
+ else:
+ setattr(self, a, obj(b) if isinstance(b, dict) else b)
diff --git a/lib/server/tools/image.py b/lib/server/tools/image.py
new file mode 100644
index 0000000..cffc156
--- /dev/null
+++ b/lib/server/tools/image.py
@@ -0,0 +1,110 @@
+
+# python import
+import logging, os, struct, StringIO
+
+# atoideweb import
+from atoideweb.tools import registry
+
+
+def compute_width_height(width, height, max_width, max_height, use_max=False):
+ # compute ratio
+ _ratio_scr = max_width / float(max_height)
+ _ratio_img = width / float(height)
+ # ..
+ if width > max_width\
+ or height > max_height:
+ if _ratio_img > _ratio_scr:
+ width = max_width
+ height = int(max_width / _ratio_img)
+ elif _ratio_img < _ratio_scr:
+ width = int(max_height * _ratio_img)
+ height = max_height
+ else:
+ width = max_width
+ height = max_height
+ # ..
+ return width, height
+ # ..
+ elif use_max is True:
+ return max_width, max_height
+ # ..
+ else:
+ return width, height
+
+
+def get_image_info(path):
+ """Tricky method found on Internet that returns the image info from a given
+ raw image data.
+ """
+ # little check
+ _info = registry.InfoRegistry().get_info(path)
+ # already exist
+ if _info is not None:
+ return _info
+ elif os.path.exists(path):
+ pass
+ else:
+ return None, 0, 0
+ # read file
+ _f = open(path)
+ _data = _f.read()
+ _f.close()
+ #
+ size = len(_data)
+ height = 0
+ width = 0
+ content_type = None
+
+ # handle GIFs
+ if (size >= 10) and _data[:6] in ('GIF87a', 'GIF89a'):
+ # Check to see if content_type is correct
+ content_type = 'image/gif'
+ w, h = struct.unpack("<HH", _data[6:10])
+ width = int(w)
+ height = int(h)
+
+ # See PNG 2. Edition spec (http://www.w3.org/TR/PNG/)
+ # Bytes 0-7 are below, 4-byte chunk length, then 'IHDR'
+ # and finally the 4-byte width, height
+ elif ((size >= 24) and _data.startswith('\211PNG\r\n\032\n')
+ and (_data[12:16] == 'IHDR')):
+ content_type = 'image/png'
+ w, h = struct.unpack(">LL", _data[16:24])
+ width = int(w)
+ height = int(h)
+
+ # Maybe this is for an older PNG version.
+ elif (size >= 16) and _data.startswith('\211PNG\r\n\032\n'):
+ # Check to see if we have the right content type
+ content_type = 'image/png'
+ w, h = struct.unpack(">LL", _data[8:16])
+ width = int(w)
+ height = int(h)
+
+ # handle JPEGs
+ elif (size >= 2) and _data.startswith('\377\330'):
+ content_type = 'image/jpeg'
+ jpeg = StringIO.StringIO(_data)
+ jpeg.read(2)
+ b = jpeg.read(1)
+ try:
+ while (b and ord(b) != 0xDA):
+ while (ord(b) != 0xFF): b = jpeg.read(1)
+ while (ord(b) == 0xFF): b = jpeg.read(1)
+ if (ord(b) >= 0xC0 and ord(b) <= 0xC3):
+ jpeg.read(3)
+ h, w = struct.unpack(">HH", jpeg.read(4))
+ break
+ else:
+ jpeg.read(int(struct.unpack(">H", jpeg.read(2))[0])-2)
+ b = jpeg.read(1)
+ width = int(w)
+ height = int(h)
+ except struct.error:
+ pass
+ except ValueError:
+ pass
+ # udpate registry
+ registry.InfoRegistry().set_info(path, (content_type, width, height))
+ # ..
+ return content_type, width, height
diff --git a/lib/server/tools/registry.py b/lib/server/tools/registry.py
new file mode 100644
index 0000000..7e575c3
--- /dev/null
+++ b/lib/server/tools/registry.py
@@ -0,0 +1,48 @@
+
+# python import
+import logging
+
+
+class Registry(object):
+
+ class __Singleton:
+ """Our singleton object.
+ """
+
+ def __init__(self):
+ """Create the new singleton for a simple use.
+ """
+ # ensure config
+ self.__dict = dict()
+
+ def get_info(self, path):
+ # ..
+ if path in self.__dict:
+ return self.__dict[path]
+ else:
+ return None
+
+ def set_info(self, path, info):
+ # clear previous
+ if path in self.__dict:
+ del self.__dict[path]
+ else:
+ pass
+ # ...
+ self.__dict[path] = info
+
+ # singleton instance
+ instance = None
+
+ def __new__(c, force=False):
+ """Singleton new init.
+ """
+ # if doesn't already initialized
+ if not Registry.instance \
+ or force is True:
+ # create a new instance
+ Registry.instance = Registry.__Singleton()
+ else:
+ pass
+ # return the manager object
+ return Registry.instance
diff --git a/lib/server/tools/sound.py b/lib/server/tools/sound.py
new file mode 100644
index 0000000..7ac6a57
--- /dev/null
+++ b/lib/server/tools/sound.py
@@ -0,0 +1,111 @@
+
+# python import
+import gst
+# ..
+from datetime import timedelta
+
+
+class Player(object):
+
+ def __init__(self, loop=False):
+ # playing flag
+ self.playing = False
+ self.loop = loop
+ # player object
+ self.player = None
+ self._init_player()
+ # file to play
+ self._soundfile = None
+
+ def _reload_cb(self, bus, message):
+ if self.loop is True:
+ self.player.set_state(gst.STATE_READY)
+ self.player.set_state(gst.STATE_PLAYING)
+ else:
+ pass
+
+ def _error_cb(self, bus, message):
+ self.player.set_state(gst.STATE_NULL)
+
+ def _init_player(self):
+ # make player
+ self.player = gst.element_factory_make("playbin", "player")
+ # video fake
+ _fakesink = gst.element_factory_make('fakesink', "my-fakesink")
+ self.player.set_property("video-sink", _fakesink)
+ # bus ..
+ bus = self.player.get_bus()
+ bus.add_signal_watch()
+ bus.connect('message::eos', self._reload_cb)
+ bus.connect('message::error', self._error_cb)
+
+ def serialize(self):
+ # little check
+ if self._soundfile is None:
+ return None
+ else:
+ return file(self._soundfile, 'r').read()
+
+ def load(self, soundfile):
+ # file to play
+ self._soundfile = soundfile
+ # little check
+ if self._soundfile is None:
+ pass
+ else:
+ # load sound file
+ self.player.set_state(gst.STATE_NULL)
+ self.player.set_property('uri', 'file://' + self._soundfile)
+
+ def get_position(self):
+ # little check
+ if self._soundfile is None:
+ return None
+ else:
+ # ...
+ _position = self.player.query_duration(gst.FORMAT_TIME)[0]
+ # ...
+ return timedelta(seconds=(_position / gst.SECOND))
+
+ def get_duration(self):
+ # little check
+ if self._soundfile is None:
+ return None
+ else:
+ # _duration = self.player.query_duration(gst.FORMAT_TIME)[0]
+ # ..
+ _parser = gst.parse_launch("filesrc name=source ! decodebin2 ! fakesink")
+ # ..
+ _source = _parser.get_by_name("source")
+ _source.set_property("location", self._soundfile)
+ # ..
+ _parser.set_state(gst.STATE_PLAYING)
+ _parser.get_state()
+ # ..
+ _format = gst.Format(gst.FORMAT_TIME)
+ _duration = _parser.query_duration(_format)[0]
+ _parser.set_state(gst.STATE_NULL)
+ # ..
+ return timedelta(seconds=(_duration / gst.SECOND))
+
+ def seek(self, time):
+ # little check
+ if self._soundfile is None:
+ return
+ else:
+ # format time
+ _seek = time * 1000000000
+ # do seek
+ self.player.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, _seek)
+
+ def play(self):
+ self.playing = True
+ self.player.set_state(gst.STATE_PLAYING)
+
+ def pause(self):
+ self.playing = False
+ self.player.set_state(gst.STATE_PAUSED)
+
+ def stop(self):
+ self.playing = False
+ self.player.set_state(gst.STATE_NULL)
diff --git a/lib/server/tools/storage.py b/lib/server/tools/storage.py
new file mode 100644
index 0000000..535eb66
--- /dev/null
+++ b/lib/server/tools/storage.py
@@ -0,0 +1,135 @@
+
+# python import
+import os
+
+# server import
+from server import BUNDLE, ROOT
+
+
+ACTIVITY_NAMES = {
+ 'paint': 'org.laptop.Oficina',
+ 'record': 'org.laptop.RecordActivity',
+ }
+
+
+def get_path(path=None, bundle=True):
+ # ..
+ path = 'static' if path is None else os.path.join('static', path)
+ # ..
+ if bundle is True:
+ return os.path.join(BUNDLE, path)
+ else:
+ return os.path.join(ROOT, 'data', path)
+
+
+def list_dir(path=None, bundle=True):
+ # ..
+ path = get_path(path=path, bundle=bundle)
+ # ..
+ return [os.path.join(path, _f) for _f in os.listdir(path)]
+
+
+def get_sound_path(filename, path=None, bundle=True, ext=None):
+ # ..
+ path = get_path(path=path, bundle=bundle)
+ filename = filename if ext is None else '%s.%s' % (filename, ext)
+ # ..
+ return os.path.join(path, filename)
+
+
+def get_sound_path(filename, path=None, bundle=True, ext='ogg'):
+ # ..
+ return get_sound_path(filename, path=path, bundle=bundle, ext=ext)
+
+
+def get_image_path(filename, path=None, bundle=True, ext='png'):
+ # ..
+ return get_sound_path(filename, path=path, bundle=bundle, ext=ext)
+
+
+def __do_query(query):
+ from sugar.datastore import datastore
+ # find in ds
+ _results, _count = datastore.find(query, sorting='timestamp')
+ for _r in _results:
+ # get meta
+ _m = _r.get_metadata()
+ if 'activity' in query:
+ yield _r
+ elif _m['activity'] == '':
+ yield _r
+ else:
+ continue
+
+
+def get_journal_objects(activity_name=None, mime_type=None):
+ # init
+ _query = dict()
+ # prepare query name
+ if activity_name is None\
+ and mime_type is None:
+ return []
+ elif mime_type is None:
+ return __do_query({'activity': ACTIVITY_NAMES[activity_name]})
+ else:
+ return __do_query({'mime_type': mime_type})
+
+
+def list_info_from_journal(activity_name=None, mime_type=None):
+ # get objects first
+ _objs = get_journal_objects(activity_name=activity_name, mime_type=mime_type)
+ # make unique titles
+ _titles = {}
+ # return infos
+ for _o in _objs:
+ # get meta
+ _m = _o.get_metadata()
+ # get title
+ _t = _m['title']
+ # ensure description
+ _d = _m['description'] if 'description' in _m else ''
+ _p = _m['preview'] if 'preview' in _m else None
+ # little check
+ if _t in _titles:
+ # udpate reg
+ _titles[_t] += 1
+ # update value to show
+ _t = '%s (%s)' % (_t, _titles[_t])
+ # init title reg
+ else:
+ _titles[_t] = 1
+ # ensure info
+ yield {
+ 'activity_id' : _m['activity_id'],
+ 'description' : _d,
+ 'timestamp' : _m['timestamp'],
+ 'preview' : _p,
+ 'title' : _t,
+ }
+
+
+def list_files_from_journal(activity_name=None, mime_type=None):
+ # get objects first
+ _objs = get_journal_objects(activity_name=activity_name,
+ mime_type=mime_type)
+ # return paths
+ for _o in _objs:
+ # TODO open the files
+ yield _o.get_file_path()
+
+
+def get_path_from_journal(timestamp, mime_type):
+ from sugar.datastore import datastore
+ # ..
+ _query = {
+ 'timestamp': int(timestamp),
+ 'mime_type': mime_type
+ }
+ # find in ds
+ _results, _count = datastore.find(_query)
+ # ..
+ if _count == 1:
+ # get path
+ return _results[0].get_file_path()
+ else:
+ return None
diff --git a/nutrinoweb/.DS_Store b/nutrinoweb/.DS_Store
deleted file mode 100644
index 8a60703..0000000
--- a/nutrinoweb/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/nutrinoweb/controllers/.DS_Store b/nutrinoweb/controllers/.DS_Store
deleted file mode 100644
index f7dace6..0000000
--- a/nutrinoweb/controllers/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/nutrinoweb/controllers/Avatar.py b/nutrinoweb/controllers/Avatar.py
index 6dbfebe..3eaab37 100644
--- a/nutrinoweb/controllers/Avatar.py
+++ b/nutrinoweb/controllers/Avatar.py
@@ -1,3 +1,10 @@
+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")
+
+
class Character:
def __init__(self):
@@ -26,75 +33,47 @@ class Character:
self.vit_total = 0.0
self.construction = 0.0
-
- def reset(self, gender=None):
- """
- Restore some character properties to its default values.
- """
- pass
+ def load_status(self):
+ fh = open(temp_json,'r')
+ status = json.load(fh)
+ fh.close()
- def load_status(self):
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/status.txt')
-
- for line in fobj:
- zuordnung = line.split("|")
- 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]
+ return status
- fobj.close()
+ def save_status(self, status):
+ fh = open(temp_json,'w')
+ 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 reset_status(self):
+ status = {
+ "water": 0,
+ "energie": 0,
+ "calcium": 0,
+ "iron" : 0,
+ "magnesium": 0,
+ "phosphorus": 0,
+ "potassium": 0,
+ "sodium": 0,
+ "zinc": 0,
+ "copper": 0,
+ "vit_c": 0,
+ "thiamin": 0,
+ "riboflavin": 0,
+ "niacin": 0,
+ "panto_acid": 0,
+ "vit_b6": 0,
+ "folate_tot": 0,
+ "vit_b12": 0,
+ "vit_a": 0,
+ "vit_e": 0,
+ "vit_d": 0,
+ "vit_total": 0,
+ "construction": 0
+ }
+ fh = open(temp_json,'w')
+ json.dump(status,fh)
+ fh.close()
- def save_status(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('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/status.txt', 'w')
- 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 f67ea23..ca33419 100644
--- a/nutrinoweb/controllers/database_manager.py
+++ b/nutrinoweb/controllers/database_manager.py
@@ -32,14 +32,14 @@ def connect_db3():
def init_db3():
"""Creates the database tables."""
with closing(connect_db3()) as db:
- with app.open_resource('schema2.sql') as f:
+ with app.open_resource('../../sample/schema2.sql') as f:
db.cursor().executescript(f.read())
db.commit()
def init_db():
"""Creates the database tables."""
with closing(connect_db()) as db:
- with app.open_resource('schema.sql') as f:
+ with app.open_resource('../../sample/schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()
@@ -153,10 +153,10 @@ def aliments():
return aliments
def save_aliments(aliments):
- fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/aliments.txt', 'w')
- fobj.truncate()
- for aliment in aliments:
- fobj.write('|' + str(aliment['quantity']) + ',' + aliment['title'])
- fobj.close()
+ fobj = open('/Users/stefanienobel/Documents/workspace/nutrinoweb/nutrinoweb/controllers/aliments.txt', 'w')
+ fobj.truncate()
+ for aliment in aliments:
+ fobj.write('|' + str(aliment['quantity']) + ',' + aliment['title'])
+ fobj.close()
diff --git a/nutrinoweb/controllers/eating.py b/nutrinoweb/controllers/eating.py
index 0fdeb94..0fb2238 100644
--- a/nutrinoweb/controllers/eating.py
+++ b/nutrinoweb/controllers/eating.py
@@ -139,9 +139,34 @@ def calculateDimension(result, entries):
#part construction
_construction = controllValue((factor*calculateConstruction(float(entry['protein']))) + float(eng['construction']))
construction = calculateHeight(_construction)
-
- status = instance.save_status(str(_water), str(_energie), str(_vitamine[1]), str(_vitamine[2]),str(_vitamine[3]),str(_vitamine[4]),str(_vitamine[5]),str(_vitamine[6]),str(_vitamine[7]),str(_vitamine[8]),str(_vitamine[9]),str(_vitamine[10]),str(_vitamine[11]),str(_vitamine[12]),str(_vitamine[13]),str(_vitamine[14]),str(_vitamine[15]),str(_vitamine[16]),str(_vitamine[17]),str(_vitamine[18]), str(_vitamine[19]), str(_vitamine[0]), str(_construction))
-
+
+ status = {
+ "water": _water,
+ "energie": _energie,
+ "calcium": _vitamine[1],
+ "iron" : _vitamine[2],
+ "magnesium": _vitamine[3],
+ "phosphorus": _vitamine[4],
+ "potassium": _vitamine[5],
+ "sodium": _vitamine[6],
+ "zinc": _vitamine[7],
+ "copper": _vitamine[8],
+ "vit_c": _vitamine[9],
+ "thiamin": _vitamine[10],
+ "riboflavin": _vitamine[11],
+ "niacin": _vitamine[12],
+ "panto_acid": _vitamine[13],
+ "vit_b6": _vitamine[14],
+ "folate_tot": _vitamine[15],
+ "vit_b12": _vitamine[16],
+ "vit_a": _vitamine[17],
+ "vit_e": _vitamine[18],
+ "vit_d": _vitamine[19],
+ "vit_total": _vitamine[0],
+ "construction": _construction
+ }
+
+ instance.save_status(status)
else:
pass
else:
diff --git a/nutrinoweb/controllers/main.py b/nutrinoweb/controllers/main.py
index b4bcd97..2dcbc76 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, database_manager
+import eating, Avatar
IM_PATH = ['../static/images/journal/jauge-energie.png']
@@ -22,7 +22,9 @@ def main():
if request.method == 'POST':
if 'reset' in request.form:
- database_manager.reset_status()
+ instance = Avatar.Character()
+
+ instance.reset_status()
_result[0] = 100.0
_result[1] = 100.0
_result[2] = 100.0
diff --git a/nutrinoweb/controllers/schema.sql b/nutrinoweb/controllers/schema.sql
deleted file mode 100644
index fab8d9a..0000000
--- a/nutrinoweb/controllers/schema.sql
+++ /dev/null
@@ -1,29 +0,0 @@
-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/nutrinoweb/controllers/schema2.sql b/nutrinoweb/controllers/schema2.sql
deleted file mode 100644
index 17bb3c7..0000000
--- a/nutrinoweb/controllers/schema2.sql
+++ /dev/null
@@ -1,30 +0,0 @@
-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/nutrinoweb/controllers/sparetime.py b/nutrinoweb/controllers/sparetime.py
index 18c3270..31e8752 100644
--- a/nutrinoweb/controllers/sparetime.py
+++ b/nutrinoweb/controllers/sparetime.py
@@ -99,8 +99,33 @@ def calculateDimension(factor, result, entries):
_construction = controllValue(float(eng['construction']) - (factor*calculateConstruction(float(entry['protein']))))
construction = calculateHeight(_construction)
- status = instance.save_status(str(_water), str(_energie), str(_vitamine[1]), str(_vitamine[2]),str(_vitamine[3]),str(_vitamine[4]),str(_vitamine[5]),str(_vitamine[6]),str(_vitamine[7]),str(_vitamine[8]),str(_vitamine[9]),str(_vitamine[10]),str(_vitamine[11]),str(_vitamine[12]),str(_vitamine[13]),str(_vitamine[14]),str(_vitamine[15]),str(_vitamine[16]),str(_vitamine[17]),str(_vitamine[18]), str(_vitamine[19]), str(_vitamine[0]), str(_construction))
-
+ status = {
+ "water": _water,
+ "energie": _energie,
+ "calcium": _vitamine[1],
+ "iron" : _vitamine[2],
+ "magnesium": _vitamine[3],
+ "phosphorus": _vitamine[4],
+ "potassium": _vitamine[5],
+ "sodium": _vitamine[6],
+ "zinc": _vitamine[7],
+ "copper": _vitamine[8],
+ "vit_c": _vitamine[9],
+ "thiamin": _vitamine[10],
+ "riboflavin": _vitamine[11],
+ "niacin": _vitamine[12],
+ "panto_acid": _vitamine[13],
+ "vit_b6": _vitamine[14],
+ "folate_tot": _vitamine[15],
+ "vit_b12": _vitamine[16],
+ "vit_a": _vitamine[17],
+ "vit_e": _vitamine[18],
+ "vit_d": _vitamine[19],
+ "vit_total": _vitamine[0],
+ "construction": _construction
+ }
+
+ instance.save_status(status)
else:
pass
diff --git a/po/.DS_Store b/po/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
--- a/po/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/nutrinoweb/controllers/aliments.txt b/sample/aliments.txt
index b43ba12..b43ba12 100644
--- a/nutrinoweb/controllers/aliments.txt
+++ b/sample/aliments.txt
diff --git a/nutrinoweb/controllers/dbinput.txt b/sample/dbinput.txt
index b9d4a11..b9d4a11 100755
--- a/nutrinoweb/controllers/dbinput.txt
+++ b/sample/dbinput.txt
diff --git a/nutrinoweb/controllers/dbinputsparetime.txt b/sample/dbinputsparetime.txt
index 7b3e42e..7b3e42e 100755
--- a/nutrinoweb/controllers/dbinputsparetime.txt
+++ b/sample/dbinputsparetime.txt
diff --git a/nutrinoweb/controllers/status.txt b/sample/status.txt
index 074328b..074328b 100644
--- a/nutrinoweb/controllers/status.txt
+++ b/sample/status.txt
diff --git a/nutrinoweb/controllers/statusanfang.txt b/sample/statusanfang.txt
index 84ae936..84ae936 100644
--- a/nutrinoweb/controllers/statusanfang.txt
+++ b/sample/statusanfang.txt
diff --git a/static/.DS_Store b/static/.DS_Store
deleted file mode 100644
index 2d8c43b..0000000
--- a/static/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/static/css/.DS_Store b/static/css/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
--- a/static/css/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/static/images/.DS_Store b/static/images/.DS_Store
deleted file mode 100644
index 4f78abc..0000000
--- a/static/images/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/static/images/journal/.DS_Store b/static/images/journal/.DS_Store
deleted file mode 100644
index 8e6e528..0000000
--- a/static/images/journal/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/static/images/journal/activities/SLEEPING.png b/static/images/journal/activities/SLEEPING.png
new file mode 100644
index 0000000..cc30c45
--- /dev/null
+++ b/static/images/journal/activities/SLEEPING.png
Binary files differ
diff --git a/static/images/journal/aliments/.DS_Store b/static/images/journal/aliments/.DS_Store
deleted file mode 100644
index 87c447d..0000000
--- a/static/images/journal/aliments/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/templates/.DS_Store b/templates/.DS_Store
deleted file mode 100644
index 0e54788..0000000
--- a/templates/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/templates/nutrinoweb/.DS_Store b/templates/nutrinoweb/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
--- a/templates/nutrinoweb/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/templates/nutrinoweb/main.html b/templates/nutrinoweb/main.html
index 8694901..20a8c9a 100644
--- a/templates/nutrinoweb/main.html
+++ b/templates/nutrinoweb/main.html
@@ -12,7 +12,7 @@
</div>
{% for cont in content %}
- <div class=alimentimages><img class=alimentimages src={{cont.pathimg}}></img></div>
+ <div class=alimentimages><img class=alimentimages src="{{cont.pathimg}}"></img></div>
<script type="text/javascript">
var images = $("img.alimentimages").hide();
images.each(function(i){$(this).delay(i*2500).fadeIn(1000);});