def get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history=False):
    collection_obj = Collection.query.get(cid)
    collection_doc = get_collection_doc_from_object(collection_obj)
    if not collection_doc:
        return (None, None)

    collection_doc["items"] = []
    tiids = collection_obj.tiids

    if tiids:
        item_metric_dicts = get_readonly_item_metric_dicts(tiids)

        for tiid in item_metric_dicts:
            #logger.info(u"got item {tiid} for {cid}".format(
            #    tiid=item_obj.tiid, cid=cid))
            try:
                item_for_client = item_module.build_item_for_client(item_metric_dicts[tiid], myrefsets, myredis)
            except (KeyError, TypeError, AttributeError):
                logger.info(u"Couldn't build item {tiid}, excluding it from the returned collection {cid}".format(
                    tiid=tiid, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection_doc["items"] += [item_for_client]
    
    something_currently_updating = not is_all_done(tiids, myredis)

    # logger.debug(u"Got items for collection_doc %s" %cid)

    return (collection_doc, something_currently_updating)
 def test_build_item_for_client_includes_history_with_arg(self):
     response = item_module.build_item_for_client(
         self.ITEM_DATA,
         self.myrefsets,
         self.d,
         include_history=True
     )
     assert_equals(
         response["metrics"]["wikipedia:mentions"]["values"]["raw_history"][self.KEY1],
         self.VAL1
     )
def get_items_for_client(tiids, myrefsets, myredis, most_recent_metric_date=None, most_recent_diff_metric_date=None):
    item_metric_dicts = get_readonly_item_metric_dicts(tiids, most_recent_metric_date, most_recent_diff_metric_date)

    dict_of_item_docs = {}
    for tiid in item_metric_dicts:
        try:
            item_doc_for_client = item_module.build_item_for_client(item_metric_dicts[tiid], myrefsets, myredis)
            dict_of_item_docs[tiid] = item_doc_for_client
        except (KeyError, TypeError, AttributeError):
            logger.info(u"Couldn't build item {tiid}".format(tiid=tiid))
            raise
    
    return dict_of_item_docs
def get_items_for_client(tiids, myrefsets, myredis):
    item_objects = get_readonly_item_objects_with_metrics(tiids)

    dict_of_item_docs = {}
    for item_obj in item_objects:
        try:
            item_doc = item_obj.as_old_doc()
            item_doc_for_client = item_module.build_item_for_client(item_doc, myrefsets, myredis)
            dict_of_item_docs[item_obj.tiid] = item_doc_for_client
        except (KeyError, TypeError, AttributeError):
            logger.info(u"Couldn't build item {tiid}".format(tiid=item_obj.tiid))
            raise
    
    return dict_of_item_docs
Exemple #5
0
 def test_build_item_for_client_includes_history_with_arg(self):
     response = item_module.build_item_for_client(
         self.ITEM_DATA,
         self.myrefsets,
         self.d,
         include_history=True
     )
     assert_equals(
         response["metrics"]["wikipedia:mentions"]["values"]["raw_history"][self.KEY1],
         self.VAL1
     )
     assert_equals(
         response["metrics"]["wikipedia:mentions"]["values"]["raw_history"][self.KEY2],
         self.VAL2
     )
def get_items_for_client(tiids, myrefsets, myredis):
    item_objects = get_readonly_item_objects_with_metrics(tiids)

    dict_of_item_docs = {}
    for item_obj in item_objects:
        try:
            item_doc = item_obj.as_old_doc()
            item_doc_for_client = item_module.build_item_for_client(
                item_doc, myrefsets, myredis)
            dict_of_item_docs[item_obj.tiid] = item_doc_for_client
        except (KeyError, TypeError, AttributeError):
            logger.info(
                u"Couldn't build item {tiid}".format(tiid=item_obj.tiid))
            raise

    return dict_of_item_docs
def get_items_for_client(tiids,
                         myrefsets,
                         myredis,
                         most_recent_metric_date=None,
                         most_recent_diff_metric_date=None):
    item_metric_dicts = get_readonly_item_metric_dicts(
        tiids, most_recent_metric_date, most_recent_diff_metric_date)

    dict_of_item_docs = {}
    for tiid in item_metric_dicts:
        try:
            item_doc_for_client = item_module.build_item_for_client(
                item_metric_dicts[tiid], myrefsets, myredis)
            dict_of_item_docs[tiid] = item_doc_for_client
        except (KeyError, TypeError, AttributeError):
            logger.info(u"Couldn't build item {tiid}".format(tiid=tiid))
            raise

    return dict_of_item_docs
def get_collection_with_items_for_client(cid,
                                         myrefsets,
                                         myredis,
                                         mydao,
                                         include_history=False):
    collection_obj = Collection.query.get(cid)
    collection_doc = get_collection_doc_from_object(collection_obj)
    if not collection_doc:
        return (None, None)

    collection_doc["items"] = []
    tiids = collection_obj.tiids

    if tiids:
        item_objects = get_readonly_item_objects_with_metrics(tiids)

        for item_obj in item_objects:
            #logger.info(u"got item {tiid} for {cid}".format(
            #    tiid=item_obj.tiid, cid=cid))
            try:
                item_doc = item_obj.as_old_doc()
                item_for_client = item_module.build_item_for_client(
                    item_doc, myrefsets, myredis)
            except (KeyError, TypeError, AttributeError):
                logger.info(
                    u"Couldn't build item {tiid}, excluding it from the returned collection {cid}"
                    .format(tiid=item_obj.tiid, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection_doc["items"] += [item_for_client]

    something_currently_updating = False
    for item in collection_doc["items"]:
        item["currently_updating"] = item_module.is_currently_updating(
            item["_id"], myredis)
        something_currently_updating = something_currently_updating or item[
            "currently_updating"]

    logger.debug(u"Got items for collection_doc %s" % cid)

    return (collection_doc, something_currently_updating)
def get_collection_with_items_for_client(cid, myrefsets, myredis, mydao, include_history=False):
    startkey = [cid, 0]
    endkey = [cid, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"]
    view_response = mydao.db.view("collections_with_items/collections_with_items", 
                        include_docs=True, 
                        startkey=startkey, 
                        endkey=endkey)
    # the first row is the collection document
    first_row = view_response.rows[0]
    collection = first_row.doc
    try:
        del collection["ip_address"]
    except KeyError:
        pass
    del collection["alias_tiids"]

    # start with the 2nd row, since 1st row is the collection document
    collection["items"] = []
    if len(view_response.rows) > 1:
        for row in view_response.rows[1:]:
            item_doc = row.doc 
            try:
                item_for_client = item_module.build_item_for_client(item_doc, myrefsets, mydao, include_history)
            except (KeyError, TypeError):
                logging.info("Couldn't build item {item_doc}, excluding it from the returned collection {cid}".format(
                    item_doc=item_doc, cid=cid))
                item_for_client = None
                raise
            if item_for_client:
                collection["items"] += [item_for_client]
    
    something_currently_updating = False
    for item in collection["items"]:
        item["currently_updating"] = item_module.is_currently_updating(item["_id"], myredis)
        something_currently_updating = something_currently_updating or item["currently_updating"]

    logging.info("Got items for collection %s" %cid)
    # print json.dumps(collection, sort_keys=True, indent=4)
    return (collection, something_currently_updating)
 def test_build_item_for_client_excludes_history_by_default(self):
     response = item_module.build_item_for_client(self.ITEM_DATA, self.myrefsets, self.r)
     assert_equals(response["metrics"]["wikipedia:mentions"]["values"].keys(), ["raw"])
     assert_equals(response["metrics"]["altmetric_com:tweets"]["values"].keys(), ["raw"])
 def test_build_item_for_client(self):
     item = {'created': '2012-08-23T14:40:16.399932', '_rev': '6-3e0ede6e797af40860e9dadfb39056ce', 'last_modified': '2012-08-23T14:40:16.399932', 'biblio': {'title': 'Perceptual training strongly improves visual motion perception in schizophrenia', 'journal': 'Brain and Cognition', 'year': 2011, 'authors': u'Norton, McBain, \xd6ng\xfcr, Chen'}, '_id': '4mlln04q1rxy6l9oeb3t7ftv', 'type': 'item', 'aliases': {'url': ['http://linkinghub.elsevier.com/retrieve/pii/S0278262611001308', 'http://www.ncbi.nlm.nih.gov/pubmed/21872380'], 'pmid': ['21872380'], 'doi': ['10.1016/j.bandc.2011.08.003'], 'title': ['Perceptual training strongly improves visual motion perception in schizophrenia']}}
     response = item_module.build_item_for_client(item, self.myrefsets, self.r)
     assert_equals(set(response.keys()), set(['currently_updating', 'created', '_rev', 'metrics', 'last_modified', 'biblio', '_id', 'type', 'aliases']))
Exemple #12
0
 def test_build_item_for_client_excludes_history_by_default(self):
     response = item_module.build_item_for_client(self.ITEM_DATA, self.myrefsets, self.d)
     assert_equals(response["metrics"]["wikipedia:mentions"]["values"].keys(), ["raw"])
     assert_equals(response["metrics"]["topsy:tweets"]["values"].keys(), ["raw"])
Exemple #13
0
 def test_build_item_for_client(self):
     item = {'created': '2012-08-23T14:40:16.399932', '_rev': '6-3e0ede6e797af40860e9dadfb39056ce', 'last_modified': '2012-08-23T14:40:16.399932', 'biblio': {'title': 'Perceptual training strongly improves visual motion perception in schizophrenia', 'journal': 'Brain and Cognition', 'year': 2011, 'authors': u'Norton, McBain, \xd6ng\xfcr, Chen'}, '_id': '4mlln04q1rxy6l9oeb3t7ftv', 'type': 'item', 'aliases': {'url': ['http://linkinghub.elsevier.com/retrieve/pii/S0278262611001308', 'http://www.ncbi.nlm.nih.gov/pubmed/21872380'], 'pmid': ['21872380'], 'doi': ['10.1016/j.bandc.2011.08.003'], 'title': ['Perceptual training strongly improves visual motion perception in schizophrenia']}}
     response = item_module.build_item_for_client(item, self.myrefsets, self.d, False)
     assert_equals(set(response.keys()), set(['created', '_rev', 'metrics', 'last_modified', 'biblio', '_id', 'type', 'aliases']))