Exemple #1
0
def receiveImage(request, idclient):
    logger.info(">>receive image idcliente: " + str(idclient))
    try:
        lastRecordId = Record.objects.latest('idRecord').idRecord + 1
    except Record.DoesNotExist:
        lastRecordId = 1
    logger.info(">>future lastRecordId: " + str(lastRecordId))

    directoryByClient = os.path.join(
        Path().absolute(),
        "opencv-face-recognition/dataset/records/" + str(idclient))

    if not os.path.exists(directoryByClient):
        os.makedirs(directoryByClient)

    feikPath = directoryByClient + "/record_" + str(lastRecordId) + "_feik.jpg"
    truePath = directoryByClient + "/record_" + str(lastRecordId) + ".jpg"

    #pathForeingImage = directoryByClient+"/record_"+str(lastRecordId)+".jpg"
    response = bytesToImage(request, feikPath)
    if response is 'ERROR':
        logger.info(">>ERROR UPLOAD IMAGEN FROM ARDUINO")
        return HttpResponse("<h1>ERROR</h1>")

    img_rt_90 = rotate_img(feikPath, -90)
    img_rt_90.save(truePath)
    os.remove(feikPath)

    personRecognition = proccessRecognition(truePath, idclient)
    logger.info("person: " + personRecognition.name)
    logger.info("percent: " + str(personRecognition.percent))
    if personRecognition.name is 'unknown':
        myFamily = Family(familyName="Desconocido", relationship="Desconocido")
    else:
        try:
            myFamily = Family.objects.get(familyName=personRecognition.name)
        except Family.DoesNotExist:
            myFamily = Family(familyName=personRecognition.name,
                              relationship="Desconocido")

    #user = User.objects.get(id=idclient)
    user = CustomUser.objects.get(id=idclient)

    arrayPath = truePath.split("/", 2)
    photoPath = arrayPath[2]

    myRecord = Record(familyName=personRecognition.name,
                      relationship=myFamily.relationship,
                      percent=str(personRecognition.percent),
                      recordPhotoPath=photoPath,
                      idClient=user)
    myRecord.save()
    logger.info(">>id record: " + str(myRecord.idRecord))
    fcm_send_topic_message(topic_name='my-event',
                           message_body='la persona ' + myRecord.familyName +
                           ' ingreso a tu hogar a las ' +
                           myRecord.dateRecord.strftime("%Y-%m-%d %H:%M:%S"),
                           message_title='Mensaje Arduino')

    return HttpResponse("<h1>OK</h1>")
Exemple #2
0
def createFacilDetection(idClient, familyName, images, idFamily):
    listPhotos = createDataset(idClient, familyName, images)
    if len(listPhotos) > 0:
        result = createUnknowFolder(idClient)
        if result != 0:
            result = extract_embeddings(idClient, familyName, result)
            logger.info(">>extract_embeddings OK")
            logger.info(">>>>>>>>>>> value result: " +
                        ("Si!!!" if result else "No!!!"))
            if result:
                result = train_Model(idClient)
                if result:
                    logger.info(">>train_Model OK")
                    Family.objects.filter(pk=idFamily).update(
                        familyPhotos=','.join(listPhotos))
                    fcm_send_topic_message(
                        topic_name='my-event',
                        message_body='El usuario ' + familyName +
                        " fue creado exitosamente, verifique el modulo de pruebas si desea comprobarlo",
                        message_title='Usuario Creado')
                    return

    fcm_send_topic_message(
        topic_name='my-event',
        message_body=
        'verifique la informacion subida, o comuniquese con el proveedor',
        message_title='Error en la creacion')
    return
Exemple #3
0
def sendNot(request):
    fcm_send_topic_message(
        topic_name='my-event',
        message_body='un objeto se encuentra cerca de la puerta',
        message_title='Mensaje arduino')

    return HttpResponse("<h1>Ok</h1>")
Exemple #4
0
    def send_notification(silo_name, level, topic):
        title = silo_name
        body = f"The level is below {level}%"
        notification = Notification(title=title, body=body)
        notification.save()

        fcm_send_topic_message(topic_name=topic, sound='default', message_body=body, message_title=title,
                               data_message={"body": body, "title": title})
Exemple #5
0
 def perform_create(self, serializer):
     serializer.save(date=str(datetime.now()))
     fcm_send_topic_message(
         topic_name='chat',
         message_body='Hey! There is a new message in the chat for you',
         message_title='New message!',
         data_message={
             "type": "chat",
             "user": self.request.user.id
         })
def notifyResidents(request, topic_name):

    k = fcm_send_topic_message(
        topic_name=topic_name,
        message_body='The vehicle has arrived in your area',
        message_title=topic_name)
    return JsonResponse(list(k))
Exemple #7
0
 def perform_create(self, serializer):
     fcm_send_topic_message(topic_name=self.request.query_params['city'],
                            message_body='Hello',
                            message_title='There is new data about ' +
                            self.request.query_params['city'])
Exemple #8
0
def report_only_after_deal_created(sender, instance, created, **kwargs):
    if created:
        fcm_send_topic_message(topic_name='new_infections',
                               data_message={"signature": instance.signature})