teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

修正

2020/07/29 09:34

投稿

yastinbieber
yastinbieber

スコア49

title CHANGED
File without changes
body CHANGED
@@ -191,4 +191,65 @@
191
191
  end
192
192
  end
193
193
 
194
+ ```
195
+
196
+ ## 質問に対するご回答をもとに出した内容
197
+ ```
198
+ ##idealweight.rb
199
+ class Idealweight < ApplicationRecord
200
+ belongs_to :user
201
+ has_many :fooddiaries
202
+ has_many :advicediaries
203
+ has_many :weightchanges
204
+
205
+ before_save do
206
+ if user.sex == "男"
207
+ self.basemetabolism = 13.397*(weight)+4.799*(height)-5.677*(user.age)+88.362 #男性の場合
208
+ else
209
+ self.basemetabolism = 9.247*(weight)+3.098*(height)-4.33*(user.age)+447.593 #女性の場合
210
+ end
211
+ self.kcalburned = (basemetabolism)*(exerciselevel)
212
+ self.minusweight = (weight)-(targetweight)
213
+ self.minuskcal = (minusweight)*7000
214
+ self.period = ((last_day) - (start_day)).to_i
215
+ self.minusweight_day = (minusweight) / (period)
216
+ self.kcalintake = (kcalburned)-(minuskcal)/(period)
217
+ self.intakeproteingram = (weight)*2
218
+ self.intakeproteinkcal = (weight)*2*4
219
+ self.intakefatgram = (weight)*0.7
220
+ self.intakefatkcal = (weight)*0.7*9
221
+ self.intakecarbokcal = (kcalintake)-(intakeproteinkcal)-(intakefatkcal)
222
+ self.intakecarbogram = (intakecarbokcal)/4
223
+ end
224
+
225
+ #リアルタイムでの今日
226
+ def today_date
227
+ @today = Date.today
228
+ @today.strftime("%Y%m%d").to_i
229
+ end
230
+
231
+ #ボディメイク開始日
232
+ def start_day_date
233
+ start_day.strftime("%Y%m%d").to_i
234
+ end
235
+
236
+ #今日は何日目か
237
+ def what_day
238
+ ((today_date)+1) - (start_day_date)
239
+ end
240
+
241
+ end
242
+
243
+ ```
244
+ ```
245
+ ##weightchange.rb
246
+ class Weightchange < ApplicationRecord
247
+ belongs_to :user
248
+ belongs_to :idealweight
249
+
250
+ before_save do
251
+ self.expected_weight = (idealweight.weight)-((idealweight.minusweight_day)*(idealweight.what_day))
252
+ end
253
+ end
254
+
194
255
  ```