Skip to content

Commit

Permalink
Merge pull request #707 from openaps/dev
Browse files Browse the repository at this point in the history
Prep for oref0 0.6.0 release dev to master
  • Loading branch information
scottleibrand authored Nov 26, 2017
2 parents 6de0437 + 156bd10 commit 174ef43
Show file tree
Hide file tree
Showing 68 changed files with 4,074 additions and 5,634 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ coverage/

npm-debug.log
bin/__pycache__

package-lock.json

*.pyc
4 changes: 2 additions & 2 deletions bin/ns-get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ case $1 in
fi
test -z "$NIGHTSCOUT_HOST" && usage && exit 1;

curl ${CURL_AUTH} ${CURL_FLAGS} $REPORT_ENDPOINT | $NIGHTSCOUT_FORMAT
curl -m 30 ${CURL_AUTH} ${CURL_FLAGS} $REPORT_ENDPOINT | $NIGHTSCOUT_FORMAT

;;
type)
Expand All @@ -69,7 +69,7 @@ case $1 in
;;
*)
test -z "$NIGHTSCOUT_HOST" && usage && exit 1;
curl ${CURL_AUTH} ${CURL_FLAGS} $REPORT_ENDPOINT | $NIGHTSCOUT_FORMAT
curl -m 30 ${CURL_AUTH} ${CURL_FLAGS} $REPORT_ENDPOINT | $NIGHTSCOUT_FORMAT
;;
esac

Expand Down
4 changes: 2 additions & 2 deletions bin/openaps-bootstrap.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ ifdown wlan0; ifup wlan0
sleep 10
echo -ne "\nWifi SSID: "; iwgetid -r
sleep 5
# TODO check for options to fix the certificate activation error message for https
cd /tmp/; wget --no-check-certificate https://raw.githubusercontent.com/openaps/docs/dev/scripts/openaps-install.sh; bash ./openaps-install.sh
curl https://raw.githubusercontent.com/openaps/oref0/master/bin/openaps-install.sh > /tmp/openaps-install.sh
bash /tmp/openaps-install.sh
)
41 changes: 30 additions & 11 deletions bin/openaps-install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
#!/bin/bash
set -e

read -p "Enter your Edison's new hostname (this will be your rig's "name" in the future, so make sure to write it down): " -r
myedisonhostname=$REPLY
echo $myedisonhostname > /etc/hostname
sed -r -i"" "s/localhost( jubilinux)?$/localhost $myedisonhostname/" /etc/hosts
read -p "Enter your rig's new hostname (this will be your rig's "name" in the future, so make sure to write it down): " -r
myrighostname=$REPLY
echo $myrighostname > /etc/hostname
sed -r -i"" "s/localhost( jubilinux)?$/localhost $myrighostname/" /etc/hosts
sed -r -i"" "s/127.0.1.1.*$/127.0.1.1 $myrighostname/" /etc/hosts

# if passwords are old, force them to be changed at next login
passwd -S edison | grep 20[01][0-6] && passwd -e root
passwd -S edison 2>/dev/null | grep 20[01][0-6] && passwd -e root
# automatically expire edison account if its password is not changed in 3 days
passwd -S edison | grep 20[01][0-6] && passwd -e edison -i 3
passwd -S edison 2>/dev/null | grep 20[01][0-6] && passwd -e edison -i 3

if [ -e /run/sshwarn ] ; then
echo Please select a secure password for ssh logins to your rig:
echo 'For the "root" account:'
passwd root
echo 'And for the "pi" account (same password is fine):'
passwd pi
fi

grep "PermitRootLogin yes" /etc/ssh/sshd_config || echo "PermitRootLogin yes" > /etc/ssh/sshd_config

# set timezone
dpkg-reconfigure tzdata

#dpkg -P nodejs nodejs-dev
# TODO: remove the `-o Acquire::ForceIPv4=true` once Debian's mirrors work reliably over IPv6
apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true -y dist-upgrade && apt-get -o Acquire::ForceIPv4=true -y autoremove
apt-get -o Acquire::ForceIPv4=true install -y sudo strace tcpdump screen acpid vim python-pip locate
adduser edison sudo
adduser edison dialout
apt-get -o Acquire::ForceIPv4=true install -y sudo strace tcpdump screen acpid vim python-pip locate ntpdate
#check if edison user exists before trying to add it to groups

if getent passwd edison > /dev/null; then
echo "Adding edison to sudo users"
adduser edison sudo
echo "Adding edison to dialout users"
adduser edison dialout
# else
# echo "User edison does not exist. Apparently, you are runnning a non-edison setup."
fi

sed -i "s/daily/hourly/g" /etc/logrotate.conf
sed -i "s/#compress/compress/g" /etc/logrotate.conf

# TODO: change back to master after docs release
curl -s https://raw.githubusercontent.com/openaps/docs/dev/scripts/quick-packages.sh | bash -
# TODO: change to dev and then master after PR and release
curl -s https://raw.githubusercontent.com/openaps/oref0/dev/bin/openaps-packages.sh | bash -
mkdir -p ~/src; cd ~/src && git clone git://github.com/openaps/oref0.git || (cd oref0 && git checkout master && git pull)
echo "Press Enter to run oref0-setup with the current release (master branch) of oref0,"
read -p "or press ctrl-c to cancel. " -r
Expand Down
2 changes: 1 addition & 1 deletion bin/openaps-packages.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# TODO: remove the `-o Acquire::ForceIPv4=true` once Debian's mirrors work reliably over IPv6
apt-get -o Acquire::ForceIPv4=true install -y sudo
sudo apt-get -o Acquire::ForceIPv4=true update && sudo apt-get -o Acquire::ForceIPv4=true -y upgrade
sudo apt-get -o Acquire::ForceIPv4=true install -y git python python-dev python-software-properties python-numpy python-pip nodejs-legacy npm watchdog strace tcpdump screen acpid vim locate jq lm-sensors && \
sudo apt-get -o Acquire::ForceIPv4=true install -y git python python-dev software-properties-common python-numpy python-pip nodejs-legacy npm watchdog strace tcpdump screen acpid vim locate jq lm-sensors && \
sudo pip install -U openaps && \
sudo pip install -U openaps-contrib && \
sudo openaps-install-udev-rules && \
Expand Down
Empty file modified bin/openaps-src.sh
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions bin/oref0-append-local-temptarget.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if [[ ! -z "$2" ]]; then
input=$(oref0-set-local-temptarget $@)
elif [[ ! -z "$1" ]]; then
input=$(cat $1)
else
input=$(cat /dev/stdin)
fi
#cat "${1:-/dev/stdin}" \
echo $input \
| tee /tmp/temptarget.json \
&& jq -s '[.[0]] + .[1]' /tmp/temptarget.json settings/local-temptargets.json \
| tee settings/local-temptargets.json.new \
&& mv settings/local-temptargets.json.new settings/local-temptargets.json
57 changes: 57 additions & 0 deletions bin/oref0-autosens-loop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
main() {
echo
echo Starting oref0-autosens-loop at $(date):
overtemp && exit 1
if highload && completed_recently; then
echo Load high at $(date): waiting up to 30m to continue
exit 2
fi

autosens 2>&1
touch /tmp/autons-completed
echo Completed oref0-autons-loop at $(date)
}

function overtemp {
# check for CPU temperature above 85°C
sensors -u 2>/dev/null | awk '$NF > 85' | grep input \
&& echo Edison is too hot: waiting for it to cool down at $(date)\
&& echo Please ensure rig is properly ventilated
}

function highload {
# check whether system load average is high
uptime | awk '$NF > 2' | grep load
}

function completed_recently {
find /tmp/ -mmin -30 | egrep -q "autosens-completed"
}

# find settings/ -newer settings/autosens.json | grep -q pumphistory-24h-zoned.json || find settings/ -size -5c | grep -q autosens.json || ! find settings/ | grep -q autosens || ! find settings/autosens.json
# openaps use detect-sensitivity shell monitor/glucose.json settings/pumphistory-24h-zoned.json settings/insulin_sensitivities.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json
function autosens {
# only run autosens if pumphistory-24h is newer than autosens
if find settings/ -newer settings/autosens.json | grep -q pumphistory-24h-zoned.json \
|| find settings/ -size -5c | grep -q autosens.json \
|| ! find settings/ | grep -q autosens \
|| ! find settings/autosens.json >/dev/null; then
if oref0-detect-sensitivity monitor/glucose.json settings/pumphistory-24h-zoned.json settings/insulin_sensitivities.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json > settings/autosens.json.new && cat settings/autosens.json.new | jq .ratio | grep -q [0-9]; then
mv settings/autosens.json.new settings/autosens.json
echo -n "Autosens refreshed: "
else
echo -n "Failed to refresh autosens: using old autosens.json: "
fi
else
echo -n "No need to refresh autosens yet: "
fi
cat settings/autosens.json | jq . -C -c
}

die() {
echo "$@"
exit 1
}

main "$@"
18 changes: 8 additions & 10 deletions bin/oref0-autotune-recommends-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ minutes_list=()
end_time=23:30
time=00:00
minutes=0
while :
do
time_list+=( "$time" )
minutes_list+=( "$minutes" )
if [ $time != "$end_time" ]; then
time="$(date --date="$time 30 minutes" +%R)";
minutes=$(expr $minutes + 30)
else
break
fi
for h in $(seq -w 0 23); do
for m in 00 30; do
time="$h:$m"
minutes=$(echo "60 * $h + $m" | bc)
#echo $time $minutes
time_list+=( "$time" )
minutes_list+=( "$minutes" )
done
done

for (( i=0; i<${#minutes_list[@]}; i++ ))
Expand Down
32 changes: 21 additions & 11 deletions bin/oref0-autotune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
# THE SOFTWARE.

die() {
echo "$@"
exit 1
if [[ -z "$API_SECRET" ]]; then
echo "Warning: API_SECRET is not set when calling oref0-autotune.sh"
echo "(this is only a problem if you have locked down read-only access to your NS)."
fi

echo "$@"
exit 1
}

# defaults
Expand All @@ -48,11 +53,6 @@ if [ -n "${API_SECRET_READ}" ]; then
echo "WARNING: API_SECRET_READ is deprecated starting with oref 0.6.x. The Nightscout authentication information is now used from the API_SECRET environment variable"
fi

if [[ -z "$API_SECRET" ]]; then
echo "Warning: API_SECRET is not set when calling oref0-autotune.sh"
# exit 1
fi

# If we are running OS X, we need to use a different version
# of the 'date' command; the built-in 'date' is BSD, which
# has fewer options than the linux version. So the user
Expand Down Expand Up @@ -155,7 +155,6 @@ fi
# If a previous valid settings/autotune.json exists, use that; otherwise start from settings/profile.json
cp settings/autotune.json autotune/profile.json && cat autotune/profile.json | jq . | grep -q start || cp autotune/profile.pump.json autotune/profile.json
cd autotune
# TODO: Need to think through what to remove in the autotune folder...

# Turn on stderr logging, if enabled (default to true)
if [[ $TERMINAL_LOGGING = "true" ]]; then
Expand All @@ -176,12 +175,23 @@ do
fi
done

echo "Compressing old json and log files to save space..."
gzip -f ns-*.json
gzip -f autotune*.json
# only gzip autotune log files more than 2 days old
find autotune.*.log -mtime +2 | while read file; do gzip -f $file; done
echo "Autotune disk usage:"
du -h .
echo "Overall disk used/avail:"
df -h .

echo "Grabbing NIGHTSCOUT treatments.json and entries/sgv.json for date range..."

# Get Nightscout BG (sgv.json) Entries
for i in "${date_list[@]}"
do
query="find%5Bdate%5D%5B%24gte%5D=`(date -d $i +%s | tr -d '\n'; echo 000)`&find%5Bdate%5D%5B%24lte%5D=`(date --date="$i +1 days" +%s | tr -d '\n'; echo 000)`&count=1000"
# pull CGM data from 4am-4am
query="find%5Bdate%5D%5B%24gte%5D=`(date -d "$i +4 hours " +%s | tr -d '\n'; echo 000)`&find%5Bdate%5D%5B%24lte%5D=`(date --date="$i +28 hours" +%s | tr -d '\n'; echo 000)`&count=1000"
echo Query: $NIGHTSCOUT_HOST $query
ns-get host $NIGHTSCOUT_HOST entries/sgv.json $query > ns-entries.$i.json || die "Couldn't download ns-entries.$i.json"
ls -la ns-entries.$i.json || die "No ns-entries.$i.json downloaded"
Expand All @@ -190,8 +200,8 @@ do
# echo $i $START_DATE;
#query="find%5Bdate%5D%5B%24gte%5D=`(date -d $i +%s | tr -d'\n'; echo 000)`&find%5Bdate%5D%5B%24lte%5D=`(date --date="$i +1 days" +%s | tr -d '\n'; echo 000)`&count=1000"
# to capture UTC-dated treatments, we need to capture an extra 12h on either side, plus the DIA lookback
# 18h = 12h for timezones + 6h for DIA; 36h = 24h for end-of-day + 12h for timezones
query="find%5Bcreated_at%5D%5B%24gte%5D=`date --date="$i -18 hours" -Iminutes`&find%5Bcreated_at%5D%5B%24lte%5D=`date --date="$i +36 hours" -Iminutes`"
# 18h = 12h for timezones + 6h for DIA; 40h = 28h for 4am + 12h for timezones
query="find%5Bcreated_at%5D%5B%24gte%5D=`date --date="$i -18 hours" -Iminutes`&find%5Bcreated_at%5D%5B%24lte%5D=`date --date="$i +42 hours" -Iminutes`"
echo Query: $NIGHTSCOUT_HOST/$query
ns-get host $NIGHTSCOUT_HOST treatments.json $query > ns-treatments.$i.json || die "Couldn't download ns-treatments.$i.json"
ls -la ns-treatments.$i.json || die "No ns-treatments.$i.json downloaded"
Expand Down
14 changes: 13 additions & 1 deletion bin/oref0-calculate-iob.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var generate = require('oref0/lib/iob');
function usage ( ) {
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory-zoned.json> <profile.json> <clock-zoned.json>');
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory-zoned.json> <profile.json> <clock-zoned.json> [autosens.json]');

}

Expand All @@ -32,6 +32,7 @@ if (!module.parent) {
}
var profile_input = process.argv.slice(3, 4).pop();
var clock_input = process.argv.slice(4, 5).pop();
var autosens_input = process.argv.slice(5, 6).pop();

if (!pumphistory_input || !profile_input) {
usage( );
Expand All @@ -43,13 +44,24 @@ if (!module.parent) {
var profile_data = require(cwd + '/' + profile_input);
var clock_data = require(cwd + '/' + clock_input);

var autosens_data = null;
if (autosens_input) {
try {
var autosens_data = require(cwd + '/' + autosens_input);
} catch (e) {}
//console.error(autosens_input, JSON.stringify(autosens_data));
}

// all_data.sort(function (a, b) { return a.date > b.date });

var inputs = {
history: all_data
, profile: profile_data
, clock: clock_data
};
if ( autosens_data ) {
inputs.autosens = autosens_data;
}

var iob = generate(inputs);
console.log(JSON.stringify(iob));
Expand Down
Loading

0 comments on commit 174ef43

Please sign in to comment.