Beispiel #1
0
def get_Alluser_work_end_time_pie(start,end):
    Worktimes=get_worktime_db()
    timeCountMap = {}
    for timesection in time_list:

        key=str(timesection[0]).zfill(2) +':01 - '+str(timesection[1]).zfill(2) +':00'
        timeCountMap[key] =Worktimes.find({'dep_hour':{"$gte": timesection[0], "$lt": timesection[1]}},\
                                          {"date": {"$gte": start, "$lt": end}}).count()

    return timeCountMap
Beispiel #2
0
def get_user_work_start_time_pie(user,start,end):
    Worktimes=get_worktime_db()
    timeCountMap = {}
    for timesection in time_list:

        key=str(timesection[0]).zfill(2) +':01 - '+str(timesection[1]).zfill(2) +':00'
        timeCountMap[key] =Worktimes.find({"$and":[{'user_id':user},{'arr_hour':{"$gte": timesection[0], "$lt": timesection[1]}},\
                                                   {"date": {"$gte": start, "$lt": end}}]}).count()

    return timeCountMap
Beispiel #3
0
def get_evening_commute_distance(user, start, end):
    # day should be from 1 to 5
    # get a list of work starttime for Mon, or ...
    Sections = get_section_db()
    Worktimes = get_worktime_db()
    totalDist = 0
    projection = {'distance': True, '_id': False}
    for section in Sections.find(
        {
            "$and": [{
                'user_id': user
            }, {
                'commute': 'from'
            }, {
                "section_start_datetime": {
                    "$gte": start,
                    "$lt": end
                }
            }]
        }, projection):
        #     logging.debug("found section with %s %s %s %s %s" %
        #       (section['trip_id'], section['section_id'], section['confirmed_mode'],
        #           section['user_id'], section['type']))
        if section['distance'] != None:
            totalDist = totalDist + section['distance']
        else:
            logging.warning(
                "distance key not found in projection, returning zero...")
            # returning zero for the distance
            pass

# logging.debug("for sectionList %s, distanceList = %s" % (len(sectionList), distanceList))
    num_commute = Worktimes.find({
        "$and": [{
            'user_id': user
        }, {
            'dep_hour': {
                "$exists": True
            }
        }, {
            "date": {
                "$gte": start,
                "$lt": end
            }
        }]
    }).count()
    if num_commute == 0:
        return 'N/A'
    else:
        return totalDist / num_commute
Beispiel #4
0
import logging
from commute import get_user_morning_commute_sections, get_user_evening_commute_sections
from work_time import get_user_work_start_time, get_user_work_end_time
from get_database import get_section_db, get_worktime_db
from datetime import datetime
from common import parse_time
from datetime import timedelta

Sections = get_section_db()
Worktimes = get_worktime_db()
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',
                    level=logging.DEBUG)
#### morning ######
for user in Sections.distinct('user_id'):
    Usermorningsections = get_user_morning_commute_sections(user)
    logging.debug("About to update %s morning commute sections for user %s" %
                  (len(Usermorningsections), user))
    for sections in Usermorningsections:
        for ss in sections:
            Sections.update({"_id": ss['_id']}, {"$set": {'commute': 'to'}})

##### evening ######
for user in Sections.distinct('user_id'):
    Usereveningsections = get_user_evening_commute_sections(user)
    logging.debug("About to update %s evening commute sections for user %s" %
                  (len(Usereveningsections), user))
    for sections in Usereveningsections:
        for ss in sections:
            Sections.update({"_id": ss['_id']}, {"$set": {'commute': 'from'}})
##### None #####
nonCommuteQuery = {
import logging
from commute import get_user_morning_commute_sections,get_user_evening_commute_sections
from work_time import get_user_work_start_time,get_user_work_end_time
from get_database import get_section_db,get_worktime_db
from datetime import datetime
from common import parse_time
from datetime import timedelta

Sections=get_section_db()
Worktimes=get_worktime_db()
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG)
#### morning ######
for user in Sections.distinct('user_id'):
    Usermorningsections=get_user_morning_commute_sections(user)
    logging.debug("About to update %s morning commute sections for user %s" % (len(Usermorningsections), user))
    for sections in Usermorningsections:
        for ss in sections:
            Sections.update({"_id":ss['_id']},{"$set":{'commute': 'to'}})

##### evening ######
for user in Sections.distinct('user_id'):
    Usereveningsections=get_user_evening_commute_sections(user)
    logging.debug("About to update %s evening commute sections for user %s" % (len(Usereveningsections), user))
    for sections in Usereveningsections:
        for ss in sections:
            Sections.update({"_id":ss['_id']},{"$set":{'commute': 'from'}})
##### None #####
nonCommuteQuery = {"$and":[{'source':'Shankari'},{'commute':{ "$exists": False }}]}
logging.debug("About to update %s non-commute sections across users" % Sections.find(nonCommuteQuery).count())
for section in Sections.find(nonCommuteQuery):
    Sections.update({'_id':section['_id']},{"$set":{'commute': None}})