Пример #1
0
def get_worker_intervals(user_entity, register_date, weeks):
    date_floor = register_date
    result = []

    if user_entity.last_updated is not None:
        # get end of incomplete fragment as we must finish it
        last_frag = TagHistory.query(ancestor=user_entity.key
            , namespace=DS_VERSION).order(
            -TagHistory.start).get()
        date_floor = user_entity.last_updated

        frag_size = get_interval_size(weeks, last_frag.start, last_frag.end)

        if frag_size < FRAGMENT_SIZE:
            start_i = bisect.bisect_right(weeks, date_floor)
            weeks_remaining = FRAGMENT_SIZE - frag_size

            end_week = weeks[min(len(weeks)-1, start_i+weeks_remaining-1)]

            result.append((weeks[start_i], end_week, last_frag.key.id()))
            date_floor = end_week

    # get the first week after 'date_floor'
    start_i = bisect.bisect_right(weeks, date_floor)

    for i in xrange(start_i+FRAGMENT_SIZE-1,
            len(weeks), FRAGMENT_SIZE):
        result.append((weeks[i-FRAGMENT_SIZE+1], weeks[i], None))

    remainder = (len(weeks)-start_i) % FRAGMENT_SIZE
    if remainder > 0:
        # submit job for last fragment
        result.append((weeks[len(weeks)-remainder], weeks[-1], None))

    return result
Пример #2
0
def get_worker_intervals(user_entity, register_date, weeks):
    date_floor = register_date
    result = []

    if user_entity.last_updated is not None:
        # get end of incomplete fragment as we must finish it
        last_frag = TagHistory.query(ancestor=user_entity.key, namespace=DS_VERSION).order(-TagHistory.start).get()
        date_floor = user_entity.last_updated

        frag_size = get_interval_size(weeks, last_frag.start, last_frag.end)

        if frag_size < FRAGMENT_SIZE:
            start_i = bisect.bisect_right(weeks, date_floor)
            weeks_remaining = FRAGMENT_SIZE - frag_size

            end_week = weeks[min(len(weeks) - 1, start_i + weeks_remaining - 1)]

            result.append((weeks[start_i], end_week, last_frag.key.id()))
            date_floor = end_week

    # get the first week after 'date_floor'
    start_i = bisect.bisect_right(weeks, date_floor)

    for i in xrange(start_i + FRAGMENT_SIZE - 1, len(weeks), FRAGMENT_SIZE):
        result.append((weeks[i - FRAGMENT_SIZE + 1], weeks[i], None))

    remainder = (len(weeks) - start_i) % FRAGMENT_SIZE
    if remainder > 0:
        # submit job for last fragment
        result.append((weeks[len(weeks) - remainder], weeks[-1], None))

    return result
Пример #3
0
    def build_response(self, user, request):
        resp = {'user': user, 'weeks': []}

        user_entity = User.get_by_id(user, namespace=DS_VERSION)
        qry = TagHistory.query(ancestor=user_entity.key,
                               namespace=DS_VERSION).order(TagHistory.start)

        for hist_frag in qry.fetch():
            resp['weeks'] += hist_frag.tag_history['weeks']

        return resp
Пример #4
0
    def build_response(self, user, request):
        resp = {'user': user, 'weeks':[]}

        user_entity = User.get_by_id(user, namespace=DS_VERSION)
        qry = TagHistory.query(ancestor=user_entity.key,
            namespace=DS_VERSION).order(
            TagHistory.start)

        for hist_frag in qry.fetch():
            resp['weeks'] += hist_frag.tag_history['weeks']

        return resp