193 lines
4.2 KiB
C#
193 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
using Android.App;
|
|
using Android.Content;
|
|
using Android.OS;
|
|
using Android.Runtime;
|
|
using Android.Views;
|
|
using Android.Widget;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Eat.Models
|
|
{
|
|
enum Sex
|
|
{
|
|
Male, Female
|
|
};
|
|
|
|
enum ActivityLevel
|
|
{
|
|
VeryLow, Low, Medium, High, VeryHigh
|
|
};
|
|
|
|
enum Goal
|
|
{
|
|
Reduce, Stay, Gain
|
|
}
|
|
|
|
class User : Product
|
|
{
|
|
[JsonProperty]
|
|
public Sex Sex
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
[JsonProperty]
|
|
public ActivityLevel ActivityLevel
|
|
{
|
|
get; set;
|
|
}
|
|
[JsonProperty]
|
|
public Goal Goal
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
[JsonProperty]
|
|
public double Weight
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
[JsonProperty]
|
|
public int Height
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
[JsonProperty]
|
|
public DateTime Birthday
|
|
{
|
|
get => Birthday;
|
|
set
|
|
{
|
|
Birthday = value;
|
|
Age = (DateTime.Now.Subtract(Birthday).Days / 365);
|
|
}
|
|
}
|
|
[JsonProperty]
|
|
public int Age
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
[JsonProperty]
|
|
public double FatRatio
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
[JsonProperty]
|
|
public double CarbsRatio
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
[JsonProperty]
|
|
public double ProteinRatio
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
static readonly Dictionary<ActivityLevel, double> ActivityFactor = new Dictionary<ActivityLevel, double>
|
|
{
|
|
{ActivityLevel.VeryLow, 1.2},
|
|
{ActivityLevel.Low, 1.375},
|
|
{ActivityLevel.Medium, 1.55},
|
|
{ActivityLevel.High, 1.725},
|
|
{ActivityLevel.VeryHigh, 1.9}
|
|
};
|
|
|
|
public User(Sex sex, ActivityLevel activityLevel, Goal goal, double weight, int height, DateTime birthday)
|
|
{
|
|
Sex = sex;
|
|
ActivityLevel = activityLevel;
|
|
Goal = Goal;
|
|
Weight = weight;
|
|
Height = height;
|
|
Birthday = birthday;
|
|
|
|
if (Goal == Goal.Reduce)
|
|
{
|
|
FatRatio = 0.3;
|
|
CarbsRatio = 0.4;
|
|
ProteinRatio = 0.3;
|
|
}
|
|
else if (Goal == Goal.Stay)
|
|
{
|
|
FatRatio = 0.275;
|
|
CarbsRatio = 0.5;
|
|
ProteinRatio = 0.225;
|
|
}
|
|
else
|
|
{
|
|
FatRatio = 0.2;
|
|
CarbsRatio = 0.6;
|
|
ProteinRatio = 0.2;
|
|
}
|
|
}
|
|
|
|
public User(Sex sex, ActivityLevel activityLevel, Goal goal, double weight, int height, DateTime birthday, double fatRatio, double carbsRatio, double proteinRatio)
|
|
{
|
|
Sex = sex;
|
|
ActivityLevel = ActivityLevel;
|
|
Goal = goal;
|
|
Weight = weight;
|
|
Height = height;
|
|
Birthday = birthday;
|
|
FatRatio = fatRatio;
|
|
CarbsRatio = carbsRatio;
|
|
ProteinRatio = proteinRatio;
|
|
}
|
|
|
|
public override void CalculateElements()
|
|
{
|
|
// Kcal
|
|
//
|
|
//
|
|
// Basic calculation
|
|
//
|
|
Kcal = Convert.ToInt32((10 * Weight) + (6.25 * Height) - (4.92 * Age));
|
|
|
|
// Gender
|
|
//
|
|
if (Sex == Sex.Male)
|
|
{
|
|
Kcal += 5;
|
|
}
|
|
else
|
|
{
|
|
Kcal -= 161;
|
|
}
|
|
|
|
// ActivityFactor
|
|
//
|
|
Kcal = Convert.ToInt32(Kcal * ActivityFactor[ActivityLevel]);
|
|
|
|
// Goal
|
|
//
|
|
if (Goal == Goal.Reduce)
|
|
{
|
|
Kcal -= 250;
|
|
}
|
|
else if (Goal == Goal.Gain)
|
|
{
|
|
Kcal += 250;
|
|
}
|
|
|
|
// Elements
|
|
//
|
|
//
|
|
Fat = Kcal / 9.0 * FatRatio;
|
|
Carbs = Kcal / 4.0 * CarbsRatio;
|
|
Protein = Kcal / 4.0 * ProteinRatio;
|
|
}
|
|
}
|
|
} |