Search in sources :

Example 1 with Activity

use of com.faltenreich.diaguard.shared.data.database.entity.Activity in project Diaguard by Faltenreich.

the class MeasurementDao method getAvgMeasurement.

public Measurement getAvgMeasurement(Category category, Interval interval) {
    long daysBetween = interval.toDuration().getStandardDays() + 1;
    switch(category) {
        case BLOODSUGAR:
            BloodSugar bloodSugar = new BloodSugar();
            bloodSugar.setMgDl(function(SqlFunction.AVG, BloodSugar.Column.MGDL, interval));
            return bloodSugar;
        case INSULIN:
            Insulin insulin = new Insulin();
            insulin.setBolus(function(SqlFunction.SUM, Insulin.Column.BOLUS, interval) / daysBetween);
            insulin.setBasal(function(SqlFunction.SUM, Insulin.Column.BASAL, interval) / daysBetween);
            insulin.setCorrection(function(SqlFunction.SUM, Insulin.Column.CORRECTION, interval) / daysBetween);
            return insulin;
        case MEAL:
            Meal meal = new Meal();
            float avg = function(SqlFunction.SUM, Meal.Column.CARBOHYDRATES, interval) / daysBetween;
            float foodEatenSum = 0;
            List<FoodEaten> foodEatenList = FoodEatenDao.getInstance().getAll(interval);
            for (FoodEaten foodEaten : foodEatenList) {
                foodEatenSum += foodEaten.getCarbohydrates();
            }
            avg = avg + (foodEatenSum / daysBetween);
            meal.setCarbohydrates(avg);
            return meal;
        case ACTIVITY:
            Activity activity = new Activity();
            activity.setMinutes((int) (function(SqlFunction.SUM, Activity.Column.MINUTES, interval) / daysBetween));
            return activity;
        case HBA1C:
            HbA1c hbA1c = new HbA1c();
            hbA1c.setPercent(function(SqlFunction.AVG, HbA1c.Column.PERCENT, interval));
            return hbA1c;
        case WEIGHT:
            Weight weight = new Weight();
            weight.setKilogram(function(SqlFunction.AVG, Weight.Column.KILOGRAM, interval));
            return weight;
        case PULSE:
            Pulse pulse = new Pulse();
            pulse.setFrequency(function(SqlFunction.AVG, Pulse.Column.FREQUENCY, interval));
            return pulse;
        case PRESSURE:
            Pressure pressure = new Pressure();
            pressure.setSystolic(function(SqlFunction.AVG, Pressure.Column.SYSTOLIC, interval));
            pressure.setDiastolic(function(SqlFunction.AVG, Pressure.Column.DIASTOLIC, interval));
            return pressure;
        case OXYGEN_SATURATION:
            OxygenSaturation oxygenSaturation = new OxygenSaturation();
            oxygenSaturation.setPercent(function(SqlFunction.AVG, OxygenSaturation.Column.PERCENT, interval));
            return oxygenSaturation;
        default:
            return null;
    }
}
Also used : Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) Pulse(com.faltenreich.diaguard.shared.data.database.entity.Pulse) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) Activity(com.faltenreich.diaguard.shared.data.database.entity.Activity) OxygenSaturation(com.faltenreich.diaguard.shared.data.database.entity.OxygenSaturation) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) Pressure(com.faltenreich.diaguard.shared.data.database.entity.Pressure) Weight(com.faltenreich.diaguard.shared.data.database.entity.Weight) HbA1c(com.faltenreich.diaguard.shared.data.database.entity.HbA1c)

Aggregations

Activity (com.faltenreich.diaguard.shared.data.database.entity.Activity)1 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)1 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)1 HbA1c (com.faltenreich.diaguard.shared.data.database.entity.HbA1c)1 Insulin (com.faltenreich.diaguard.shared.data.database.entity.Insulin)1 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)1 OxygenSaturation (com.faltenreich.diaguard.shared.data.database.entity.OxygenSaturation)1 Pressure (com.faltenreich.diaguard.shared.data.database.entity.Pressure)1 Pulse (com.faltenreich.diaguard.shared.data.database.entity.Pulse)1 Weight (com.faltenreich.diaguard.shared.data.database.entity.Weight)1