Ejemplo n.º 1
0
    def getRangeData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        samplingPoints = self.samplingPoints.num()
        pools = [(v.id, v.name) for v in ServicePool.objects.filter(uuid__in=self.pools.value)]
        if len(pools) == 0:
            raise Exception(_('Select at least a service pool for the report'))

        logger.debug('Pools: {}'.format(pools))

        # x axis label format
        if end - start > 3600 * 24 * 2:
            xLabelFormat = 'SHORT_DATE_FORMAT'
        else:
            xLabelFormat = 'SHORT_DATETIME_FORMAT'

        # Generate samplings interval
        samplingIntervals = []
        prevVal = None
        for val in range(start, end, (end - start) / (samplingPoints + 1)):
            if prevVal is None:
                prevVal = val
                continue
            samplingIntervals.append((prevVal, val))
            prevVal = val

        # Store dataUsers for all pools
        poolsData = []

        fld = events.statsManager().getEventFldFor('username')

        reportData = []
        for p in pools:
            dataUsers = []
            dataAccesses = []
            for interval in samplingIntervals:
                key = (interval[0] + interval[1]) / 2
                q = events.statsManager().getEvents(events.OT_DEPLOYED, events.ET_ACCESS, since=interval[0], to=interval[1], owner_id=p[0]).values(fld).annotate(cnt=Count(fld))
                accesses = 0
                for v in q:
                    accesses += v['cnt']

                dataUsers.append((key, len(q)))  # @UndefinedVariable
                dataAccesses.append((key, accesses))
                reportData.append(
                    {
                        'name': p[1],
                        'date': tools.timestampAsStr(interval[0], xLabelFormat) + ' - ' + tools.timestampAsStr(interval[1], xLabelFormat),
                        'users': len(q),
                        'accesses': accesses
                    }
                )
            poolsData.append({
                'pool': p[0],
                'name': p[1],
                'dataUsers': dataUsers,
                'dataAccesses': dataAccesses,
            })

        return (xLabelFormat, poolsData, reportData)
Ejemplo n.º 2
0
    def getData(self):
        # Generate the sampling intervals and get dataUsers from db
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        logger.debug(self.pool.value)
        pool = ServicePool.objects.get(uuid=self.pool.value)

        items = events.statsManager().getEvents(
            events.OT_DEPLOYED, (events.ET_LOGIN, events.ET_LOGOUT),
            owner_id=pool.id,
            since=start,
            to=end).order_by('stamp')

        logins = {}
        data = []
        for i in items:
            # if '\\' in i.fld1:
            #    continue

            if i.event_type == events.ET_LOGIN:
                logins[i.fld4] = i.stamp
            else:
                if i.fld4 in logins:
                    stamp = logins[i.fld4]
                    del logins[i.fld4]
                    total = i.stamp - stamp
                    data.append({
                        'name': i.fld4,
                        'date': datetime.datetime.fromtimestamp(stamp),
                        'time': total
                    })

        logger.debug('data')

        return data, pool.name
Ejemplo n.º 3
0
    def getRangeData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        samplingPoints = self.samplingPoints.num()

        # x axis label format
        if end - start > 3600 * 24 * 2:
            xLabelFormat = 'SHORT_DATE_FORMAT'
        else:
            xLabelFormat = 'SHORT_DATETIME_FORMAT'

        samplingIntervals = []
        prevVal = None
        for val in range(start, end, (end - start) / (samplingPoints + 1)):
            if prevVal is None:
                prevVal = val
                continue
            samplingIntervals.append((prevVal, val))
            prevVal = val

        data = []
        reportData = []
        for interval in samplingIntervals:
            key = (interval[0] + interval[1]) / 2
            val = events.statsManager().getEvents(events.OT_AUTHENTICATOR, events.ET_LOGIN, since=interval[0], to=interval[1]).count()
            data.append((key, val))  # @UndefinedVariable
            reportData.append(
                {
                    'date': tools.timestampAsStr(interval[0], xLabelFormat) + ' - ' + tools.timestampAsStr(interval[1], xLabelFormat),
                    'users': val
                }
            )

        return (xLabelFormat, data, reportData)
Ejemplo n.º 4
0
    def getData(self):
        # Generate the sampling intervals and get dataUsers from db
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        logger.debug(self.pool.value)
        pool = ServicePool.objects.get(uuid=self.pool.value)

        items = events.statsManager().getEvents(events.OT_DEPLOYED, (events.ET_LOGIN, events.ET_LOGOUT), owner_id=pool.id, since=start, to=end).order_by('stamp')

        logins = {}
        data = []
        for i in items:
            # if '\\' in i.fld1:
            #    continue

            if i.event_type == events.ET_LOGIN:
                logins[i.fld4] = i.stamp
            else:
                if i.fld4 in logins:
                    stamp = logins[i.fld4]
                    del logins[i.fld4]
                    total = i.stamp - stamp
                    data.append({
                        'name': i.fld4,
                        'date': datetime.datetime.fromtimestamp(stamp),
                        'time': total
                    })

        logger.debug('data: {}'.format(data))

        return data, pool.name
Ejemplo n.º 5
0
    def getWeekHourlyData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()

        dataWeek = [0] * 7
        dataHour = [0] * 24
        for val in events.statsManager().getEvents(events.OT_AUTHENTICATOR, events.ET_LOGIN, since=start, to=end):
            s = datetime.datetime.fromtimestamp(val.stamp)
            dataWeek[s.weekday()] += 1
            dataHour[s.hour] += 1

        return (dataWeek, dataHour)
Ejemplo n.º 6
0
    def getWeekHourlyData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()

        dataWeek = [0] * 7
        dataHour = [0] * 24
        for val in events.statsManager().getEvents(events.OT_AUTHENTICATOR, events.ET_LOGIN, since=start, to=end):
            s = datetime.datetime.fromtimestamp(val.stamp)
            dataWeek[s.weekday()] += 1
            dataHour[s.hour] += 1

        return (dataWeek, dataHour)
Ejemplo n.º 7
0
    def getPoolData(
            self, pool
    ) -> typing.Tuple[typing.List[typing.Dict[str, typing.Any]], str]:
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        logger.debug(self.pool.value)

        items = events.statsManager().getEvents(
            events.OT_DEPLOYED, (events.ET_LOGIN, events.ET_LOGOUT),
            owner_id=pool.id,
            since=start,
            to=end).order_by('stamp')

        logins: typing.Dict[str, int] = {}
        users: typing.Dict[str, typing.Dict] = {}
        for i in items:
            # if '\\' in i.fld1:
            #    continue
            username = i.fld4
            if i.event_type == events.ET_LOGIN:
                logins[username] = i.stamp
            else:
                if username in logins:
                    stamp = logins[username]
                    del logins[username]
                    total = i.stamp - stamp
                    if username not in users:
                        users[username] = {'sessions': 0, 'time': 0}
                    users[username]['sessions'] += 1
                    users[username]['time'] += total
                    # data.append({
                    #    'name': i.fld4,
                    #    'date': datetime.datetime.fromtimestamp(stamp),
                    #    'time': total
                    # })

        # Extract different number of users
        data = [{
            'user':
            k,
            'sessions':
            v['sessions'],
            'hours':
            '{:.2f}'.format(float(v['time']) / 3600),
            'average':
            '{:.2f}'.format(float(v['time']) / 3600 / v['sessions'])
        } for k, v in users.items()]

        return data, pool.name
Ejemplo n.º 8
0
    def getData(
            self
    ) -> typing.Tuple[typing.List[typing.Dict[str, typing.Any]], str]:
        # Generate the sampling intervals and get dataUsers from db
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        logger.debug(self.pool.value)
        if '0-0-0-0' in self.pool.value:
            pools = ServicePool.objects.all()
        else:
            pools = ServicePool.objects.filter(uuid__in=self.pool.value)
        data = []
        for pool in pools:
            items = (events.statsManager().getEvents(
                events.OT_DEPLOYED,
                (events.ET_LOGIN, events.ET_LOGOUT),
                owner_id=pool.id,
                since=start,
                to=end,
            ).order_by('stamp'))

            logins = {}
            for i in items:
                # if '\\' in i.fld1:
                #    continue

                if i.event_type == events.ET_LOGIN:
                    logins[i.fld4] = i.stamp
                else:
                    if i.fld4 in logins:
                        stamp = logins[i.fld4]
                        del logins[i.fld4]
                        total = i.stamp - stamp
                        data.append({
                            'name':
                            i.fld4,
                            'origin':
                            i.fld2.split(':')[0],
                            'date':
                            datetime.datetime.fromtimestamp(stamp),
                            'time':
                            total,
                            'pool':
                            pool.uuid,
                            'pool_name':
                            pool.name,
                        })

        return data, ','.join([p.name for p in pools])
Ejemplo n.º 9
0
    def getRangeData(self) -> typing.Tuple[str, typing.List, typing.List]:
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        if self.samplingPoints.num() < 8:
            self.samplingPoints.value = (self.endDate.date() -
                                         self.startDate.date()).days
        if self.samplingPoints.num() < 2:
            self.samplingPoints.value = 2
        if self.samplingPoints.num() > 128:
            self.samplingPoints.value = 128

        samplingPoints = self.samplingPoints.num()

        # x axis label format
        if end - start > 3600 * 24 * 2:
            xLabelFormat = 'SHORT_DATE_FORMAT'
        else:
            xLabelFormat = 'SHORT_DATETIME_FORMAT'

        samplingIntervals: typing.List[typing.Tuple[int, int]] = []
        prevVal = None
        for val in range(start, end, int(
            (end - start) / (samplingPoints + 1))):
            if prevVal is None:
                prevVal = val
                continue
            samplingIntervals.append((prevVal, val))
            prevVal = val

        data = []
        reportData = []
        for interval in samplingIntervals:
            key = (interval[0] + interval[1]) / 2
            val = (events.statsManager().getEvents(
                events.OT_AUTHENTICATOR,
                events.ET_LOGIN,
                since=interval[0],
                to=interval[1],
            ).count())
            data.append((key, val))  # @UndefinedVariable
            reportData.append({
                'date':
                tools.timestampAsStr(interval[0], xLabelFormat) + ' - ' +
                tools.timestampAsStr(interval[1], xLabelFormat),
                'users':
                val,
            })

        return xLabelFormat, data, reportData
Ejemplo n.º 10
0
    def getWeekHourlyData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()

        dataWeek = [0] * 7
        dataHour = [0] * 24
        dataWeekHour = [[0] * 24 for _ in range(7)]
        for val in events.statsManager().getEvents(events.OT_AUTHENTICATOR, events.ET_LOGIN, since=start, to=end):
            s = datetime.datetime.fromtimestamp(val.stamp)
            dataWeek[s.weekday()] += 1
            dataHour[s.hour] += 1
            dataWeekHour[s.weekday()][s.hour] += 1
            logger.debug('Data: {} {}'.format(s.weekday(), s.hour))

        return dataWeek, dataHour, dataWeekHour
Ejemplo n.º 11
0
    def getWeekHourlyData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()

        dataWeek = [0] * 7
        dataHour = [0] * 24
        dataWeekHour = [[0] * 24 for _ in range(7)]
        for val in events.statsManager().getEvents(events.OT_AUTHENTICATOR,
                                                   events.ET_LOGIN,
                                                   since=start,
                                                   to=end):
            s = datetime.datetime.fromtimestamp(val.stamp)
            dataWeek[s.weekday()] += 1
            dataHour[s.hour] += 1
            dataWeekHour[s.weekday()][s.hour] += 1
            logger.debug('Data: %s %s', s.weekday(), s.hour)

        return dataWeek, dataHour, dataWeekHour
Ejemplo n.º 12
0
    def getPoolData(self, pool):
        start = self.startDate.stamp()
        end = self.endDate.stamp()
        logger.debug(self.pool.value)

        items = events.statsManager().getEvents(events.OT_DEPLOYED, (events.ET_LOGIN, events.ET_LOGOUT), owner_id=pool.id, since=start, to=end).order_by('stamp')

        logins = {}
        users = {}
        for i in items:
            # if '\\' in i.fld1:
            #    continue
            username = i.fld4
            if i.event_type == events.ET_LOGIN:
                logins[username] = i.stamp
            else:
                if username in logins:
                    stamp = logins[username]
                    del logins[username]
                    total = i.stamp - stamp
                    if username not in users:
                        users[username] = { 'sessions': 0, 'time': 0 }
                    users[username]['sessions'] += 1
                    users[username]['time'] += total
                    # data.append({
                    #    'name': i.fld4,
                    #    'date': datetime.datetime.fromtimestamp(stamp),
                    #    'time': total
                    # })

        # Extract different number of users
        data = []
        for k, v in six.iteritems(users):

            data.append({
                'user': k,
                'sessions': v['sessions'],
                'hours': '{:.2f}'.format(float(v['time']) / 3600),
                'average': '{:.2f}'.format(float(v['time']) / 3600 / v['sessions'])
            })

        return data, pool.name
Ejemplo n.º 13
0
    def getRangeData(self):
        start = self.startDate.stamp()
        end = self.endDate.stamp()

        if self.samplingPoints.num() < 2:
            self.samplingPoints.value = (self.endDate.date() -
                                         self.startDate.date()).days
        if self.samplingPoints.num() < 2:
            self.samplingPoints.value = 2
        if self.samplingPoints.num() > 32:
            self.samplingPoints.value = 32

        samplingPoints = self.samplingPoints.num()

        pools = self.getPools()

        if len(pools) == 0:
            raise Exception(_('Select at least a service pool for the report'))

        logger.debug('Pools: {}'.format(pools))

        # x axis label format
        if end - start > 3600 * 24 * 2:
            xLabelFormat = 'SHORT_DATE_FORMAT'
        else:
            xLabelFormat = 'SHORT_DATETIME_FORMAT'

        # Generate samplings interval
        samplingIntervals = []
        prevVal = None
        for val in range(start, end, int(
            (end - start) / (samplingPoints + 1))):
            if prevVal is None:
                prevVal = val
                continue
            samplingIntervals.append((prevVal, val))
            prevVal = val

        # Store dataUsers for all pools
        poolsData = []

        fld = events.statsManager().getEventFldFor('username')

        reportData = []
        for p in pools:
            dataUsers = []
            dataAccesses = []
            for interval in samplingIntervals:
                key = (interval[0] + interval[1]) / 2
                q = events.statsManager().getEvents(
                    events.OT_DEPLOYED,
                    events.ET_ACCESS,
                    since=interval[0],
                    to=interval[1],
                    owner_id=p[0]).values(fld).annotate(cnt=Count(fld))
                accesses = 0
                for v in q:
                    accesses += v['cnt']

                dataUsers.append((key, len(q)))  # @UndefinedVariable
                dataAccesses.append((key, accesses))
                reportData.append({
                    'name':
                    p[1],
                    'date':
                    tools.timestampAsStr(interval[0], xLabelFormat) + ' - ' +
                    tools.timestampAsStr(interval[1], xLabelFormat),
                    'users':
                    len(q),
                    'accesses':
                    accesses
                })
            poolsData.append({
                'pool': p[0],
                'name': p[1],
                'dataUsers': dataUsers,
                'dataAccesses': dataAccesses,
            })

        return xLabelFormat, poolsData, reportData