def test_enabled_status(self): alarm_wrong_status = Alarm(enabled='feraok', beamy=beamy) alarm_false_status = Alarm(enabled="false", beamy=beamy) alarm_true_status = Alarm(enabled="true", beamy=beamy) self.assertEqual( (alarm_wrong_status.is_valid(), alarm_false_status.is_valid(), alarm_true_status.is_valid()), (False, True, True))
def test_running_status(self): alarm_wrong_running_status = Alarm(running="feroj", beamy=beamy) alarm_false_running_status = Alarm(running="false", beamy=beamy) alarm_true_running_status = Alarm(running="true", beamy=beamy) self.assertEqual((alarm_wrong_running_status.is_valid(), alarm_false_running_status.is_valid(), alarm_true_running_status.is_valid()), (False, True, True))
def check_and_save(request, alarm_time): ip = get_client_ip(request) current_alarm = None for alarm in Alarm.objects.all(): if ip == alarm.ip_address: current_alarm = alarm break if current_alarm == None: current_alarm = Alarm(alarm_time=alarm_time, ip_address=ip) else: current_alarm.alarm_time = alarm_time current_alarm.save()
def _create_alarm(self): for a in alarms: try: Alarm.objects.get(beamy=Beamy.objects.get(name=a['beamy']), day=a['day'], hour=a['hour']) except: b = Beamy.objects.get(name=a['beamy']) alarm = Alarm(name=a['name'], beamy=b, day=a['day'], hour=a['hour'], minute=a['minute'], enabled=a['enabled']) alarm.save()
def analyze_image(imgpath, username): """Detect people on image.""" pid = os.getpid() logger.info('Pid %s >>> Going to run detector on %s', pid, imgpath.name) predicted = run_detector(imgpath.as_posix()) logger.info( 'Pid %s >>> Detector finished on %s, it tooks %s', pid, imgpath.name, predicted['ptime'] ) if predicted['person_detected']: logger.info( 'Person detected on %s, prediction saved on %s, detected %s', imgpath.name, str(predicted['saved']), predicted['labels'] ) alarm = Alarm.get_by_username(username) alarm_image = AlarmImage(alarm=alarm, image=str(predicted['saved'])) alarm_image.save() channel_layer.send('messenger.telegram', { 'text': 'Persona detectada.', 'username': username, 'filepath': str(predicted['saved']), }) onesignal.send_message(alarm.owner, 'Persona detectada', 'Tero',data={"action": "updateImages"} big_picture="%s%s" % (settings.DOMAIN, alarm_image.image.url)) logger.info("Pid %s >>> Saved image on DB. Alarm id %s", pid, alarm_image.id)
def handle_image(payload): """Handle images.""" encoded_image = payload['encoded_image'] filetype = payload['filetype'] username = payload['username'] sender = payload['sender'] LOGGER.debug('Received image from %s', sender) if Alarm.is_active_for(username): Alarm.notify( event_type=events.MOTION_DETECTED, sender=sender, username=username, filetype=filetype, encoded_image=encoded_image, )
def handle_image(payload): """Handle images.""" image64 = payload['encoded_image'] # image encoded in base64 filetype = payload['filetype'] username = payload['username'] sender = payload['sender'] logger.debug('Received image from %s', sender) alarm = Alarm.get_by_username(username) if alarm.active: Alarm.notify( Event=events.MotionDetected, alarm=alarm, sender=sender, username=username, filetype=filetype, image64=image64, )
def analyze_image(imgpath, username): """Detect people on image.""" pid = os.getpid() logger.info('Pid %s >>> Going to run detector on %s', pid, imgpath.name) predicted = run_detector(imgpath.as_posix()) logger.info('Pid %s >>> Detector finished on %s, it tooks %s', pid, imgpath.name, predicted['ptime']) if predicted['person_detected']: logger.info( 'Person detected on %s, prediction saved on %s, detected %s', imgpath.name, str(predicted['saved']), predicted['labels']) alarm = Alarm.get_by_username(username) alarm_image = AlarmImage(alarm=alarm, image=str(predicted['saved'])) alarm_image.save() channel_layer.send( 'messenger.telegram', { 'text': 'Persona detectada.', 'username': username, 'filepath': str(predicted['saved']), }) logger.info("Pid %s >>> Saved image on DB. Alarm id %s", pid, alarm_image.id)
def form_valid(self, form): user = form.save() Alarm.create(user.username, form.cleaned_data['password1']) return super(Register, self).form_valid(form)
def test_default(self): alarm_default = Alarm() # Default alarm self.assertEqual(alarm_default.is_valid(), True)
def test_minute(self): alarm_wrong_minutes = Alarm(minute=61, beamy=beamy) self.assertEqual(alarm_wrong_minutes.is_valid(), False)
def test_hour(self): alarm_wrong_hour = Alarm(hour=25, beamy=beamy) self.assertEqual(alarm_wrong_hour.is_valid(), False)
def test_name(self): alarm_wrong_name = Alarm(name=432890, beamy=beamy) self.assertEqual(alarm_wrong_name.is_valid(), True)
def test_days_format(self): alarm_days = Alarm(day="lundi") self.assertEqual(alarm_days.is_valid(), False)