Beispiel #1
0
    public CaliperMethod GetCaliperMeasurements(string code, string title, string description, int gender)
    {
        CaliperMethod x = new CaliperMethod();

        x.code         = code;
        x.title        = title;
        x.description  = description;
        x.measurements = new List <CaliperMeasurement>();
        x.measurements.Add(new CaliperMeasurement {
            code = Chest, title = "Chest", description = null, value = 0, isSelected = CheckCaliperMethod(code, Chest, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Abdominal, title = "Abdominal", description = null, value = 0, isSelected = CheckCaliperMethod(code, Abdominal, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Thigh, title = "Thigh", description = null, value = 0, isSelected = CheckCaliperMethod(code, Thigh, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Tricep, title = "Tricep", description = null, value = 0, isSelected = CheckCaliperMethod(code, Tricep, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Subscapular, title = "Subscapular", description = null, value = 0, isSelected = CheckCaliperMethod(code, Subscapular, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Suprailiac, title = "Suprailiac", description = null, value = 0, isSelected = CheckCaliperMethod(code, Suprailiac, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Midaxillary, title = "Midaxillary", description = null, value = 0, isSelected = CheckCaliperMethod(code, Midaxillary, gender)
        });
        x.measurements.Add(new CaliperMeasurement {
            code = Bicep, title = "Bicep", description = null, value = 0, isSelected = CheckCaliperMethod(code, Bicep, gender)
        });

        return(x);
    }
Beispiel #2
0
 public string Save(CaliperMethod x)
 {
     try {
         db.CreateDataBase(x.clientData.userId, db.bodyfat);
         string        measurements = null;
         List <string> list         = new List <string>();
         foreach (var m in x.measurements)
         {
             if (m.isSelected)
             {
                 list.Add(string.Format("{0}:{1}", m.code, m.value));
             }
         }
         measurements = string.Join(";", list);
         string sql = string.Format(@"BEGIN;
                 INSERT OR REPLACE INTO bodyfat (recordDate, clientId, bodyFat, records, recordMethod)
                 VALUES ('{0}', '{1}', '{2}', '{3}', '{4}');
                 COMMIT;", x.recordDate, x.clientData.clientId, x.bodyFat, measurements, x.code);
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(x.clientData.userId, dataBase))) {
             connection.Open();
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.ExecuteNonQuery();
             }
             connection.Close();
         }
         return(JsonConvert.SerializeObject(x.bodyFat, Formatting.None));
     } catch (Exception e) { return(e.Message); }
 }
Beispiel #3
0
    private List <CaliperMeasurement> GetMeasurements(string str)
    {
        List <CaliperMeasurement> xx = new List <CaliperMeasurement>();

        if (!string.IsNullOrEmpty(str))
        {
            CaliperMeasurement x    = new CaliperMeasurement();
            CaliperMethod      cm   = GetCaliperMeasurements(null, null, null, 0);
            CaliperMeasurement calM = new CaliperMeasurement();
            string[]           ss   = str.Split(';');
            string[]           m;
            foreach (var s in ss)
            {
                m             = s.Split(':');
                x             = new CaliperMeasurement();
                x.code        = m[0];
                x.value       = Convert.ToDouble(m[1]);
                calM          = cm.measurements.Where(a => a.code == x.code).FirstOrDefault();
                x.title       = calM.title;
                x.description = calM.description;
                x.isSelected  = true;
                xx.Add(x);
            }
        }
        return(xx);
    }
Beispiel #4
0
 public CaliperMethod GetLastMeasurement(ClientsData.NewClientData clientData)
 {
     try {
         List <CaliperMethod> xx         = new List <CaliperMethod>();
         CaliperMethod        lastRecord = new CaliperMethod();
         string measurements             = null;
         db.CreateDataBase(clientData.userId, db.bodyfat);
         string sql = string.Format("SELECT recordDate, bodyFat, records, recordMethod FROM bodyfat WHERE clientId = '{0}'", clientData.clientId);
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(clientData.userId, dataBase))) {
             connection.Open();
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         CaliperMethod x = new CaliperMethod();
                         x.recordDate   = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
                         x.bodyFat      = reader.GetValue(1) == DBNull.Value ? 0 : Convert.ToDouble(reader.GetString(1));
                         measurements   = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                         x.measurements = GetMeasurements(measurements);
                         x.code         = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                         xx.Add(x);
                     }
                 }
             }
             connection.Close();
         }
         if (xx.Count > 0)
         {
             lastRecord = xx.OrderByDescending(a => Convert.ToDateTime(a.recordDate)).FirstOrDefault();
         }
         return(lastRecord);
     } catch (Exception e) {
         return(new CaliperMethod());
     }
 }
Beispiel #5
0
    public string CaliperCalculate(CaliperMethod data)
    {
        double x = 0.0;

        try {
            x = CaliperCalc(data);
            return(JsonConvert.SerializeObject(CaliperCalc(data), Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, data.code, data.clientData.userId, "BodyFat", "CaliperCalculate");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Beispiel #6
0
 public string CaliperCalculate(CaliperMethod data)
 {
     try {
         return(JsonConvert.SerializeObject(CaliperCalc(data), Formatting.None));
     } catch (Exception e) { return("Error: " + e); }
 }
Beispiel #7
0
    public double CaliperCalc(CaliperMethod data)
    {
        double x           = 0;
        double skinfolds   = data.measurements.Where(a => a.isSelected == true).Sum(a => a.value);
        double bodyDensity = 0;
        int    gender      = data.clientData.gender.value;
        int    age         = data.clientData.age;

        if (data.code == JacksonPollock3)
        {
            if (gender == 0)
            {
                //Body Density = 1.10938 – (0.0008267 x sum of skinfolds) +(0.0000016 x square of the sum of skinfolds) – (0.0002574 x age)
                bodyDensity = 1.10938 - (0.0008267 * skinfolds) + (0.0000016 * skinfolds * skinfolds) - (0.0002574 * age);
            }
            else
            {
                //Body Density = 1.0994921 – (0.0009929 x sum of skinfolds) +(0.0000023 x square of the sum of skinfolds) – (0.0001392 x age)
                bodyDensity = 1.0994921 - (0.0009929 * skinfolds) + (0.0000023 * skinfolds * skinfolds) - (0.0001392 * age);
            }
            x = (495 / bodyDensity) - 450;
        }
        if (data.code == JacksonPollock4)
        {
            if (gender == 0)
            {
                //Body Density = (0.29288 x sum of skinfolds) – (0.0005 x square of the sum of skinfolds) + (0.15845 x age) – 5.76377
                x = (0.29288 * skinfolds) - (0.0005 * skinfolds * skinfolds) + (0.15845 * age) - 5.76377;
            }
            else
            {
                //Body Density = (0.29669 x sum of skinfolds) – (0.00043 x square of the sum of skinfolds) + (0.02963 x age) + 1.4072
                x = (0.29669 * skinfolds) - (0.00043 * skinfolds * skinfolds) + (0.02963 * age) + 1.4072;
            }
        }
        if (data.code == JacksonPollock7)
        {
            if (gender == 0)
            {
                //Body Density = 1.112 – (0.00043499 x sum of skinfolds) + (0.00000055 x square of the sum of skinfold sites) – (0.00028826 x age)
                bodyDensity = 1.112 - (0.00043499 * skinfolds) + (0.00000055 * skinfolds * skinfolds) - (0.00028826 * age);
            }
            else
            {
                //Body Density = 1.097 – (0.00046971 x sum of skinfolds) + (0.00000056 x square of the sum of skinfold sites) – (0.00012828 x age)
                bodyDensity = 1.097 - (0.00046971 * skinfolds) + (0.00000056 * skinfolds * skinfolds) - (0.00012828 * age);
            }
            x = (495 / bodyDensity) - 450;
        }
        if (data.code == DurninWomersley)
        {
            double log = Math.Log10(skinfolds); //Log of the sum of skinfolds
            if (gender == 0)
            {
                if (age < 17)
                {
                    bodyDensity = 1.1533 - (0.0643 * log);
                }
                if (age > 17 && age < 20)
                {
                    bodyDensity = 1.1620 - (0.0630 * log);
                }
                if (age > 20 && age < 30)
                {
                    bodyDensity = 1.1631 - (0.0632 * log);
                }
                if (age > 30 && age < 40)
                {
                    bodyDensity = 1.1422 - (0.0544 * log);
                }
                if (age > 40 && age < 50)
                {
                    bodyDensity = 1.1620 - (0.0700 * log);
                }
                if (age > 50)
                {
                    bodyDensity = 1.1715 - (0.0779 * log);
                }
            }
            else
            {
                if (age < 17)
                {
                    bodyDensity = 1.1369 - (0.0598 * log);
                }
                if (age > 17 && age < 20)
                {
                    bodyDensity = 1.1549 - (0.0678 * log);
                }
                if (age > 20 && age < 30)
                {
                    bodyDensity = 1.1599 - (0.0717 * log);
                }
                if (age > 30 && age < 40)
                {
                    bodyDensity = 1.1423 - (0.0632 * log);
                }
                if (age > 40 && age < 50)
                {
                    bodyDensity = 1.1333 - (0.0612 * log);
                }
                if (age > 50)
                {
                    bodyDensity = 1.1339 - (0.0645 * log);
                }
            }
            x = (495 / bodyDensity) - 450;
        }

        return(Math.Round(x, 1));
    }