Esta aplicación Flask proporciona un conjunto de rutas para sincronizar datos con una tabla de base de datos llamada "ambulancias" en la cual se guardan datos de un monitor de signos vitales que reporta cada segundo.
-
/sincronizar_datos
: Esta ruta recupera el registro más reciente con unestado
de 0 de la tabla "ambulancias" y lo devuelve como un objeto JSON. -
/actualizar_datos_sincronizados/<id>
: Esta ruta actualiza elestado
del registro con elid
especificado en la tabla "ambulancias" a 1. -
/sincronizar_datos_faltantes/<dispositivo_id>
: Esta ruta recupera todos los registros con unestado
de 0 y unid
que coincida con eldispositivo_id
especificado de la tabla "ambulancias" y los devuelve como una lista de objetos JSON. -
/sincronizar_datos_masivos/<dispositivo_id>
: Esta ruta actualiza elestado
de todos los registros con unid
que coincida con eldispositivo_id
especificado en la tabla "ambulancias" a 1. -
/eliminar_registros/<dispositivo_id>
: Esta ruta elimina todos los registros con unid
que coincida con eldispositivo_id
especificado y unestado
de 1 de la tabla "ambulancias".
Para ejecutar esta aplicación, deberás instalar los paquetes necesarios y configurar una base de datos MySQL.
- Instala los paquetes necesarios:
pip install flask mysql-connector-python
- Configura una base de datos MySQL y una tabla con la siguiente estructura:
CREATE TABLE ambulancias (
_id INT AUTO_INCREMENT PRIMARY KEY,
ip VARCHAR(15) NOT NULL,
id VARCHAR(50) NOT NULL,
msg VARCHAR(250) NOT NULL,
time DATETIME NOT NULL,
estado INT NOT NULL
);
-
Actualiza la variable
mydb
en el código con los detalles de conexión a MySQL. -
Ejecuta la aplicación:
python nombre_archivo.py
Para utilizar las rutas de esta aplicación de Flask, envía solicitudes HTTP a los puntos finales especificados utilizando el método apropiado (GET, PUT, DELETE). La respuesta será un objeto JSON o una matriz que contenga los datos devueltos por la ruta.
Esta aplicación está licenciada bajo la Licencia MIT. Consulta el archivo LICENSE para más detalles.
This Flask app provides a set of routes for syncing data with a database table called "ambulancias" in which data of a vital signs monitor that reports every second is saved.
-
/sincronizar_datos
: This route retrieves the most recent record with astatus
of 0 from the "ambulancias" table and returns it as a JSON object. -
/actualizar_datos_sincronizados/<id>
: This route updates thestatus
of the record with the specifiedid
in the "ambulancias" table to 1. -
/sincronizar_datos_faltantes/<dispositivo_id>
: This route retrieves all records with astatus
of 0 and aid
that matches the specifieddispositivo_id
from the "ambulancias" table and returns them as a list of JSON objects. -
/sincronizar_datos_masivos/<dispositivo_id>
: This route updates thestatus
of all records with aid
that matches the specifieddispositivo_id
in the "ambulancias" table to 1. -
/eliminar_registros/<dispositivo_id>
: This route deletes all records with aid
that matches the specifieddispositivo_id
and astatus
of 1 from the "ambulancias" table.
To run this app, you will need to install the necessary packages and set up a MySQL database.
- Install the necessary packages:
pip install flask mysql-connector-python
- Set up a MySQL database and table with the following structure:
CREATE TABLE ambulancias (
_id INT AUTO_INCREMENT PRIMARY KEY,
ip VARCHAR(15) NOT NULL,
id VARCHAR(50) NOT NULL,
msg VARCHAR(250) NOT NULL,
time DATETIME NOT NULL,
estado INT NOT NULL
);
-
Update the
mydb
variable in the code with the MySQL connection details. -
Run the app:
python nombre_archivo.py
To use the routes in this Flask app, send HTTP requests to the specified endpoints using the appropriate method (GET, PUT, DELETE). The response will be a JSON object or an array containing the data returned by the route.
This app is licensed under the MIT License. See the LICENSE file for more details.