Skip to content

Instantly share code, notes, and snippets.

@shollingsworth
Last active November 30, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shollingsworth/0947f1a21616468169347275b370575c to your computer and use it in GitHub Desktop.
Save shollingsworth/0947f1a21616468169347275b370575c to your computer and use it in GitHub Desktop.
Convert weight in lbs to stats about glucose replacement for your brain.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Convert weight in lbs to stats about glucose replacement for your brain."""
# After reading reading "Thinking, Fast and Slow"
# by Daniel Kahneman
#
# Based docs from https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3900881/
# and
# https://www.nutritionix.com/food/light-corn-syrup
from __future__ import unicode_literals
import json # noqa: F401
from collections import OrderedDict
import logging
import os
import argparse
G_LIGHT_CORN_SYRUP_TBSP = 17
LBS_TO_GRAMS = 453.592
logging.basicConfig()
LOG = logging.getLogger(os.path.basename(__file__).replace('.py', ''))
LOG.setLevel(logging.INFO)
def get_args(test_args=None):
"""Get Arg parse object."""
parser = argparse.ArgumentParser(
description=__doc__,
add_help=True,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'weight',
type=int,
help='body weight in lbs',
)
if test_args:
args = type(str('args'), (), {})()
[setattr(args, k, v) for k, v in test_args.items()]
else:
args = parser.parse_args()
return args
if __name__ == '__main__':
r"""
test_args = {
'weight': 500,
}
args = get_args(test_args)
"""
args = get_args()
lbs_weight = args.weight
brain_weight_grams = (lbs_weight * LBS_TO_GRAMS) * .02
g_per_minute = ((brain_weight_grams / 100) * 5.6) / 1000
g_per_hour = g_per_minute * 60
out = OrderedDict([
('lbs_body_weight', lbs_weight),
('g_brain_weight', '{:.2f}'.format(brain_weight_grams)),
('g_burn_per_minute', '{:.2f}'.format(g_per_minute)),
('g_burn_per_hour', '{:.2f}'.format(g_per_hour)),
('total_hr', int(g_per_hour)),
('total_2hr', {
'used': int(g_per_hour * 2),
'tbsp_light_corn':
'{:.2f}'.format(
(g_per_hour * 2) /
G_LIGHT_CORN_SYRUP_TBSP),
}),
('total_8hr', {
'used': int(g_per_hour * 8),
'tbsp_light_corn':
'{:.2f}'.format(
(g_per_hour * 8) /
G_LIGHT_CORN_SYRUP_TBSP),
}),
])
print(json.dumps(out, indent=4, separators=(',', ' : ')))
$ ./glucose_brain_burn_rate.py 200
{
"lbs_body_weight" : 200,
"g_brain_weight" : "1814.37",
"g_burn_per_minute" : "0.10",
"g_burn_per_hour" : "6.10",
"total_hr" : 6,
"total_2hr" : {
"used" : 12,
"tbsp_light_corn" : "0.72"
},
"total_8hr" : {
"used" : 48,
"tbsp_light_corn" : "2.87"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment