def index(request): timezone.activate(pytz.timezone("America/Argentina/Buenos_Aires")) max_sources = map(convDolar, maxSources()) max_sources_yesterday = map(convDolar, maxSourcesYesterday()) all_sources = map(lambda x: {"name":x.source, "description":x.description},Source.objects.all()) context = { 'max_sources': json.dumps(max_sources, cls=DecimalEncoder), 'max_sources_yesterday': json.dumps(max_sources_yesterday, cls=DecimalEncoder), 'all_sources': json.dumps(all_sources) } return render(request, 'index.html', context)
def calculator(request): timezone.activate(pytz.timezone("America/Argentina/Buenos_Aires")) max_sources = map(convDolar, maxSources()) max_currencies = map(convCurr, maxCurrencies()) max_currencies.sort(key=itemgetter('code')) all_sources = map(lambda x: {"name":x.source, "description":x.description},Source.objects.all()) context = { 'max_sources': json.dumps(max_sources, cls=DecimalEncoder), 'all_sources': json.dumps(all_sources), 'max_currencies': json.dumps(max_currencies, cls=DecimalEncoder) } return render(request, 'calculator.html', context)
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
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
def json_lastprice(request): max_sources = map(convDolar, maxSources()) return max_sources