vector<Tag> TagDB::getTopTags(int number) { vector<Tag> topTag; if (number == 0 || number<-1) { poco_error_f1(*logger, "getTopTags: Number %d is available", number); return topTag; } vector<Tag> listTag = getAllTag(); int n = listTag.size(); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (listTag.at(i).viewCounts < listTag.at(j).viewCounts) { Tag temp = listTag.at(i); listTag.at(i) = listTag.at(j); listTag.at(j) = temp; } } } if (number > n) { poco_warning_f2(*logger, "getTopTags: number= %d > listTag.size()= %d", number, n); number = n; } for (int i = 0; i < number; i++) { topTag.push_back(listTag.at(i)); } return topTag; }
/*********************************************************************** * Query JSON docs from node **********************************************************************/ static Poco::JSON::Array::Ptr queryBlockDescs(const QString &uri) { try { auto client = Pothos::RemoteClient(uri.toStdString()); auto env = client.makeEnvironment("managed"); return env->findProxy("Pothos/Util/DocUtils").call<Poco::JSON::Array::Ptr>("dumpJson"); } catch (const Pothos::Exception &ex) { poco_warning_f2(Poco::Logger::get("PothosGui.BlockCache"), "Failed to query JSON Docs from %s - %s", uri.toStdString(), ex.displayText()); } return Poco::JSON::Array::Ptr(); //empty JSON array }
vector<Item> ItemDB::getItemsPageKeyword(string keyWord, int64_t pageNumber, int64_t itemNumber) { vector<Item> lItem; if (pageNumber < 1) { poco_error(*logger, "getItemsPage: pageNumber < 0"); return lItem; } if (itemNumber < 1) { poco_error(*logger, "getItemsPage: numberItems < 0"); return lItem; } int64_t size = grassDB.count(); int totalPageNumber; if (size % itemNumber == 0) totalPageNumber = size / itemNumber; else totalPageNumber = size / itemNumber + 1; if (pageNumber > totalPageNumber) { poco_warning_f2(*logger, "getItemsPage: pageNumber = %d > totalPageNumber = %d", pageNumber, totalPageNumber); pageNumber = totalPageNumber; } int64_t first = (pageNumber - 1) * itemNumber; int64_t last = pageNumber * itemNumber; int count = 0; string key, value; DB::Cursor* cur = grassDB.cursor(); cur->jump(); Item item; while (cur->get(&key, &value, true)) { if (Utils::findStringInString(value, keyWord)) { count++; if (count < first) continue; item = convertJsonToItem(value); item.itemID = key; lItem.push_back(item); if (count >= last) break; } } delete cur; return lItem; }
vector<Item> ItemDB::getListTopItem(int64_t number) { vector<Item> result; if (number < 1) { poco_error_f1(*logger, "getListTopItem: number = %d < 0.", number); return result; } if (lTopItemID.empty()) { poco_error(*logger, "getListTopItem: lTopItemID is empty."); return result; } int64_t sizeLTop = lTopItemID.size(); if (number > sizeLTop) { poco_warning_f2(*logger, "getListTopItem: number = %d > lTopItemID.size() = %d", number, sizeLTop); number = sizeLTop; } for (int i = 0; i < number; i++) result.push_back(getItemFromItemID(lTopItemID[i])); return result; }
/** * Lấy List Item theo kiểu phân trang, nếu tagID==-1 thì sẽ lấy trong ItemDB, * tagID>1 thì sẽ lấy Item thuộc tagID đó. * @param pageNumber * @param itemNumber * @param tagID * @return vector<Item> */ vector<Item> ItemDB::getItemsPage(int64_t pageNumber, int32_t numberItems, string tagID, ItemTagDB& itemTagDB) { vector<Item> lItem; if (pageNumber < 1) { poco_error(*logger, "getItemsPage: pageNumber < 0"); return lItem; } if (numberItems < 1) { poco_error(*logger, "getItemsPage: numberItems < 0"); return lItem; } Item item; if (tagID == "-1") { int64_t size = grassDB.count(); int totalPageNumber; if (size % numberItems == 0) totalPageNumber = size / numberItems; else totalPageNumber = size / numberItems + 1; if (pageNumber > totalPageNumber) { poco_warning_f2(*logger, "getItemsPage: pageNumber = %d > totalPageNumber = %d", pageNumber, totalPageNumber); pageNumber = totalPageNumber; } int64_t last = pageNumber * numberItems; int64_t first = (pageNumber - 1) * numberItems - 1; int64_t i = 0; string key, value; DB::Cursor* cur = grassDB.cursor(); cur->jump(); while (i < last) { cur->get(&key, &value, true); if (i > first) { item = convertJsonToItem(value); item.itemID = key; lItem.push_back(item); } i++; } delete cur; } else { vector<string> lItemID = itemTagDB.getAllItemsIdHaveTag(tagID); int64_t sizeLItemID = lItemID.size(); int totalPageNumber; if (sizeLItemID % numberItems == 0) totalPageNumber = sizeLItemID / numberItems; else totalPageNumber = sizeLItemID / numberItems + 1; if (pageNumber > totalPageNumber) { poco_warning_f2(*logger, "getItemsPage: pageNumber = %d > totalPageNumber = %d", pageNumber, totalPageNumber); pageNumber = totalPageNumber; } int64_t last = pageNumber * numberItems; int64_t first = (pageNumber - 1) * numberItems - 1; int64_t i = 0; if (!lItemID.empty()) { for (i = first + 1; i < last; i++) { if (i == sizeLItemID) return lItem; lItem.push_back(getItemFromItemID(lItemID[i])); } } } return lItem; }