Skip to content

Commit

Permalink
added backfill from eversensedms
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardRo committed Feb 9, 2024
1 parent b6ce9f8 commit fa5cf3a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
Binary file modified app/debug/app-debug.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/java/esel/esel/esel/LogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
public static void addLog(String type,String tag, String value){
String msg = SP.getString("logging","");
int lines_limit = 500;
int lines_limit = 800;
String[] lines = msg.split("\n");
if(lines.length>lines_limit){
int limit_to = (int)(lines_limit * 0.7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void onNotificationPosted(StatusBarNotification sbn) {
SGV sgv = generateSGV(notification,lastReadings.size());
if(sgv != null) {
lastReadings.add(sgv);
rr.CallBroadcast(null);
}
} catch (NumberFormatException err) {
err.printStackTrace();
}

long lastReadingTime = SP.getLong("lastReadingTime", System.currentTimeMillis());
rr.broadcastData(null, lastReadingTime, true);


}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ public EsNowDatareader() {

static public void updateLogin(){
EsNowDatareader reader = new EsNowDatareader();

if(reader.bearer_token == "" || reader.tokenHasExpired() ) {
reader.login();
}
if(reader.userId == 0 ){
reader.currentUser();
}
}

private void login() {
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/esel/esel/esel/receivers/ReadReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import esel.esel.esel.util.LocalBroadcaster;
import esel.esel.esel.util.SP;
import esel.esel.esel.util.ToastUtils;
import retrofit2.Call;

/**
* Created by adrian on 04/08/17.
Expand All @@ -46,10 +47,16 @@ public synchronized void onReceive(Context context, Intent intent) {
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Esel:ReadReceiver:Broadcast");//Boradcast
wl.acquire();

EselLog.LogV(TAG,"onReceive called");
EselLog.LogV(TAG, "onReceive called");
setAlarm(Esel.getsInstance());

CallBroadcast(context);

wl.release();

}

public void CallBroadcast(Context context){
int sync = 8;
try {

Expand Down Expand Up @@ -93,8 +100,11 @@ public synchronized void onReceive(Context context, Intent intent) {
FullSync(context,sync);
}

boolean use_esdms = SP.getBoolean("use_esdms",false);
if(use_esdms){
EsNowDatareader.updateLogin();
}

wl.release();
}

public void FullSync(Context context, int syncHours){
Expand Down Expand Up @@ -216,7 +226,7 @@ private void WriteData(File file,String data){

}

public int broadcastData(Context context, long lastReadingTime, boolean smoothEnabled) {
public int broadcastData(Context context, long lastReadingTime, boolean is_continuous_run) {
int result = 0;
try {

Expand All @@ -227,7 +237,7 @@ public int broadcastData(Context context, long lastReadingTime, boolean smoothEn
long updatedReadingTime = lastReadingTime;

boolean use_patched_es = SP.getBoolean("use_patched_es", true);
boolean use_esdms = SP.getBoolean("use_esdms",false);


do {
lastReadingTime = updatedReadingTime;
Expand All @@ -254,9 +264,6 @@ public int broadcastData(Context context, long lastReadingTime, boolean smoothEn
}
}else {
boolean read_from_nl = true;
if(use_esdms){
EsNowDatareader.updateLogin();
}
if(read_from_nl){
valueArray = EsNotificationListener.getData(size,lastReadingTime);
}
Expand All @@ -266,7 +273,7 @@ public int broadcastData(Context context, long lastReadingTime, boolean smoothEn
return result;
}

result += ProcesssValues(smoothEnabled,valueArray);
result += ProcesssValues(is_continuous_run,valueArray);

updatedReadingTime = SP.getLong("lastReadingTime", lastReadingTime);
} while (updatedReadingTime != lastReadingTime);
Expand All @@ -285,7 +292,7 @@ public int broadcastData(Context context, long lastReadingTime, boolean smoothEn
return result;
}

private int ProcesssValues( boolean smoothEnabled, List<SGV> valueArray) {
private int ProcesssValues( boolean is_continuous_run, List<SGV> valueArray) {
int result = 0;

long currentTime = System.currentTimeMillis();
Expand Down Expand Up @@ -317,17 +324,11 @@ private int ProcesssValues( boolean smoothEnabled, List<SGV> valueArray) {

if (sgv.value >= 39 /*&& oldValue >= 39*/) { //check for old value to ignore first 5 min
//ToastUtils.makeToast(sgv.toString());
if(smoothEnabled) {
if(is_continuous_run) {
boolean enable_smooth = SP.getBoolean("smooth_data", false) && !hasTimeGap;
sgv.smooth(oldValue, enable_smooth);
}

// if(SP.getBoolean("smooth_data",false) && smoothEnabled){
// sgv.smooth(oldValue,hasTimeGap);
// }else {
// sgv.smooth(oldValue,true); //
// }

double slopeByMinute = 0d;
if (oldTime != sgvTime) {
slopeByMinute = (sgv.value - oldValue ) * 60000.0d / (( sgvTime - oldTime) * 1.0d);
Expand All @@ -338,7 +339,7 @@ private int ProcesssValues( boolean smoothEnabled, List<SGV> valueArray) {

try {
if (!suppressBroadcast) {
LocalBroadcaster.broadcast(sgv);
LocalBroadcaster.broadcast(sgv,is_continuous_run);
} else {
LocalBroadcaster.addSgvEntry(output, sgv);
}
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/esel/esel/esel/util/LocalBroadcaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LocalBroadcaster {
private static final String TAG = "LocalBroadcaster";
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);

public static void broadcast(SGV sgv) {
public static void broadcast(SGV sgv, boolean log) {
try {

int timeShift = SP.getInt("shift_days",0);
Expand All @@ -40,15 +40,16 @@ public static void broadcast(SGV sgv) {
if (SP.getBoolean("send_to_AAPS", true)) {
final JSONArray entriesBody = new JSONArray();
addSgvEntry(entriesBody, sgv);
sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR);
sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR, log);
}

if (SP.getBoolean("send_to_NS", true)) {
sendBundle("dbAdd", "entries", generateSgvEntry(sgv), ACTION_DATABASE);
sendBundle("dbAdd", "entries", generateSgvEntry(sgv), ACTION_DATABASE, log);
}

EselLog.LogI(TAG, String.valueOf(sgv.value) + " " + sgv.direction );

if(log) {
EselLog.LogI(TAG, String.valueOf(sgv.value) + " " + sgv.direction);
}
} catch (Exception e) {
String msg = "Unable to send bundle: " + e;
EselLog.LogE(TAG,msg);
Expand Down Expand Up @@ -77,7 +78,7 @@ private static JSONObject generateSgvEntry(SGV sgv) throws Exception {
return json;
}

private static void sendBundle(String action, String collection, Object json, String intentIdAction) {
private static void sendBundle(String action, String collection, Object json, String intentIdAction,boolean log) {
final Bundle bundle = new Bundle();
bundle.putString("action", action);
bundle.putString("collection", collection);
Expand All @@ -94,7 +95,9 @@ private static void sendBundle(String action, String collection, Object json, St
if (packageName != null) {
intent.setPackage(packageName);
Esel.getsInstance().sendBroadcast(intent);
EselLog.LogI(TAG,"send to: " + packageName);
if(log) {
EselLog.LogI(TAG, "send to: " + packageName);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">Esel</string>
<string name="app_version">Version 3.0.1</string>
<string name="app_version">Version 3.0.2_nl</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
Expand Down

0 comments on commit fa5cf3a

Please sign in to comment.