Brand new logins each day, and total of users each day.

    :return: data, total
      2 lists of dictionaries of the following format [{'x':epoch, 'y': value},]
9544
def newlogins(sessions):
    
    if not sessions:
        return [], []
    users = {}
    dates = {}

    for session in sessions:
        user = session.user
        # time value is discarded to aggregate on days only
        date = session.started_at.strftime("%Y/%m/%d")
        # keep the info only it's the first time we encounter a user
        if user not in users:
            users[user] = date
            # build the list of users on a given day
            if date not in dates:
                dates[date] = [user]
            else:
                dates[date].append(user)

    data = []
    total = []
    previous = 0
    for date in sorted(dates.keys()):
        # print u"{} : {}".format(date, len(dates[date]))
        date_epoch = unix_time_millis(datetime.strptime(date, "%Y/%m/%d"))
        data.append({"x": date_epoch, "y": len(dates[date])})
        previous += len(dates[date])
        total.append({"x": date_epoch, "y": previous})

    return data, total
1221988
def get_stats_daily(start=None, end=None, last=None, **kwargs):
    
    import warnings
    warnings.warn(WNG_MSG % ("get_stats_daily", "iexdata.get_stats_daily"))
    start, end = _sanitize_dates(start, end)
    return DailySummaryReader(start=start, end=end, last=last,
                              **kwargs).fetch()
1217810
def fetch_logins(roles, repo):
    
    users = set()
    if 'stargazer' in roles:
        printmp('Fetching stargazers')
        users |= set(repo.stargazers())
    if 'collaborator' in roles:
        printmp('Fetching collaborators')
        users |= set(repo.collaborators())
    if 'issue' in roles:
        printmp('Fetching issues creators')
        users |= set([i.user for i in repo.issues(state='all')])
    return users
1270335
def get_users():
    '''
    
    '''
    try:
        recs = psutil.users()
        return [dict(x._asdict()) for x in recs]
    except AttributeError:
        # get_users is only present in psutil > v0.5.0
        # try utmp
        try:
            import utmp  # pylint: disable=import-error

            result = []
            while True:
                rec = utmp.utmpaccess.getutent()
                if rec is None:
                    return result
                elif rec[0] == 7:
                    started = rec[8]
                    if isinstance(started, tuple):
                        started = started[0]
                    result.append({'name': rec[4], 'terminal': rec[2],
                                   'started': started, 'host': rec[5]})
        except ImportError:
            return False
544468
def users(self):
        
        # We do here some lazy loading.
        if not self._users:
            self._users = UserManager(self)
        return self._users
757605
def list_user_logins_users(self, user_id):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - user_id
        """ID"""
        path["user_id"] = user_id

        self.logger.debug("GET /api/v1/users/{user_id}/logins with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/users/{user_id}/logins".format(**path), data=data, params=params, all_pages=True)
456739
def snapshot_statistics(self):
        
        with self._lock:

            stats = {
                'request_count': self.request_count,
                'borrow_count': self.borrow_count,
                'sampled_count': self.sampled_count,
            }

            self._reset_statistics()
            return stats
402614
def to_dict(self):
        
        users = dict(users=list())
        for user in self:
            users['users'].append(user.to_dict())
        return users
286778
def get_all_days():
    
    weekly = get_weekly()
    daily = get_daily()

    return [w * (d / 100.0) for w in weekly for d in daily]
1199958
def create_user(post_data):
        '''
        
        '''
        out_dic = {'success': False, 'code': '00'}

        if not tools.check_username_valid(post_data['user_name']):
            out_dic['code'] = '11'
            return out_dic

        if not tools.check_email_valid(post_data['user_email']):
            out_dic['code'] = '21'
            return out_dic

        try:
            TabMember.create(uid=tools.get_uuid(),
                             user_name=post_data['user_name'],
                             user_pass=tools.md5(post_data['user_pass']),
                             user_email=post_data['user_email'],
                             role='1000',  # ‘1000' as default role.
                             time_create=tools.timestamp(),
                             time_update=tools.timestamp(),
                             time_reset_passwd=tools.timestamp(),
                             time_login=tools.timestamp(),
                             time_email=tools.timestamp())

            out_dic['success'] = True
        except:
            out_dic['code'] = '91'
        return out_dic
458053
def _days(cls, start, end):
        
        days = []
        # datetime
        start_day, end_day = dt.strptime(start, cls.DATE_FORMAT), dt.strptime(end, cls.DATE_FORMAT)
        delta = end_day - start_day

        for day in range(delta.days+1):
            days.append(start_day + timedelta(days=day))
        return days
953025
def date_totals(entries, by):
    """"""
    date_dict = {}
    for date, date_entries in groupby(entries, lambda x: x['date']):
        if isinstance(date, datetime.datetime):
            date = date.date()
        d_entries = list(date_entries)

        if by == 'user':
            name = ' '.join((d_entries[0]['user__first_name'],
                             d_entries[0]['user__last_name']))
        elif by == 'project':
            name = d_entries[0]['project__name']
        else:
            name = d_entries[0][by]

        pk = d_entries[0][by]
        hours = get_hours_summary(d_entries)
        date_dict[date] = hours
    return name, pk, date_dict
564796
def users(self):
        
        return Users(url="%s/users" % self.root,
                     securityHandler=self._securityHandler,
                     proxy_url=self._proxy_url,
                     proxy_port=self._proxy_port)
425566
def users(self):
        
        if not self.__users:
            self.__users = Users(self.__connection)
        return self.__users
941089
def _user_raw_from_login_content(login_content):
    """"""
    matching_keys = [
        'displayName',
        'lastLogin',
        'active',
        'name',
        'isMe',
        'lastPasswordChangedDate',
        'passwordResetRequired',
        'groups',
        'roles',
        'email',
        'isAdmin',
        'createdDate',
        'modifiedDate',
        'createdByUser',
        'modifiedByUser',
        'userName',
        'id',
        'disabled'
    ]

    raw_data = {
        '$type': User._type,
    }

    for key in matching_keys:
        if key in login_content:
            raw_data[key] = login_content[key]

    return raw_data
128465
def get_user_cumulate(self, begin_date, end_date):
        
        res = self._post(
            'getusercumulate',
            data={
                'begin_date': self._to_date_str(begin_date),
                'end_date': self._to_date_str(end_date)
            },
            result_processor=lambda x: x['list']
        )
        return res
747708
def accounts(self):
        
        response = self.graph.get('%s/accounts' % self.id)

        accounts = []
        for item in response['data']:
            account = Structure(
                page = Page(
                    id = item['id'],
                    name = item['name'],
                    category = item['category']
                ),
                access_token = item['access_token'],
                permissions = item['perms']
            )

            accounts.append(account)

        return accounts