Git Product home page Git Product logo

autotuneweb's Introduction

AutotuneWeb

Run AutotuneWeb Now

This project aims to simplify the process of running Autotune for non-OpenAPS users, e.g. people running AndroidAPS.

There are two main steps in the project:

  1. Converting a profile (basal rates, IC and CR values) from Nightscout into a format ready to be used with Autotune, and
  2. Optionally, automatically running Autotune on the converted profile and emailing the results back once complete

To implement this there are several resources required. This has been designed to run in Azure but could be adapted to run elsewhere:

  1. Website to receive user input and convert Nightscout profile to OpenAPS format
  2. Linux VM image with Autotune installed ready to run
  3. Azure Storage account to hold the Autotune input and output files
  4. Azure Batch account to execute the Autotune jobs on a VM instance
  5. SendGrid account to send the Autotune results by email

VM image setup

In Azure, create a new Linux VM. Once the VM is provisioned, install Autotune using the standard installation instructions. In my case I followed the instructions to install the latest dev version.

Once Autotune is installed on your VM, create an image of that VM. This image will be used later to dynamically create VMs as needed to process Autotune jobs. The instructions for how to create an image from a VM can be found on the Azure documentation site.

Azure Storage Accout setup

In Azure, create a new storage account. You should select a general purpose v2 account type. There's no further configuration of the storage account required.

Azure Batch Account setup

In Azure, create a new batch account. This is going to manage the actual execution of the Autotune jobs. When creating the account, select to use the storage account you have just created.

Within the batch account, create a new pool. This is going to manage the individual VMs that Autotune is going to run on. You want this to use the VM image with Autotune installed on that you created earlier, so change the Image Type to Custom and select your VM image.

Crucially, you want the pool to automatically scale up and down to handle the Autotune jobs that need to be run. I have set this up to use low-priority VMs to reduce costs using the following formula:

// Get pending tasks for the past 5 minutes.
$samples = $ActiveTasks.GetSamplePercent(TimeInterval_Minute * 5);

// If we have fewer than 70 percent data points, we use the last sample point, otherwise we use the maximum of last sample point and the history average.
$tasks = $samples < 70 ? max(0, $ActiveTasks.GetSample(1)) : 
max( $ActiveTasks.GetSample(1), avg($ActiveTasks.GetSample(TimeInterval_Minute * 5)));

// If number of pending tasks is not 0, set targetVM to pending tasks, otherwise half of current dedicated.
$targetVMs = $tasks > 0 ? max(1, $tasks) : max(0, $TargetLowPriorityNodes / 2);

// The pool size is capped at 20, if target VM value is more than that, set it to 20. This value should be adjusted according to your use case.
cappedPoolSize = 20;
$TargetLowPriorityNodes = max(0, min($targetVMs, cappedPoolSize));

// Set node deallocation mode - keep nodes active only until tasks finish
$NodeDeallocationOption = taskcompletion;

Website Setup

Create an Azure App Service and deploy the AutotuneWeb project to it.

In the App Service configuration, go to the Application settings option and add connection strings with the following details:

Name Value Type
Storage (Connection string for your Azure Storage account) Custom

Also add the following application settings:

Name Value
BatchAccountUrl The URL of your Azure Batch account
BatchAccountName The name of your Azure Batch account
BatchAccountKey One of the keys for your Azure Batch account
BatchPoolId The name of your Azure Batch pool
SendGridApiKey The API Key for your SendGrid account
SendGridFromAddress The email address to use as the From address on your emails
ResultsCallbackKey A random value to use to ensure that only your batch jobs can send you results

autotuneweb's People

Contributors

danamlewis avatar markmpn avatar suchiman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.