<commit_before>package info.nightscout.androidaps.plugins.general.overview;

import android.view.View;
import android.widget.TextView;

import androidx.arch.core.util.Function;

import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SetWarnColor;

class StatuslightHandler {

    /**
     * applies the statuslight subview on the overview fragement
     */
    void statuslight(TextView cageView, TextView iageView, TextView reservoirView,
                     TextView sageView, TextView batteryView) {
        PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();

        applyStatuslight("cage", CareportalEvent.SITECHANGE, cageView, "CAN", 48, 72);
        applyStatuslight("iage", CareportalEvent.INSULINCHANGE, iageView, "INS", 72, 96);

        double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
        applyStatuslightLevel(R.string.key_statuslights_res_critical, 10.0,
                R.string.key_statuslights_res_warning, 80.0, reservoirView, "RES", reservoirLevel);

        applyStatuslight("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN", 164, 166);

        if (pump.model() != PumpType.AccuChekCombo) {
            double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
            applyStatuslightLevel(R.string.key_statuslights_bat_critical, 5.0,
                    R.string.key_statuslights_bat_warning, 22.0,
                    batteryView, "BAT", batteryLevel);
        } else {
            applyStatuslight("page", CareportalEvent.PUMPBATTERYCHANGE, batteryView, "BAT", 504, 240);
        }

    }

    void applyStatuslight(String nsSettingPlugin, String eventName, TextView view, String text,
                          int defaultWarnThreshold, int defaultUrgentThreshold) {
        NSSettingsStatus nsSettings = NSSettingsStatus.getInstance();

        if (view != null) {
            double urgent = nsSettings.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold);
            double warn = nsSettings.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold);
            CareportalEvent event = MainApp.getDbHelper().getLastCareportalEvent(eventName);
            double age = event != null ? event.getHoursFromStart() : Double.MAX_VALUE;
            applyStatuslight(view, text, age, warn, urgent, Double.MAX_VALUE, true);
        }
    }<commit_msg>fix page -> bage<commit_after>package info.nightscout.androidaps.plugins.general.overview;

import android.view.View;
import android.widget.TextView;

import androidx.arch.core.util.Function;

import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SetWarnColor;

class StatuslightHandler {

    /**
     * applies the statuslight subview on the overview fragement
     */
    void statuslight(TextView cageView, TextView iageView, TextView reservoirView,
                     TextView sageView, TextView batteryView) {
        PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();

        applyStatuslight("cage", CareportalEvent.SITECHANGE, cageView, "CAN", 48, 72);
        applyStatuslight("iage", CareportalEvent.INSULINCHANGE, iageView, "INS", 72, 96);

        double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
        applyStatuslightLevel(R.string.key_statuslights_res_critical, 10.0,
                R.string.key_statuslights_res_warning, 80.0, reservoirView, "RES", reservoirLevel);

        applyStatuslight("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN", 164, 166);

        if (pump.model() != PumpType.AccuChekCombo) {
            double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
            applyStatuslightLevel(R.string.key_statuslights_bat_critical, 5.0,
                    R.string.key_statuslights_bat_warning, 22.0,
                    batteryView, "BAT", batteryLevel);
        } else {
            applyStatuslight("bage", CareportalEvent.PUMPBATTERYCHANGE, batteryView, "BAT", 504, 240);
        }

    }

    void applyStatuslight(String nsSettingPlugin, String eventName, TextView view, String text,
                          int defaultWarnThreshold, int defaultUrgentThreshold) {
        NSSettingsStatus nsSettings = NSSettingsStatus.getInstance();

        if (view != null) {
            double urgent = nsSettings.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold);
            double warn = nsSettings.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold);
            CareportalEvent event = MainApp.getDbHelper().getLastCareportalEvent(eventName);
            double age = event != null ? event.getHoursFromStart() : Double.MAX_VALUE;
            applyStatuslight(view, text, age, warn, urgent, Double.MAX_VALUE, true);
        }
    }
{'fraction_non_alphanumeric': 0.09826686858488978, 'fraction_numerical': 0.01110550227158001, 'mean_word_length': 3.789685737308622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381430', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1703, 'n_words': 304}