Exemplo n.º 1
0
def materials_compute():
  materials = item_db.all_materials()
  # List of (material name, buy price, quantity, value).
  result = []
  total_value = 0.0
  for name in sorted(request.forms):
    quantity = request.forms[name]
    if not quantity:
      continue
    try:
      quantity = int(quantity)
    except ValueError:
      abort(400, 'Invalid quantity of %s' % name)
    buy_price = get_buy_price(materials, name)
    if buy_price is None:
      abort(400, 'Invalid material: %s' % name)
    value = buy_price * quantity
    total_value += value
    result.append((name,
                   buy_price,
                   format_number(quantity),
                   format_number(value)))
  # TODO: add sell_price to Item and use that instead of hard-coding here.
  return template('compute_materials.html',
                  materials=result,
                  buy_price=format_number(total_value),
                  sell_price=format_number(total_value * MINERAL_SELL_MARKUP))
Exemplo n.º 2
0
def materials_page():
  materials = item_db.all_materials()
  item_quantities = get_item_quantities()

  ore_data = []
  for ore_name in sorted(ores.ORES):
    ore = ores.ORES[ore_name]
    variants = []
    for ore_variant in [ore.name, ore.name5, ore.name10]:
      buy_price = ore.calculate_buy_price(materials, ore_variant)
      variants.append((ore_variant, buy_price, buy_price / ore.volume))
    ore_data.append((ore_name, variants))
  if request.query.get('format') == 'json':
    return dict((material.name, material.to_dict(
          item_quantities.get(material.name, 0))) for material in materials)
  return template('materials',
                  is_current_user_admin=is_current_user_admin(),
                  materials=materials,
                  salvage=[],
                  ores=ore_data,
                  item_quantities=item_quantities)