<commit_before>import pandas as pd
import folium.folium as folium
import itertools
import numpy as np
import logging
import geojson as gj
import copy
import attrdict as ad
from functional import seq

# import emission.analysis.classification.cleaning.location_smoothing as ls
import bson.json_util as bju

import emission.storage.decorations.location_queries as lq
import emission.storage.decorations.trip_queries as esdt
import emission.storage.decorations.place_queries as esdp
import emission.storage.decorations.stop_queries as esds
import emission.storage.decorations.section_queries as esdsc

import emission.storage.timeseries.abstract_timeseries as esta

import emission.core.wrapper.stop as ecws
import emission.core.wrapper.section as ecwsc

import emission.analysis.plotting.geojson.geojson_feature_converter as gfc
import emission.analysis.plotting.leaflet_osm.folium_geojson_plugin as fgjp

import emission.net.usercache.abstract_usercache as enua
import emission.net.api.usercache as enau

all_color_list = ['black', 'brown', 'blue', 'chocolate', 'cyan', 'fuschia', 'green', 'lime', 'magenta', 'navy', 'pink', 'purple', 'red', 'snow', 'yellow']
sel_color_list = ['black', 'blue', 'chocolate', 'cyan', 'fuschia', 'green', 'lime', 'magenta', 'pink', 'purple', 'red', 'yellow']

def df_to_string_list(df):
    """
    Convert the input df into a list of strings, suitable for using as popups in a map.
    This is a utility function.
    """
    # print "Converting df with size %s to string list" % df.shape[0]
    array_list = df.to_dict(orient='records')
    return [str(line) for line in array_list]

def get_maps_for_range(user_id, start_ts, end_ts):
    map_list = []
    geojson_list = gfc.get_geojson_for_range(user_id, start_ts, end_ts)
    return get_maps_for_geojson_list(geojson_list)

def get_maps_for_usercache(user_id):
    data_to_phone = seq(enau.sync_server_to_phone(user_id))
    logging.debug("Before pipeline, trips to phone list has length %d" % len(data_to_phone.to_list()))
    logging.debug("keys are %s" % data_to_phone.map(lambda e: ad.AttrDict(e).metadata.key))
    trips_to_phone = data_to_phone.map(lambda e: ad.AttrDict(e))\
                                    .filter(lambda e: e.metadata.key.startswith("diary/trips")) \
                                    .map(lambda e: e.data)
    logging.debug("After pipeline, trips to phone list has length %d" % len(trips_to_phone.to_list()))
    assert(len(trips_to_phone.to_list()) == 1)
    # logging.debug("trips_to_phone = %s" % trips_to_phone)
    return get_maps_for_geojson_list(trips_to_phone[0])

def get_maps_for_geojson_list(trip_geojson_list):
    map_list = []
    for trip_doc in trip_geojson_list:
        # logging.debug(trip_geojson)
        trip_geojson = ad.AttrDict(trip_doc)
        logging.debug("centering based on start = %s, end = %s " % (trip_geojson.features[0], trip_geojson.features[1]))
        flipped_midpoint = lambda(p1, p2): [(p1.coordinates[1] + p2.coordinates[1])/2,
                                            (p1.coordinates[0] + p2.coordinates[0])/2]

        curr_map = folium.Map(flipped_midpoint((trip_geojson.features[0].geometry,
                                                trip_geojson.features[1].geometry)))
        curr_plugin = fgjp.FoliumGeojsonPlugin(dict(trip_geojson))
        curr_map.add_plugin(curr_plugin)
        map_list.append(curr_map)
    return map_list
    
def flipped(coord):
    return (coord[1], coord[0])
    
def get_center_for_map(coords):
    # logging.debug(trip_geojson)
    midpoint = lambda(p1, p2): [(p1[0] + p2[0])/2,
                                (p1[1] + p2[1])/2]<commit_msg>Display data from the user cache for multiple days<commit_after>import pandas as pd
import folium.folium as folium
import itertools
import numpy as np
import logging
import geojson as gj
import copy
import attrdict as ad
from functional import seq

# import emission.analysis.classification.cleaning.location_smoothing as ls
import bson.json_util as bju

import emission.storage.decorations.location_queries as lq
import emission.storage.decorations.trip_queries as esdt
import emission.storage.decorations.place_queries as esdp
import emission.storage.decorations.stop_queries as esds
import emission.storage.decorations.section_queries as esdsc

import emission.storage.timeseries.abstract_timeseries as esta

import emission.core.wrapper.stop as ecws
import emission.core.wrapper.section as ecwsc

import emission.analysis.plotting.geojson.geojson_feature_converter as gfc
import emission.analysis.plotting.leaflet_osm.folium_geojson_plugin as fgjp

import emission.net.usercache.abstract_usercache as enua
import emission.net.api.usercache as enau

all_color_list = ['black', 'brown', 'blue', 'chocolate', 'cyan', 'fuschia', 'green', 'lime', 'magenta', 'navy', 'pink', 'purple', 'red', 'snow', 'yellow']
sel_color_list = ['black', 'blue', 'chocolate', 'cyan', 'fuschia', 'green', 'lime', 'magenta', 'pink', 'purple', 'red', 'yellow']

def df_to_string_list(df):
    """
    Convert the input df into a list of strings, suitable for using as popups in a map.
    This is a utility function.
    """
    # print "Converting df with size %s to string list" % df.shape[0]
    array_list = df.to_dict(orient='records')
    return [str(line) for line in array_list]

def get_maps_for_range(user_id, start_ts, end_ts):
    map_list = []
    geojson_list = gfc.get_geojson_for_range(user_id, start_ts, end_ts)
    return get_maps_for_geojson_list(geojson_list)

def get_maps_for_usercache(user_id):
    data_to_phone = seq(enau.sync_server_to_phone(user_id))
    logging.debug("Before pipeline, trips to phone list has length %d" % len(data_to_phone.to_list()))
    logging.debug("keys are %s" % data_to_phone.map(lambda e: ad.AttrDict(e).metadata.key))
    trips_to_phone = data_to_phone.map(lambda e: ad.AttrDict(e))\
                                    .filter(lambda e: e.metadata.key.startswith("diary/trips")) \
                                    .map(lambda e: e.data)
    logging.debug("After pipeline, trips to phone list has length %d" % len(trips_to_phone.to_list()))
    # logging.debug("trips_to_phone = %s" % trips_to_phone)
    maps_for_day = []
    for day in trips_to_phone:
        maps_for_day.append(get_maps_for_geojson_list(day))
    return maps_for_day

def get_maps_for_geojson_list(trip_geojson_list):
    map_list = []
    for trip_doc in trip_geojson_list:
        # logging.debug(trip_doc)
        trip_geojson = ad.AttrDict(trip_doc)
        logging.debug("centering based on start = %s, end = %s " % (trip_geojson.features[0], trip_geojson.features[1]))
        flipped_midpoint = lambda(p1, p2): [(p1.coordinates[1] + p2.coordinates[1])/2,
                                            (p1.coordinates[0] + p2.coordinates[0])/2]

        curr_map = folium.Map(flipped_midpoint((trip_geojson.features[0].geometry,
                                                trip_geojson.features[1].geometry)))
        curr_plugin = fgjp.FoliumGeojsonPlugin(dict(trip_geojson))
        curr_map.add_plugin(curr_plugin)
        map_list.append(curr_map)
    return map_list
    
def flipped(coord):
    return (coord[1], coord[0])
    
def get_center_for_map(coords):
    # logging.debug(trip_geojson)
    midpoint = lambda(p1, p2): [(p1[0] + p2[0])/2,
                                (p1[1] + p2[1])/2]
{'fraction_non_alphanumeric': 0.1116392774684232, 'fraction_numerical': 0.008692109194621758, 'mean_word_length': 3.6785260482846254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2490928', 'n_tokens_mistral': 2498, 'n_tokens_neox': 2462, 'n_words': 541}