Created
July 30, 2014 05:26
-
-
Save euclidjda/7c70c35d8ffc61c932cb to your computer and use it in GitHub Desktop.
Script for populating a cgm-remote-monitor
This file contains hidden or 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
| #!/usr/local/bin/perl -w | |
| # This script is intended to be run as a cron job every n-minutes | |
| # Or whatever the equiv is on windows | |
| use strict; | |
| use MongoDB; | |
| use MongoDB::OID; | |
| use POSIX qw(strftime); | |
| use POSIX qw(tzset); | |
| main(); | |
| sub main { | |
| # Set time-zone to pacific. I'm on the west coast but my server is EST. Don't ask. | |
| $ENV{TZ} = 'America/Los_Angeles'; | |
| tzset; | |
| my $connection = MongoDB::Connection->new(host => 'mongodb://ds053429.mongolab.com:53429', | |
| username => 'nstest', | |
| password => 'dexcom', | |
| db_name => 'nstest'); | |
| my $database = $connection->get_database('nstest'); | |
| my $collection = $database->get_collection('cgmdata'); | |
| my $curtime = time(); | |
| my $date = int( sprintf("%d000",$curtime) ); | |
| my $datestr = strftime "%m/%d/%Y %I:%M:%S %p", localtime($curtime); | |
| my $range = ($curtime % 1800)/900 - 1.0; | |
| my $svg = int(360*(cos( 10.0 * $range / 3.14 ) / 2 + 0.5)) + 40; | |
| my $dir = $range > 0.0 ? "FortyFiveDown" : "FortyFiveUp"; | |
| $collection->insert( { | |
| "device" => "dexcom" , | |
| "date" => $date , | |
| "dateString" => $datestr , | |
| "sgv" => $svg , | |
| "direction" => $dir } ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment