示例#1
0
def _calculate_category_duration(user_id: str, category_id: str) -> float:
    category = Categories.get_specific_category(category_id=category_id)

    activities = Activities.objects(user_id=user_id, category=category).exclude("id")

    sum_duration = sum([activity.duration for activity in activities])

    return sum_duration
示例#2
0
def get_user_activities(token_info: dict) -> Tuple[Response, int]:

    activities = Activities.objects(user_id=token_info["public_id"]).exclude("id")

    parsed_activities = [
        {
            "activity_id": activity.activity_id,
            "user_id": activity.user_id,
            "name": activity.name,
            "category": activity.category.public_id,
            "activity_start": _convert_unix_to_iso8610(activity.activity_start),
            "activity_end": _convert_unix_to_iso8610(activity.activity_end),
        }
        for activity in activities
    ]

    return jsonify({"activities": parsed_activities}), 200
示例#3
0
def get_rolling_meter(
    token_info: dict, include_unassigned: bool = True
) -> Tuple[Response, int]:
    activities = Activities.objects(user_id=token_info["public_id"]).exclude("id")

    if include_unassigned:
        time_window = _calculate_time_window(activities)
    else:
        time_window = sum([activity.duration for activity in activities])

    share_response = _build_shared_json(time_window, token_info["public_id"])

    average_response = _build_averages_json(time_window, token_info["public_id"])

    share_response.update(average_response)

    return jsonify(share_response)