Created
March 25, 2014 15:11
-
-
Save ryanthejuggler/9763822 to your computer and use it in GitHub Desktop.
Blood caffeine concentration estimate
This file contains 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
var duration = 24*3600*1000; // 24 hours as milliseconds | |
var halfLife = 5*3600*1000; // 5 hours as milliseconds | |
var absorpLife = 3600*1000; // 1 hour as milliseconds | |
var end = +(new Date()); | |
var start = end - duration; | |
var numSteps = 24*60; | |
var step = duration/numSteps; | |
var startVal = 106; | |
var rows = []; | |
var log2 = Math.log(2); | |
var log95 = Math.log(0.05); | |
var mymass = 68; // kg | |
var bloodVolume = 70e-3; // L/kg | |
function calculateConcentration(events, t, start){ | |
var sum = 0; | |
var e; | |
for(var i=0;i<events.length;i++){ | |
e = events[i]; | |
if(e.time > (t+start)) continue; | |
sum += e.amt * Math.exp(-(t-(e.time-start))*log2/halfLife) | |
* (1-Math.exp((t-(e.time-start))*log95/absorpLife)); | |
} | |
return sum/(mymass*bloodVolume); | |
} | |
var evts = [ | |
{time: new Date("7/17/2013 1:30 AM"), amt:80}, | |
{time: new Date("7/17/2013 3:00 AM"), amt:80}, | |
{time: new Date("7/16/2013 10:30 PM"), amt:80} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment