Ejemplo n.º 1
0
def init_state(terms=None, tilds=None, timestamp=None):
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')

    date = models.get_current_date(tilds)

    return {
        'terms'         : terms or '',
        'terms_v'       : terms or '',

        'tilds'         : tilds or '',
        'tilds_v'       : tilds or '',

        'timestamp'     : tools.to_timestamp(date) or timestamp or '',
        'timestamp_v'   : tools.to_verbose(d=date) or tools.to_verbose(t=timestamp) or ''
    }
Ejemplo n.º 2
0
    def get_json(self, tilds):
        context = { }

        try:
            date = models.get_current_date(tilds)

            context = {
                'tilds'         : tilds,
                'timestamp'     : tools.to_timestamp(date) or '',
                'timestamp_v'   : tools.to_verbose(d=date) or ''
            }

        except Exception as e:
            context['error'] = str(e)

        finally:
            tools.json_response(self, context)
Ejemplo n.º 3
0
def extract_app_usage_data(userId, filepath):
    # Format : App name / Date / Time / Duration
    data = tools.get_dataframe(filepath)
    new_data = {'User_ID': [], 'Time': [], 'App Name': [], 'Duration': []}
    # For each data line
    for i in range(data.shape[0]):
        # Create a dict with formatted values
        doc = {
            'User_ID': userId,
            'Time': tools.to_timestamp(data['Date'][i], data['Time'][i]),
            'App Name': tools.appname_process(data['App name'][i]),
            'Duration': tools.time_in_seconds(data['Duration'][i])
        }

        # If the data needs to be stored, addition to the dict new_data
        if doc['Duration'] != 0 and doc['App Name'] not in tools.app_to_remove():
            for k in new_data:
                new_data[k].append(doc[k])
    # Create a df with new data and return it
    return pd.DataFrame(new_data)