Beispiel #1
0
 def __init__(self, entkey, rkey):
     super(AlarmReportWorker, self).__init__(rkey,
                                             start_att="dt_start",
                                             start_att_direction="")
     self.enterprise = self.report.enterprise
     self.FILTERS = [("enterprise =", self.enterprise)]
     specs = self.report.getSpecs()
     start = specs.get("start", 0)
     end = specs.get("end", 0)
     if start:
         self.FILTERS.append(("dt_start >=", tools.dt_from_ts(start)))
     if end:
         self.FILTERS.append(("dt_start <", tools.dt_from_ts(end)))
     self.report.generate_title("Alarm Report", ts_start=start, ts_end=end)
     self.sensor_lookup = tools.lookupDict(
         Sensor,
         self.enterprise.sensor_set.fetch(limit=200),
         valueTransform=lambda s: s.name,
         keyprop="key_name")
     self.rule_lookup = tools.lookupDict(
         Rule, self.enterprise.rule_set.fetch(limit=100))
     self.headers = [
         "Alarm ID", "Sensor ID", "Sensor", "Rule ID", "Rule", "Apex",
         "Start", "End"
     ]
Beispiel #2
0
 def __init__(self, entkey, rkey):
     super(AlarmReportWorker, self).__init__(rkey, start_att="dt_start", start_att_direction="-")
     self.enterprise = self.report.enterprise
     self.FILTERS = [("enterprise =", self.enterprise)]
     self.report.title = "Alarm Report [ %s ]" % (self.enterprise)
     # specs = self.report.getSpecs()
     # ts_start = specs.get("ts_start", 0)
     # ts_end = specs.get("ts_end", 0)
     # if ts_start:
     #     self.FILTERS.append(("dt_start >=", tools.dt_from_ts(ts_start)))
     # if ts_end:
     #     self.FILTERS.append(("dt_start <", tools.dt_from_ts(ts_end)))
     self.sensor_lookup = tools.lookupDict(Sensor, self.enterprise.sensor_set.fetch(limit=100))
     self.rule_lookup = tools.lookupDict(Rule, self.enterprise.rule_set.fetch(limit=100))
     self.headers = ["Sensor","Rule","Apex","Start","End"]
Beispiel #3
0
 def __init__(self, entkey, rkey):
     super(AlarmReportWorker, self).__init__(rkey, start_att="dt_start", start_att_direction="-")
     self.enterprise = self.report.enterprise
     self.FILTERS = [("enterprise =", self.enterprise)]
     specs = self.report.getSpecs()
     start = specs.get("start", 0)
     end = specs.get("end", 0)
     if start:
         self.FILTERS.append(("dt_start >=", tools.dt_from_ts(start)))
     if end:
         self.FILTERS.append(("dt_start <", tools.dt_from_ts(end)))
     self.report.generate_title("Alarm Report", ts_start=start, ts_end=end)
     self.sensor_lookup = tools.lookupDict(Sensor, self.enterprise.sensor_set.fetch(limit=200), valueTransform=lambda s : s.name)
     self.rule_lookup = tools.lookupDict(Rule, self.enterprise.rule_set.fetch(limit=100))
     self.headers = ["Sensor","Rule","Apex","Start","End"]
Beispiel #4
0
 def __init__(self, entkey, rkey):
     super(AnalysisReportWorker, self).__init__(rkey,
                                                start_att="dt_created",
                                                start_att_direction="")
     self.enterprise = self.report.enterprise
     self.FILTERS = [("enterprise =", self.enterprise)]
     specs = self.report.getSpecs()
     start = specs.get("start", 0)
     end = specs.get("end", 0)
     self.columns = specs.get('columns', [])
     if isinstance(self.columns, basestring):
         self.columns = self.columns.split(',')
     sensortype_id = specs.get("sensortype_id")
     self.report.generate_title("Analysis Report",
                                ts_start=start,
                                ts_end=end,
                                sensortype_id=sensortype_id)
     if start:
         self.FILTERS.append(("dt_created >=", tools.dt_from_ts(start)))
     if end:
         self.FILTERS.append(("dt_created <", tools.dt_from_ts(end)))
     if sensortype_id:
         self.FILTERS.append(("sensortype =",
                              db.Key.from_path('Enterprise',
                                               self.enterprise.key().id(),
                                               'SensorType',
                                               int(sensortype_id))))
     self.sensor_lookup = tools.lookupDict(
         Sensor,
         self.enterprise.sensor_set.fetch(limit=200),
         valueTransform=lambda s: s.name)
     self.headers = ["Key", "Sensor", "Created", "Updated"] + self.columns
Beispiel #5
0
 def testLookupDicts(self):
     user1 = User.Create(email="*****@*****.**", name="Person 1")
     user1.put()
     user2 = User.Create(email="*****@*****.**", name="Person 2")
     user2.put()
     lookup = tools.lookupDict([user1, user2], keyprop="key_string")
     u1_key = user1.key.urlsafe()
     u2_key = user2.key.urlsafe()
     self.assertTrue(u1_key in lookup)
     self.assertTrue(u2_key in lookup)
     self.assertEqual(lookup.get(u1_key).name, "Person 1")
 def testLookupDicts(self):
     user1 = User.Create(email="*****@*****.**", name="Person 1")
     user1.put()
     user2 = User.Create(email="*****@*****.**", name="Person 2")
     user2.put()
     lookup = tools.lookupDict([user1, user2], keyprop="key_string")
     u1_key = user1.key.urlsafe()
     u2_key = user2.key.urlsafe()
     self.assertTrue(u1_key in lookup)
     self.assertTrue(u2_key in lookup)
     self.assertEqual(lookup.get(u1_key).name, "Person 1")
Beispiel #7
0
 def range(self, d):
     '''
     Return recent days of all active habits
     '''
     start = self.request.get('start_date')
     end = self.request.get('end_date')
     habits = Habit.Active(self.user)
     habitdays = HabitDay.Range(self.user, habits, tools.fromISODate(start), until_date=tools.fromISODate(end))
     self.set_response({
         'habits': [habit.json() for habit in habits],
         'habitdays': tools.lookupDict(habitdays,
                 keyprop="key_id",
                 valueTransform=lambda hd: hd.json())
     }, success=True)
Beispiel #8
0
 def recent(self, d):
     '''
     Return recent days of all active habits
     '''
     self.success = True
     days = self.request.get_range('days', default=5)
     habits = Habit.Active(self.user)
     start_date = datetime.today() - timedelta(days=days)
     habitdays = HabitDay.Range(self.user, habits, start_date)
     self.set_response({
         'habits': [habit.json() for habit in habits],
         'habitdays': tools.lookupDict(habitdays,
                 keyprop="key_id",
                 valueTransform=lambda hd: hd.json())
     })
Beispiel #9
0
 def __init__(self, entkey, rkey):
     super(AnalysisReportWorker, self).__init__(rkey, start_att="dt_created", start_att_direction="-")
     self.enterprise = self.report.enterprise
     self.FILTERS = [("enterprise =", self.enterprise)]
     specs = self.report.getSpecs()
     start = specs.get("start", 0)
     end = specs.get("end", 0)
     self.columns = specs.get("columns", "").split(",")
     sensortype_id = specs.get("sensortype_id")
     self.report.generate_title("Analysis Report", ts_start=start, ts_end=end, sensortype_id=sensortype_id)
     if start:
         self.FILTERS.append(("dt_created >=", tools.dt_from_ts(start)))
     if end:
         self.FILTERS.append(("dt_created <", tools.dt_from_ts(end)))
     if sensortype_id:
         self.FILTERS.append(("sensortype =", db.Key.from_path('Enterprise', self.enterprise.key().id(), 'SensorType', int(sensortype_id))))
     self.sensor_lookup = tools.lookupDict(Sensor, self.enterprise.sensor_set.fetch(limit=200), valueTransform=lambda s : s.name)
     self.headers = ["Key","Sensor","Created","Updated"] + self.columns
Beispiel #10
0
 def get(self, d):
     # TODO: Async fetches
     with_habits = self.request.get_range('with_habits', default=0) == 1
     with_tracking = self.request.get_range('with_tracking', default=1) == 1
     with_goals = self.request.get_range('with_goals', default=1) == 1
     with_tasks = self.request.get_range('with_tasks', default=1) == 1
     date_start = self.request.get('date_start')
     date_end = self.request.get('date_end')
     dt_start, dt_end = tools.fromISODate(date_start), tools.fromISODate(
         date_end)
     iso_dates = []
     habits = []
     today = datetime.today()
     habitdays = []
     goals = []
     journals, iso_dates = MiniJournal.Fetch(self.user, dt_start, dt_end)
     if with_habits:
         habits = Habit.Active(self.user)
         habitdays = HabitDay.Range(self.user, habits, dt_start, dt_end)
     if with_tracking:
         tracking_days = TrackingDay.Range(self.user, dt_start, dt_end)
     if with_goals:
         goals = Goal.Year(self.user, today.year)
     if with_tasks:
         tasks = Task.DueInRange(self.user, dt_start, dt_end, limit=100)
     self.set_response(
         {
             'dates':
             iso_dates,
             'journals': [j.json() for j in journals if j],
             'habits': [h.json() for h in habits],
             'goals': [g.json() for g in goals],
             'tasks': [t.json() for t in tasks],
             'tracking_days': [p.json() for p in tracking_days],
             'habitdays':
             tools.lookupDict(habitdays,
                              keyprop="key_id",
                              valueTransform=lambda hd: hd.json())
         },
         success=True)
Beispiel #11
0
 def _maybe_get_habits(self):
     if self.habits is None:
         self.habits = tools.lookupDict(Habit.Active(self.user), "key_id")
 def _maybe_get_habits(self):
     if self.habits is None:
         self.habits = tools.lookupDict(Habit.Active(self.user), "key_id")