コード例 #1
0
def get_organizations(verify_status=0):
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    query = {"dateDelete": {"$exists": False}, "verifyStatus": verify_status}
    projection = {"_id": 1, "name": 1, "role": 1, "ports": 1}
    organizations = epmongo.get_docs_by_query("organizations", query, projection)
    # sort by dataUpdate
    organizations = organizations.sort([('dateUpdate', pymongo.DESCENDING)])
    logging.debug((organizations.count(), type(organizations)))

    ports = epmongo.get_docs_by_query("ports", None, {'name': 1, 'code': 1, '_id': 1})
    ports = {doc.get('_id'): (doc.get('code'), doc.get('name')) for doc in ports}

    organizations_list = []
    for doc in organizations:
        service_ports = doc.get('ports', '')
        if service_ports:
            str_ports = '\n'.join(
                [(ports.get(service_port)[0] + ': ' + ports.get(service_port)[1]) for service_port in service_ports])
            doc['ports'] = str_ports
        else:
            doc['ports'] = ''
        organizations_list.append(doc)
    return len(organizations_list), organizations_list
コード例 #2
0
ファイル: get_ordertypes.py プロジェクト: gy890/ep
def get_ordertypes():
    ep = EPMongo()
    # ep = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    docs = ep.get_docs_by_query('ordertypes',
                                query=None,
                                projection={
                                    'name': 1,
                                    'code': 1,
                                    'defaults': 1
                                })
    docs.sort([('code', pymongo.ASCENDING)])
    products = ep.get_docs_by_query('products',
                                    query=None,
                                    projection={
                                        'name': 1,
                                        'code': 1
                                    })
    products = {
        product.get('_id', ''): (product.get('name',
                                             ''), product.get('code', ''))
        for product in products
    }
    ordertypes = []
    for doc in docs:
        name = doc.get('name', '')
        code = doc.get('code', '')
        defaults = doc.get('defaults', '')
        default_products = []
        if defaults:
            for default in defaults:
                product_name, product_code = products.get(default, '')
                default_products.append((product_name, product_code))
        ordertypes.append((name, code, default_products))
    return ordertypes
コード例 #3
0
def get_order_types():
    epmongo = EPMongo()
    # epmongo = EPMongo(
    #     uri="mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
    #     db_name='epdb-prod')
    docs = epmongo.get_docs_by_query('ordertypes',
                                     {'dateDelete': {
                                         '$exists': False
                                     }}, {
                                         'name': 1,
                                         'code': 1
                                     })
    order_types = {}
    for doc in docs:
        code = doc.get('code')
        name = doc.get('name')
        order_types[code] = name
    return order_types
コード例 #4
0
            "$unwind": {
                "path": "$position.group",
            }
        },
        {
            "$project": {
                "username": 1,
                "account": "$position.group.account"
            }
        },
    ]
    return pipeline


if __name__ == '__main__':
    epmongo = EPMongo()
    users = epmongo.get_docs_by_query('users',
                                      query=None,
                                      projection={'_id': 1})
    # print(c, users[0])
    # pipeline = generate_pipeline(users[0]['_id'])
    # docs = epmongo.aggregate('users', pipeline)
    # print(docs)
    # for each in docs:
    #     print(each)
    for each in users:
        pipeline = generate_pipeline(each['_id'])
        print(pipeline)
        for result in (epmongo.aggregate('users', pipeline)):
            print(result)
コード例 #5
0
ファイル: get_ships.py プロジェクト: gy890/ep
            return 'invalid'


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)s %(message)s')
    # epmongo = EPMongo()
    epmongo = EPMongo(
        uri=
        "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
        db_name='epdb-prod')
    ships = epmongo.get_docs_by_query('ships',
                                      {'dateDelete': {
                                          '$exists': False
                                      }}, {
                                          'name': 1,
                                          'imo': 1,
                                          'type': 1,
                                          'dateCreate': 1,
                                          'dateUpdate': 1
                                      })
    ships = ships.sort([('imo', pymongo.ASCENDING)])
    logging.info('total {} ships.'.format(ships.count()))
    wb = Workbook()
    ws = wb.active
    ws.cell(row=1, column=1).value = 'No.'
    ws.cell(row=1, column=2).value = 'id'
    ws.cell(row=1, column=3).value = 'name'
    ws.cell(row=1, column=4).value = 'imo'
    ws.cell(row=1, column=5).value = 'type'
    ws.cell(row=1, column=6).value = 'dateCreate'
    ws.cell(row=1, column=7).value = 'dateUpdate'
コード例 #6
0
class PORTS(object):
    def __init__(self):
        # self._epmongo = EPMongo()
        self._epmongo = EPMongo(
            uri=
            "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
            db_name='epdb-prod')

    def get_ports(self):
        self.ports = self._epmongo.get_docs_by_query(
            'ports', {'dateDelete': {
                '$exists': False
            }}, {
                'name': 1,
                'code': 1,
                'country': 1,
                'terminals': 1,
                'shipyards': 1,
                'defaultTerminal': 1
            })
        return self.ports

    def _get_country(self, country_id):
        doc = self._epmongo.get_doc_by_query('countries', {'_id': country_id},
                                             {'name': 1})
        return doc['name']

    def _get_terminal(self, terminal_id):
        doc = self._epmongo.get_doc_by_query('terminals', {'_id': terminal_id},
                                             {
                                                 'name': 1,
                                                 '_id': 1
                                             })
        return doc

    def _get_shipyard(self, shipyard_id):
        doc = self._epmongo.get_doc_by_query('shipyards', {'_id': shipyard_id},
                                             {
                                                 'name': 1,
                                                 '_id': 1
                                             })
        return doc

    def parse_one(self, port_doc):
        port_dict = {}
        _id = port_doc.get('_id')
        port_dict['_id'] = _id
        name = port_doc.get('name')
        port_dict['name'] = name
        code = port_doc.get('code')
        port_dict['code'] = code
        country = self._get_country(port_doc.get('country'))
        port_dict['country'] = country

        terminals = port_doc.get('terminals')
        if terminals is not None and len(terminals) != 0:
            terminals_list = []
            for terminal_id in terminals:
                terminal_doc = self._get_terminal(terminal_id)
                terminals_list.append(terminal_doc)
            port_dict['terminals'] = terminals_list
        shipyards = port_doc.get('shipyards')
        if shipyards is not None and len(shipyards) != 0:
            shipyards_list = []
            for shipyard_id in shipyards:
                shipyard_doc = self._get_shipyard(shipyard_id)
                shipyards_list.append(shipyard_doc)
            port_dict['shipyards'] = shipyards_list

        default_terminal = port_doc.get('defaultTerminal')
        if default_terminal:
            stdb = default_terminal.get('STDB')
            if stdb:
                port_dict['STDB'] = self._get_terminal(stdb)
            stot = default_terminal.get('STOT')
            if stot:
                port_dict['STOT'] = self._get_terminal(stot)
        return port_dict
コード例 #7
0
class CHECK(object):
    def __init__(self):
        with open('check_ships.txt') as f:
            self._ships = [l.strip() for l in f.readlines()]
            # self._epmongo = EPMongo()
        self._epmongo = EPMongo(
            uri=
            "mongodb://*****:*****@172.16.100.1:30001,172.16.100.11:30001,172.16.120.30:30001",
            db_name='epdb-prod')

    @timeit.timeit
    def check_orders(self):
        results = []
        docs = self._epmongo.get_docs_by_query('orders', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_inquiryorders(self):
        results = []
        docs = self._epmongo.get_docs_by_query('inquiryorders', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_voyagesegments(self):
        results = []
        docs = self._epmongo.get_docs_by_query('voyagesegments', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_messages(self):
        results = []
        docs = self._epmongo.get_docs_by_query('messages', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_operationlogs(self):
        results = []
        docs = self._epmongo.get_docs_by_query('operationlogs', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_favships(self):
        results = []
        docs = self._epmongo.get_docs_by_query('favships', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_shipcorrections(self):
        results = []
        docs = self._epmongo.get_docs_by_query('shipcorrections', {}, {
            '_id': 1,
            'ship': 1
        })
        for i, doc in enumerate(docs, 1):
            if str(doc.get('ship')) in self._ships:
                results.append(doc)
        return results

    @timeit.timeit
    def check_fleets(self):
        results = []
        docs = self._epmongo.get_docs_by_query('fleets', {}, {
            '_id': 1,
            'ships': 1
        })
        for i, doc in enumerate(docs, 1):
            ships = doc.get('ships')
            for ship in ships:
                if str(ship) in self._ships:
                    results.append((doc, str(ship)))
        return results

    @timeit.timeit
    def check_ownerships(self):
        results = []
        docs = self._epmongo.get_docs_by_query('ownerships', {}, {
            '_id': 1,
            'ships': 1
        })
        for i, doc in enumerate(docs, 1):
            ships = doc.get('ships')
            for ship in ships:
                if str(ship) in self._ships:
                    results.append((doc, str(ship)))
        return results