コード例 #1
0
ファイル: tracking.py プロジェクト: vanderheyde/ecm
def getDiffs(oldMembers, newMembers, date):
    removed, added = tools.diff(old_items=oldMembers, new_items=newMembers)

    diffs = []

    LOG.debug("RESIGNED MEMBERS:")
    if not removed: LOG.debug("(none)")
    for oldmember in removed:
        LOG.debug("- %s (%s)", oldmember.name, oldmember.nickname)
        diffs.append(
            MemberDiff(member_id=oldmember.characterID,
                       name=oldmember.name,
                       nickname=oldmember.nickname,
                       new=False,
                       date=date))
    LOG.debug("NEW MEMBERS:")
    if not added: LOG.debug("(none)")
    for newmember in added:
        LOG.debug("+ %s (%s)", newmember.name, newmember.nickname)
        diffs.append(
            MemberDiff(member_id=newmember.characterID,
                       name=newmember.name,
                       nickname=newmember.nickname,
                       new=True,
                       date=date))
    return diffs, removed
コード例 #2
0
def process_contracts(contract_list, connection):
    """
    Process all contracts from the API
    """
    try:
        alliance_id = Corporation.objects.mine().alliance.allianceID
    except AttributeError:
        alliance_id = 0
    LOG.debug("Fetching contracts from DB...")    
    # Get old contracts
    old_contracts = {}
    for contract in Contract.objects.all():
        old_contracts[contract] = contract
    LOG.debug("%s contracts found in DB..." % len(old_contracts))
    
    # Get new contracts
    LOG.debug("Fetching contracts from API...")   
    new_contracts = {}
    for entry in contract_list:
        if entry.assigneeID != alliance_id:
            contract = populate_contract(entry)
            new_contracts[contract] = contract
    
    # Get changes
    removed_contracts, added_contracts = tools.diff(old_items=old_contracts, new_items=new_contracts)
    LOG.debug("Contracts from API: %s" % len(new_contracts))
    LOG.debug("Removed contracts: %s" % len(removed_contracts))
    LOG.debug("Added contracts: %s" % len(added_contracts))
    
    # Query the contract items
    old_items = {}
    for item in ContractItem.objects.all():
        old_items[item] = item

    # Note: We dont need to diff items, since they are contained in contracts
    # Get new items by contractID from EVE API
    new_items = {}
    for contract in added_contracts:
        if contract.type != 2: # 'Courier' No items for courier contracts from API
            try:
                items_api = connection.corp.ContractItems(contractID=contract.contractID)
                item_list = items_api.itemList
                LOG.debug("%s items for contract id %s..." % (len(item_list), contract.contractID))
                for item in item_list:
                    new_item = populate_contract_item(item, contract)
                    new_items[new_item] = new_item
            except api.RequestError:
                LOG.debug("Invalid or missing contractID: %s" % contract.contractID)
            except RuntimeError:
                LOG.debug("Unable to fetch items for contract ID: %s" % contract.contractID)
                continue
    # Get all contractitem ids for removed contracts
    removed_items = []
    for contract in removed_contracts:
        removed_items.append(ContractItem.objects.filter(contract=contract))
    
    LOG.debug("Writing contracts to DB...")
    write_contracts(added_contracts, removed_contracts)
    LOG.debug("Writing contract items to DB...")
    write_contract_items(new_items, removed_items)
コード例 #3
0
ファイル: marketorders.py プロジェクト: vanderheyde/ecm
def processOrders(orders, connection):
    # Get old Orders
    old_orders = {}
    for order in MarketOrder.objects.all():
        old_orders[order] = order

    # Get new orders
    new_orders = {}
    for entry in orders:
        order = create_order_fom_row(entry)
        new_orders[order] = order

    removed_orders, added_orders = tools.diff(old_orders, new_orders)
    write_orders(added_orders, removed_orders)
コード例 #4
0
ファイル: marketorders.py プロジェクト: RebelFist/ecm
def processOrders(orders, connection):
    # Get old Orders
    old_orders = {}
    for order in MarketOrder.objects.all():
        old_orders[order] = order

    # Get new orders
    new_orders = {}
    for entry in orders:
        order = create_order_fom_row(entry)
        new_orders[order] = order

    removed_orders, added_orders = tools.diff(old_orders, new_orders)
    write_orders(added_orders, removed_orders)
コード例 #5
0
ファイル: assets.py プロジェクト: vanderheyde/ecm
def calc_assets_diff(old_items, new_items, date):
    removed, added = tools.diff(old_items=old_items, new_items=new_items)
    merge_duplicates(removed)
    merge_duplicates(added)

    diffs = []

    # so we don't get an Attribute error when calling addasset.duplicate
    for asset in added:
        asset.duplicate = False

    for remasset in removed:
        added_qty = 0
        for addasset in added:
            if not addasset.duplicate and addasset.lookslike(remasset):
                # if there is a match (there cannot be more than one), the added asset
                # was already in the removed assets. We tag the added asset to duplicate
                # and take it in consideration when creating the "removed" AssetDiff
                addasset.duplicate = True
                added_qty = addasset.quantity
                break
        if (added_qty - remasset.quantity):
            # if the added asset doesn't negate the removed one, we create a diff
            diffs.append(
                AssetDiff(solarSystemID=remasset.solarSystemID,
                          stationID=remasset.stationID,
                          hangarID=remasset.hangarID,
                          eve_type=remasset.eve_type,
                          flag=remasset.flag,
                          quantity=added_qty - remasset.quantity,
                          date=date,
                          new=False,
                          volume=remasset.volume))
    for addasset in added:
        if not addasset.duplicate:
            diffs.append(
                AssetDiff(solarSystemID=addasset.solarSystemID,
                          stationID=addasset.stationID,
                          hangarID=addasset.hangarID,
                          eve_type=addasset.eve_type,
                          flag=addasset.flag,
                          quantity=addasset.quantity,
                          date=date,
                          new=True,
                          volume=addasset.volume))
    return diffs
コード例 #6
0
ファイル: assets.py プロジェクト: Betriebsrat/ecm
def calc_assets_diff(old_items, new_items, date):
    removed, added = tools.diff(old_items=old_items, new_items=new_items)
    merge_duplicates(removed)
    merge_duplicates(added)

    diffs = []

    # so we don't get an Attribute error when calling addasset.duplicate
    for asset in added: asset.duplicate = False

    for remasset in removed:
        added_qty = 0
        for addasset in added:
            if not addasset.duplicate and addasset.lookslike(remasset):
                # if there is a match (there cannot be more than one), the added asset
                # was already in the removed assets. We tag the added asset to duplicate
                # and take it in consideration when creating the "removed" AssetDiff
                addasset.duplicate = True
                added_qty = addasset.quantity
                break
        if (added_qty - remasset.quantity):
            # if the added asset doesn't negate the removed one, we create a diff
            diffs.append(AssetDiff(solarSystemID=remasset.solarSystemID,
                                       stationID=remasset.stationID,
                                        hangarID=remasset.hangarID,
                                        eve_type=remasset.eve_type,
                                            flag=remasset.flag,
                                        quantity=added_qty - remasset.quantity,
                                            date=date,
                                             new=False,
                                          volume=remasset.volume))
    for addasset in added:
        if not addasset.duplicate:
            diffs.append(AssetDiff(solarSystemID=addasset.solarSystemID,
                                       stationID=addasset.stationID,
                                        hangarID=addasset.hangarID,
                                        eve_type=addasset.eve_type,
                                            flag=addasset.flag,
                                        quantity=addasset.quantity,
                                            date=date,
                                             new=True,
                                          volume=addasset.volume))
    return diffs
コード例 #7
0
ファイル: tracking.py プロジェクト: Betriebsrat/ecm
def getDiffs(oldMembers, newMembers, date):
    removed, added = tools.diff(old_items=oldMembers, new_items=newMembers)

    diffs  = []

    LOG.debug("RESIGNED MEMBERS:")
    if not removed : LOG.debug("(none)")
    for oldmember in removed:
        LOG.debug("- %s (%s)", oldmember.name, oldmember.nickname)
        diffs.append(MemberDiff(member_id   = oldmember.characterID,
                                name        = oldmember.name,
                                nickname    = oldmember.nickname,
                                new=False, date=date))
    LOG.debug("NEW MEMBERS:")
    if not added : LOG.debug("(none)")
    for newmember in added:
        LOG.debug("+ %s (%s)", newmember.name, newmember.nickname)
        diffs.append(MemberDiff(member_id   = newmember.characterID,
                                name        = newmember.name,
                                nickname    = newmember.nickname,
                                new=True, date=date))
    return diffs, removed
コード例 #8
0
def getTitleMemberDiffs(oldTitles, newTitles, date):
    removed, added = tools.diff(new_items=newTitles, old_items=oldTitles)
    return __storeTitleDiffs(removed, added, date)
コード例 #9
0
ファイル: security.py プロジェクト: vanderheyde/ecm
def getTitleMemberDiffs(oldTitles, newTitles, date):
    removed, added = tools.diff(new_items=newTitles, old_items=oldTitles)
    return __storeTitleDiffs(removed, added, date)