From 06a10819f3ec2a53e232fc45a5957644bb5f01f8 Mon Sep 17 00:00:00 2001 From: MauronMP Date: Mon, 21 Nov 2022 13:57:03 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20ci(pmp=5Fiv/models/*)=20Delete?= =?UTF-8?q?=20folder=20#25,=20#26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmp_iv/models/coordenada.py | 14 ------- pmp_iv/models/correlacion_area.py | 56 ------------------------- pmp_iv/models/day.py | 10 ----- pmp_iv/models/eda.py | 46 -------------------- pmp_iv/models/estado.py | 21 ---------- pmp_iv/models/fecha.py | 18 -------- pmp_iv/models/fwi.py | 19 --------- pmp_iv/models/month.py | 15 ------- pmp_iv/validaciones/model_validation.py | 37 ---------------- pmp_iv/validaciones/validation.py | 41 ------------------ 10 files changed, 277 deletions(-) delete mode 100644 pmp_iv/models/coordenada.py delete mode 100644 pmp_iv/models/correlacion_area.py delete mode 100644 pmp_iv/models/day.py delete mode 100644 pmp_iv/models/eda.py delete mode 100644 pmp_iv/models/estado.py delete mode 100644 pmp_iv/models/fecha.py delete mode 100644 pmp_iv/models/fwi.py delete mode 100644 pmp_iv/models/month.py delete mode 100644 pmp_iv/validaciones/model_validation.py delete mode 100644 pmp_iv/validaciones/validation.py diff --git a/pmp_iv/models/coordenada.py b/pmp_iv/models/coordenada.py deleted file mode 100644 index dd54286..0000000 --- a/pmp_iv/models/coordenada.py +++ /dev/null @@ -1,14 +0,0 @@ -from dataclasses import dataclass -from pmp_iv.validaciones.model_validation import ModelValidation -from pmp_iv.validaciones.validation import Validation - -'''Establece en un perímetro una zona delimitada una área''' -@dataclass -class Coordenada: - '''Primera coordenada de un cuadrado 3x3''' - x: int - '''Segunda coordenada de un cuadrado 3x3''' - y: int - - def __post_init__(self): - Validation.validate(self, ModelValidation.coordenada()) diff --git a/pmp_iv/models/correlacion_area.py b/pmp_iv/models/correlacion_area.py deleted file mode 100644 index d8123de..0000000 --- a/pmp_iv/models/correlacion_area.py +++ /dev/null @@ -1,56 +0,0 @@ -from pmp_iv.models.eda import * -from math import * - -class correlacion_area(): - - def __init__(self, propiedad, area_quemada): - self.X = propiedad - self.Y = area_quemada - - def media_muestra_x(self): - sumatoria = 0 - for i in self.X: - sumatoria += i - self.media_x = sumatoria / len(self.X) - return self.media_x - - def media_muestra_y(self): - sumatoria = 0 - for i in self.Y: - sumatoria += i - self.media_y = sumatoria / len(self.Y) - return self.media_y - - def distancia_media_x(self): - self.dist_x = [] - for i in self.X: - self.dist_x.append((i - self.media_muestra_x())) - return self.dist_x - - def distancia_media_y(self): - self.dist_y = [] - for i in self.Y: - self.dist_y.append((i - self.media_muestra_y())) - return self.dist_y - - def num_coeficiente_x_y(self): - self.numerador = 0 - for i in range(len(self.X)): - self.numerador += self.distancia_media_x()[i]*self.distancia_media_y()[i] - return self.numerador - - def den_coeficiente_x_y(self): - cuadrado_x = 0 - cuadrado_y = 0 - - for i in range(len(self.X)): - cuadrado_x += pow(self.distancia_media_x()[i],2) - for i in range(len(self.Y)): - cuadrado_y += pow(self.distancia_media_y()[i],2) - - self.denominador = sqrt(cuadrado_x*cuadrado_y) - return self.denominador - - - def calculo_coeficiente(self): - return (self.num_coeficiente_x_y() / self.den_coeficiente_x_y()) \ No newline at end of file diff --git a/pmp_iv/models/day.py b/pmp_iv/models/day.py deleted file mode 100644 index ac788bb..0000000 --- a/pmp_iv/models/day.py +++ /dev/null @@ -1,10 +0,0 @@ -from enum import Enum - -class Day(Enum): - L = 1 - M = 2 - X = 3 - J = 4 - V = 5 - S = 6 - D = 7 diff --git a/pmp_iv/models/eda.py b/pmp_iv/models/eda.py deleted file mode 100644 index f0d60b0..0000000 --- a/pmp_iv/models/eda.py +++ /dev/null @@ -1,46 +0,0 @@ -import csv -from pmp_iv.models.correlacion_area import * -class EDA(): - - def __init__(self): - with open('data/incendiosForestales.csv', 'r', newline='') as csvfile: - self.weather_data = csv.DictReader(csvfile) - self._datos_csv = self.get_data_values() - self._area = self.by_property('area') - - def get_data_values(self): - filter_data = [] - for row in self.weather_data: - my_dict = {} - for key, value in row.items(): - if key != 'month' and key != 'day': - my_dict[key] = float(value) - else: - my_dict[key] = value - filter_data.append(my_dict) - return filter_data - - def by_date_property(self, mes, dia, propiedad): - data_by_property = [] - for i in self.valores: - if i['month']==mes and i['day']==dia: - data_by_property.append([i['X'], i['Y'],i['month'], i['day'], i[propiedad]]) - return data_by_property - - - def by_property(self,propiedad): - data_by_property = [i[propiedad] for i in self.valores] - return data_by_property - - def weather_values(self): - data_by_value = [[i['FFMC'],i['DMC'],i['DC'],i['ISI'], - i['temp'],i['RH'],i['wind'],i['area']] for i in self.valores] - return data_by_value - - @property - def valores(self): - return self._datos_csv - - @property - def area(self): - return self._area \ No newline at end of file diff --git a/pmp_iv/models/estado.py b/pmp_iv/models/estado.py deleted file mode 100644 index 6c37d07..0000000 --- a/pmp_iv/models/estado.py +++ /dev/null @@ -1,21 +0,0 @@ -from dataclasses import dataclass -from pmp_iv.validaciones.model_validation import ModelValidation - -from pmp_iv.validaciones.validation import Validation - -'''Propiedades últiles para poder realizar el cálculo de los elementos de la clase fwi''' -@dataclass -class Estado: - '''Temperatura en la coordenada''' - temperature: int - '''Humedad en la coordenada''' - humidity: int - '''Densidad del viento en la coordenada''' - wind: float - '''Cantidad de lluvia en la coordenada''' - rain: float - '''Superficie de la coordenada''' - surface: int - - def __post_init__(self): - Validation.validate(self, ModelValidation.estado()) diff --git a/pmp_iv/models/fecha.py b/pmp_iv/models/fecha.py deleted file mode 100644 index c9c79f2..0000000 --- a/pmp_iv/models/fecha.py +++ /dev/null @@ -1,18 +0,0 @@ -from dataclasses import dataclass -from enum import Enum -from pmp_iv.validaciones.model_validation import ModelValidation -from pmp_iv.models.day import Day -from pmp_iv.models.month import Month -from pmp_iv.validaciones.validation import Validation - -'''Utilizado para segmentar la información''' -@dataclass -class Fecha: - '''Opciones posibles para segmentar información mediante meses''' - mes: Month - '''Opciones posibles para segmentar información mediante día de la semana''' - dia: Day - - def __post_init__(self): - Validation.validate(self, ModelValidation.fecha()) - diff --git a/pmp_iv/models/fwi.py b/pmp_iv/models/fwi.py deleted file mode 100644 index 6e27d65..0000000 --- a/pmp_iv/models/fwi.py +++ /dev/null @@ -1,19 +0,0 @@ -from dataclasses import dataclass -from pmp_iv.validaciones.model_validation import ModelValidation - -from pmp_iv.validaciones.validation import Validation - -'''Fire weather index''' -@dataclass -class FWI: - '''Fine fuel moisture code''' - FFMC: float - '''Duff moisture code''' - DMC: float - '''Drought code''' - DC: float - '''Indicador de la velocidad de propagación del incendio''' - ISI: float - - def __post_init__(self): - Validation.validate(self, ModelValidation.fwi()) diff --git a/pmp_iv/models/month.py b/pmp_iv/models/month.py deleted file mode 100644 index 4e20f2f..0000000 --- a/pmp_iv/models/month.py +++ /dev/null @@ -1,15 +0,0 @@ -from enum import Enum - -class Month(Enum): - enero = 1 - febrero = 2 - marzo = 3 - abril = 4 - mayo = 5 - junio = 6 - julio = 7 - agosto = 8 - septiembre = 9 - octubre = 10 - noviembre = 11 - diciembre = 12 diff --git a/pmp_iv/validaciones/model_validation.py b/pmp_iv/validaciones/model_validation.py deleted file mode 100644 index 910dbc6..0000000 --- a/pmp_iv/validaciones/model_validation.py +++ /dev/null @@ -1,37 +0,0 @@ -from dataclasses import dataclass -from pmp_iv.models.day import Day -from pmp_iv.models.month import Month - -from pmp_iv.validaciones.validation import Validation - -@dataclass -class ModelValidation: - @staticmethod - def coordenada(): - return [ - Validation('x', 1, 9), - Validation('y', 2, 9) - ] - @staticmethod - def estado(): - return [ - Validation('temperature', -15, 45), - Validation('humidity', 0, 100), - Validation('wind', 0.0, 10.0), - Validation('rain', 0.0, 7.0), - Validation('surface', 0, 1000) - ] - @staticmethod - def fecha(): - return [ - Validation('mes', enum=Month), - Validation('dia', enum=Day) - ] - @staticmethod - def fwi(): - return [ - Validation('FFMC', 18.7, 96.0), - Validation('DMC', 1.1, 290.0), - Validation('DC', 7.9, 860.0), - Validation('ISI', 0.0, 56.0) - ] diff --git a/pmp_iv/validaciones/validation.py b/pmp_iv/validaciones/validation.py deleted file mode 100644 index ba31873..0000000 --- a/pmp_iv/validaciones/validation.py +++ /dev/null @@ -1,41 +0,0 @@ -from dataclasses import dataclass -from enum import Enum -from typing import Optional - -@dataclass -class Validation: - prop_name: str - min: Optional[float] = None - max: Optional[float] = None - enum: Optional[Enum] = None - - def __post_init__(self): - if not self.prop_name or len(self.prop_name) == 0: - raise Exception('validation must refer to a property name') - if self.enum and not issubclass(self.enum, Enum): - raise Exception('if set, enum property must be of type Enum') - - @staticmethod - def validate(target, validators): - if (not hasattr(validators, "__len__") and isinstance(validators, Validation)): - validators = [validators] - - if (not hasattr(validators, "__len__")): - raise Exception("validators is not Validation or Validation array instance".format()) - - i=0 - for validator in validators: - i+=1 - # Validator checks - if (not isinstance(validator, Validation)): - raise Exception("validator {} is not validation instance".format(i)) - if (not hasattr(target, validator.prop_name)): - raise Exception("to validate property {} it must exists at target object".format(validator.prop_name)) - # Target instance checks - if (validator.min != None and getattr(target, validator.prop_name) < validator.min): - raise Exception("{} property only allows greater or equal than {}".format(validator.prop_name, validator.min)) - if (validator.max != None and getattr(target, validator.prop_name) > validator.max): - raise Exception("{} property only allows lower or equal than {}".format(validator.prop_name, validator.max)) - if (validator.enum != None and not isinstance(getattr(target, validator.prop_name), validator.enum)): - raise Exception("{} property must be of type {}".format(validator.prop_name, validator.enum)) -