Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/nutrinoweb/controllers/sparetime.py
blob: 18c3270169f4e7d5eb8482929b8751d349222c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# gettext import
from gettext import gettext as _

# server import
from server.flask import app, logger, render, request, jsonify

#database import
import database_manager

#Avatar import
import Avatar

IM_PATH = ['../static/images/journal/jauge-energie.png']

@app.route('/sparetime', methods=['GET', 'POST'])
def sparetime():
    #database_manager.init_db()
    #database_manager.load_inputfile()
    entries = database_manager.entriessparetime()
    content = [ ]
    # POST
    if request.method == 'POST':
        if 'activity' in request.form:
	    result = request.form['activity']
	    factor = float(request.form['time'])
	    position = calculateTime(factor)
	    pathi = '../../static/images/journal/activities/' + result + '.png'
	    _result = calculateDimension(factor, result, entries)
	    cont = {
               	'image': IM_PATH,
		'water': _result[0],
		'energie': _result[1],
		'vitamine': _result[2],
		'construction': _result[3],
		'waterstart': _result[4],
		'energiestart': _result[5],
		'vitaminestart': _result[6],
		'constructionstart': _result[7],
		'pathimg': pathi,
               	}
	    content.append(cont)
	    _content = { 'content': content, 'result' : result, 'position': position }
    	    # render result
    	    return render('nutrinoweb/main.html', **_content)

	else:
            _result = '??'
    # GET
    else:
 	entries = entries
	_result = ''
    #  
    _content = {
                'title': _('What do you want to play?'),
                'activities': entries,
		'result': _result,
                }
    # render result
    return render('nutrinoweb/sparetime.html', **_content)

def calculateTime(f):
    if f == 15.0:
	position = [60 , 5]
    elif f == 30.0:
	position = [50 , 10]
    elif f == 45.0:
	position = [40 , 15]
    elif f == 60.0:
	position = [30 , 20]
    else:
	pass
    return position

def calculateDimension(factor, result, entries):
    water = None
    energie = None
    vitamine = None
    construction = None
    vitstart = None
    instance = Avatar.Character()
    eng = instance.load_status()
    if result != None and entries != None:
       eng = instance.load_status()
       for entry in entries:
	   if result in entry['title']:
	      #part water
	      _water = controllValue(float(eng['water']) - ((factor*calculateWater(float(entry['water']))) / 2))
	      water = calculateHeight(_water)
	      
	      #part energie               
	      _energie = controllValue(float(eng['energie']) - (factor*calculateEnergie(float(entry['energie']))))
	      energie = calculateHeight(_energie)    
	      
	      #part vitamine
	      _vitamine = calculateVitamine(1, entry, eng)
	      vitamine = calculateHeight(_vitamine[0])  

	      #part construction
	      _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))
	      
	   else:
               pass	  

    _result = [water, energie, vitamine, construction, calculateHeight(float(eng['water'])), calculateHeight(float(eng['energie'])), calculateHeight(float(eng['vit_total'])), calculateHeight(float(eng['construction']))]
    return _result

def calculateEnergie(energie):
   height = energie/4.0
   return height

def calculateVitamine(f, entry, status):
   calcium = controllValue(float(status['calcium']) - (f*(float(entry['calcium']) / 9.0)))
   iron = controllValue(float(status['iron']) - (f*(float(entry['iron']) / 0.125)))
   magnesium = controllValue(float(status['magnesium']) - (f*(float(entry['magnesium']) / 2.1)))
   phosphorus = controllValue(float(status['phosphorus']) - (f*(float(entry['phosphorus']) / 10)))	
   potassium = controllValue(float(status['potassium']) - (f*(float(entry['potassium']) / 15.5)))
   sodium = controllValue(float(status['sodium']) - (f*(float(entry['sodium']) / 4.85)))
   zinc = controllValue(float(status['zinc']) - (f*(float(entry['zinc']) / 0.08)))
   copper = controllValue(float(status['copper']) - (f*(float(entry['copper']) / 0.0115)))
   vit_c = controllValue(float(status['vit_c']) - (f*(float(entry['vit_c']) / 0.85)))
   thiamin = controllValue(float(status['thiamin']) - (f*(float(entry['thiamin']) / 0.012)))
   riboflavin = controllValue(float(status['riboflavin']) - (f*(float(entry['riboflavin']) / 0.011)))
   niacin = controllValue(float(status['niacin']) - (f*(float(entry['niacin']) / 0.13)))
   panto_acid = controllValue(float(status['panto_acid']) - (f*(float(entry['panto_acid']) / 0.05)))
   vit_b6 = controllValue(float(status['vit_b6']) - (f*(float(entry['vit_b6']) / 0.0085)))
   folate_tot = controllValue(float(status['folate_tot']) - (f*(float(entry['folate_tot']) / 3.5)))
   vit_b12 = controllValue(float(status['vit_b12']) - (f*(float(entry['vit_b12']) / 0.019)))
   vit_a = controllValue(float(status['vit_a']) - (f*(float(entry['vit_a']) / 0.11)))
   vit_e = controllValue(float(status['vit_e']) - (f*(float(entry['vit_e']) / 0.05)))
   vit_d = controllValue(float(status['vit_d']) - (f*(float(entry['vit_d']) / 0.315)))

   height = (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)/19.0
   height = [height, 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]
   return height

def controllValue(value):
    if value < 0.00:
       return 0.00
    return value


def calculateWater(water):
   height = water/17.5
   return height

def calculateConstruction(construction):
   height = construction/0.215                #daily value 0.9g/kg weight, a child of 35kg needs 21.5g
   return height

def calculateHeight(height):
    height = 100.0 - height
    if height < 0.0:
       return 5.0
    elif height == 0.0:
       return 5.0
    elif height > 100.0:
       return 99.00
    return int(height)