Esempio n. 1
0
def pickweek():
    """Process chosen date inputted from user and returns data for that week to chart"""

    #get date from form on mainpage
    formdate = request.form.get("date")

    if not formdate:
        return redirect("/sendjson")

    #turn date from mainpage into a datetime object
    date = datetime.strptime(formdate, "%Y-%m-%d")

    monday, sunday = get_monday_sunday(date)#call helper function that converts dates
    print monday, sunday

    week_data_query = (db.session.query(Response)
                       .filter(Response.user_id == session["user_id"],
                               Response.date >= monday,
                               Response.date <= sunday).all())
    # print week_data_query
    #create json dictionary from query responses
    to_json = []


    for response in week_data_query:
        to_json.append(response.to_d3_dict())

    #return json data object of list containing json dictionary
    return jsonify(data=to_json)
Esempio n. 2
0
    def test_week_data(self):
        """does this successfully pull the start and end dates of a given week?"""
        input_date = "2015-02-04"
        input_date_obj = datetime.strptime(input_date, "%Y-%m-%d")

        monday = datetime.strptime("2015, 2, 2", "%Y, %m, %d")
        # monday_obj = datetime.date(monday)
        sunday = datetime.strptime("2015, 2, 8", "%Y, %m, %d")
        # sunday_obj = datetime.date(sunday)

        self.assertEqual(get_monday_sunday(input_date_obj), (monday, sunday))
Esempio n. 3
0
def send_json():
    """Send current week of JSON data for signed in user to chart"""
    #figure out the start and end dates of the week based on the Monday and Sunday of that week
    date = datetime.now()
    monday, sunday = get_monday_sunday(date)#call helper function that converts dates

    week_data_query = (db.session.query(Response)
                       .filter(Response.user_id == session["user_id"],
                               Response.date >= monday,
                               Response.date <= sunday).all())

    #create json dictionary from query responses, append to list
    to_json = []

    for response in week_data_query:
        to_json.append(response.to_d3_dict())


    #return json data object of list containing json dictionary
    return jsonify(data=to_json)