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
|
# python import
import os
# gettext import
from gettext import gettext as _
# server import
from server.flask import app, logger, render, request, jsonify
#eating import for the status
import Avatar, database_manager
@app.route('/main', methods=['GET', 'POST'])
def main():
logger.debug("controllermain: enter")
# list images
i = Avatar.Character(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, [70, 0])
if request.method == 'POST':
if 'reset' in request.form:
i.reset_status()
#log reset
database_manager.write_log('reset', 's')
i.load_status()
#prepare position for the sun
position = i.Position
positionX = position[0]
positionY = position[1]
#calculate time
daytime = "am"
hours = int(round(i.Time//60)) + 8
minutes = int((i.Time % 60))
if (minutes == 0):
minutes = "00"
else:
minutes = str(minutes)
if (hours > 11):
daytime = "pm"
if (hours > 12):
hours = hours - 12
time = str(hours) + ":" + minutes + " " + daytime
#status- and progressinformation of the progressbars (water, energie, vitamine and construction), bars should not move
progressbar = [dict(
water= calculateHeight(i.Water),
energie= calculateHeight(i.Energie),
vitamine= calculateHeight(i.Vit_total),
construction= calculateHeight(i.Construction),
waterstart= calculateHeight(i.Water),
energiestart= calculateHeight(i.Energie),
vitaminestart= calculateHeight(i.Vit_total),
constructionstart= calculateHeight(i.Construction),
pathimg = '../../static/images/journal/default.png'
)]
#Sun should not move, so start- and endposition have the same coordinates
positionSun = {
'positionX': positionX,
'positionstartX': positionX,
'positionY': positionY,
'positionstartY': positionY,
'timeString': time
}
#prepare result
_content = { 'progressbar': progressbar, 'positionSun': positionSun }
# render result
return render('nutrinoweb/main.html', **_content)
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)
|