Merge pull request #1204 from jotomo/pluginstats

Fabric-log enabled plugins once a day.
This commit is contained in:
Milos Kozak 2018-07-12 16:06:10 +03:00 committed by GitHub
commit ba945f334b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 15 deletions

View file

@ -194,18 +194,8 @@ public class MainApp extends Application {
MainApp.getConfigBuilder().initialize(); MainApp.getConfigBuilder().initialize();
} }
NSUpload.uploadAppStart();
if (Config.NSCLIENT) NSUpload.uploadAppStart();
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-NSClient"));
else if (Config.G5UPLOADER)
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-G5Uploader"));
else if (Config.PUMPCONTROL)
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-PumpControl"));
else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value())
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop"));
else
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop"));
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump != null) { if (pump != null) {

View file

@ -1,9 +1,5 @@
package info.nightscout.androidaps.receivers; package info.nightscout.androidaps.receivers;
/**
* Created by mike on 07.07.2016.
*/
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -11,6 +7,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.PowerManager; import android.os.PowerManager;
import info.nightscout.utils.FabricPrivacy;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -25,6 +22,10 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.LocalAlertUtils; import info.nightscout.utils.LocalAlertUtils;
/**
* Created by mike on 07.07.2016.
*/
public class KeepAliveReceiver extends BroadcastReceiver { public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class); private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);
public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L; public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L;
@ -45,6 +46,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
LocalAlertUtils.shortenSnoozeInterval(); LocalAlertUtils.shortenSnoozeInterval();
LocalAlertUtils.checkStaleBGAlert(); LocalAlertUtils.checkStaleBGAlert();
checkPump(); checkPump();
FabricPrivacy.uploadDailyStats();
log.debug("KeepAlive received"); log.debug("KeepAlive received");
wl.release(); wl.release();

View file

@ -3,6 +3,13 @@ package info.nightscout.utils;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent; import com.crashlytics.android.answers.CustomEvent;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import java.util.Date;
/** /**
* Created by jamorham on 21/02/2018. * Created by jamorham on 21/02/2018.
@ -80,4 +87,51 @@ public class FabricPrivacy {
} }
} }
public static void uploadDailyStats() {
if (!fabricEnabled()) return;
long lastUploadDay = SP.getLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), 0L);
Date date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
long today = date.getTime() - date.getTime() % 1000;
if (today > lastUploadDay) {
uploadAppUsageType();
uploadPluginStats();
SP.putLong(MainApp.gs(R.string.key_plugin_stats_report_timestamp), today);
}
}
private static void uploadPluginStats() {
CustomEvent pluginStats = new CustomEvent("PluginStats");
pluginStats.putCustomAttribute("version", BuildConfig.VERSION);
for (PluginBase plugin : MainApp.getPluginsList()) {
if (plugin.isEnabled(plugin.getType()) && !plugin.pluginDescription.alwaysEnabled) {
pluginStats.putCustomAttribute(plugin.getName(), "enabled");
}
}
getInstance().logCustom(pluginStats);
}
private static void uploadAppUsageType() {
CustomEvent type = new CustomEvent("AppUsageType");
if (Config.NSCLIENT)
type.putCustomAttribute("type", "NSClient");
else if (Config.G5UPLOADER)
type.putCustomAttribute("type", "G5Uploader");
else if (Config.PUMPCONTROL)
type.putCustomAttribute("type", "PumpControl");
else if (MainApp.getConstraintChecker().isClosedLoopAllowed().value())
type.putCustomAttribute("type", "ClosedLoop");
else
type.putCustomAttribute("type", "OpenLoop");
getInstance().logCustom(type);
}
} }

View file

@ -1164,6 +1164,7 @@
<string name="storedsettingsfound">Stored settings found</string> <string name="storedsettingsfound">Stored settings found</string>
<string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time.</string> <string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time.</string>
<string name="generated_ecarbs_note">Generated eCarbs with amount: %1$dg, duration: %2$dh, delay: %3$dm</string> <string name="generated_ecarbs_note">Generated eCarbs with amount: %1$dg, duration: %2$dh, delay: %3$dm</string>
<string name="key_plugin_stats_report_timestamp" translatable="false">key_plugin_stats_report_timestamp</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%d day</item> <item quantity="one">%d day</item>