diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..76307af5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +name: Build +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] +jobs: + sonarcloud: + name: SonarCloud + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Instalación de librerías y dependencias + run: | + python -m pip install --upgrade pip + python -m pip install pytest + - name: pruebas+coverage + run: | + pytest + exit 5 + continue-on-error: true + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/IOTMonitoringServer/settings.py b/IOTMonitoringServer/settings.py index 114ccc2f..20a5f8dc 100644 --- a/IOTMonitoringServer/settings.py +++ b/IOTMonitoringServer/settings.py @@ -27,7 +27,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["localhost", "ip.maquina.visualizador"] +ALLOWED_HOSTS = ["localhost", "3.237.205.218"] # Application definition @@ -96,7 +96,7 @@ "NAME": "iot_data", # Nombre de la base de datos "USER": "dbadmin", # Nombre de usuario "PASSWORD": "uniandesIOT1234*", # Contraseña - "HOST": "ip.maquina.db", # Dirección IP de la base de datos + "HOST": "44.213.121.117", # Dirección IP de la base de datos "PORT": "", # Puerto de la base de datos } } @@ -156,7 +156,7 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4' # Dirección del bróker MQTT -MQTT_HOST = "ip.maquina.mqtt" +MQTT_HOST = "18.205.3.25" # Puerto del bróker MQTT MQTT_PORT = 8082 diff --git a/control/monitor.py b/control/monitor.py index 43d7af0c..a7411fff 100644 --- a/control/monitor.py +++ b/control/monitor.py @@ -12,10 +12,7 @@ def analyze_data(): - # Consulta todos los datos de la última hora, los agrupa por estación y variable - # Compara el promedio con los valores límite que están en la base de datos para esa variable. - # Si el promedio se excede de los límites, se envia un mensaje de alerta. - + print("Calculando alertas...") data = Data.objects.filter( diff --git a/receiver/models.py b/receiver/models.py index 8becaf00..799ab7f3 100644 --- a/receiver/models.py +++ b/receiver/models.py @@ -10,15 +10,14 @@ class City(models.Model): name = models.CharField(max_length=50, unique=True, blank=False) - code = models.CharField(max_length=50, null=True) + code = models.CharField(max_length=50, blank=True) def str(self): return "{}".format(self.name) - class State(models.Model): name = models.CharField(max_length=50, unique=False, blank=False) - code = models.CharField(max_length=50, null=True) + code = models.CharField(max_length=50, blank=True) def str(self): return "{}".format(self.name) @@ -26,7 +25,7 @@ def str(self): class Country(models.Model): name = models.CharField(max_length=50, unique=False, blank=False) - code = models.CharField(max_length=50, null=True) + code = models.CharField(max_length=50, blank=True) def str(self): return "{}".format(self.name) @@ -43,6 +42,118 @@ class Location(models.Model): country = models.ForeignKey(Country, on_delete=models.CASCADE) active = models.BooleanField(default=True) +class Location2(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location3(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location4(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location5(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location6(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location7(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location10(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location11(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location12(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + +class Location13(models.Model): + description = models.CharField(max_length=200, blank=True) + lat = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + lng = models.DecimalField( + max_digits=9, decimal_places=6, null=True, blank=True) + city = models.ForeignKey(City, on_delete=models.CASCADE) + state = models.ForeignKey(State, on_delete=models.CASCADE) + country = models.ForeignKey(Country, on_delete=models.CASCADE) + active = models.BooleanField(default=True) + + + class Meta: unique_together = ("city", "state", "country") diff --git a/requeriments.py b/requeriments.txt similarity index 100% rename from requeriments.py rename to requeriments.txt diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..11c60df2 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,14 @@ +sonar.projectKey=alexyirsa_IOTMonitoringServer +sonar.organization=alexyirsa +sonar.coverage.exclusions=**tests/**,**src/vista/**,**docs/**,**setup.py** + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=IOTMonitoringServer +#sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 \ No newline at end of file