text: files=["./pump-data-bg.csv","./pump-data-insulin.csv","./cgm.csv"];function select_tab(a){d3.select("#hourly_tab").attr("class","inactive");d3.select("#day_tab").attr("class","inactive");d3.select("#detail_tab").attr("class","inactive");d3.select("#hourly_tab_cgm").attr("class","inactive");d3.select("#day_tab_cgm").attr("class","inactive");d3.select(a).attr("class","active")}var daterange={};function data_ready(){view_set_date(midnight(telemetry.maxDate));build_dashboard()}function draw_dashboard(b,g){dashboard_clear();var c=telemetry.selectBGs(b,g);var e=telemetry.selectCarbs(b,g);var j=telemetry.selectBolus(b,g);var d=telemetry.selectBasal(b,g);var a=d3.select("#dashboard");var i=parseInt(a.style("width"));var f=Math.round(0.67*i);dbd.init(a,b,g,i,f);dbd.data(c,e,j,d);select_tab("#day_tab");dbd.set_mode("scatter");refresh_date_selector(daterange.sdate,daterange.edate)}function dashboard_clear(){d3.select("#dashboard").selectAll("svg").remove()}function dashboard_resize(){draw_dashboard(daterange.sdate,daterange.edate)}var resize_callback=undefined;function check_for_resize(){dashboard_clear();if(resize_callback!=undefined){clearTimeout(resize_callback)}resize_callback=setTimeout(function(){dashboard_resize()},500)}d3.select(window).on("resize",function(){check_for_resize()});function set_daily(){dbd.set_mode("scatter");select_tab("#day_tab")}function set_hourly(){dbd.set_mode("dist");select_tab("#hourly_tab")}function set_detail(){dbd.set_mode("detail");select_tab("#detail_tab")}function set_day_by_day_cgm(){dbd.plot("day",ts_cgm);select_tab("#day_tab_cgm")}function set_hourly_cgm(){dbd.plot("bg",ts_cgm);select_tab("#hourly_tab_cgm")}function sidebar_select(a){log("SIDEBAR: "+a)}var sidebar_info=[{heading:"Views"},{text:"Sugarbook",onclick:"build_dashboard()"},{text:"Summary",onclick:"build_summary()"},{text:"Insulin",onclick:"build_app_unimp()"},{text:"Analysis",onclick:"build_analysis()"},{heading:"Pals"},{text:"Current pals",onclick:"build_app_unimp()"},{text:"Invite pals",onclick:"build_app_unimp()"},{text:"Chat",onclick:"build_app_unimp()"},{heading:"Messages"},{text:"Notifications",onclick:"build_notifications()"},{text:"Alerts",onclick:"build_app_unimp()"},{heading:"Devices"},{text:"Sync pump",onclick:"build_app_unimp()"},{text:"Sync CGM",onclick:"build_app_unimp()"},{text:"Sync fitbit",onclick:"build_app_unimp()"},{text:"Settings",onclick:"build_app_unimp()"},{text:"Add device",onclick:"build_app_unimp()"}];var site_items=[{text:"Home",onclick:"build_home()",id:"hometest"},{text:"About",onclick:"build_about()"},{text:"Tutorials",onclick:"build_main_unimp()"},{text:"Blogs",onclick:"build_main_unimp()"},{text:"Related Sites",onclick:"build_main_unimp()"},{text:"Contact Us",onclick:"build_main_unimp()"}];var user_items=[{text:"Profile",onclick:"build_main_unimp()"},{text:"-divider-"},{text:"Signout",onclick:"build_main_unimp()"}];function init_app_frame(){var a=new bamba("root");a.navbar("GreenDotz","electra@greendotz.org",0,user_items,site_items).div().id("bamba_permanent");reset_main_frame()}function reset_main_frame(){d3.select("#bamba_dynamic").remove();var a=new bamba("bamba_permanent");return a.div().id("bamba_dynamic")}function unimp(a){var c="<h1>Under construction...!</h1>";a.div().div("class=hero-unit").html(c).pop().p().text("This page under contruction...").pop().pop()}function build_main_unimp(){var a=reset_main_frame();unimp(a)}function build_about(){var c="<h1>Welcome to sugarpals!</h1>";c+="<p><p>";c+="Sugarpals is your on-line place for understanding and tracking your blood sugar, insulin, carb intake, and physical activity.  Diabetes sucks, but it doesn't have to be hard.  Sugarpals will make dealing with diabetes easier for you.  And it can even be fun!";var a=reset_main_frame();a.div().div("class=hero-unit").html(c).pop().p().text("This page under contruction...").pop().pop()}function build_app_unimp(){d3.select("#app-child").remove();var a=new bamba("app-parent");unimp(a.div().id("app-child"))}function select_green_dots(){dbd.set_mode("simple")}function select_detail_dots(){dbd.set_mode("detail")}function build_notifications(){d3.select("#app-child").remove();var a=new bamba("app-parent");a.div().id("app-child").vbox(10).hbox().h(2,"Recent Updates");build_fake_updates(a)}function update_summary(a,b){}var s='<table class="table table-striped">';s+="<thead>";s+="<tr>";s+="<th> time </th>";s+="<th> old </th>";s+="<th> new </th>";s+="</tr>";s+="</thead>";s+="<tbody>";s+="<tr>";s+="<td> midnight </td>";s+="<td> 16 </td>";s+="<td> 16 </td>";s+="</tr>";s+="<tr>";s+="<td> 6am </td>";s+='<td class="highlight-table-entry"> 12 </td>';s+='<td class="highlight-table-entry"> 14 </td>';s+="</tr>";s+="<tr>";s+="<td> 10am </td>";s+="<td> 15 </td>";s+="<td> 15 </td>";s+="</tr>";s+="<tr>";s+="<td> 1pm </td>";s+="<td> 16 </td>";s+="<td> 16 </td>";s+="</tr>";s+="</tbody>";s+="</table>";var sugar_content="<h3>New I:C Ratio</h3><p>12:44pm Fri 6/8/12</p><p>Patient changed setting...</p>"+s;function summary_sugar(a){a.dl().dt().push("span",["class=data-item"]).text("187").style("font-size","150%").style("text-align","right").pop().push("span").text("  average").pop().pop().dd().text("from Sat May 29 to Mon Jun 12").pop().dt().push("span").text("66").style("font-size","150%").pop().push("span").text("  low").pop().pop().dd().text("occurred 1:42pm on Sat May 29").pop().dt().push("span").text("412").style("font-size","150%").pop().push("span").text("  high").pop().pop().dd().text("occurred 9:37pm on Mon Jun 2").pop().dt().text("Testing").pop().dd().text("You tested enough only 15% of the time. It is really important to test more often.").pop().dd().text("You had been testing more often in the past.  Has something changed?").pop().pop()}function summary_insulin(a){a.dl().dt().push("span").text("32").style("font-size","150%").pop().push("span").text("  average units / day").pop().pop().dd().text("occurred 9:37pm on Mon Jun 2").pop().dt().text("Lowest 28 units").pop().dd().text("occurred on Sun May 30").pop().dt().text("Highest 38 units").pop().dd().text("occured Fri Jun 2").pop().dt().text("Basal/Bolus").pop().dd().text("53% basal, 47% bolus over last two weeks").pop().dd().text("XXX put pie chart here?").pop().pop()}function summary_carbs(a){a.dl().dt().text("Average 84g / day").pop().dd().text("from Mon May 22 to Tue Jun 7").pop().dt().text("Lowest 55g").pop().dd().text("occurred on Sun May 30").pop().dt().text("Highest 155g").pop().dd().text("occured Fri Jun 2").pop().pop()}function build_summary(){d3.select("#app-child").remove();var a=new bamba("app-parent");var c=a.div().id("app-child");c.well().id("d3-summary").pop();draw_summary()}function build_analysis(){d3.select("#app-child").remove();var a=new bamba("app-parent");var c=a.div().id("app-child");c.well().id("analysis").pop();draw_analysis()}function refresh_date_selector(a,b){d3.select("#date-button").text(friendly_date3(b));var c="<i>Displaying two weeks from ";c+=friendly_date2(a);c+=" to ";c+=friendly_date2(b);c+="</i>";d3.select("#date-desc").html(c)}function view_set_date(b){var a=midnight(add_days(b,-13));if(b.valueOf()>midnight(telemetry.maxDate)){b=midnight(telemetry.maxDate);a=add_days(b,-13)}if(a.valueOf()<midnight(telemetry.minDate)){a=telemetry.minDate;b=add_days(b,13)}daterange.sdate=a;daterange.edate=b;refresh_date_selector(a,b)}function date_right(){view_set_date(add_days(daterange.edate,7));draw_dashboard(daterange.sdate,daterange.edate)}function date_left(){view_set_date(add_days(daterange.edate,-7));draw_dashboard(daterange.sdate,daterange.edate)}function build_dashboard(){d3.select("#app-child").remove();var a=new bamba("app-parent");a.div().id("app-child").well().div("class=col1").h(2,"Electra's Sugarbook").br().div("class=btn-group").a("class=btn","onclick=date_left()").icon("icon-chevron-left").pop().a("class=btn","href=#").push("text",[]).text("6/2/2012").id("date-button").pop().pop().a("class=btn","onclick=date_right()").icon("icon-chevron-right").pop().pop().br().p().html("<i>Displaying two weeks from XXX to YYY</i>").id("date-desc").pop().br().tab_menu([{text:"Sugar by Day",id:"day_tab",onclick:"set_daily()"},{text:"Sugar by Hour",id:"hourly_tab",onclick:"set_hourly()"},{text:"Sugar detail",id:"detail_tab",onclick:"set_detail()"}]).div().id("dashboard").pop().pop();draw_dashboard(daterange.sdate,daterange.edate)}function init_edate_datepicker(){var a=$("#db-edate");a.datepicker({format:"m/d/yyyy"});a.datepicker().on("changeDate",function(d){var c=new Date(d.date);var b=midnight(add_days(c,-13));if(c.valueOf()>midnight(telemetry.maxDate)){c=midnight(telemetry.maxDate);b=add_days(c,-13)}if(b.valueOf()<midnight(telemetry.minDate)){b=telemetry.minDate;c=add_days(c,13)}a.attr("value",c);a.text(friendly_date3(c));a.datepicker("hide");a.attr("class","inactive");a.blur();dashboard_clear();draw_dashboard(b,c)})}function build_fake_update(d,b,c){var a="From ";a+=d;a+=" "+b;a+='<div class="well">';a+="<p>"+c+"</p></div>";return a}function build_fake_updates(a){var c='<span class="label label-success">dad</span>';var g='<span class="label label-success">mom</span>';var d='<span class="label label-inverse">fitbit</span>';var f='<span class="label label-inverse">pump</span>';var e="<p><p>";e+=build_fake_update(c,"8:37am today","hey electra, remember to do temp basal before PE today... I set a sugarpals alarm to remind you an hour before");e+=build_fake_update(g,"8:46am today","oops we forgot to bolus for breakfast... correcting BG now");e+=build_fake_update(d,"7:05am today","Detected first activity of day.");e+=build_fake_update(d,"9:37pm yesterday","Detected sleep.");e+=build_fake_update(f,"7:32pm yesterday",'Pumped synced to <a href="http://www.sugarpals.org">sugarpals</a>.');a.div().html(e).pop()}function build_home(){var a=reset_main_frame();a.div("class=frame-top").div("class=frame-sidebar").style("margin-left","5px").sidebar(sidebar_info).pop().div("class=frame-app").id("app-parent")}tooltip.init();init_app_frame();build_home();telemetry.load(files,data_ready);d3.select("#hometest").attr("class","active");