def __init__(self, date=None, timespan=None, level=None, pk=None): self.calendar = calendar_utils.calendar_iterators() self.level = level self.pk = pk self.timespan = timespan if timespan == 'day': self.start, self.end = self.calendar.daystartend(strdate=date) elif timespan == 'week': self.start, self.end = self.calendar.weekstartend(strdate=date) elif timespan == 'month': self.start, self.end = self.calendar.monthstartend(strdate=date) elif timespan == 'recent': self.start, self.end = self.calendar.lastmonthstartend() else: self.start = None self.end = None if level == 'post': self.verified, self.non_human, self.neutralized, self.detected = FetchData.get_data_post( self.start, self.end, self.pk) elif level == 'morcha': self.verified, self.non_human, self.neutralized, self.detected = FetchData.get_data_morcha( self.start, self.end, self.pk) elif level == 'battalion': self.verified, self.non_human, self.neutralized, self.detected = FetchData.get_data_battalion( self.start, self.end, self.pk) else: pass
def insert(request): morcha_instance = models.Morcha.objects.get(name='morcha3') post_instance = models.Post.objects.get(name=morcha_instance.post) print post_instance obj = calendar_utils.calendar_iterators() counter = 1 # date = datetime.datetime(2017, 1, 2).replace(tzinfo=pytz.UTC) for date in obj.lastmonthiterator('2017-02-01'): print date.tzinfo data = models.Intrusion() data.morcha = morcha_instance data.post = post_instance data.detected_datetime = date newdate = date + datetime.timedelta(hours=2, minutes=10) data.verified_datetime = newdate if (counter < 6): data.non_human_intrusion_datetime = newdate if (counter == 10 or counter == 15): data.neutralized_datetime = newdate + datetime.timedelta(days=1) elif (counter == 11): pass else: data.neutralized_datetime = newdate + datetime.timedelta( hours=2, minutes=10) data.duration = 2000.0 data.save() counter += 1
def __init__(self, date=None, timespan=None, level=None, pk=None): self.calendar = calendar_utils.calendar_iterators() self.level = level self.pk = pk self.timespan = timespan if timespan == 'day': self.start, self.end = self.calendar.daystartend(strdate=date) elif timespan == 'week': self.start, self.end = self.calendar.weekstartend(strdate=date) elif timespan == 'month': self.start, self.end = self.calendar.monthstartend(strdate=date) else: self.start, self.end = self.calendar.lastmonthstartend() if level == 'post': self.weaksignal, self.offline, self.backup = FetchData.get_data_post( self.start, self.end, self.pk) elif level == 'morcha': self.weaksignal, self.offline, self.backup = FetchData.get_data_morcha( self.start, self.end, self.pk) elif level == 'battalion': self.weaksignal, self.offline, self.backup = FetchData.get_data_battalion( self.start, self.end, self.pk) else: pass
def retrieve(self, request): self.calendar = calendar_utils.calendar_iterators() start, end = self.calendar.lastmonthstartend() battalions = models.Battalion.objects.all() obj = {} for battalion in battalions: data = {} data['battalion_name'] = battalion.name posts = battalion.posts.all() data['post_count'] = posts.count() morcha_count = 0 for post in posts: morcha_count += post.morchas.count() data['morcha_count'] = morcha_count pk = battalion.uuid data['intrusions'] = models.Intrusion.objects.filter( morcha__post__battalion=pk).count() obj[str(pk)] = data return Response(obj)