示例#1
0
def _build(cfg: dict):
    def _deserialize_model(cfg_model: dict):
        model_als = model.deserialize(cfg_model['als'])
        mappings = model.deserialize(cfg_model['mappings'])
        return model_als, mappings

    cfg_model_reviews, cfg_model_commits = cfg['models']['reviews'], cfg[
        'models']['commits']
    cfg_results = cfg['results']

    model_reviews_als, mappings_reviews = _deserialize_model(cfg_model_reviews)
    model_commits_als, mappings_commits = _deserialize_model(cfg_model_commits)

    model_recommender = model.build(
        layers.MappingsValueToIdPairFallback(
            (mappings_reviews[model.MAPPINGS_ITEM_TO_ID],
             mappings_commits[model.MAPPINGS_ITEM_TO_ID])),
        layers.MappingsIdToEmbeddingPair(
            (model_reviews_als.item_factors, model_commits_als.item_factors)),
        layers.CandidateRecommender(
            (model_reviews_als.user_factors, model_commits_als.user_factors),
            (mappings_reviews[model.MAPPINGS_ID_TO_USER],
             mappings_reviews[model.MAPPINGS_USER_TO_ID]),
            (mappings_commits[model.MAPPINGS_ID_TO_USER],
             mappings_commits[model.MAPPINGS_USER_TO_ID]),
        ),
        layers.RankingRecommender(
            (mappings_reviews[model.MAPPINGS_ID_TO_USER],
             mappings_commits[model.MAPPINGS_ID_TO_USER]),
            (model_reviews_als.user_factors, model_commits_als.user_factors),
        ))

    if cfg_results.get('save', True):
        model.serialize(cfg_results['out'], model_recommender)
示例#2
0
def _train(cfg: dict):
    hyperparameters, cfg_dataset = cfg['hyperparameters'], cfg['dataset']
    cfg_model, cfg_mappings = cfg['model'], cfg['mappings']

    x_df = utils.read_csv(cfg_dataset['path'], usecols=cfg_dataset['cols'])
    model_als, mappings = model.train_als(x_df, cfg_dataset['cols'],
                                          hyperparameters)

    if cfg_model.get('save', True):
        model.serialize(cfg_model['out'], model_als)
    if cfg_mappings.get('save', True):
        model.serialize(cfg_mappings['out'], mappings)
示例#3
0
文件: Orders.py 项目: vdog/piedb
 def serialize(self):
     ret = model.serialize(self)
     if isinstance(self.employee, Employee):
         ret["employee"] = model.serialize(self.employee)
     if isinstance(self.shipper, Shippers):
         ret["shipper"] = model.serialize(self.shipper)
     if isinstance(self.customer, Customer):
         ret["customer"] = model.serialize(self.customer)
     else:
         ret["customer"] = model.serialize(Customer())
     ret["details"] = []
     for d in self.details:
         ret["details"].append(d.serialize())
     return ret
示例#4
0
文件: api.py 项目: vdog/piedb
def get_customers():
    searchTerm = request.args.get("search", "")
    offset = request.args.get("offset", 0)
    limit = request.args.get("limit", 0)
    customers = (
        model.db.query(Customer)
        .filter(
            or_(
                Customer.CustomerID.like("%" + searchTerm + "%"),
                or_(
                    Customer.CustomerFirstName.like("%" + searchTerm + "%"),
                    Customer.CompanyName.like("%" + searchTerm + "%"),
                ),
            )
        )
        .order_by(Customer.CompanyName, Customer.CustomerFirstName, Customer.CustomerID)
        .offset(offset)
        .limit(10)
    )
    # try:
    #    customers = model.db.query(Customer)
    # except Exception, e:
    #    print(e.pgerror)

    if limit == 1:
        return json.dumps(serialize(customers[0]))
    return json.dumps([model.serialize(customer) for customer in customers])
示例#5
0
文件: api.py 项目: vdog/piedb
def get_subproducts():
    productID = request.args.get("productID", "NONE")
    if productID != "NONE":
        subproducts = model.db.query(Prod_SubProd).filter(Prod_SubProd.ProductID == productID)
    else:
        subproducts = model.db.query(Prod_SubProd)
    return json.dumps([model.serialize(sub) for sub in subproducts])
    def test_serialization(self):
        a = A()
        a.b = 1

        d = D()
        d.e = 2
        d.f = 3

        a.c = d

        streams = serialize(a, "a")
        self.assertEquals(streams,
            [
                {"kind": "D", "attrs": {"e": 2, "f": 3}, "uid": "a.c"},
                {"kind": "A", "attrs": {"b": 1}, "uid": "a", "refs": {"a.c": "c"}},
            ]
        )
    def test_serialization_lists(self):
        ## XXX stand by
        return
        a1 = A()
        a1.b = 1
        a1.c = 2

        a2 = A()
        a2.b = 3
        a2.c = 4

        l = L()
        l.l = [a1, a2]
        streams = serialize(l, "l")
        self.assertEquals(streams,
            [
                {"kind": "A", "attrs": {"b": 1, "c": 2}, "uid": "l.l.0"},
                {"kind": "A", "attrs": {"b": 3, "c": 4}, "uid": "l.l.1"},
                {"kind": "L", "uid": "l", "lists": {"l": 2}},
            ]
        )
示例#8
0
文件: api.py 项目: vdog/piedb
def new_detail():
    detail = OrderDetails()
    return json.dumps(model.serialize(detail))
示例#9
0
文件: api.py 项目: vdog/piedb
def get_employees():
    employees = model.db.query(Employee)
    return json.dumps([model.serialize(employee) for employee in employees])
示例#10
0
 def serialize(self):
   ret = model.serialize(self)
   ret['subproducts'] = []
   for s in self.subproducts:
     ret['subproducts'].append(model.serialize(s))
   return ret
示例#11
0
 def serialize(self):
   ret = model.serialize(self)
   ret['product'] = self.product.serialize()
   ret['subproduct'] = model.serialize(self.subproduct)
   return ret