コード例 #1
0
ファイル: station.py プロジェクト: SectorUnkown/element43
def import_system(request, station_id=60003760, system_id=30000142):

    """
    Generates a list like http://goonmetrics.com/importing/
    Pattern: System -> Station
    """

    # Get system, station and markup
    system = MapSolarSystem.objects.get(id=system_id)
    station = StaStation.objects.get(id=station_id)

    # get the path to destination, assume trying for highsec route
    path = find_path(system_id, station.solar_system_id)
    numjumps = len(path) - 1 # don't count the start system

    # Mapping: (invTyeID, invTypeName, foreign_ask, local_bid, markup, invTyeID)
    markup = import_markup(station_id, 0, system_id, 0)

    # Get last week for history query
    last_week = pytz.utc.localize(
        datetime.datetime.utcnow() - datetime.timedelta(days=7))
    data = []

    for point in markup:
        # Add new values to dict and if there's a weekly volume append it to list
        new_values = {
            # Get local weekly volume for that item
            'weekly_volume': OrderHistory.objects.filter(mapregion_id=station.region.id,
                                                                 invtype_id=point['id'],
                                                                 date__gte=last_week)
            .aggregate(Sum("quantity"))['quantity__sum'],

            # Get filtered local bid qty
            'bid_qty_filtered': Orders.active.filter(stastation_id=station_id,
                                                      invtype_id=point['id'], is_bid=True,
                                                      minimum_volume=1,
                                                      price__gte=(point['local_bid'] - (point['local_bid'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum'],

            # Get filtered ask qty of the other system
            'ask_qty_filtered': Orders.active.filter(mapsolarsystem_id=system_id,
                                                      invtype_id=point['id'], is_bid=False,
                                                      minimum_volume=1,
                                                      price__lte=(point['foreign_ask'] + (point['foreign_ask'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum']}
        point.update(new_values)

        # Calculate potential profit ((local_bid - foreign_ask) * weekly_volume)
        if point['weekly_volume'] is not None:
            point['potential_profit'] = ((point['local_bid'] - point['foreign_ask']) * point['weekly_volume'])
            data.append(point)

    data.sort(key=itemgetter('potential_profit'), reverse=True)

    rcontext = RequestContext(request, {'system': system, 'markup':
                              data, 'path': path, 'jumps': numjumps})

    return render_to_response('station/_import_system.haml', rcontext)
コード例 #2
0
def import_system(request, station_id=60003760, system_id=30000142):

    """
    Generates a list like http://goonmetrics.com/importing/
    Pattern: System -> Station
    """

    # Get system, station and markup
    system = MapSolarSystem.objects.get(id=system_id)
    station = StaStation.objects.get(id=station_id)

    # get the path to destination, assume trying for highsec route
    path = find_path(system_id, station.solar_system_id)
    numjumps = len(path) - 1 # don't count the start system

    # Mapping: (invTyeID, invTypeName, foreign_ask, local_bid, markup, invTyeID)
    markup = import_markup(station_id, 0, system_id, 0)

    # Get last week for history query
    last_week = pytz.utc.localize(
        datetime.datetime.utcnow() - datetime.timedelta(days=7))
    data = []

    for point in markup:
        # Add new values to dict and if there's a weekly volume append it to list
        new_values = {
            # Get local weekly volume for that item
            'weekly_volume': OrderHistory.objects.filter(mapregion_id=station.region.id,
                                                                 invtype_id=point['id'],
                                                                 date__gte=last_week)
            .aggregate(Sum("quantity"))['quantity__sum'],

            # Get filtered local bid qty
            'bid_qty_filtered': Orders.active.filter(stastation_id=station_id,
                                                      invtype_id=point['id'], is_bid=True,
                                                      minimum_volume=1,
                                                      price__gte=(point['local_bid'] - (point['local_bid'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum'],

            # Get filtered ask qty of the other system
            'ask_qty_filtered': Orders.active.filter(mapsolarsystem_id=system_id,
                                                      invtype_id=point['id'], is_bid=False,
                                                      minimum_volume=1,
                                                      price__lte=(point['foreign_ask'] + (point['foreign_ask'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum']}
        point.update(new_values)

        # Calculate potential profit ((local_bid - foreign_ask) * weekly_volume)
        if point['weekly_volume'] is not None:
            point['potential_profit'] = ((point['local_bid'] - point['foreign_ask']) * point['weekly_volume'])
            data.append(point)

    data.sort(key=itemgetter('potential_profit'), reverse=True)

    rcontext = RequestContext(request, {'system': system, 'markup':
                              data, 'path': path, 'jumps': numjumps})

    return render_to_response('station/_import_system.haml', rcontext)
コード例 #3
0
ファイル: station.py プロジェクト: SectorUnkown/element43
def import_region(request, station_id=60003760, region_id=10000002):

    """
    Generates a list like http://goonmetrics.com/importing/
    Pattern: Region -> Station
    """

    # Get region, station and markup
    region = MapRegion.objects.get(id=region_id)
    station = StaStation.objects.get(id=station_id)
    markup = import_markup(station_id, region_id, 0, 0)

    # Get last week for history query
    last_week = pytz.utc.localize(
        datetime.datetime.utcnow() - datetime.timedelta(days=7))

    data = []

    for point in markup:
    # Add new values to dict and if there's a weekly volume append it to list
        new_values = {
            # Get local weekly volume for that item
            'weekly_volume': OrderHistory.objects.filter(mapregion_id=station.region.id,
                                                         invtype_id=point['id'],
                                                         date__gte=last_week)
            .aggregate(Sum("quantity"))['quantity__sum'],

            # Get filtered local bid qty
            'bid_qty_filtered': Orders.active.filter(stastation_id=station_id,
                                                      invtype_id=point['id'], is_bid=True,
                                                      minimum_volume=1,
                                                      price__gte=(point['local_bid'] - (point['local_bid'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum'],

            # Get filtered ask qty of the other region
            'ask_qty_filtered': Orders.active.filter(mapregion_id=region_id,
                                                      invtype_id=point['id'], is_bid=False,
                                                      minimum_volume=1,
                                                      price__lte=(point['foreign_ask'] + (point['foreign_ask'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum']}
        point.update(new_values)

        # Calculate potential profit ((foreign_ask - local_bid) * weekly_volume)
        if point['weekly_volume'] is not None:
            point['potential_profit'] = ((point['local_bid'] - point['foreign_ask']) * point['weekly_volume'])
            data.append(point)

    data.sort(key=itemgetter('potential_profit'), reverse=True)

    rcontext = RequestContext(request, {'region': region, 'markup': data})

    return render_to_response('station/_import_region.haml', rcontext)
コード例 #4
0
def import_region(request, station_id=60003760, region_id=10000002):

    """
    Generates a list like http://goonmetrics.com/importing/
    Pattern: Region -> Station
    """

    # Get region, station and markup
    region = MapRegion.objects.get(id=region_id)
    station = StaStation.objects.get(id=station_id)
    markup = import_markup(station_id, region_id, 0, 0)

    # Get last week for history query
    last_week = pytz.utc.localize(
        datetime.datetime.utcnow() - datetime.timedelta(days=7))

    data = []

    for point in markup:
    # Add new values to dict and if there's a weekly volume append it to list
        new_values = {
            # Get local weekly volume for that item
            'weekly_volume': OrderHistory.objects.filter(mapregion_id=station.region.id,
                                                         invtype_id=point['id'],
                                                         date__gte=last_week)
            .aggregate(Sum("quantity"))['quantity__sum'],

            # Get filtered local bid qty
            'bid_qty_filtered': Orders.active.filter(stastation_id=station_id,
                                                      invtype_id=point['id'], is_bid=True,
                                                      minimum_volume=1,
                                                      price__gte=(point['local_bid'] - (point['local_bid'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum'],

            # Get filtered ask qty of the other region
            'ask_qty_filtered': Orders.active.filter(mapregion_id=region_id,
                                                      invtype_id=point['id'], is_bid=False,
                                                      minimum_volume=1,
                                                      price__lte=(point['foreign_ask'] + (point['foreign_ask'] * 0.01)))
            .aggregate(Sum("volume_remaining"))['volume_remaining__sum']}
        point.update(new_values)

        # Calculate potential profit ((foreign_ask - local_bid) * weekly_volume)
        if point['weekly_volume'] is not None:
            point['potential_profit'] = ((point['local_bid'] - point['foreign_ask']) * point['weekly_volume'])
            data.append(point)

    data.sort(key=itemgetter('potential_profit'), reverse=True)

    rcontext = RequestContext(request, {'region': region, 'markup': data})

    return render_to_response('station/_import_region.haml', rcontext)