Exemplo n.º 1
0
def send_report(org, rangestart):
    hearts = Heart.all().ancestor(org.key()).filter('title !=', '').count()
    oldflatlines = Flatline.all().filter("start >", rangestart).order("-start").fetch(2000)
    oldflatlinesactive = Flatline.all().filter("end >", rangestart).order("-end").fetch(2000)
    oldflatlines = list(set(oldflatlines) | set(oldflatlinesactive)) 
    alltime = hearts*24*60*60*7 if hearts > 0 else 1
    downtime = sum(map(lambda x: x.seconds, map(lambda x: (x.end if x.end is not None else datetime.utcnow()) - (x.start if x.start < rangestart else rangestart),oldflatlines)))
    availablility = 1 - float(downtime)/alltime;
   
    message = mail.EmailMessage(sender="*****@*****.**",
                                subject=org.title + " weekly report")

    message.to = map(lambda user: user, org.users)
    message.body = """
    Here is the weekly report of how your hearts are doing.

    Availablility: """+str(availablility)+"""
    Downtime: """+str(downtime)+""" seconds
    Flatlines: """+str(len(oldflatlines))+"""

    Details for 7 days backwards can be found here:
    https://heartrate-monitor.appspot.com/app/organizations/"""+str(org.key().id())+"""/report

    Check out the current state of your hearts at:
    https://heartrate-monitor.appspot.com/app/organizations/"""+str(org.key().id())+"""

    Kind regards
    https://heartrate-monitor.appspot.com/app/
    """

    try:
        message.send()
    except:
        print 'failed to send mail'
        pass
Exemplo n.º 2
0
 def get(self):
     id = int(self.request.url.rsplit('/', 3)[1])
     org = Organization.get_by_id(id)
     key = self.request.url.rsplit('/', 1)[1]
     heart = Heart.get_by_key_name(key, parent=org)
     flatlines = Flatline.all().ancestor(heart).order("-start").fetch(10)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps({'title': heart.title or heart.key().id_or_name(), 'time_zone': heart.time_zone, 'cron': heart.cron, 'threshold': heart.threshold, 'last_pulse': str(heart.last_pulse), 'flatlines': map(lambda f: {'start': str(f.start), 'end': str(f.end), 'active': str(f.active)}, flatlines)}))
Exemplo n.º 3
0
 def get(self):
  id = int(self.request.url.rsplit('/', 2)[1])
  org = Organization.get_by_id(id)
  rangestart = datetime.utcnow() - timedelta(days=7)
  hearts = Heart.all().ancestor(org.key()).filter('title !=', '').count()
  oldflatlines = Flatline.all().filter("start >", rangestart).order("-start").fetch(2000)
  oldflatlinesactive = Flatline.all().filter("end >", rangestart).order("-end").fetch(2000)
  oldflatlines = list(set(oldflatlines) | set(oldflatlinesactive))
  alltime = hearts*24*60*60*7 if hearts > 0 else 1
  downtime = sum(map(lambda x: x.seconds, map(lambda x: (x.end if x.end is not None else datetime.utcnow()) - (x.start if x.start < rangestart else rangestart),oldflatlines)))
  self.response.headers['Content-Type'] = 'application/json'
  self.response.out.write(json.dumps({
      'organization': indextransform( org ),
      'flatlines': map(flatlinetransform, oldflatlines),
      'availablility' : 1 - float(downtime)/alltime,
      'downtime' : downtime,
      'hearts': hearts
  }))
Exemplo n.º 4
0
 def delete(self):
     id = int(self.request.url.rsplit('/', 3)[1])
     org = Organization.get_by_id(id)
     key = self.request.url.rsplit('/', 1)[1]
     heart = Heart.get_by_key_name(key, parent=org)
     flatlines = Flatline.all(keys_only=True).ancestor(heart).order("-start")
     heart.delete()
     for f in flatlines:
         db.delete(f)
Exemplo n.º 5
0
 def get(self):
     id = int(self.request.url.rsplit('/', 1)[1])
     org = Organization.get_by_id(id)
     newhearts = Heart.all().ancestor(org.key()).filter('title =', '').fetch(2000)
     flatlines = Flatline.all().filter("active =", True).fetch(2000)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps({
         'newhearts': map(indextransform, newhearts),
         'flatlines': map(flatlinetransform, flatlines),
     }))
Exemplo n.º 6
0
 def get(self):
     id = int(self.request.url.rsplit('/', 1)[1])
     org = Organization.get_by_id(id)
     newhearts = Heart.all().ancestor(org.key()).filter('title =',
                                                        '').fetch(2000)
     flatlines = Flatline.all().filter("active =", True).fetch(2000)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(
         json.dumps({
             'newhearts': map(indextransform, newhearts),
             'flatlines': map(flatlinetransform, flatlines),
         }))
Exemplo n.º 7
0
 def get(self):
     org_id = self.request.url.rsplit('/', 1)[1]
     if not org_id.isdigit():
         self.abort(404)
     org = Organization.get_by_id(int(org_id))
     if org is None:
         self.abort(404)
     newhearts = Heart.all().ancestor(org.key()).filter('title =', '').fetch(2000)
     maintenancehearts = Heart.all().ancestor(org.key()).filter('maintenance_day !=', None).order('-maintenance_day').fetch(2000)
     flatlines = Flatline.all().filter("active =", True).fetch(2000)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps({
         'title': org.title,
         'newhearts': map(indextransform, newhearts),
         'flatlines': map(flatlinetransform, flatlines),
         'maintenancehearts': map(heartlisttransform, maintenancehearts),
         'users': org.users,
         'alert_email' : org.alert_email,
     }))
Exemplo n.º 8
0
    def get(self):
        id = int(self.request.url.rsplit('/', 3)[1])
        org = Organization.get_by_id(id)
        key = self.request.url.rsplit('/', 1)[1]
        
        heart = Heart.get_by_key_name(key, parent=org)
        flatlines = Flatline.all().ancestor(heart).order("-active").order("-start").order("-end").fetch(10)

        response = {'organization': indextransform(org),
                    'title': heart.title or heart.key().id_or_name(), 
                    'time_zone': heart.time_zone, 
                    'cron': heart.cron, 
                    'threshold': heart.threshold, 
                    'last_pulse': str(heart.last_pulse or ''), 
                    'maintenance_day': str(heart.maintenance_day or ''), 
                    'flatlines': map(flatlinetransform, flatlines),
                    'calculated_flatline': str(heart.calculate_next_flatline() or '')
                    }

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(response))