void FeedPool::UpdateInteraction(){ MCE_INFO("FeedPool::UpdateInteraction --> begin cache size:" << TotalCount()); int miss_size = 0; for(int i=0; i<kPoolSize; i++){ LongSeq feed_ids; set<Ice::Long> idset; //map<Ice::Long, int> reply_counts; FeedInteractionCountSeq counts; { IceUtil::Mutex::Lock lock(mutex_[i]); hash_map<Ice::Long, Feed*>::iterator it = feed_map_[i].begin(); for(; it!=feed_map_[i].end(); ++it){ feed_ids.push_back(it->first); idset.insert(it->first); } } //MCE_INFO("FeedPool::UpdateInteraction --> pool " << i << " size:" << feed_ids.size()); LongSeq tmp_ids; for(size_t j=0; j<feed_ids.size(); j++){ //MCE_INFO("@@@@@@@@ " << feed_ids.at(j)); tmp_ids.push_back(feed_ids.at(j)); if(tmp_ids.size()==1000 || j==feed_ids.size()-1){ FeedInteractionCountSeq count_seq; try{ MCE_INFO("FeedPool::UpdateInteraction --> update size:" << tmp_ids.size()); //TimeStat ts; count_seq = FeedInteractionNAdapter::instance().GetFeedInteractionCountSeq(tmp_ids, false); //PerformanceStat::instance().stat("QueryInteractionCache", ts.getTime()); //fdict = FeedInteractionAdapter::instance().getFeedDict(tmp_ids); }catch(Ice::Exception& e){ MCE_WARN("FeedPool::UpdateInteraction --> call FeedInteractionN size:" << tmp_ids.size() << ", " << e); } counts.insert(counts.end(), count_seq.begin(), count_seq.end()); tmp_ids.clear(); } } { IceUtil::Mutex::Lock lock(mutex_[i]); for(size_t n=0; n<counts.size(); n++){ idset.erase(counts.at(n)->feed); //set<Ice::Long>::iterator it = idset.find(counts.at(n)->feed); //MCE_INFO("@@@Interaction --> feed:" << counts.at(n)->feed << " click:" << counts.at(n)->clickCount << " reply:" << counts.at(n)->replyCount); FeedMap::iterator tmp_it = feed_map_[i].find(counts.at(n)->feed); if(tmp_it != feed_map_[i].end()){ tmp_it->second->reply_count_ = counts.at(n)->replyCount; tmp_it->second->click_count_ = counts.at(n)->clickCount; tmp_it->second->range_ = counts.at(n)->range; } } } MCE_INFO("FeedPool::UpdateInteraction --> " << feed_ids.size() << " miss " << idset.size()); miss_size += idset.size(); set<Ice::Long>::iterator it = idset.begin(); for(; it!=idset.end(); ++it){ UpdateInteractionInDBTimer::instance().insert(*it); } } MCE_INFO("FeedPool::UpdateInteraction --> end miss:" << miss_size); }
void GenerateEncounterTable (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; // Get the criteria from the command line SEncounterCriteria Criteria; ParseEncounterCriteria(pCmdLine->GetAttribute(CRITERIA_ATTRIB), &Criteria); bool bAll = pCmdLine->GetAttributeBool(ALL_ATTRIB); // Generate a table of all matching encounters CSymbolTable Table(FALSE, TRUE); // Loop over all items for this level and add them to // a sorted table. for (i = 0; i < Universe.GetStationTypeCount(); i++) { CStationType *pType = Universe.GetStationType(i); int iLevel = pType->GetLevel(); if (iLevel == 0 && !bAll) continue; // If we don't match the criteria, then continue if (!MatchesEncounterCriteria(Criteria, pType->GetAttributes())) continue; // Get the category and name CString sCategory = pType->GetDataField(FIELD_CATEGORY); CString sName = pType->GetDataField(FIELD_NAME); if (*sName.GetASCIIZPointer() == '(') sName = strSubString(sName, 1, -1); // Figure out the sort order char szBuffer[1024]; wsprintf(szBuffer, "%02d%s%s", pType->GetLevel(), sCategory.GetASCIIZPointer(), sName.GetASCIIZPointer()); Table.AddEntry(CString(szBuffer), (CObject *)pType); } // Generate a list of columns to display CStringArray Cols; Cols.AppendString(FIELD_LEVEL); Cols.AppendString(FIELD_CATEGORY); Cols.AppendString(FIELD_NAME); if (pCmdLine->GetAttributeBool(FIELD_ARMOR_CLASS)) Cols.AppendString(FIELD_ARMOR_CLASS); if (pCmdLine->GetAttributeBool(FIELD_HP)) Cols.AppendString(FIELD_HP); if (pCmdLine->GetAttributeBool(FIELD_FIRE_RATE_ADJ)) Cols.AppendString(FIELD_FIRE_RATE_ADJ); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) Cols.AppendString(FIELD_TOTAL_COUNT); if (pCmdLine->GetAttributeBool(FIELD_CAN_ATTACK)) Cols.AppendString(FIELD_CAN_ATTACK); if (pCmdLine->GetAttributeBool(FIELD_EXPLOSION_TYPE)) Cols.AppendString(FIELD_EXPLOSION_TYPE); // If we need to output total count, then load the table CSymbolTable TotalCount(TRUE, TRUE); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) { if (error = LoadTotalCount(TOTAL_COUNT_FILENAME, TotalCount)) return; } // If we've got any entries in the table, output now if (Table.GetCount()) { // Output the header for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); printf(Cols.GetStringValue(j).GetASCIIZPointer()); } printf("\n"); // Output each row for (i = 0; i < Table.GetCount(); i++) { CStationType *pType = (CStationType *)Table.GetValue(i); for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); CString sField = Cols.GetStringValue(j); CString sValue = pType->GetDataField(sField); if (strEquals(sField, FIELD_FIRE_RATE_ADJ)) printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0); else if (strEquals(sField, FIELD_TOTAL_COUNT)) { double rCount = 0.0; CString sKey = strFromInt(pType->GetUNID(), FALSE); EntryInfo *pEntry; if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR) rCount = pEntry->rTotalCount; printf("%.2f", rCount); } else printf(sValue.GetASCIIZPointer()); } printf("\n"); } printf("\n"); } else printf("No entries match criteria.\n"); }
void GenerateEncounterTable (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; // Get the criteria from the command line. Always append 't' because we // want station types. CString sCriteria = strPatternSubst(CONSTLIT("%s t"), pCmdLine->GetAttribute(CRITERIA_ATTRIB)); // Parse it CDesignTypeCriteria Criteria; if (CDesignTypeCriteria::ParseCriteria(sCriteria, &Criteria) != NOERROR) { printf("ERROR: Unable to parse criteria.\n"); return; } bool bAll = pCmdLine->GetAttributeBool(ALL_ATTRIB); // Generate a table of all matching encounters CSymbolTable Table(FALSE, TRUE); // Loop over all items for this level and add them to // a sorted table. for (i = 0; i < Universe.GetStationTypeCount(); i++) { CStationType *pType = Universe.GetStationType(i); int iLevel = pType->GetLevel(); if (iLevel == 0 && !bAll) continue; // If we don't match the criteria, then continue if (!pType->MatchesCriteria(Criteria)) continue; // Get the category and name CString sCategory = pType->GetDataField(FIELD_CATEGORY); CString sName = pType->GetDataField(FIELD_NAME); if (*sName.GetASCIIZPointer() == '(') sName = strSubString(sName, 1, -1); // Figure out the sort order char szBuffer[1024]; wsprintf(szBuffer, "%02d%s%s", pType->GetLevel(), sCategory.GetASCIIZPointer(), sName.GetASCIIZPointer()); Table.AddEntry(CString(szBuffer), (CObject *)pType); } // Generate a list of columns to display TArray<CString> Cols; Cols.Insert(FIELD_LEVEL); Cols.Insert(FIELD_CATEGORY); Cols.Insert(FIELD_NAME); for (i = 0; i < pCmdLine->GetAttributeCount(); i++) { CString sAttrib = pCmdLine->GetAttributeName(i); if (!strEquals(sAttrib, CONSTLIT("all")) && !strEquals(sAttrib, CONSTLIT("criteria")) && !strEquals(sAttrib, CONSTLIT("encountertable")) && !strEquals(sAttrib, CONSTLIT("nologo"))) { CString sValue = pCmdLine->GetAttribute(i); if (!strEquals(sValue, CONSTLIT("true"))) Cols.Insert(strPatternSubst(CONSTLIT("%s:%s"), sAttrib, sValue)); else Cols.Insert(sAttrib); } } #if 0 if (pCmdLine->GetAttributeBool(FIELD_ARMOR_CLASS)) Cols.Insert(FIELD_ARMOR_CLASS); if (pCmdLine->GetAttributeBool(FIELD_HP)) Cols.Insert(FIELD_HP); if (pCmdLine->GetAttributeBool(FIELD_FIRE_RATE_ADJ)) Cols.Insert(FIELD_FIRE_RATE_ADJ); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) Cols.Insert(FIELD_TOTAL_COUNT); if (pCmdLine->GetAttributeBool(FIELD_CAN_ATTACK)) Cols.Insert(FIELD_CAN_ATTACK); if (pCmdLine->GetAttributeBool(FIELD_EXPLOSION_TYPE)) Cols.Insert(FIELD_EXPLOSION_TYPE); #endif // If we need to output total count, then load the table CSymbolTable TotalCount(TRUE, TRUE); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) { if (error = LoadTotalCount(TOTAL_COUNT_FILENAME, TotalCount)) return; } // If we've got any entries in the table, output now if (Table.GetCount()) { // Output the header for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); printf(Cols[j].GetASCIIZPointer()); } printf("\n"); // Output each row for (i = 0; i < Table.GetCount(); i++) { CStationType *pType = (CStationType *)Table.GetValue(i); for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); const CString &sField = Cols[j]; CString sValue = pType->GetDataField(sField); if (strEquals(sField, FIELD_FIRE_RATE_ADJ)) printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0); else if (strEquals(sField, FIELD_TOTAL_COUNT)) { double rCount = 0.0; CString sKey = strFromInt(pType->GetUNID(), false); EntryInfo *pEntry; if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR) rCount = pEntry->rTotalCount; printf("%.2f", rCount); } else printf(sValue.GetASCIIZPointer()); } printf("\n"); } printf("\n"); } else printf("No entries match criteria.\n"); }
void GenerateItemTable (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; // Compute the criteria CItemCriteria Crit; CString sCriteria; if (pCmdLine->FindAttribute(CRITERIA_ATTRIB, &sCriteria)) CItem::ParseCriteria(sCriteria, &Crit); else CItem::InitCriteriaAll(&Crit); // Generate a table CSymbolTable Table(FALSE, TRUE); // Loop over all items that match and add them to // a sorted table. for (j = 0; j < Universe.GetItemTypeCount(); j++) { CItemType *pType = Universe.GetItemType(j); CItem Item(pType, 1); if (!Item.MatchesCriteria(Crit)) continue; // Figure out the sort order char szBuffer[1024]; wsprintf(szBuffer, "%02d%s%02d%s", pType->GetLevel(), g_szTypeCode[GetItemType(pType)], GetItemFreq(pType), pType->GetNounPhrase().GetASCIIZPointer()); Table.AddEntry(CString(szBuffer), (CObject *)pType); } // If we need to output total count, then load the table CSymbolTable TotalCount(TRUE, TRUE); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) { if (error = LoadTotalCount(TOTAL_COUNT_FILENAME, TotalCount)) return; } // If we've got any entries in the table, output now if (Table.GetCount()) { // Generate a list of columns to display CStringArray Cols; Cols.AppendString(FIELD_LEVEL); Cols.AppendString(FIELD_TYPE); Cols.AppendString(FIELD_FREQUENCY); Cols.AppendString(FIELD_NAME); // More columns from command-line if (pCmdLine->GetAttributeBool(FIELD_AVERAGE_COUNT)) Cols.AppendString(FIELD_AVERAGE_COUNT); if (pCmdLine->GetAttributeBool(FIELD_BALANCE)) Cols.AppendString(FIELD_BALANCE); if (pCmdLine->GetAttributeBool(FIELD_COST)) Cols.AppendString(FIELD_COST); if (pCmdLine->GetAttributeBool(FIELD_INSTALL_COST)) Cols.AppendString(FIELD_INSTALL_COST); if (pCmdLine->GetAttributeBool(FIELD_MASS)) Cols.AppendString(FIELD_MASS); if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)) Cols.AppendString(FIELD_TOTAL_COUNT); if (pCmdLine->GetAttributeBool(FIELD_REFERENCE)) Cols.AppendString(FIELD_REFERENCE); if (pCmdLine->GetAttributeBool(FIELD_HP)) Cols.AppendString(FIELD_HP); if (pCmdLine->GetAttributeBool(FIELD_HP_BONUS)) Cols.AppendString(FIELD_HP_BONUS); if (pCmdLine->GetAttributeBool(FIELD_REGEN)) Cols.AppendString(FIELD_REGEN); if (pCmdLine->GetAttributeBool(FIELD_FIRE_DELAY)) Cols.AppendString(FIELD_FIRE_DELAY); if (pCmdLine->GetAttributeBool(FIELD_THRUST)) Cols.AppendString(FIELD_THRUST); if (pCmdLine->GetAttributeBool(FIELD_POWER)) Cols.AppendString(FIELD_POWER); if (pCmdLine->GetAttributeBool(FIELD_POWER_PER_SHOT)) Cols.AppendString(FIELD_POWER_PER_SHOT); if (pCmdLine->GetAttributeBool(FIELD_AVERAGE_DAMAGE)) Cols.AppendString(FIELD_AVERAGE_DAMAGE); if (pCmdLine->GetAttributeBool(FIELD_MAX_SPEED)) Cols.AppendString(FIELD_MAX_SPEED); // Output the header for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); printf(Cols.GetStringValue(j).GetASCIIZPointer()); } printf("\n"); // Output each row for (i = 0; i < Table.GetCount(); i++) { CItemType *pType = (CItemType *)Table.GetValue(i); for (j = 0; j < Cols.GetCount(); j++) { if (j != 0) printf("\t"); CString sField = Cols.GetStringValue(j); CString sValue = pType->GetDataField(sField); if (strEquals(sField, FIELD_AVERAGE_DAMAGE) || strEquals(sField, FIELD_POWER_PER_SHOT)) printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0); else if (strEquals(sField, FIELD_POWER)) printf("%.1f", strToInt(sValue, 0, NULL) / 1000.0); else if (strEquals(sField, FIELD_TOTAL_COUNT)) { double rCount = 0.0; CString sKey = strFromInt(pType->GetUNID(), FALSE); EntryInfo *pEntry; if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR) rCount = pEntry->rTotalCount; printf("%.2f", rCount); } else printf(sValue.GetASCIIZPointer()); } printf("\n"); } printf("\n"); } else printf("No entries match criteria.\n"); }