Example #1
0
def after_request():
    msTimeNow = time.time()
    duration = msTimeNow - request.params.start_ts
    print ("END %s %s %s %s %s " % (datetime.now(), request.method, request.path, request.params.user_uuid, duration))
    logging.debug("END %s %s %s %s " % (request.method, request.path, request.params.user_uuid, duration))
    # Keep track of the time and duration for each call
    stats.storeServerEntry(request.params.user_uuid, "%s %s" % (request.method, request.path), msTimeNow, duration)
Example #2
0
def after_request():
  msTimeNow = time.time()
  duration = msTimeNow - request.params.start_ts
  print("END %s %s %s %s %s " % (datetime.now(), request.method, request.path, request.params.user_uuid, duration))
  logging.debug("END %s %s %s %s " % (request.method, request.path, request.params.user_uuid, duration))
  # Keep track of the time and duration for each call
  stats.storeServerEntry(request.params.user_uuid, "%s %s" % (request.method, request.path),
        msTimeNow, duration)
def queryUnclassifiedSections(uuid):
    now = datetime.now()
    weekago = now - timedelta(weeks=1)

    user_uuid = uuid
    clientSpecificQuery = getClientSpecificQueryFilter(user_uuid)
    Sections = get_section_db()
    logging.debug("section.count = %s" % Sections.count())
    # Theoretically, we shouldn't need the 'predicted_mode' code because we
    # predict values right after reading the trips from moves. However, there
    # is still a small race window in which we are reading trips for other
    # users and haven't yet run the classifier. As we get more users, this
    # window can only grow, and it is easy to handle it, so let's just do so now.
    defaultQueryList = [
        {"source": "Shankari"},
        {"user_id": user_uuid},
        {"predicted_mode": {"$exists": True}},
        {"confirmed_mode": ""},
        {"retained": True},
        {"type": "move"},
        {"section_end_datetime": {"$gt": weekago}},
    ]
    completeQueryList = defaultQueryList + clientSpecificQuery
    unclassifiedSections = Sections.find({"$and": completeQueryList})

    # totalUnclassifiedSections are for debugging only, can remove after we know that this works well
    totalUnclassifiedSections = Sections.find(
        {"$and": [{"source": "Shankari"}, {"user_id": user_uuid}, {"confirmed_mode": ""}, {"type": "move"}]}
    )

    unclassifiedSectionCount = unclassifiedSections.count()
    totalUnclassifiedSectionCount = totalUnclassifiedSections.count()

    logging.debug("Unsec.count = %s" % unclassifiedSectionCount)
    logging.debug("Total Unsec.count = %s" % totalUnclassifiedSectionCount)
    # Keep track of what percent of sections are stripped out.
    # Sections can be stripped out for various reasons:
    # - they are too old
    # - they have enough confidence that above the magic threshold (90%) AND
    # the client has requested stripping out
    # - they have already been identified as being too short by the filter label
    stats.storeServerEntry(
        user_uuid,
        stats.STAT_TRIP_MGR_PCT_SHOWN,
        time.time(),
        0 if totalUnclassifiedSectionCount == 0 else float(unclassifiedSectionCount) / totalUnclassifiedSectionCount,
    )
    return unclassifiedSections
Example #4
0
def queryUnclassifiedSections(uuid):
    now = datetime.now()
    weekago = now - timedelta(weeks=1)

    user_uuid = uuid
    clientSpecificQuery = getClientSpecificQueryFilter(user_uuid)
    Sections = get_section_db()
    logging.debug('section.count = %s' % Sections.count())
    # Theoretically, we shouldn't need the 'predicted_mode' code because we
    # predict values right after reading the trips from moves. However, there
    # is still a small race window in which we are reading trips for other
    # users and haven't yet run the classifier. As we get more users, this
    # window can only grow, and it is easy to handle it, so let's just do so now.
    defaultQueryList = [{
        'source': 'Shankari'
    }, {
        'user_id': user_uuid
    }, {
        'predicted_mode': {
            '$exists': True
        }
    }, {
        'confirmed_mode': ''
    }, {
        'retained': True
    }, {
        'type': 'move'
    }, {
        'section_end_datetime': {
            "$gt": weekago
        }
    }]
    completeQueryList = defaultQueryList + clientSpecificQuery
    unclassifiedSections = Sections.find({"$and": completeQueryList})

    # totalUnclassifiedSections are for debugging only, can remove after we know that this works well
    totalUnclassifiedSections = Sections.find({
        "$and": [{
            'source': 'Shankari'
        }, {
            'user_id': user_uuid
        }, {
            'confirmed_mode': ''
        }, {
            'type': 'move'
        }]
    })

    unclassifiedSectionCount = unclassifiedSections.count()
    totalUnclassifiedSectionCount = totalUnclassifiedSections.count()

    logging.debug('Unsec.count = %s' % unclassifiedSectionCount)
    logging.debug('Total Unsec.count = %s' % totalUnclassifiedSectionCount)
    # Keep track of what percent of sections are stripped out.
    # Sections can be stripped out for various reasons:
    # - they are too old
    # - they have enough confidence that above the magic threshold (90%) AND
    # the client has requested stripping out
    # - they have already been identified as being too short by the filter label
    stats.storeServerEntry(
        user_uuid, stats.STAT_TRIP_MGR_PCT_SHOWN, time.time(),
        0 if totalUnclassifiedSectionCount == 0 else
        float(unclassifiedSectionCount) / totalUnclassifiedSectionCount)
    return unclassifiedSections