def quicklook(request, type_id=34): """ Generates a market overview for a certain type. Defaults to tritanium. """ # Get the item type type_object = InvType.objects.get(id=type_id) # Add regions region_ids = [10000002, 10000043, 10000032, 10000030] region_names = {} for region in region_ids: region_names[region] = MapRegion.objects.get(id=region).name # Get requested type type_object = InvType.objects.get(id=type_id) # Get list of materials to build materials = InvTypeMaterial.objects.values( 'material_type__name', 'quantity', 'material_type__id').filter(type=type_id) totalprice = 0 for material in materials: # Get jita pricing stat_object = ItemRegionStat() try: stat_object = ItemRegionStat.objects.get( invtype_id__exact=material['material_type__id'], mapregion_id__exact=10000002) except: stat_object.sellmedian = 0 try: stats = ItemRegionStat.objects.get( invtype_id__exact=material['material_type__id'], mapregion_id__exact=10000002) material['total'] = stats.sell_95_percentile * material['quantity'] material['min_price'] = stats.sell_95_percentile except: material['total'] = 0 material['min_price'] = 0 material['price'] = stat_object.sellmedian totalprice += material['total'] # Fetch top 50 buy/sell orders from DB buy_orders = Orders.active.select_related( 'stastation__id', 'stastation__name', 'mapregion__id', 'mapregion__name', 'mapsolarsystem__security_level').filter( invtype=type_id, is_bid=True, is_active=True).order_by('-price')[:50] sell_orders = Orders.active.select_related( 'stastation__id', 'stastation__name', 'mapregion__id', 'mapregion__name', 'mapsolarsystem__security_level').filter( invtype=type_id, is_bid=False, is_active=True).order_by('price')[:50] # Force evaluation of queryset to avoid re-evaluation in the template len(buy_orders) len(sell_orders) # Load bredcrubs breadcrumbs = group_breadcrumbs(type_object.market_group_id) rcontext = RequestContext( request, { 'type': type_object, 'region_ids': region_ids, 'region_names': json.dumps(region_names), 'materials': materials, 'totalprice': totalprice, 'buy_orders': buy_orders, 'sell_orders': sell_orders, 'breadcrumbs': breadcrumbs }) return render_to_response('quicklook.haml', rcontext)
def quicklook_region(request, region_id=10000002, type_id=34): """ Generates system level overview for a specific type. Defaults to tritanium & the forge. """ # Get the item type type_object = InvType.objects.get(id=type_id) # Get list of materials to build materials = InvTypeMaterial.objects.values( 'material_type__name', 'quantity', 'material_type__id').filter(type=type_id) totalprice = 0 for material in materials: # Get jita pricing stat_object = ItemRegionStat() try: stat_object = ItemRegionStat.objects.get( invtype_id__exact=material['material_type__id'], mapregion_id__exact=10000002) except: stat_object.sellmedian = 0 try: stats = ItemRegionStat.objects.get( invtype_id__exact=material['material_type__id'], mapregion_id__exact=10000002) material['total'] = stats.sell_95_percentile * material['quantity'] material['min_price'] = stats.sell_95_percentile except: material['total'] = 0 material['min_price'] = 0 material['price'] = stat_object.sellmedian # material['total']=min_price['min_price']*material['quantity'] totalprice += material['total'] # Get the region type region_object = MapRegion.objects.get(id=region_id) # # Orders # # Fetch all buy/sell orders from DB buy_orders = Orders.active.select_related( 'stastation__id', 'stastation__name', 'mapregion__id', 'mapregion__name', 'mapsolarsystem__security_level').filter( invtype=type_id, is_bid=True, mapregion_id=region_id).order_by('-price') sell_orders = Orders.active.select_related( 'stastation__id', 'stastation__name', 'mapregion__id', 'mapregion__name', 'mapsolarsystem__security_level').filter( invtype=type_id, is_bid=False, mapregion_id=region_id).order_by('price') orders = [] orders += buy_orders orders += sell_orders breadcrumbs = group_breadcrumbs(type_object.market_group_id) # Use all orders for quicklook and add the system_data to the context # We shouldn't need to limit the amount of orders displayed here as they all are in the same region rcontext = RequestContext( request, { 'region': region_object, 'type': type_object, 'materials': materials, 'totalprice': totalprice, 'buy_orders': buy_orders, 'sell_orders': sell_orders, 'breadcrumbs': breadcrumbs }) return render_to_response('quicklook_region.haml', rcontext)