Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
some cleanups in the merged changes from andrew
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjorn committed Aug 31, 2016
1 parent 944f3d5 commit e9b8467
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions FloatingGlucose/Classes/Pebble/PebbleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PebbleData
public double Delta = 0.0;
public string Direction;

public bool IsMmol => Default.GlucoseUnits == "mmol";
public static bool IsMmol => Default.GlucoseUnits == "mmol";
public string FormattedDelta => $"{(this.Delta >= 0.0 ? "+" : "")}{this.Delta:N1}";
public double RawDelta => this.RawGlucose - this.PreviousRawGlucose;
public string FormattedRawDelta => $"{(this.RawDelta >= 0.0 ? "+" : "")}{this.RawDelta:N1}";
Expand All @@ -32,31 +32,46 @@ class PebbleData
public static double CalculateRawGlucose(Cal cal, Bg bg, double actualGlucose)
{
double number;
double rawOffset = 5;
double curBG = actualGlucose;
int specialValue = 0;

if (Default.GlucoseUnits == "mmol")
if (IsMmol)
{
if ((actualGlucose < 2.2) || (actualGlucose > 22.2))
{
specialValue = 1;
curBG = curBG * 18.018;
}

curBG = curBG * 18.01559;
}
else
if ((actualGlucose < 40) || (actualGlucose > 400))
specialValue = 1;
{
if ((actualGlucose < 40) || (actualGlucose > 400))
{
specialValue = 1;

}

}

//this special value is only triggered when the dexcom upload is brand new
//from a brand new sensor?
if (specialValue == 1)
{
number = cal.scale * (bg.unfiltered - cal.intercept) / cal.slope;
}
else
{
number = cal.scale * (bg.filtered - cal.intercept) / cal.slope / curBG;
number = cal.scale * (bg.unfiltered - cal.intercept) / cal.slope / number;
}

if (Default.GlucoseUnits == "mmol")
number = number / 18.018;

if (IsMmol)
{
number = number / 18.01559;
}


return number;
}

Expand Down

0 comments on commit e9b8467

Please sign in to comment.