Java Code Examples for com.eveningoutpost.dexdrip.Models.Sensor#currentSensor()

The following examples show how to use com.eveningoutpost.dexdrip.Models.Sensor#currentSensor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart");
    wakeLock.acquire(40000);
    Log.d(TAG, "onStartCommand");
    try {

        if (shouldServiceRun(getApplicationContext())) {
            setFailoverTimer();
        } else {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (Sensor.currentSensor() == null) {
            setRetryTimer();
            return START_NOT_STICKY;
        }
        Log.i(TAG, "STARTING SERVICE");
        attemptConnection();
    } finally {
        if(wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    }
    return START_STICKY;
}
 
Example 2
Source File: SensorStatus.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static String status() {
    final StringBuilder sensor_status = new StringBuilder();
    if (Sensor.isActive()) {
        final Sensor sensor = Sensor.currentSensor();
        final Date date = new Date(sensor.started_at);
        DateFormat df = new SimpleDateFormat();
        sensor_status.append(df.format(date));
        sensor_status.append(" (");
        sensor_status.append((tsl() - sensor.started_at) / Constants.DAY_IN_MS);
        sensor_status.append("d ");
        sensor_status.append(((tsl() - sensor.started_at) % Constants.DAY_IN_MS) / Constants.HOUR_IN_MS);
        sensor_status.append("h)");
    } else {
        sensor_status.append("not available");
    }
    return sensor_status.toString();
}
 
Example 3
Source File: Blukon.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example 4
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        android.util.Log.i("timestamp create", Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, filtered_data, this, transmitterData.timestamp);
    }
 
Example 5
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void syncSensorData(DataMap dataMap, Context context) {//KS
    Log.d(TAG, "syncSensorData");
    if (dataMap != null) {
        String uuid = dataMap.getString("uuid");
        Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid);
        long started_at = dataMap.getLong("started_at");
        Integer latest_battery_level = dataMap.getInt("latest_battery_level");
        String sensor_location = dataMap.getString("sensor_location");
        Sensor.InitDb(context);//ensure database has already been initialized
        if (uuid != null && !uuid.isEmpty()) {
            Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid + " timestamp=" + started_at + " timeString=" +  JoH.dateTimeText(started_at));
            Sensor sensor = Sensor.getByUuid(uuid);
            if (sensor == null) {
                Log.d(TAG, "syncSensorData createUpdate new Sensor...");
                Sensor.createUpdate(started_at, 0, latest_battery_level, sensor_location, uuid);
                Sensor newsensor = Sensor.currentSensor();
                if (newsensor != null) {
                    Log.d(TAG, "syncSensorData createUpdate Sensor with uuid=" + uuid + " started at=" + started_at);
                } else
                    Log.d(TAG, "syncSensorData Failed to createUpdate new Sensor for uuid=" + uuid);
            } else
                Log.d(TAG, "syncSensorData Sensor already exists with uuid=" + uuid);
        }
    }
}
 
Example 6
Source File: LibreReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null) {
        l.add(new StatusItem("Libre2 Sensor", sensor.uuid + "\nStart: " + DateFormat.format("dd.MM.yyyy kk:mm", sensor.started_at)));
    }
    String lastReading ="";
    try {
        lastReading = DateFormat.format("dd.MM.yyyy kk:mm:ss", last_reading).toString();
        l.add(new StatusItem("Last Reading", lastReading));
    } catch (Exception e) {
        Log.e(TAG, "Error readlast: " + e);
    }
    if (get_engineering_mode()) {
        l.add(new StatusItem("Last Calc.", libre_calc_doku));
    }
    if (Pref.getBooleanDefaultFalse("Libre2_showSensors")) {
        l.add(new StatusItem("Sensors", Libre2Sensors()));
    }
    return l;
}
 
Example 7
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart");
    wakeLock.acquire(40000);
    Log.d(TAG, "onStartCommand");
    try {

        if (shouldServiceRun(getApplicationContext())) {
            setFailoverTimer();
        } else {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (Sensor.currentSensor() == null) {
            setRetryTimer();
            return START_NOT_STICKY;
        }
        Log.i(TAG, "STARTING SERVICE");
        attemptConnection();
    } finally {
        if(wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    }
    return START_STICKY;
}
 
Example 8
Source File: DexCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, timestamp);
}
 
Example 9
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 10
Source File: PebbleSync.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public String bgReading() {
    Sensor sensor = new Sensor();
    if(PreferenceManager.getDefaultSharedPreferences(mContext).getString("dex_collection_method", "DexbridgeWixel").compareTo("DexbridgeWixel")==0 ) {
        Log.d(TAG, "bgReading: found xBridge wixel, sensor.isActive=" +sensor.isActive()+", sensor.stopped_at="+sensor.currentSensor().stopped_at+", sensor.started_at="+sensor.currentSensor().started_at);
        if (!(sensor.isActive())) {
            Log.d(TAG, "bgReading: No active Sensor");
            return "?SN";
        }
        if ((sensor.currentSensor().started_at + 60000 * 60 * 2 >= System.currentTimeMillis())) {
            return "?CD";
        }
    }
    return bgGraphBuilder.unitized_string(mBgReading.calculated_value);
}
 
Example 11
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 12
Source File: SensorDays.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private long getDexcomStart() {
    if (usingNativeMode()) {
        return DexSessionKeeper.getStart();
    } else {
        try {
            // In non-native mode the expiration is a guide only
            return Sensor.currentSensor().started_at;
        } catch (Exception e) {
            return -1;
        }
    }
}
 
Example 13
Source File: XDripViewer.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void readSensorData(String baseUrl, String key) {

        NsRestApiReader nsRestApiReader = new NsRestApiReader();
        Long LastReportedTime = 0L;

        Sensor lastSensor = Sensor.currentSensor();

        if(lastSensor != null) {
            LastReportedTime = (long)lastSensor.started_at;
        }
        Log.e(TAG, "readSensorData  LastReportedTime = " + LastReportedTime);

        List<NightscoutSensor> nightscoutSensors = nsRestApiReader.readSensorDataFromNs(baseUrl, key, LastReportedTime, 10 );
        if(nightscoutSensors == null) {
            Log.e(TAG, "readBgDataFromNs returned null");
            return;
        }

        ListIterator<NightscoutSensor> li = nightscoutSensors.listIterator(nightscoutSensors.size());
        long lastInserted = 0;
        while(li.hasPrevious()) {
            NightscoutSensor nightscoutSensor = li.previous();
            Log.e(TAG, "nightscoutSensor " + nightscoutSensor.xDrip_uuid + " " + nightscoutSensor.xDrip_started_at);
            if(nightscoutSensor.xDrip_started_at < lastInserted) {
                Log.e(TAG, "not inserting Sensor, since order is wrong. ");
                continue;
            }
            Sensor.createUpdate(nightscoutSensor.xDrip_started_at, nightscoutSensor.xDrip_stopped_at, nightscoutSensor.xDrip_latest_battery_level, nightscoutSensor.xDrip_uuid);
            lastInserted = nightscoutSensor.xDrip_started_at;
        }
    }
 
Example 14
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 15
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncTransmitterData(DataMap dataMap, boolean bBenchmark) {//KS
    Log.d(TAG, "syncTransmitterData");

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastBG = 0;
    Log.d(TAG, "syncTransmitterData add BgReading Table");
    if (entries != null) {

        Gson gson = new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .registerTypeAdapter(Date.class, new DateTypeAdapter())
                .serializeSpecialFloatingPointValues()
                .create();

        int idx = 0;
        int count = entries.size();
        Log.d(TAG, "syncTransmitterData add BgReading Table entries count=" + count);
        for (DataMap entry : entries) {
            if (entry != null) {
                //Log.d(TAG, "syncTransmitterData add BgReading Table entry=" + entry);
                idx++;
                String bgrecord = entry.getString("bgs");
                if (bgrecord != null) {//for (TransmitterData bgData : bgs) {
                    //Log.d(TAG, "syncTransmitterData add TransmitterData Table bgrecord=" + bgrecord);
                    TransmitterData bgData = gson.fromJson(bgrecord, TransmitterData.class);
                    //TransmitterData bgData = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(bgrecord, TransmitterData.class);
                    TransmitterData exists = TransmitterData.getForTimestamp(bgData.timestamp);
                    TransmitterData uuidexists = TransmitterData.findByUuid(bgData.uuid);
                    timeOfLastBG = bgData.timestamp + 1;
                    if (exists != null || uuidexists != null) {
                        Log.d(TAG, "syncTransmitterData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                    } else {
                        Log.d(TAG, "syncTransmitterData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                        if (!bBenchmark) {
                            bgData.save();

                            //Check
                            if (TransmitterData.findByUuid(bgData.uuid) != null)
                                Log.d(TAG, "syncTransmitterData: TransmitterData was saved for uuid:" + bgData.uuid);
                            else {
                                Log.e(TAG, "syncTransmitterData: TransmitterData was NOT saved for uuid:" + bgData.uuid);
                                return;
                            }

                            //KS the following is from G5CollectionService processNewTransmitterData()
                            Sensor sensor = Sensor.currentSensor();
                            if (sensor == null) {
                                Log.e(TAG, "syncTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
                                return;
                            }
                            //TODO : LOG if unfiltered or filtered values are zero
                            Sensor.updateBatteryLevel(sensor, bgData.sensor_battery_level);
                            Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));//android.util.Log.i
                            BgReading bgExists;

                            //KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
                            if (count > 1 && idx < count) {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);//Disable Notifications for bulk insert
                            } else {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp);
                            }
                            if (bgExists != null)
                                Log.d(TAG, "syncTransmitterData BG GSON saved BG: " + bgExists.toS());
                            else
                                Log.e(TAG, "syncTransmitterData BG GSON NOT saved");
                        }
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_BGS count=" + entries.size(), timeOfLastBG, bBenchmark ? "BM" : "BG", -1);
    }
}
 
Example 16
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
            // TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }

        if (transmitterData.unchangedRaw() && !SensorSanity.allowTestingWithDeadSensor()) {
            UserError.Log.wtf(TAG, "Raw values are not changing - blocking further processing: " + raw_data + " " + filtered_data);
            return;
        }

        final Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            UserError.Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        if (d)
            UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));

        if ((lastGlucoseBgReading != null) && (msSince(lastUsableGlucosePacket) < Constants.SECOND_IN_MS * 30)) {
            UserError.Log.d(TAG, "Updating BgReading provided by transmitter");
            // use sensor data to update previous record instead of trying to calculate with it
            lastGlucoseBgReading.raw_data = transmitterData.raw_data / 1000;
            lastGlucoseBgReading.filtered_data = transmitterData.filtered_data / 1000;
            // TODO calculate filtered calculated value from internal alg??
            lastGlucoseBgReading.calculateAgeAdjustedRawValue();
            lastGlucoseBgReading.save();
        } else {
            if (!Ob1G5CollectionService.usingNativeMode() || Ob1G5CollectionService.fallbackToXdripAlgorithm() || BgReading.latest(3).size() < 3) {
                final BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
                UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
            }
        }

        //   UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));//KS
        //   UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));//KS
        //   UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));//KS
        //   UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));//KS


        // TODO static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 17
Source File: PersistentHigh.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static boolean dataQualityCheck(final long since, final double highMarkMgDl) {

        final Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "Cannot raise persistent high alert as no active sensor!");
            return false;
        }
        if (since < sensor.started_at) {
            Log.e(TAG, "Cannot raise persistent high alert as high time pre-dates sensor start");
            return false;
        }
        final long duration = msSince(since);
        if (duration > Constants.DAY_IN_MS || duration < 0) {
            Log.e(TAG, "Cannot raise persistent high alert as duration doesn't make sense: " + JoH.niceTimeScalar(duration));
            return false;
        }

        final List<BgReading> readings = BgReading.latestForSensorAsc(2000, since, JoH.tsl(), Home.get_follower());
        if (readings == null) {
            Log.e(TAG, "Cannot raise persistent high alert as there are no readings for this sensor!");
            return false;
        }

        final int numberOfReadings = readings.size();

        if (numberOfReadings == 0) {
            Log.e(TAG, "Cannot raise persistent high alert as there are 0 readings for this sensor!");
            return false;
        }

        final long frequency = duration / numberOfReadings;
        //Log.d(TAG, "Frequency Calculated as: " + frequency);
        if (frequency > MINUTE_IN_MS * 15) {
            Log.e(TAG, "Cannot raise persistent high alert as readings frequency is: " + niceTimeScalar(frequency));
            return false;
        }

        for (final BgReading bgr : readings) {
            if (bgr.getDg_mgdl() < highMarkMgDl) {
                Log.e(TAG, "High not persistent as reading at: " + JoH.dateTimeText(bgr.timestamp) + " does not exceed " + JoH.qs(highMarkMgDl) + " mgdl / high mark");
                return false;
            }
        }

        return true;

    }
 
Example 18
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
            // TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }

        if (transmitterData.unchangedRaw() && !SensorSanity.allowTestingWithDeadSensor()) {
            UserError.Log.wtf(TAG, "Raw values are not changing - blocking further processing: " + raw_data + " " + filtered_data);
            return;
        }

        final Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            UserError.Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        if (d)
            UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));

        if ((lastGlucoseBgReading != null) && (msSince(lastUsableGlucosePacket) < Constants.SECOND_IN_MS * 30)) {
            UserError.Log.d(TAG, "Updating BgReading provided by transmitter");
            // use sensor data to update previous record instead of trying to calculate with it
            lastGlucoseBgReading.raw_data = transmitterData.raw_data / 1000;
            lastGlucoseBgReading.filtered_data = transmitterData.filtered_data / 1000;
            // TODO calculate filtered calculated value from internal alg??
            lastGlucoseBgReading.calculateAgeAdjustedRawValue();
            lastGlucoseBgReading.save();
        } else {
            if (!Ob1G5CollectionService.usingNativeMode() || Ob1G5CollectionService.fallbackToXdripAlgorithm() || BgReading.latest(3).size() < 3) {
                final BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
                UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
            }
        }

        //   UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));//KS
        //   UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));//KS
        //   UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));//KS
        //   UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));//KS


        // TODO static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 19
Source File: Telemetry.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static void sendCaptureReport() {
    try {
        if (JoH.ratelimit("capture-report", 50000)) {
            Log.d(TAG, "SEND EVENT START");

            if (Pref.getBooleanDefaultFalse("enable_crashlytics") && Pref.getBooleanDefaultFalse("enable_telemetry")) {

                final Sensor sensor = Sensor.currentSensor();

                if (sensor != null) {
                    if (JoH.msSince(sensor.started_at) > 86400000) {

                        final StatsResult statsResult = new StatsResult(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()), true);
                        final int capture_percentage = statsResult.getCapturePercentage();
                        final int capture_set = (capture_percentage / 10) * 10;

                        if (capture_set > 60) {
                            final boolean use_transmiter_pl_bluetooth = Pref.getBooleanDefaultFalse("use_transmiter_pl_bluetooth");
                            final boolean use_rfduino_bluetooth = Pref.getBooleanDefaultFalse("use_rfduino_bluetooth");
                            final String subtype = (use_transmiter_pl_bluetooth ? "TR" : "") + (use_rfduino_bluetooth ? "RF" : "") + (Home.get_forced_wear() ? "W" : "") + (NFCReaderX.used_nfc_successfully ? "N" : "");
                            final String capture_id = DexCollectionType.getDexCollectionType().toString() + subtype + " Captured " + capture_set;

                            Log.d(TAG, "SEND CAPTURE EVENT PROCESS: " + capture_id);
                            String watch_model = "";

                            if (Home.get_forced_wear()) {
                                // anonymize watch model
                                final String wear_node = Pref.getStringDefaultBlank("node_wearG5");
                                if (wear_node.length() > 0) {
                                    final String[] wear_array = wear_node.split(" ");
                                    for (String ii : wear_array) {
                                        if (!ii.contains("|"))
                                            watch_model = watch_model + ii;
                                    }
                                }
                            }
                            if (watch_model.length() > 0) {
                                Answers.getInstance().logCustom(new CustomEvent(capture_id)
                                        .putCustomAttribute("Model", Build.MODEL + " " + Build.VERSION.RELEASE)
                                        .putCustomAttribute("Manufacturer", Build.MANUFACTURER)
                                        .putCustomAttribute("Version", Build.VERSION.RELEASE)
                                        .putCustomAttribute("xDrip", getVersionDetails())
                                        .putCustomAttribute("Watch", watch_model)
                                        .putCustomAttribute("Percentage", capture_percentage));
                            } else {
                                Answers.getInstance().logCustom(new CustomEvent(capture_id)
                                        .putCustomAttribute("Model", Build.MODEL + " " + Build.VERSION.RELEASE)
                                        .putCustomAttribute("Manufacturer", Build.MANUFACTURER)
                                        .putCustomAttribute("Version", Build.VERSION.RELEASE)
                                        .putCustomAttribute("xDrip", getVersionDetails())
                                        .putCustomAttribute("Percentage", capture_percentage));
                            }
                        }
                    } else {
                        Log.d(TAG, "Sensor not running for more than 24 hours yet");
                    }
                } else {
                    Log.d(TAG, "No sensor active");
                }
                Log.d(TAG, "SEND EVENT DONE");
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception sending Capture Report");
    }

}
 
Example 20
Source File: LibreReceiver.java    From xDrip-plus with GNU General Public License v3.0 3 votes vote down vote up
private static void processValues(Libre2RawValue currentValue, List<Libre2RawValue> smoothingValues, Context context) {
    if (Sensor.currentSensor() == null) {
        Sensor.create(currentValue.timestamp, currentValue.serial);

    }

    double value = calculateWeightedAverage(smoothingValues, currentValue.timestamp);

    BgReading.bgReadingInsertLibre2(value, currentValue.timestamp,currentValue.glucose);
}