Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions AutotuneWeb/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ActionResult Autotune(Uri nsUrl, decimal? cr, decimal? sens)
ModelState.SetModelValue(nameof(nsUrl), nsUrl, nsUrl.ToString());
ViewBag.NSUrl = nsUrl;
ViewBag.ProfileActivation = profileActivation;
ViewBag.CanRunAutotuneInCloud = CanRunAutotuneInCloud();
ViewBag.PreviousResults = HasPreviousResults(nsUrl);

nsProfile.CarbRatio = CombineAdjacentTimeBlocks(nsProfile.CarbRatio);
Expand Down Expand Up @@ -90,9 +91,33 @@ public ActionResult Autotune(Uri nsUrl, decimal? cr, decimal? sens)
return View("Converted", oapsProfile);
}

private bool CanRunAutotuneInCloud()
{
string[] requiredKeys = {
"Storage",
"BatchAccountUrl",
"BatchAccountName",
"BatchAccountKey",
"BatchPoolId",
"SendGridApiKey",
"SendGridFromAddress",
"ResultsCallbackKey",
};
foreach (var key in requiredKeys)
{
if (String.IsNullOrEmpty(Startup.Configuration[key]))
return false;
}
return true;
}

private bool HasPreviousResults(Uri nsUrl)
{
var connectionString = Startup.Configuration.GetConnectionString("Storage");
if (connectionString == null)
{
return false;
}
var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("jobs");
Expand Down Expand Up @@ -430,16 +455,23 @@ public async Task<ActionResult> About()
{
// Get the details of the Autotune commit used for the latest job
var connectionString = Startup.Configuration.GetConnectionString("Storage");
var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("settings");
await table.CreateIfNotExistsAsync();
if (connectionString != null)
{
var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("settings");
await table.CreateIfNotExistsAsync();

var commit = table.CreateQuery<Settings>()
.Where(s => s.PartitionKey == "Commit" && s.RowKey == "")
.SingleOrDefault();
var commit = table.CreateQuery<Settings>()
.Where(s => s.PartitionKey == "Commit" && s.RowKey == "")
.SingleOrDefault();

ViewBag.Commit = commit?.Value ?? "";
ViewBag.Commit = commit?.Value ?? "";
}
else
{
ViewBag.Commit = "";
}

return View();
}
Expand All @@ -463,6 +495,10 @@ public ActionResult Error()
public async Task<ActionResult> Delete(string url, string email)
{
var connectionString = Startup.Configuration.GetConnectionString("Storage");
if (connectionString == null)
{
return View(0);
}
var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("jobs");
Expand Down
8 changes: 6 additions & 2 deletions AutotuneWeb/Views/Home/About.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@
exactly what it's doing. You can also take a look at the @Html.ActionLink("privacy policy", "Privacy")</dd>

<dt>What version of Autotune is it running?</dt>
<dd>The details of the version of Autotune used on any particular run is included in the result email. The latest job ran with version
<a href="https://github.com/openaps/oref0/tree/@ViewBag.Commit">@ViewBag.Commit</a></dd>
<dd>The details of the version of Autotune used on any particular run is included in the result email.
@if (ViewBag.Commit != "")
{
@:The latest job ran with version <a href="https://github.com/openaps/oref0/tree/@ViewBag.Commit">@ViewBag.Commit</a>
}
</dd>

<dt>Why do I get the same results regardless of whether I tick "Categorize UAM as basal"?</dt>
<dd>If Autotune detects at least 1 hour of carb absoption, it will assume that all carbs have been entered and so you get the same result as if this
Expand Down
181 changes: 95 additions & 86 deletions AutotuneWeb/Views/Home/Converted.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -168,117 +168,126 @@

<h2>Running Autotune in the Cloud</h2>

<p>
Complete the remaining fields below to run Autotune on this profile
</p>

@using (Html.BeginForm("RunJob", "Home"))
@if (ViewBag.CanRunAutotuneInCloud)
{
@Html.Hidden("nsUrl", (Uri)ViewBag.NSUrl)
@Html.Hidden("oapsProfile", profileJson)
@Html.Hidden("units", (string)ViewBag.Units)
@Html.Hidden("timezone", (string)ViewBag.TimeZone)
<p>
Ready to run Autotune now? Enter a few more details, then click Run Now to have us run Autotune for you.
Complete the remaining fields below to run Autotune on this profile
</p>

<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="min5MinCarbImpact">Min. 5 Minutes Carb Impact</label>
<div class="input-group">
<input type="number" step="0.1" min="1" max="20" name="min5MCarbImpact" value="@Model.Min5mCarbImpact" class="form-control" required />
<span class="input-group-addon">mg/dL/5m</span>
@using (Html.BeginForm("RunJob", "Home"))
{
@Html.Hidden("nsUrl", (Uri)ViewBag.NSUrl)
@Html.Hidden("oapsProfile", profileJson)
@Html.Hidden("units", (string)ViewBag.Units)
@Html.Hidden("timezone", (string)ViewBag.TimeZone)
<p>
Ready to run Autotune now? Enter a few more details, then click Run Now to have us run Autotune for you.
</p>

<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="min5MinCarbImpact">Min. 5 Minutes Carb Impact</label>
<div class="input-group">
<input type="number" step="0.1" min="1" max="20" name="min5MCarbImpact" value="@Model.Min5mCarbImpact" class="form-control" required />
<span class="input-group-addon">mg/dL/5m</span>
</div>
</div>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
The minimum amount of the expected carb impact that should be assumed when no carb absorption is identified from the CGM data,
forcing the remaining carbs on board to decay.
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="pumpBasalIncrement">Pump Basal Increment</label>
<div class="input-group">
<input type="number" step="0.005" min="0.005" max="1" name="pumpBasalIncrement" value="0.01" class="form-control" required />
<span class="input-group-addon">U/h</span>
<div class="col-md-8">
<div class="alert alert-info">
The minimum amount of the expected carb impact that should be assumed when no carb absorption is identified from the CGM data,
forcing the remaining carbs on board to decay.
</div>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
Autotune will likely recommend basals in fractions of a unit that you can't program into your pump, so enter here what
increments your pump can handle (0.1, 0.5 etc.) to get your results rounded for you.
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="pumpBasalIncrement">Pump Basal Increment</label>
<div class="input-group">
<input type="number" step="0.005" min="0.005" max="1" name="pumpBasalIncrement" value="0.01" class="form-control" required />
<span class="input-group-addon">U/h</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="checkbox">
<label>
<input type="checkbox" name="uamAsBasal" value="true" />
Categorize UAM as basal
</label>
<div class="col-md-8">
<div class="alert alert-info">
Autotune will likely recommend basals in fractions of a unit that you can't program into your pump, so enter here what
increments your pump can handle (0.1, 0.5 etc.) to get your results rounded for you.
</div>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
If Autotune sees some sudden rises in your CGM data, it may conclude that there were carbs eaten but not entered into Nightscout.
If you have reliably entered all carbs eaten, tick this box and those rises will be used to recommend changes to the basal rate.
<div class="row">
<div class="col-md-4">
<div class="checkbox">
<label>
<input type="checkbox" name="uamAsBasal" value="true" />
Categorize UAM as basal
</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="curve">Insulin Type</label>
<select name="curve" class="form-control">
<option value="rapid-acting">Rapid Acting (Humalog/Novolog/Novorapid)</option>
<option value="ultra-rapid">Ultra Rapid (Fiasp)</option>
</select>
</div>
<div class="col-md-8">
<div class="alert alert-info">
Select the type of insulin you use so that Autotune can tell how quickly it acts and decays.
<div class="col-md-8">
<div class="alert alert-info">
If Autotune sees some sudden rises in your CGM data, it may conclude that there were carbs eaten but not entered into Nightscout.
If you have reliably entered all carbs eaten, tick this box and those rises will be used to recommend changes to the basal rate.
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="days">Days of Data</label>
<div class="input-group">
<input type="number" name="days" min="1" max="30" value="@days" class="form-control" required />
<span class="input-group-addon">days</span>
<div class="row">
<div class="col-md-4">
<label for="curve">Insulin Type</label>
<select name="curve" class="form-control">
<option value="rapid-acting">Rapid Acting (Humalog/Novolog/Novorapid)</option>
<option value="ultra-rapid">Ultra Rapid (Fiasp)</option>
</select>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
The number of days of data to be processed by Autotune (up to 30)
<div class="col-md-8">
<div class="alert alert-info">
Select the type of insulin you use so that Autotune can tell how quickly it acts and decays.
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="emailResultsTo">Email Results To</label>
<div class="row">
<div class="col-md-4">
<label for="days">Days of Data</label>
<div class="input-group">
<span class="input-group-addon">@@</span>
<input type="email" name="emailResultsTo" class="form-control" required value="@ViewBag.Email" />
<input type="number" name="days" min="1" max="30" value="@days" class="form-control" required />
<span class="input-group-addon">days</span>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
The number of days of data to be processed by Autotune (up to 30)
</div>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
Autotune takes a few minutes to run, so we'll email the results to you when they're ready. You should get them in 10 - 20 minutes,
check your spam folder if you don't get it.
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="emailResultsTo">Email Results To</label>
<div class="input-group">
<span class="input-group-addon">@@</span>
<input type="email" name="emailResultsTo" class="form-control" required value="@ViewBag.Email" />
</div>
</div>
</div>
<div class="col-md-8">
<div class="alert alert-info">
Autotune takes a few minutes to run, so we'll email the results to you when they're ready. You should get them in 10 - 20 minutes,
check your spam folder if you don't get it.
</div>
</div>
</div>
</div>
<p>
<input type="submit" class="btn btn-success" value="Run Now" />
</p>
}
}
else
{
<p>
<input type="submit" class="btn btn-success" value="Run Now" />
This server is not configured to support running Autotune in cloud
</p>
}

Expand Down