Esempio n. 1
0
    def _reportTopTitles(self, startTime, endTime, count_, startRank, namePrefix, volumeScale, viewTimeScale, sessionScale):

        entries = [] 
        for index in range(startRank, min(startRank + count_, 31) ): # don't return more than 201 titles
            entry = {}
            entry['name']          = "title-%s%03d" % (namePrefix, index)
            entry['rank']          = index + 1
            entry['siteId']        = self.getSite(index+50)

            titleValue = 2./(1.+index)
            entry['totalVolume']   = int(volumeScale*titleValue)
            entry['totalViewTime'] = int(viewTimeScale*titleValue)
            entry['sessionNumber'] = int(sessionScale*titleValue)
    
            entries.append( entry )
        
        result = {}
        result['entries'] = entries
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime),
                                'to'    : utils.formatUtcTimeAsIsoLocalTime(endTime), 
                                'count' : count_, 'startRank' : startRank, 
                                'len(entries)' : len(entries)
                              }
    
        return result
Esempio n. 2
0
    def _reportTopSubscribers(self, startTime, endTime, count_, startRank,
                              dataType):

        responder = ux_module.ReportsProcessor(self.topperReportsDir,
                                               self.uxParameters,
                                               self.topperLogger)
        data = responder.top(startTime, endTime, ux_module.CLIENTS, dataType,
                             startRank + count_)

        firstIndex = startRank
        dataEntries = data[ux_module.ENTRIES]
        lastIndex = min(len(dataEntries), startRank + count_)

        entries = []
        for index, values in enumerate(dataEntries[firstIndex:lastIndex]):

            entry = {}
            entry['subscriberId'] = values['key']
            entry['value'] = values['total']
            entry['rank'] = firstIndex + index + 1
            entries.append(entry)

        result = {}
        result['entries'] = entries
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'startRank': startRank,
            'count': count_,
            'len(dataEntries)': len(dataEntries)
        }

        return result
Esempio n. 3
0
    def _reportTopSites(self, startTime, endTime, count_, offset, factor):

        entries = [] 
        for index in range(0, min(count_, 201-offset)): # Return maximum 201 sites
            entry = {}
            vol = max(100 - 3 * index, 15 ) * factor / 200. * (endTime-startTime)
            entry['served']    = int(vol * 0.5)
            entry['potential'] = int(vol * 0.7)
            entry['total']     = int(vol * 1.0)
            entry['rank']      = index + 1
            siteId = self.getSite(offset + index)
            entry['siteId'] = siteId
    
            entries.append( entry )
        
        result = {}
        result['entries'] = entries
        # accumulate grandTotal
        sumServed = sum(e['served'] for e in entries)
        sumPotential = sum(e['potential'] for e in entries)
        sumTotal = sum(e['total'] for e in entries)
        result['grandTotal'] = {'total' : int(sumTotal * 1.3),
                                'potential': int(sumPotential * 1.3),
                                'served': int(sumServed * 1.3)
                               }
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime), 
                                'to'    : utils.formatUtcTimeAsIsoLocalTime(endTime), 
                                'count' : count_,
                                'len(entries)' : len(entries) 
                              }
    
        return result
Esempio n. 4
0
    def _reportTopTitles(self, startTime, endTime, count_, startRank,
                         namePrefix, volumeScale, viewTimeScale, sessionScale):

        entries = []
        for index in range(startRank,
                           min(startRank + count_,
                               31)):  # don't return more than 201 titles
            entry = {}
            entry['name'] = "title-%s%03d" % (namePrefix, index)
            entry['rank'] = index + 1
            entry['siteId'] = self.getSite(index + 50)

            titleValue = 2. / (1. + index)
            entry['totalVolume'] = int(volumeScale * titleValue)
            entry['totalViewTime'] = int(viewTimeScale * titleValue)
            entry['sessionNumber'] = int(sessionScale * titleValue)

            entries.append(entry)

        result = {}
        result['entries'] = entries
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'count': count_,
            'startRank': startRank,
            'len(entries)': len(entries)
        }

        return result
Esempio n. 5
0
    def _reportTopSubscribers(self, startTime, endTime, count_, startRank,
                              magic, scale):

        entries = []
        for index in range(startRank,
                           min(startRank + count_,
                               24)):  # don't return more than 24 titles
            entry = {}
            entry['subscriberId'] = "333.444.%03d.%03d" % (magic, index * 2)
            entry['value'] = int(magic * max(30 - index, 4) / 30.0 * 10 *
                                 scale)
            entry['rank'] = index + 1
            entries.append(entry)

        result = {}
        result['entries'] = entries
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'count': count_,
            'startRank': startRank,
            'len(entries)': len(entries)
        }

        return result
Esempio n. 6
0
    def _reportTopSubscribers(self, startTime, endTime, count_, startRank, dataType):
       
        responder  = ux_module.ReportsProcessor(self.topperReportsDir, self.uxParameters, self.topperLogger)   
        data       = responder.top(startTime, endTime, ux_module.CLIENTS, dataType, startRank + count_)
         
        firstIndex =  startRank
        dataEntries = data[ux_module.ENTRIES]
        lastIndex  = min( len(dataEntries), startRank + count_ )

        entries = [] 
        for index, values in enumerate( dataEntries[ firstIndex : lastIndex ] ):

            entry = {}
            entry['subscriberId']  = values['key']
            entry['value']         = values['total']
            entry['rank']          = firstIndex + index + 1
            entries.append( entry )
                   
        result = {}
        result['entries'] = entries
        result['debug']     = { 'from'      : utils.formatUtcTimeAsIsoLocalTime(startTime), 
                                'to'        : utils.formatUtcTimeAsIsoLocalTime(endTime), 
                                'startRank' : startRank,
                                'count'     : count_ ,
                                'len(dataEntries)' : len(dataEntries) }
    
        return result
Esempio n. 7
0
    def _reportTopTitles(self, startTime, endTime, count_, startRank, dataType):
       
        responder  = ux_module.ReportsProcessor(self.topperReportsDir, self.uxParameters, self.topperLogger)   
        data       = responder.top(startTime, endTime, ux_module.TITLES, dataType, startRank + count_)
         
        firstIndex =  startRank
        dataEntries = data[ux_module.ENTRIES]
        lastIndex  = min( len(dataEntries), startRank + count_ )

        entries = [] 
        for index, values in enumerate( dataEntries[ firstIndex : lastIndex ] ):

            entry = {}
            entry['name']      = values['key']
            entry['rank']      = firstIndex + index + 1

            entry['siteId']        = values[ux_module.SITE_ID]

            entry['totalVolume']   = values[ux_module.VOLUME]
            entry['totalViewTime'] = values[ux_module.VIEW_TIME]
            entry['sessionNumber'] = values[ux_module.SESSIONS]
            entries.append( entry )
                   
        result = {}
        result['entries'] = entries
        result['debug']     = { 'from'      : utils.formatUtcTimeAsIsoLocalTime(startTime), 
                                'to'        : utils.formatUtcTimeAsIsoLocalTime(endTime), 
                                'startRank' : startRank,
                                'count'     : count_ ,
                                'len(dataEntries)' : len(dataEntries) }
    
        return result
Esempio n. 8
0
    def _reportTopSites(self, startTime, endTime, count_, dataType):
      
        responder  = ux_module.ReportsProcessor(self.topperReportsDir, self.uxParameters, self.topperLogger)
        data       = responder.top(startTime, endTime, ux_module.SITES, dataType, count_)

        entries = [] 
        dataEntries = data[ux_module.ENTRIES]
        for index, values in enumerate(dataEntries):
            entry = {}
            entry['siteId']    = values['key'] # "youtube"   
            entry['served']    = values['delivered']
            entry['potential'] = values['cachable']
            entry['total']     = values['total']
            entry['rank']      = index + 1
            #entry['debug']     = { 'key': values['key'] }
            entries.append( entry )
                   
        result = {}
        result['entries'] = entries

        grandTotalData = data[ux_module.GRAND_TOTAL]
        result['grandTotal'] = { 'total':     grandTotalData['total'],
                                 'potential': grandTotalData['cachable'],
                                 'served':    grandTotalData['delivered']
                               }
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime), 
                                'to'    : utils.formatUtcTimeAsIsoLocalTime(endTime),
                                'count' : count_ ,
                                'len(dataEntries)' : len(dataEntries) }
    
        return result
Esempio n. 9
0
    def _reportOverTime(self, startTime, endTime, interval, dataType,
                        intervalUnit, aggregationType):

        potentialPoints = []
        servedPoints = []
        totalPoints = []

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            servedPoints.append({'date': oldestTime, 'value': 0})
            potentialPoints.append({'date': oldestTime, 'value': 0})
            totalPoints.append({'date': oldestTime, 'value': 0})
        else:
            if intervalUnit == 'month':
                uInterval = ux_module.MONTH
            else:
                # assume that in all other cases it is seconds
                uInterval = 's'

            self.apiLogger.debug(
                "startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s"
                % (startTime, endTime, interval, uInterval, dataType))

            responder = ux_module.ReportsProcessor(self.topperReportsDir,
                                                   self.uxParameters,
                                                   self.topperLogger)
            data = responder.overTime(startTime, endTime, interval, uInterval,
                                      dataType, aggregationType)

            for entry in data:
                entryDate = entry['date']
                debugDate = utils.formatUtcTimeAsIsoLocalTime(entryDate)
                servedPoints.append({
                    'date': entryDate,
                    'value': entry['delivered'],
                    'debugDate1': debugDate
                })
                potentialPoints.append({
                    'date': entryDate,
                    'value': entry['cachable'],
                    'debugDate1': debugDate
                })
                totalPoints.append({
                    'date': entryDate,
                    'value': entry['total'],
                    'debugDate1': debugDate
                })

        result = {}
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'interval': interval
        }
        result['potential'] = {'points': potentialPoints}
        result['served'] = {'points': servedPoints}
        result['total'] = {'points': totalPoints}

        return result
Esempio n. 10
0
    def _reportOverTime(self, startTime, endTime, interval, factor, intervalUnit, normalizationType, aggregationType=None, dateFieldName = 'date'):

        potentialPoints = [] 
        servedPoints = [] 
        totalPoints = [] 

        if intervalUnit == 'month':
            # just make it fast
            interval = interval * 30 * 24 * 60 * 60

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            servedPoints.append(   { dateFieldName: oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            potentialPoints.append({ dateFieldName: oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            totalPoints.append(    { dateFieldName: oldestTime, 'value': 0 , 'debugDate': debugDate }) 
        else:
            k = 1
            count_ = 1.0 * (endTime - startTime) / interval
            step   = 0.5 * factor / count_
            val    = 0.5 * factor

            for entryDate in range(startTime, endTime, interval):
                if aggregationType == "max":
                    # we will generate some offset to simulate peak time values
                    # offset is in round minutes
                    offset = (entryDate/24/3600*60) % 3600 + 18 * 3600 + time.timezone
                    date = entryDate + offset
                    calcInterval = 60
                else:
                    date = entryDate
                    calcInterval = interval

                if normalizationType == "avg":
                    norm = calcInterval
                else:
                    norm = 1
                debugDate = utils.formatUtcTimeAsIsoLocalTime(date)
                # add some 24 hours distribution
                # Consider it is sin^2 (no use at night)
                radF = math.pi/24./60./60. # convert seconds to radians
                # Integrate over distribution and normalize to get result at any value of interval parameter
                dist24 = (0.5 * calcInterval * radF - (math.sin(2. * (date + calcInterval) * radF ) -  math.sin(2 * date * radF ))/ 4.) / radF / norm
                servedPoints.append(    { dateFieldName: date * k, 'value': int(dist24 * val *  .2) , 'debugDate': debugDate } )
                potentialPoints.append( { dateFieldName: date * k, 'value': int(dist24 * val *  .6) , 'debugDate': debugDate } )
                totalPoints.append(     { dateFieldName: date * k, 'value': int(dist24 * val * 1.0) , 'debugDate': debugDate  } )
                val += step
        
        result = {}
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime), 'to' : utils.formatUtcTimeAsIsoLocalTime(endTime), 'interval' : interval }
        result['potential'] = { 'points': potentialPoints }
        result['served']    = { 'points': servedPoints }
        result['total']     = { 'points': totalPoints }
        return result
Esempio n. 11
0
    def reportOverTimeL2BW(self, startTime, endTime, interval, intervalUnit, aggregationType):
    
        totalPoints = [] 
        videoPoints = [] 
        videoServedPoints = [] 
    
        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            videoPoints.append(      { 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            videoServedPoints.append({ 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            totalPoints.append(      { 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
        else:
            factor = 5e9
            layer2Overhead = 1.2

            k = 1
            count_ = 1.0 * (endTime - startTime) / interval
            step   = 0.5 * factor / count_
            val    = 0.5 * factor * layer2Overhead

            for entryDate in range(startTime, endTime, interval):
                if aggregationType == "max":
                    # we will generate some offset to simulate peak time values
                    # offset is in round minutes
                    offset = (entryDate/24/3600*60) % 3600 + 18 * 3600 + time.timezone
                    date = entryDate + offset
                    calcInterval = 60
                else:
                    date = entryDate
                    calcInterval = interval
                debugDate = utils.formatUtcTimeAsIsoLocalTime(date)
                # add some 24 hours distribution
                # Consider it is sin^2 (no use at night max use at day time)
                radF = math.pi/24./60./60. # convert seconds to radians
                # Integrate over distribution and normalize to get result at any value of interval parameter
                dist24 = 0.5 - (math.sin(2. * (date + calcInterval) * radF ) -  math.sin(2 * (date) * radF ))/ calcInterval / radF / 4.

                videoServedPoints.append({ 'date': date * k, 'value': int(dist24 * val *  .4) , 'debugDate': debugDate } )
                videoPoints.append(      { 'date': date * k, 'value': int(dist24 * val *  .6) , 'debugDate': debugDate } )
                totalPoints.append(      { 'date': date * k, 'value': int(dist24 * val * 2.0 + val * .2), 'debugDate': debugDate  } )
                val += step
        
        result = {}
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime), 'to' : utils.formatUtcTimeAsIsoLocalTime(endTime), 'interval' : interval }
        result['videoServed'] = { 'points': videoServedPoints }
        result['video']       = { 'points': videoPoints }
        result['total']       = { 'points': totalPoints }
        return result
Esempio n. 12
0
 def point(value, unit):
     debugDate = utils.formatUtcTimeAsIsoLocalTime(unit.unitTime)
     return {
         'value': value,
         'date': unit.unitTime,
         'debugDate': debugDate
     }
Esempio n. 13
0
    def _reportTopSubscribers(self, startTime, endTime, count_, startRank, magic, scale):

        entries = [] 
        for index in range(startRank, min(startRank + count_, 24) ): # don't return more than 24 titles
            entry = {}
            entry['subscriberId']  = "333.444.%03d.%03d" % (magic, index * 2)
            entry['value']         = int(magic * max( 30 - index, 4) / 30.0 * 10 * scale)
            entry['rank']          = index + 1
            entries.append( entry )
        
        result = {}
        result['entries'] = entries
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime),
                                'to'    : utils.formatUtcTimeAsIsoLocalTime(endTime), 
                                'count' : count_, 'startRank' : startRank, 
                                'len(entries)' : len(entries)
                              }
    
        return result
Esempio n. 14
0
    def _reportTopTitles(self, startTime, endTime, count_, startRank,
                         dataType):

        responder = ux_module.ReportsProcessor(self.topperReportsDir,
                                               self.uxParameters,
                                               self.topperLogger)
        data = responder.top(startTime, endTime, ux_module.TITLES, dataType,
                             startRank + count_)

        firstIndex = startRank
        dataEntries = data[ux_module.ENTRIES]
        lastIndex = min(len(dataEntries), startRank + count_)

        entries = []
        for index, values in enumerate(dataEntries[firstIndex:lastIndex]):

            entry = {}
            entry['name'] = values['key']
            entry['rank'] = firstIndex + index + 1

            entry['siteId'] = values[ux_module.SITE_ID]

            entry['totalVolume'] = values[ux_module.VOLUME]
            entry['totalViewTime'] = values[ux_module.VIEW_TIME]
            entry['sessionNumber'] = values[ux_module.SESSIONS]
            entries.append(entry)

        result = {}
        result['entries'] = entries
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'startRank': startRank,
            'count': count_,
            'len(dataEntries)': len(dataEntries)
        }

        return result
Esempio n. 15
0
    def _reportOverTime(self, startTime, endTime, interval, dataType, intervalUnit, aggregationType):
    
        potentialPoints = [] 
        servedPoints = [] 
        totalPoints = [] 
    
        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            servedPoints.append(   { 'date': oldestTime, 'value': 0 }) 
            potentialPoints.append({ 'date': oldestTime, 'value': 0 }) 
            totalPoints.append(    { 'date': oldestTime, 'value': 0 }) 
        else:
            if intervalUnit == 'month':
                uInterval = ux_module.MONTH
            else:
                # assume that in all other cases it is seconds
                uInterval = 's'
            
            self.apiLogger.debug("startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s" % (startTime ,endTime,interval,uInterval,dataType) )

            responder = ux_module.ReportsProcessor(self.topperReportsDir,self.uxParameters,self.topperLogger)
            data      = responder.overTime(startTime ,endTime,interval,uInterval,dataType, aggregationType)

            for entry in data:
                entryDate = entry['date']
                debugDate = utils.formatUtcTimeAsIsoLocalTime(entryDate)
                servedPoints.append(    { 'date': entryDate , 'value': entry['delivered'] , 'debugDate1': debugDate } )
                potentialPoints.append( { 'date': entryDate , 'value': entry['cachable']  , 'debugDate1': debugDate } )
                totalPoints.append(     { 'date': entryDate , 'value': entry['total']     , 'debugDate1': debugDate } )
            
        result = {}
        result['debug']     = { 'from'  : utils.formatUtcTimeAsIsoLocalTime(startTime), 'to' : utils.formatUtcTimeAsIsoLocalTime(endTime), 'interval' : interval }
        result['potential'] = { 'points': potentialPoints }
        result['served']    = { 'points': servedPoints }
        result['total']     = { 'points': totalPoints }
    
        return result
Esempio n. 16
0
    def _reportTopSites(self, startTime, endTime, count_, dataType):

        responder = ux_module.ReportsProcessor(self.topperReportsDir,
                                               self.uxParameters,
                                               self.topperLogger)
        data = responder.top(startTime, endTime, ux_module.SITES, dataType,
                             count_)

        entries = []
        dataEntries = data[ux_module.ENTRIES]
        for index, values in enumerate(dataEntries):
            entry = {}
            entry['siteId'] = values['key']  # "youtube"
            entry['served'] = values['delivered']
            entry['potential'] = values['cachable']
            entry['total'] = values['total']
            entry['rank'] = index + 1
            #entry['debug']     = { 'key': values['key'] }
            entries.append(entry)

        result = {}
        result['entries'] = entries

        grandTotalData = data[ux_module.GRAND_TOTAL]
        result['grandTotal'] = {
            'total': grandTotalData['total'],
            'potential': grandTotalData['cachable'],
            'served': grandTotalData['delivered']
        }
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'count': count_,
            'len(dataEntries)': len(dataEntries)
        }

        return result
Esempio n. 17
0
    def reportOverTimeL2BW(self, startTime, endTime, interval, intervalUnit, aggregationType):
        self.apiLogger.debug("startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s" % (startTime ,endTime,interval,intervalUnit,ux_module.L2_BW) )
    
        result = {}
        videoServedPoints = []
        videoPoints = []
        totalPoints = []

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            videoServedPoints.append({ 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            videoPoints.append(      { 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
            totalPoints.append(      { 'date': oldestTime, 'value': 0 , 'debugDate': debugDate }) 
        else:
            if intervalUnit == 'month':
                uInterval = ux_module.MONTH
            else:
                # assume that in all other cases it is seconds
                uInterval = 's'
            
            self.apiLogger.debug("startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s" % (startTime ,endTime,interval,uInterval,ux_module.L2_BW) )

            responder = ux_module.ReportsProcessor(self.topperReportsDir,self.uxParameters,self.topperLogger)
            data      = responder.l2BWOverTime(startTime ,endTime,interval,uInterval, aggregationType)
            for entry in data:
                entryDate = entry['date']
                debugDate = utils.formatUtcTimeAsIsoLocalTime(entryDate)
                videoServedPoints.append({ 'date': entryDate , 'value': entry[ux_module.VIDEO_DELIVERED], 'debugDate1': debugDate } )
                videoPoints.append(      { 'date': entryDate , 'value': entry[ux_module.VIDEO]          , 'debugDate1': debugDate } )
                totalPoints.append(      { 'date': entryDate , 'value': entry[ux_module.TOTAL]          , 'debugDate1': debugDate } )

        result['videoServed'] = { 'points': videoServedPoints }
        result['video']       = { 'points': videoPoints }
        result['total']       = { 'points': totalPoints }
        return result
Esempio n. 18
0
    def _reportTopSites(self, startTime, endTime, count_, offset, factor):

        entries = []
        for index in range(0, min(count_,
                                  201 - offset)):  # Return maximum 201 sites
            entry = {}
            vol = max(100 - 3 * index,
                      15) * factor / 200. * (endTime - startTime)
            entry['served'] = int(vol * 0.5)
            entry['potential'] = int(vol * 0.7)
            entry['total'] = int(vol * 1.0)
            entry['rank'] = index + 1
            siteId = self.getSite(offset + index)
            entry['siteId'] = siteId

            entries.append(entry)

        result = {}
        result['entries'] = entries
        # accumulate grandTotal
        sumServed = sum(e['served'] for e in entries)
        sumPotential = sum(e['potential'] for e in entries)
        sumTotal = sum(e['total'] for e in entries)
        result['grandTotal'] = {
            'total': int(sumTotal * 1.3),
            'potential': int(sumPotential * 1.3),
            'served': int(sumServed * 1.3)
        }
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'count': count_,
            'len(entries)': len(entries)
        }

        return result
Esempio n. 19
0
    def _reportOverTime(self,
                        startTime,
                        endTime,
                        interval,
                        factor,
                        intervalUnit,
                        normalizationType,
                        aggregationType=None,
                        dateFieldName='date'):

        potentialPoints = []
        servedPoints = []
        totalPoints = []

        if intervalUnit == 'month':
            # just make it fast
            interval = interval * 30 * 24 * 60 * 60

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            servedPoints.append({
                dateFieldName: oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            potentialPoints.append({
                dateFieldName: oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            totalPoints.append({
                dateFieldName: oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
        else:
            k = 1
            count_ = 1.0 * (endTime - startTime) / interval
            step = 0.5 * factor / count_
            val = 0.5 * factor

            for entryDate in range(startTime, endTime, interval):
                if aggregationType == "max":
                    # we will generate some offset to simulate peak time values
                    # offset is in round minutes
                    offset = (entryDate / 24 / 3600 *
                              60) % 3600 + 18 * 3600 + time.timezone
                    date = entryDate + offset
                    calcInterval = 60
                else:
                    date = entryDate
                    calcInterval = interval

                if normalizationType == "avg":
                    norm = calcInterval
                else:
                    norm = 1
                debugDate = utils.formatUtcTimeAsIsoLocalTime(date)
                # add some 24 hours distribution
                # Consider it is sin^2 (no use at night)
                radF = math.pi / 24. / 60. / 60.  # convert seconds to radians
                # Integrate over distribution and normalize to get result at any value of interval parameter
                dist24 = (0.5 * calcInterval * radF -
                          (math.sin(2. * (date + calcInterval) * radF) -
                           math.sin(2 * date * radF)) / 4.) / radF / norm
                servedPoints.append({
                    dateFieldName: date * k,
                    'value': int(dist24 * val * .2),
                    'debugDate': debugDate
                })
                potentialPoints.append({
                    dateFieldName: date * k,
                    'value': int(dist24 * val * .6),
                    'debugDate': debugDate
                })
                totalPoints.append({
                    dateFieldName: date * k,
                    'value': int(dist24 * val * 1.0),
                    'debugDate': debugDate
                })
                val += step

        result = {}
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'interval': interval
        }
        result['potential'] = {'points': potentialPoints}
        result['served'] = {'points': servedPoints}
        result['total'] = {'points': totalPoints}
        return result
Esempio n. 20
0
 def point(value, unit):
     debugDate = utils.formatUtcTimeAsIsoLocalTime(unit.unitTime)
     return {'value': value, 'date': unit.unitTime, 'debugDate': debugDate }
Esempio n. 21
0
    def reportOverTimeL2BW(self, startTime, endTime, interval, intervalUnit,
                           aggregationType):

        totalPoints = []
        videoPoints = []
        videoServedPoints = []

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            videoPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            videoServedPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            totalPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
        else:
            factor = 5e9
            layer2Overhead = 1.2

            k = 1
            count_ = 1.0 * (endTime - startTime) / interval
            step = 0.5 * factor / count_
            val = 0.5 * factor * layer2Overhead

            for entryDate in range(startTime, endTime, interval):
                if aggregationType == "max":
                    # we will generate some offset to simulate peak time values
                    # offset is in round minutes
                    offset = (entryDate / 24 / 3600 *
                              60) % 3600 + 18 * 3600 + time.timezone
                    date = entryDate + offset
                    calcInterval = 60
                else:
                    date = entryDate
                    calcInterval = interval
                debugDate = utils.formatUtcTimeAsIsoLocalTime(date)
                # add some 24 hours distribution
                # Consider it is sin^2 (no use at night max use at day time)
                radF = math.pi / 24. / 60. / 60.  # convert seconds to radians
                # Integrate over distribution and normalize to get result at any value of interval parameter
                dist24 = 0.5 - (
                    math.sin(2. * (date + calcInterval) * radF) -
                    math.sin(2 * (date) * radF)) / calcInterval / radF / 4.

                videoServedPoints.append({
                    'date': date * k,
                    'value': int(dist24 * val * .4),
                    'debugDate': debugDate
                })
                videoPoints.append({
                    'date': date * k,
                    'value': int(dist24 * val * .6),
                    'debugDate': debugDate
                })
                totalPoints.append({
                    'date': date * k,
                    'value': int(dist24 * val * 2.0 + val * .2),
                    'debugDate': debugDate
                })
                val += step

        result = {}
        result['debug'] = {
            'from': utils.formatUtcTimeAsIsoLocalTime(startTime),
            'to': utils.formatUtcTimeAsIsoLocalTime(endTime),
            'interval': interval
        }
        result['videoServed'] = {'points': videoServedPoints}
        result['video'] = {'points': videoPoints}
        result['total'] = {'points': totalPoints}
        return result
Esempio n. 22
0
    def reportOverTimeL2BW(self, startTime, endTime, interval, intervalUnit,
                           aggregationType):
        self.apiLogger.debug(
            "startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s" %
            (startTime, endTime, interval, intervalUnit, ux_module.L2_BW))

        result = {}
        videoServedPoints = []
        videoPoints = []
        totalPoints = []

        if startTime == 0 and endTime == 0 and interval == 0:
            oldestTime = self.getOldestDataTime()
            debugDate = utils.formatUtcTimeAsIsoLocalTime(oldestTime)
            videoServedPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            videoPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
            totalPoints.append({
                'date': oldestTime,
                'value': 0,
                'debugDate': debugDate
            })
        else:
            if intervalUnit == 'month':
                uInterval = ux_module.MONTH
            else:
                # assume that in all other cases it is seconds
                uInterval = 's'

            self.apiLogger.debug(
                "startTime=%s endTime=%s interval=%s uInterval=%s dataType=%s"
                % (startTime, endTime, interval, uInterval, ux_module.L2_BW))

            responder = ux_module.ReportsProcessor(self.topperReportsDir,
                                                   self.uxParameters,
                                                   self.topperLogger)
            data = responder.l2BWOverTime(startTime, endTime, interval,
                                          uInterval, aggregationType)
            for entry in data:
                entryDate = entry['date']
                debugDate = utils.formatUtcTimeAsIsoLocalTime(entryDate)
                videoServedPoints.append({
                    'date':
                    entryDate,
                    'value':
                    entry[ux_module.VIDEO_DELIVERED],
                    'debugDate1':
                    debugDate
                })
                videoPoints.append({
                    'date': entryDate,
                    'value': entry[ux_module.VIDEO],
                    'debugDate1': debugDate
                })
                totalPoints.append({
                    'date': entryDate,
                    'value': entry[ux_module.TOTAL],
                    'debugDate1': debugDate
                })

        result['videoServed'] = {'points': videoServedPoints}
        result['video'] = {'points': videoPoints}
        result['total'] = {'points': totalPoints}
        return result