-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dex Share Follow Delay #3663
Open
Navid200
wants to merge
2
commits into
NightscoutFoundation:master
Choose a base branch
from
Navid200:Navid_2024_09_13
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dex Share Follow Delay #3663
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
package com.eveningoutpost.dexdrip.cgm.nsfollow.utils; | ||
|
||
import com.eveningoutpost.dexdrip.utilitymodels.Constants; | ||
import com.eveningoutpost.dexdrip.utilitymodels.Pref; | ||
|
||
/** | ||
* Choose optimum anticipation times for re-attempting data collection to minimize | ||
* number of requests to nightscout but at the same time reduce latency from new | ||
* value is available till it is shown in xdrip. | ||
* number of requests from the source but at the same time reduce latency for new | ||
* value shown in xdrip. | ||
* | ||
* We're trying to give the user the lowest latency on the data we can, but avoiding constantly | ||
* polling for data to conserve battery life and mobile data costs. | ||
* We're trying to provide the lowest latency we can, but avoid constantly | ||
* polling the source to conserve battery life and mobile data costs. | ||
* | ||
* @author Original author jamorham | ||
*/ | ||
|
@@ -20,9 +17,11 @@ public class Anticipate { | |
* If last + period and a bit >= now, ask again after last + period and grace | ||
*/ | ||
|
||
public static long next(long now, final long lastTimeStamp, final long period, final long grace) { | ||
final long lag = Constants.SECOND_IN_MS * Pref.getStringToInt("nsfollow_lag", 0); // User can choose a wake delay with a 0 default. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this from inside Anticipate is probably a good idea |
||
final long last = lastTimeStamp + lag; // We delay the source timestamp and use it as the time we received the reading to account for any source delay. | ||
public static long next(long now, final long lastTimeStamp, final long period, final long grace) { // Calling the anticipate method without a lag parameter will use a default lag of 0 | ||
return next(now, lastTimeStamp, period, grace, 0); | ||
} | ||
public static long next(long now, final long lastTimeStamp, final long period, final long grace, final long lag) { | ||
final long last = lastTimeStamp + lag; // The calling method can include a non-zero lag parameter to delay the anticipation time to account for source delay. | ||
|
||
final long since = now - last; | ||
if (since <= (grace * 2)) { | ||
|
@@ -47,4 +46,4 @@ public static long next(long now, final long lastTimeStamp, final long period, f | |
|
||
return nextMin; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ public class ShareFollowService extends ForegroundService { | |
private static volatile long lastBgTime; | ||
|
||
private static ShareFollowDownload downloader; | ||
private static long lag = Constants.SECOND_IN_MS * Pref.getStringToInt("dex_share_follow_lag", 0); // User can choose a wake delay with a 0 default. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here about storing this statically. |
||
|
||
@Override | ||
public void onCreate() { | ||
|
@@ -120,7 +121,7 @@ static void scheduleWakeUp() { | |
final long last = lastBg != null ? lastBg.timestamp : 0; | ||
|
||
final long grace = Constants.SECOND_IN_MS * 10; | ||
final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace) + grace; | ||
final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace, lag) + grace; | ||
wakeup_time = next; | ||
UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + " last: " + JoH.dateTimeText(last)); | ||
|
||
|
@@ -173,7 +174,7 @@ private static String getBestStatusMessage() { | |
} | ||
|
||
/** | ||
* MegaStatus for Nightscout Follower | ||
* MegaStatus for Dex Share Follower | ||
*/ | ||
public static List<StatusItem> megaStatus() { | ||
final BgReading lastBg = BgReading.lastNoSenssor(); | ||
|
@@ -185,10 +186,10 @@ public static List<StatusItem> megaStatus() { | |
StatusItem.Highlight ageOfLastBgPollHighlight = StatusItem.Highlight.NORMAL; | ||
if (bgReceiveDelay > 0) { | ||
ageOfBgLastPoll = JoH.niceTimeScalar(bgReceiveDelay); | ||
if (bgReceiveDelay > SAMPLE_PERIOD / 2) { | ||
if (bgReceiveDelay - lag > SAMPLE_PERIOD / 2) { | ||
ageOfLastBgPollHighlight = StatusItem.Highlight.BAD; | ||
} | ||
if (bgReceiveDelay > SAMPLE_PERIOD * 2) { | ||
if (bgReceiveDelay - lag > SAMPLE_PERIOD * 2) { | ||
ageOfLastBgPollHighlight = StatusItem.Highlight.CRITICAL; | ||
} | ||
} | ||
|
@@ -199,7 +200,7 @@ public static List<StatusItem> megaStatus() { | |
if (lastBg != null) { | ||
long age = JoH.msSince(lastBg.timestamp); | ||
ageLastBg = JoH.niceTimeScalar(age); | ||
if (age > SAMPLE_PERIOD + hightlightGrace) { | ||
if (age > SAMPLE_PERIOD + hightlightGrace + lag) { | ||
bgAgeHighlight = StatusItem.Highlight.BAD; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By setting this in a static field it will not get updated if the user changes the preference value while the class remains loaded.