// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct


import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.Sort;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.SensorData.maxSensorAgeInMinutes;
import static de.dorianscholz.openlibre.model.SensorData.minSensorAgeInMinutes;
import static java.lang.Math.min;
package de.dorianscholz.openlibre.model;





public class ReadingData extends RealmObject {
    public static final String ID = "id";
    public static final String SENSOR = "sensor";
    public static final String SENSOR_AGE_IN_MINUTES = "sensorAgeInMinutes";
    public static final String DATE = "date";
    public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
    public static final String TREND = "trend";
    public static final String HISTORY = "history";


    public static final int numHistoryValues = 32;
    public static final int historyIntervalInMinutes = 15;
    public static final int numTrendValues = 16;

    @PrimaryKey
    private String id;
    private SensorData sensor;
    private int sensorAgeInMinutes = -1;
    private long date = -1;
    private int timezoneOffsetInMinutes;
    private RealmList<GlucoseData> trend = new RealmList<>();
    private RealmList<GlucoseData> history = new RealmList<>();

    public ReadingData() {}
    public ReadingData(RawTagData rawTagData) {
        id = rawTagData.getId();
        date = rawTagData.getDate();
        timezoneOffsetInMinutes = rawTagData.getTimezoneOffsetInMinutes();
        sensorAgeInMinutes = rawTagData.getSensorAgeInMinutes();

// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct


// Path: app/src/main/java/de/dorianscholz/openlibre/model/ReadingData.java
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.Sort;
import io.realm.annotations.PrimaryKey;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.SensorData.maxSensorAgeInMinutes;
import static de.dorianscholz.openlibre.model.SensorData.minSensorAgeInMinutes;
import static java.lang.Math.min;

package de.dorianscholz.openlibre.model;





public class ReadingData extends RealmObject {
    public static final String ID = "id";
    public static final String SENSOR = "sensor";
    public static final String SENSOR_AGE_IN_MINUTES = "sensorAgeInMinutes";
    public static final String DATE = "date";
    public static final String TIMEZONE_OFFSET_IN_MINUTES = "timezoneOffsetInMinutes";
    public static final String TREND = "trend";
    public static final String HISTORY = "history";


    public static final int numHistoryValues = 32;
    public static final int historyIntervalInMinutes = 15;
    public static final int numTrendValues = 16;

    @PrimaryKey
    private String id;
    private SensorData sensor;
    private int sensorAgeInMinutes = -1;
    private long date = -1;
    private int timezoneOffsetInMinutes;
    private RealmList<GlucoseData> trend = new RealmList<>();
    private RealmList<GlucoseData> history = new RealmList<>();

    public ReadingData() {}
    public ReadingData(RawTagData rawTagData) {
        id = rawTagData.getId();
        date = rawTagData.getDate();
        timezoneOffsetInMinutes = rawTagData.getTimezoneOffsetInMinutes();
        sensorAgeInMinutes = rawTagData.getSensorAgeInMinutes();

        Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);