예제 #1
0
async def _get_user_progress(
    user: Optional[BlossomUser],
    after_time: Optional[datetime],
    before_time: Optional[datetime],
    blossom_api: BlossomAPI,
) -> int:
    """Get the number of transcriptions made in the given time frame."""
    from_str = after_time.isoformat() if after_time else None
    until_str = before_time.isoformat() if before_time else None

    # We ask for submission completed by the user in the time frame
    # The response will contain a count, so we just need 1 result
    progress_response = blossom_api.get(
        "submission/",
        params={
            "completed_by": get_user_id(user),
            "complete_time__gte": from_str,
            "complete_time__lte": until_str,
            "page_size": 1,
        },
    )
    if progress_response.status_code != 200:
        raise BlossomException(progress_response)

    return progress_response.json()["count"]
예제 #2
0
def get_user_gamma(user: Optional[BlossomUser],
                   blossom_api: BlossomAPI) -> int:
    """Get the gamma of the given user.

    If it is None, it will get the total gamma of everyone.
    This makes a server request, so the result should be reused.
    """
    if user:
        return user["gamma"]

    gamma_response = blossom_api.get(
        "submission/",
        params={
            "page_size": 1,
            "completed_by__isnull": False
        },
    )
    if not gamma_response.ok:
        raise BlossomException(gamma_response)
    return gamma_response.json()["count"]