forked from tusharshetty61/Fitr.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.py
169 lines (147 loc) · 5.82 KB
/
User.py
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
162
163
164
165
166
167
168
169
import streamlit as st
import pandas as pd
import pickle as pkl
import joblib
food=pd.read_csv('/mnt/d/Hashcode/Hashcode_2022/data/calories.csv')
class User:
def __init__(self, username):
self.user=username
self.status = " "
self.goals= {'steps':0,'calories':0,'wellnessgoals':0,'screentimegoals':0}
self.uinfo={'ht':0,'wt':0,'activity':0,'gender':"F",'age':0,'hours':0}
self.tinfo={'boolBF':False,'breakfast':[],'lunch':[],'dinner':[],'heartRate':0,'hours':0,'stepsWalked':0,'phy_wellness':0,'mood':""}
def update_user_goals(self,steps,calories,wellnessgoals,screentimegoals):
self.goals['steps']=steps
self.goals['calories']=calories
self.goals['wellnessgoals']=wellnessgoals
self.goals['screentimegoals']=screentimegoals
def update_user_stats(self,ht,wt,activity,gender,age,hours):
self.uinfo['ht']=ht
self.uinfo['wt']=wt
# print(self.uinfo['wt'])
self.uinfo['activity']=activity
self.uinfo['gender']=gender
self.uinfo['age']=age
self.uinfo['hours']=hours
def update_obese_state(self):
bmi=self.uinfo['wt']*100*100/(self.uinfo['ht']*self.uinfo['ht'])
status=""
if(bmi<18.5):
status='underweight'
elif bmi>18.5 and bmi<=24.9:
status="normal"
elif bmi>=25 and bmi<=29.9:
status="overweight"
else:
status="obese"
return status
def cintake(self):
x=0.0
if(self.uinfo['gender']=='M'):
x=9.99*self.uinfo['wt']+6.25*self.uinfo['ht']-4.92*self.uinfo['age']+5
else:
x=9.99*self.uinfo['wt']+6.25*self.uinfo['ht']-4.92*self.uinfo['age']-161
if(self.uinfo['activity']==1):
return x*1.2
elif self.uinfo['activity']==2:
return x*1.375
elif self.uinfo['activity']==3:
return x*1.55
elif self.uinfo['activity']==4:
return x*1.725
else:
x*1.9
#need to write function for self.uinfo['activity']ivity levelhuhuhu
def update_user_progress(self,boolBf,breakfast,lunch,dinner,rate,hoursSlept,stepsWalked):
self.tinfo['boolBf']=boolBf
self.tinfo['breakfast']=breakfast
self.tinfo['lunch']=lunch
self.tinfo['dinner']=dinner
self.tinfo['heartRate']=rate
self.uinfo['hours']=hoursSlept
self.tinfo['stepsWalked']=stepsWalked
self.update_score()
def heartScore(self):
score=10
max_rate=220-self.uinfo['age']
min_range=0.5*max_rate
max_range=0.85*max_rate
if int(self.uinfo['activity'])<3:
if self.tinfo['heartRate']<min_range and self.tinfo['heartRate']>max_range:
score=score-2
if self.tinfo['heartRate']>max_rate:
score =score -1
else:
if self.tinfo['heartRate']<min_range and self.tinfo['heartRate']>max_rate:
score=score-2
return score
#breakfast bool value
#scores - if good then
# best score 10, worst score 6, mid way score 8
def sleep_score(self):
score=10
if(self.uinfo['age']>=13 and self.tinfo['heartRate']<=18):
if(self.uinfo['hours']>=10 or self.uinfo['hours']<=8):
score = score - 2
if(self.tinfo['heartRate']>18 or self.tinfo['heartRate']<=64):
if(self.uinfo['hours']>9 or self.uinfo['hours']<7):
score = score - 2
if(self.tinfo['heartRate']>64):
if(self.uinfo['hours']>8 or self.uinfo['hours']<7):
score = score - 2;
if self.tinfo['boolBf']==1:
score=score-2
return score
def calc_calories(self):
cal = 0
df_cal = pd.read_csv("/mnt/d/Hashcode/Hashcode_2022/data/calories.csv")
df_cal['Cals_per100grams'] = df_cal['Cals_per100grams'].str.replace(' cal','')
i = 0
for food in self.tinfo['breakfast']:
if (df_cal['FoodItem'][i] == food):
cal = cal + int(df_cal['Cals_per100grams'][i])
i = i + 1
i = 0
for food in self.tinfo['lunch']:
if (df_cal['FoodItem'][i] == food):
cal = cal + int(df_cal['Cals_per100grams'][i])
i = i + 1
i = 0
for food in self.tinfo['dinner']:
if (df_cal['FoodItem'][i] == food):
cal = cal + int(df_cal['Cals_per100grams'][i])
i = i + 1
return 1800
def get_mood(self):
model=joblib.load('/mnt/d/Hashcode/Hashcode_2022/model')
act=0
if(self.uinfo['activity'])<3:
act=0
else:
act=1
y=model.predict(7000,900,int(self.uinfo['hours']),act,int(self.uinfo['wt']))
if y==1:
self.tinfo['mood']='Sad'
elif y==2:
self.tinfo['mood']='neutral'
else:
self.tinfo['mood']='happy'
def update_score(self):
print(self.uinfo['wt'])
bmi=self.uinfo['wt']*100*100/(self.uinfo['ht']*self.uinfo['ht'])
self.status=""
if(bmi<18.5):
self.status='underweight'
elif bmi>18.5 and bmi<=24.9:
self.status="normal"
elif bmi>=25 and bmi<=29.9:
self.status="overweight"
else:
self.status="obese"
calorie=self.cintake()
heart=self.heartScore()
sleep=self.sleep_score()
cal_score= calorie- self.calc_calories()
phy_wellness= heart*10 + sleep*10
#men_health= load model and give output
self.tinfo['phy_wellness'] = phy_wellness