Exemplo n.º 1
0
  def process (self, cursor=None):

    if cursor:
        cursor = Cursor(urlsafe=cursor)

    total_clicks = 0
    total_opens = 0
    
    self.temp_clicks = {}
    self.temp_opens = {}
    if cursor == None: #skip all cursor continuations, these values are already init'd
      self.tags = {}
      self.urls = {}
      self.clients = {}
      self.clicks = []
      self.opens = []
      self.total_sends = 0
      self.total_clicks = 0
      self.total_opens = 0

      from bulkmail.api.models import Campaign
      c = Campaign.query(Campaign.campaign_id == self.campaign_id, Campaign.list_id == self.list_id).get()
      
      for key in c.send_data:
        sd = key.get()
        self.total_sends += len(sd.data)

    tracks, cursor, more = Track.query(
        Track.list_id == self.list_id,
        Track.campaign_id == self.campaign_id,
        ndb.OR(Track.ttype == 'click', Track.ttype == 'open')
      ).order(Track._key).fetch_page(100, start_cursor=cursor)

    for t in tracks:
      self.process_track(t)
      if t.ttype == 'click':
        total_clicks += 1
      elif t.ttype == 'open':
        total_opens += 1

    #set total_clicks/total_opens
    self.total_clicks = self.total_clicks + total_clicks
    self.total_opens = self.total_opens + total_opens
    #set clicks/opens
    self.sort_data('clicks')
    self.sort_data('opens')

    self.put()

    if more and cursor:
      taskqueue.add(
        url='/api/compile-stats',
        params={
          'list_id': self.list_id,
          'campaign_id': self.campaign_id,
          'key': self.key.urlsafe(),
          'cursor': cursor.urlsafe()
        },
        queue_name='stats'
      )
Exemplo n.º 2
0
 def process (self, ptype):
   ttype = ptype[:-1]
   
   cursor = None
   total = 0
   
   self.temp = {}
   if ptype == 'clicks':
     self.tags = {}
     self.urls = {}
     
   if ptype == 'opens':
     self.clients = {}
     self.total_sends = 0
     
     from bulkmail.api.models import Campaign
     c = Campaign.query(Campaign.campaign_id == self.campaign_id, Campaign.list_id == self.list_id).get()
     
     for key in c.send_data:
       sd = key.get()
       self.total_sends += len(sd.data)
       
   while 1:
     tracks, cursor, more = Track.query(
       Track.list_id == self.list_id,
       Track.campaign_id == self.campaign_id,
       Track.ttype == ttype,
     ).fetch_page(100, start_cursor=cursor)
     
     for t in tracks:
       self.process_track(t, ptype)
       total += 1
       
     if more and cursor:
       continue
       
     else:
       break
       
   setattr(self, 'total_' + ptype, total)
   self.sort_data(ptype)