Exemplo n.º 1
0
def get_tutoring_sessions(qle: QueueLoginEvent, queue: Queue, grader: User,
                          start_date: datetime = None):
    """
    Gets all the tutoring sessions of a grader within a given time frame.
    Sessions include info about start/end time, duration, time helping,
    utilization rate, and number of tickets accepted/resolved.
    Inputs:
    qle --> QueueLoginEvent object used to access the database
    queue --> queue on which the grader worked
    grader --> grader bing queried
    start_date --> (optional) start time of week being queried
    Return:
    List of sessions
    """
    if start_date is None:
        events = qle.find_event_in_range(queue, datetime.min, datetime.now(),
                                         grader)
    else:
        end_date = (start_date.convert_str_to_datetime()
                    + datetime.timedelta(days=7)).isoformat()
        events = qle.find_event_in_range(queue, start_date, end_date, grader)

    sessions = []
    for i in range(0, len(events), 2):
        start = events[i].timestamp
        end = (datetime.now() if i == len(events) - 1
               else events[i + 1].timestamp)
        duration = end - start

        tickets = Ticket.find_tickets_in_range(queue, start, end, grader)

        time_accepted = datetime.min()
        total_time_helping = 0
        accepted = 0
        resolved = 0

        for ticket in tickets:
            for e in events:
                if e.is_accepted():
                    accepted += 1
                    time_accepted = e.timestamp

                if e.is_resolved():
                    resolved += 1

                if (time_accepted != datetime.min and
                   (e.is_resolved() or e.is_deferred() or e.is_canceled)):
                    time_helping = e.timestamp - time_accepted
                    total_time_helping += time_helping.seconds
                    time_accepted = datetime.min()

        utilization = time_helping / duration

    sessions.append(TutoringSession(start, end, duration, total_time_helping,
                                    utilization, accepted, resolved))

    return sessions
Exemplo n.º 2
0
async def get_user_creation_date(user: str) -> datetime:
    headers = get_headers(use_kraken=True)
    if not _check_headers_has_auth(headers):
        warnings.warn(
            '[GET_USER_CREATION_DATE] headers for the twitch api request are missing authorization'
        )
        return datetime.min()

    _, json = await get_url(USER_ACCOUNT_AGE_API.format(user), headers)
    if 'created_at' not in json:
        return datetime.min()
    #                                            2012-09-03T01:30:56Z
    return datetime.strptime(json['created_at'], '%Y-%m-%dT%H:%M:%SZ')
Exemplo n.º 3
0
async def get_user_creation_date(user: str) -> datetime:
    _, json = await get_url(USER_ACCOUNT_AGE_API.format(user), get_headers(use_kraken=True))

    if 'created_at' not in json:
        return datetime.min()
    #                                            2012-09-03T01:30:56Z
    return datetime.strptime(json['created_at'], '%Y-%m-%dT%H:%M:%SZ')
Exemplo n.º 4
0
    def resolve_statstotal(self, info, **kwargs):
        initial_timestamp = kwargs.get('initial_timestamp')
        final_timestamp = kwargs.get('final_timestamp')

        if initial_timestamp is None:
            initial_timestamp = datetime.min()
        if final_timestamp is None:
            final_timestamp = datetime.max()
        if final_timestamp and initial_timestamp is not None:
            s = Visit.objects.select_related(
                visit__timestamp_range=(initial_timestamp, final_timestamp))
        return s.stats.count()
Exemplo n.º 5
0
def get_total_time_spent_resolving_tickets(queue: Queue, grader: User,
                                           start_date: datetime = None):
    """
    Gets the amount of time a tutor has spent resolving tickets within a given
    time frame.
    Inputs:
    queue --> queue on which the grader worked
    grader --> grader bing queried
    start_date --> (optional) start time of week being queried
    Return:
    Amount of time (in seconds) that grader spent resolving tickets during the
    week that starts at start_date (if it was passed in) or during the whole
    quarter (if it was not).
    """
    if start_date is None:
        tickets = Ticket.find_all_tickets_in_range(queue, grader)
    else:
        end_date = (start_date.convert_str_to_datetime()
                    + datetime.timedelta(days=7)).isoformat()
        tickets = Ticket.find_tickets_in_range(queue, start_date, end_date,
                                               grader)

    for ticket in tickets:
        events = TicketEvent.find_all_events_for_ticket(ticket)
        events = [event for event in events if event.user_id == grader.id]

        total_time = 0
        time_accepted = datetime.min()

        for e in events:
            if e.is_accepted():
                time_accepted = e.timestamp

            if (time_accepted != datetime.min and
               (e.is_resolved() or e.is_deferred() or e.is_canceled)):
                time_helping = e.timestamp - time_accepted
                total_time += time_helping.seconds
                time_accepted = datetime.min()

    return total_time
Exemplo n.º 6
0
def filter_by_dates(df, start_date, end_date=None, format=None):
    if not start_date:
        start_date = datetime.min()
    if not end_date:
        end_date = datetime.utcnow()

    if format:
        if not isinstance(start_date, datetime):
            start_date = datetime.strptime(start_date, format)
        if not isinstance(end_date, datetime):
            end_date = datetime.strptime(end_date, format)

    valid_check = end_date > start_date
    return df[(df.index >= start_date)
              & (df.index <= end_date)] if valid_check else df[
                  (df.index >= end_date) & (df.index <= start_date)]