Testeado el batch de indices en dev.

This commit is contained in:
pablomartincalvo 2018-12-23 18:30:11 +01:00
parent d71b69a611
commit c234679a10
7 changed files with 170 additions and 23 deletions

View file

@ -1,37 +1,49 @@
from analysis.market_snapshot import Market, available_date_ranges
from db_layer.capturas_interface import capturas_interface
from db_layer.indices_interface import indices_interface
class IndexMM:
def __init__(self):
self.name = 'indexmm'
self.market = None
self.date = None
self.data = None
self.value = None
def calculate(self, market):
self.market = market
self.date = self.market.end_date
self.data = market.get_market_data()
self.data = self.market.get_market_data()
data_coche_pequeno = {'count': self.data[self.data['tamano_categorico'] == 'coche pequeño'].count(),
'mean': self.data[self.data['tamano_categorico' == 'coche pequeño']]['precio'].transform('mean')}
data_coche_grande = {'count': self.data[self.data['tamano_categorico'] == 'coche grande'].count(),
'mean': self.data[self.data['tamano_categorico' == 'coche grande']]['precio'].transform('mean')}
data_coche_moto = {'count': self.data[self.data['tamano_categorico'] == 'coche y moto'].count(),
'mean': self.data[self.data['tamano_categorico' == 'coche y moto']]['precio'].transform('mean')}
data_coche_pequeno = {'count': self.data[self.data['tamano_categorico'] == 'coche pequeño'].shape[0],
'mean': self.data[self.data['tamano_categorico'] == 'coche pequeño']['precio'].mean()}
data_coche_grande = {'count': self.data[self.data['tamano_categorico'] == 'coche grande'].shape[0],
'mean': self.data[self.data['tamano_categorico'] == 'coche grande']['precio'].mean()}
data_coche_moto = {'count': self.data[self.data['tamano_categorico'] == 'coche y moto'].shape[0],
'mean': self.data[self.data['tamano_categorico'] == 'coche y moto']['precio'].mean()}
self.value = (((data_coche_grande['count'] * data_coche_grande['mean']) + (data_coche_moto['count'] * data_coche_moto['mean'])
+ (data_coche_pequeno['count'] * data_coche_pequeno['mean']))
/ (data_coche_grande['count'] + data_coche_moto['count'] + data_coche_pequeno['count']))
#SEGUIR AQUI
def get_data(self):
return {'name': self.name,
'date': self.date,
'value': self.value}
'value': self.value.item()}
if __name__ == '__main__':
for date_range in available_date_ranges:
market = Market()
market.load_market(capturas_interface.get_market_snapshot(date_range['start'], date_range['end']),
date_range=date_range)
market.clean_market('index')
index = IndexMM()
index.calculate(market)
indices_interface.write_index(index.get_data())

View file

@ -18,27 +18,29 @@ available_date_ranges = [{'start': datetime(2017, 10, 1), 'end': datetime(2018,
class Market:
def __init__(self):
self.start_date = datetime.today() - timedelta(days=90)
self.end_date = datetime.today()
self.start_date = None
self.end_date = None
self.market = None
def load_market(self, market_query_results):
def load_market(self, market_query_results, date_range):
self.market = pd.DataFrame(market_query_results)
self.start_date = date_range['start']
self.end_date = date_range['end']
def clean_market(self, method):
if method == 'index':
self.market.dropna(subset=['tamano_categorico'])
self.market = self.market.dropna(subset=['tamano_categorico'])
self.market = self.market[~self.market['tamano_categorico'].isin(['2 coches o más', 'moto'])]
self.market.drop_duplicates(subset=['precio', 'latitud', 'longitud'], keep='last')
self.market = self.market.drop_duplicates(subset=['tamano_categorico', 'precio', 'latitud', 'longitud', 'telefono'], keep='last')
self.market = self.market[self.market['tipo_anuncio'] == 1]
self.delete_outliers()
if method == 'valoracion':
self.market.dropna(subset=['tamano_categorico'])
self.market = self.market.dropna(subset=['tamano_categorico'])
self.market = self.market[~self.market['tamano_categorico'].isin(['2 coches o más', 'moto'])]
self.market = self.market[self.market['precision'].isin(['ROOFTOP'])]
self.market.drop_duplicates(subset=['precio', 'latitud', 'longitud'], keep='last')
self.market = self.market.drop_duplicates(subset=['tamano_categorico', 'precio', 'latitud', 'longitud', 'telefono'], keep='last')
self.market = self.market[self.market['tipo_anuncio'] == 1]
self.delete_outliers()