def Layout(self, request, response): """Filter the last week of flows.""" try: # TODO(user): Replace with Duration(). now = int(rdfvalue.RDFDatetime().Now()) week_duration = 7 * 24 * 60 * 60 * 1000000 fd = aff4.FACTORY.Open("aff4:/audit/log", aff4_type="VersionedCollection", token=request.token) self.client_activity = {} for week in range(self.WEEKS): start = now - week * week_duration for event in fd.GenerateItems(timestamp=(start, start + week_duration)): self.weekly_activity = self.client_activity.setdefault( event.client, [[x, 0] for x in range(-self.WEEKS, 0, 1)]) self.weekly_activity[-week][1] += 1 self.data = [] for client, data in self.client_activity.items(): if client: self.data.append(dict(label=str(client), data=data)) self.data = renderers.JsonDumpForScriptContext(self.data) except IOError: pass return super(ClientActivity, self).Layout(request, response)
def _HistogramToJSON(self, histogram): hist_data = [(b.range_max_value, b.num) for b in histogram.bins] return renderers.JsonDumpForScriptContext(hist_data)