Ejemplo n.º 1
0
def avgBlue(input):
  i = 0
  v = 0
  c = 0
  c_a = 0
  v_a = 0
  d = 0
  blue = filter(lambda x: x['name'] != 'oficial', input)
  return {'date': datetime.datetime.now().isoformat(),
        'compra': median(map(lambda x: x['venta'], blue)) * buy_multiplier,
        'venta': median(map(lambda x: x['venta'], blue)),
        'compra_ayer': median(map(lambda x: x['venta_ayer'], blue))* buy_multiplier,
        'venta_ayer': median(map(lambda x: x['venta_ayer'], blue)),
        'name': 'blue',
        'long_name': 'Dolar Blue'
          }
Ejemplo n.º 2
0
    def prepare_data(self):
        last_data = map(convDolar, maxSources())
        only_blue = filter(lambda x: x['source'] != 'oficial', last_data)
        only_oficial = filter(lambda x: x['source'] == 'oficial', last_data)
        avg_blue = {
            'value_sell': median(map(lambda x: x['value_sell'], only_blue))
        }
        avg_blue['value_buy'] = avg_blue['value_sell'] * buy_multiplier
        avg_blue['value_avg'] = (avg_blue['value_buy'] + avg_blue['value_sell']) / 2
        oficial = only_oficial[0]

        self.dolar = {}
        self.dolar['blue'] = convert_presentacion(avg_blue)
        self.dolar['oficial'] = convert_presentacion(oficial)
        self.dolar['ahorro'] = convert_presentacion(multiply(oficial, Decimal('1.20')))
        self.dolar['turismo'] = convert_presentacion(multiply(oficial, Decimal('1.35')))

        self.avg_blue = avg_blue
Ejemplo n.º 3
0
def latest(request):
    max_sources = map(convDolar, maxSources())
    sources_blue = filter(lambda x: x['source'] != 'oficial',max_sources)
    source_oficial = filter(lambda x: x['source'] == 'oficial',max_sources)[0]

    euro = Currency.objects.filter(code__exact='EUR')[0]
    eurovalue = CurrencyValue.objects.filter(curr__exact=euro.id).last()
    euro_avg = eurovalue.value
    euro_buy = euro_avg * Decimal(1.03)
    euro_sell = euro_avg * Decimal(0.97)
    last_date = None

    blue_sell = Decimal(median(map(lambda x: x['value_sell'], sources_blue)))
    blue_buy = blue_sell * Decimal(buy_multiplier)
    blue_avg = (blue_sell + blue_buy) / 2

    response = {}
    response['oficial'] = {'value_buy': source_oficial['value_buy'], 'value_avg': source_oficial['value_avg'], 'value_sell': source_oficial['value_sell']}
    response['blue'] = {'value_buy': blue_buy,  'value_avg': blue_avg, 'value_sell': blue_sell}
    response['last_update'] = max(map(lambda x:x['date'], max_sources))
    response['oficial_euro'] = {'value_buy': source_oficial['value_buy']/euro_buy, 'value_avg': source_oficial['value_avg']/euro_avg, 'value_sell': source_oficial['value_sell']/euro_sell}
    response['blue_euro'] = {'value_buy': blue_buy/euro_buy, 'value_avg': blue_avg/euro_avg, 'value_sell': blue_sell/euro_sell}
    return response