class PersistentHigh {

    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;

    }

}