def process_timeline(user_id, time_range, tag=''):
    """
    process single user's timeline with timerange
    :param user_id:
    :param time_range: 10 digits
    :return:
    """
    print '[%s]start process user:%s time_range: from %s to %s' % (
        datetime.datetime.now(), user_id, datetime.datetime.fromtimestamp(time_range[0]),
        datetime.datetime.fromtimestamp(time_range[1]))
    combined_timelines = combine_timeline(user_id, (time_range[0], time_range[1]))
    # insert_count = save_timeline2mongo(combined_timelines)
    insert_count = dao_utils.save_raw_timeline2mongo(combined_timelines, tag=tag)
    if insert_count is not None:
        print '[%s]user:%s done, process timeline count = %s' % (datetime.datetime.now(), user_id, insert_count)
    else:
        print '[%s]user:%s error' % (datetime.datetime.now(), user_id)
def process_timeline(user_id, time_range, tag=''):
    """
    process single user's timeline with timerange
    :param user_id:
    :param time_range: 10 digits
    :return:
    """
    print '[%s]start process user:%s time_range: from %s to %s' % (
        datetime.datetime.now(), user_id,
        datetime.datetime.fromtimestamp(
            time_range[0]), datetime.datetime.fromtimestamp(time_range[1]))
    combined_timelines = combine_timeline(user_id,
                                          (time_range[0], time_range[1]))
    # insert_count = save_timeline2mongo(combined_timelines)
    insert_count = dao_utils.save_raw_timeline2mongo(combined_timelines,
                                                     tag=tag)
    if insert_count is not None:
        print '[%s]user:%s done, process timeline count = %s' % (
            datetime.datetime.now(), user_id, insert_count)
    else:
        print '[%s]user:%s error' % (datetime.datetime.now(), user_id)
                 'timestamp': item['data']['startTime'],
                 'start_ts': item['data']['startTime'],
                 'start_datetime': datetime.datetime.fromtimestamp(item['data']['startTime'] / 1000,
                                                                   pytz.timezone('UTC')),
                 'end_ts': item['data']['endTime'],
                 'end_datetime': datetime.datetime.fromtimestamp(item['data']['endTime'] / 1000, pytz.timezone('UTC')),
                 'start_location': {'title': start_poi[0], 'dist': start_poi[1],
                                    'geo_point': start_location_item['location']},
                 'end_location': {'title': end_poi[0], 'dist': end_poi[1],
                                  'geo_point': end_location_item['location']},
                 'evidence_list': {'location_ids': location_ids,
                                   'motion_ids': motion_ids, 'event_ids': [item['data']['_id']]},
                 'motion_count': motion_dict,
                 'poi': {'title': nearest_poi[0], 'dist': nearest_poi[1], 'geo_point': poi['location']}})
            # for
            # print '12312'
            # pass
    return timeline


if __name__ == '__main__':
    # get_user_hos('564ee2fbddb28e2d3f880165', (start_timestamp, end_timestamp))
    # get_user_events('560388c100b09b53b59504d2', (start_timestamp, end_timestamp))
    start_timestamp = time_utils.trans_strtime2timestamp('2016-01-10 00:00:00')
    end_timestamp = time_utils.trans_strtime2timestamp('2016-01-21 23:59:59')
    combined_timelines = combine_timeline('5634da2360b22ab52ef82a45', (start_timestamp, end_timestamp))
    if dao_utils.save_raw_timeline2mongo(combined_timelines):
        print 'done'
    else:
        print 'error'
                'evidence_list': {
                    'location_ids': location_ids,
                    'motion_ids': motion_ids,
                    'event_ids': [item['data']['_id']]
                },
                'motion_count':
                motion_dict,
                'poi': {
                    'title': nearest_poi[0],
                    'dist': nearest_poi[1],
                    'geo_point': poi['location']
                }
            })
            # for
            # print '12312'
            # pass
    return timeline


if __name__ == '__main__':
    # get_user_hos('564ee2fbddb28e2d3f880165', (start_timestamp, end_timestamp))
    # get_user_events('560388c100b09b53b59504d2', (start_timestamp, end_timestamp))
    start_timestamp = time_utils.trans_strtime2timestamp('2016-01-10 00:00:00')
    end_timestamp = time_utils.trans_strtime2timestamp('2016-01-21 23:59:59')
    combined_timelines = combine_timeline('5634da2360b22ab52ef82a45',
                                          (start_timestamp, end_timestamp))
    if dao_utils.save_raw_timeline2mongo(combined_timelines):
        print 'done'
    else:
        print 'error'