質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -385,3 +385,125 @@
|
|
385
385
|
|
386
386
|
|
387
387
|
```
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
## 質問に対するご回答をもとに出した内容
|
392
|
+
|
393
|
+
```
|
394
|
+
|
395
|
+
##idealweight.rb
|
396
|
+
|
397
|
+
class Idealweight < ApplicationRecord
|
398
|
+
|
399
|
+
belongs_to :user
|
400
|
+
|
401
|
+
has_many :fooddiaries
|
402
|
+
|
403
|
+
has_many :advicediaries
|
404
|
+
|
405
|
+
has_many :weightchanges
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
before_save do
|
410
|
+
|
411
|
+
if user.sex == "男"
|
412
|
+
|
413
|
+
self.basemetabolism = 13.397*(weight)+4.799*(height)-5.677*(user.age)+88.362 #男性の場合
|
414
|
+
|
415
|
+
else
|
416
|
+
|
417
|
+
self.basemetabolism = 9.247*(weight)+3.098*(height)-4.33*(user.age)+447.593 #女性の場合
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
self.kcalburned = (basemetabolism)*(exerciselevel)
|
422
|
+
|
423
|
+
self.minusweight = (weight)-(targetweight)
|
424
|
+
|
425
|
+
self.minuskcal = (minusweight)*7000
|
426
|
+
|
427
|
+
self.period = ((last_day) - (start_day)).to_i
|
428
|
+
|
429
|
+
self.minusweight_day = (minusweight) / (period)
|
430
|
+
|
431
|
+
self.kcalintake = (kcalburned)-(minuskcal)/(period)
|
432
|
+
|
433
|
+
self.intakeproteingram = (weight)*2
|
434
|
+
|
435
|
+
self.intakeproteinkcal = (weight)*2*4
|
436
|
+
|
437
|
+
self.intakefatgram = (weight)*0.7
|
438
|
+
|
439
|
+
self.intakefatkcal = (weight)*0.7*9
|
440
|
+
|
441
|
+
self.intakecarbokcal = (kcalintake)-(intakeproteinkcal)-(intakefatkcal)
|
442
|
+
|
443
|
+
self.intakecarbogram = (intakecarbokcal)/4
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
#リアルタイムでの今日
|
450
|
+
|
451
|
+
def today_date
|
452
|
+
|
453
|
+
@today = Date.today
|
454
|
+
|
455
|
+
@today.strftime("%Y%m%d").to_i
|
456
|
+
|
457
|
+
end
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
#ボディメイク開始日
|
462
|
+
|
463
|
+
def start_day_date
|
464
|
+
|
465
|
+
start_day.strftime("%Y%m%d").to_i
|
466
|
+
|
467
|
+
end
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
#今日は何日目か
|
472
|
+
|
473
|
+
def what_day
|
474
|
+
|
475
|
+
((today_date)+1) - (start_day_date)
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
```
|
486
|
+
|
487
|
+
```
|
488
|
+
|
489
|
+
##weightchange.rb
|
490
|
+
|
491
|
+
class Weightchange < ApplicationRecord
|
492
|
+
|
493
|
+
belongs_to :user
|
494
|
+
|
495
|
+
belongs_to :idealweight
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
before_save do
|
500
|
+
|
501
|
+
self.expected_weight = (idealweight.weight)-((idealweight.minusweight_day)*(idealweight.what_day))
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
end
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
```
|