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())