def view_calories_over_date_range():
    # Need to get user's range of dates, and then for those simply bring back all matching tuples from table daily_totals.
    date_range = raw_input("Enter date range as 'year-mm-dd TO year-mm-dd': ")
    date_range = date_range.split(" TO ", 1)
    start = date_range[0]
    end = date_range[1]

    range_calories = list(c.execute("SELECT * FROM daily_totals WHERE date BETWEEN ? AND ?", (start, end)))

    if not range_calories:
        # If it should happen that the end is chronologically before start, query will fail and list will be empty
        print "Records not found for given range."
        calorie_analysis()

    else:
        for record in range_calories:
            print record[0] + "  " + str(record[1])

    pipe_to_visuals = raw_input("Plot information? -- Y or N: ")

    if pipe_to_visuals == "Y":
        visual_tools.calories_over_range(range_calories, None)
        calorie_analysis()

    else:
        calorie_analysis()
def compute_bmr():
    # Give user information about the BMR formula, then get operands. Compute. Then use Harris Benedict equation to compute
    # an approximation for daily expenditures that include physical activity.
    # This number will be used in visualization as line against which calorie intake will be compared.
    # This comparison can be used to generate predictions on calories lost/gained/maintained

    print "------------------"
    print "We'll first collect gender, height, weight, and age information to compute your base metabolic rate, or BMR."
    print "Your BMR represents the estimated number of calories your body would burn in maintaining itself if you were to "
    print "lay motionless for an entire 24 hour period."
    print "------------------"

    gender = raw_input("Would your physiology be best categorized as MALE or FEMALE?: ")
    height = raw_input("In inches, how tall are you: ")
    height = float(height)
    weight = raw_input("In pounds, how much do you weigh: ")
    weight = float(weight)
    age = raw_input("Age: ")
    age = float(age)

    if gender == "MALE":
        estimated_BMR = 66 + ((6.23 * weight) + (12.7 * height) - (6.8 * age))
    elif gender == "FEMALE":
        estimated_BMR = 655 + ((4.35 * weight) + (4.7 * height) - (4.7 * age))
    else:
        print "Gotta fit the binary. Try again."
        calorie_analysis()

    print "------------------"
    print "Estimated BMR: " + str(estimated_BMR)
    print "------------------"

    print "Now consider your level of activity. If you are a bed-desk-car type person with basically no physical activity, "
    print "enter SEDENTARY. If you are lightly active, with perhaps a brisk walk 1-3 times per week, enter LIGHT."
    print "If you are get your pulse up with biking, light jogging, or other not-overly-intense but decent activities, enter "
    print "MODERATE. If you are serious about exercise and work out hard most days of the week, input INTENSE. Finally, if you "
    print "are an athlete, in marathon training, or workout in addition to having a physical job, input MAXIMUM."

    print "------------------"

    activity_level = raw_input("Enter activity level: ")

    # Multiply BMR by a scalar associated with each activity level to get estimated daily calorie burn

    if activity_level == "SEDENTARY":
        estimated_daily_burn = estimated_BMR * 1.2
    elif activity_level == "LIGHT":
        estimated_daily_burn = estimated_BMR * 1.375
    elif activity_level == "MODERATE":
        estimated_daily_burn = estimated_BMR * 1.55
    elif activity_level == "INTENSE":
        estimated_daily_burn = estimated_BMR * 1.725
    elif activity_level == "MAXIMUM":
        estimated_daily_burn = estimated_BMR * 1.9
    else:
        print "Activity level description not found. Use the indicated descriptors."

    print "Estimated daily burn: " + str(estimated_daily_burn)
    print "------------------"

    # Enter estimated daily burn rate for a date range into database -- with this data persistant for a date range, user can
    # adjust BMR assumptions for ranges of time (particularly active phases, long holidays, weight loss, etc.)
    enter_new_range_assumption = raw_input("Enter new BMR and daily burn assumption for a date range? Y or N: ")

    if enter_new_range_assumption == "Y":
        date_range = raw_input("Enter date range as 'year-mm-dd TO year-mm-dd': ")
        date_range = date_range.split(" TO ", 1)
        start = date_range[0]
        end = date_range[1]
        new_metabolic_estimate(start, end, estimated_BMR, estimated_daily_burn)

    pipe_to_visuals = raw_input("Prepare output with imposed daily expense rate for visual comparison? Y or N: ")

    if pipe_to_visuals == "Y":
        date_range = raw_input("Enter date range as 'year-mm-dd TO year-mm-dd': ")
        date_range = date_range.split(" TO ", 1)
        start = date_range[0]
        end = date_range[1]

        range_calories = list(c.execute("SELECT * FROM daily_totals WHERE date BETWEEN ? AND ?", (start, end)))

        if not range_calories:
            print "Records not found for given range."
            calorie_analysis()

        visual_tools.calories_over_range(range_calories, estimated_daily_burn)
        calorie_analysis()

    else:
        calorie_analysis()