edwinaaa
Member
- Joined
- Jan 31, 2014
- Messages
- 75
- Reaction score
- 11
Hello, how are you? I'm having a problem with the updatestadistic system. What it does is set the lowest and highest price and the average price of said product. The problem is that it shows everything in min 0, max 0, etc., in advance say that the market_history table already has the records but in the C++ of the code there is a problem that it does not read the amounts can someone help me?
C++:
(iomarket.cpp)
void IOMarket::updateStatistics()
{
Database& db = Database::getInstance();
std::ostringstream query;
query << "SELECT `sale`, `itemtype`, COUNT(`price`) AS `num`, MIN(`price`) AS `min`, MAX(`price`) AS `max`, SUM(`price`) AS `sum` FROM `market_history` WHERE `state` = "
<< OFFERSTATE_ACCEPTED << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " GROUP BY `itemtype`, `sale`;";
DBResult_ptr result = db.storeQuery(query.str());
if (!result) {
return;
}
do {
MarketStatistics* statistics;
if (result->getNumber<uint16_t>("sale") == MARKETACTION_BUY) {
statistics = &purchaseStatistics[result->getNumber<uint16_t>("itemtype")];
}
else {
statistics = &saleStatistics[result->getNumber<uint16_t>("itemtype")];
}
statistics->numTransactions = result->getNumber<uint32_t>("num");
statistics->lowestPrice = result->getNumber<uint32_t>("min");
statistics->totalPrice = result->getNumber<uint64_t>("sum");
statistics->highestPrice = result->getNumber<uint32_t>("max");
} while (result->next());
}
C++:
(protocolgame.cpp)
MarketStatistics* statistics = IOMarket::getInstance().getPurchaseStatistics(itemId);
if (statistics)
{
msg.addByte(0x01);
msg.add<uint32_t>(statistics->numTransactions);
msg.add<uint64_t>(statistics->totalPrice);
msg.add<uint64_t>(statistics->highestPrice);
msg.add<uint64_t>(statistics->lowestPrice);
}
else
{
msg.addByte(0x00);
}
statistics = IOMarket::getInstance().getSaleStatistics(itemId);
if (statistics)
{
msg.addByte(0x01);
msg.add<uint32_t>(statistics->numTransactions);
msg.add<uint64_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), statistics->totalPrice));
msg.add<uint64_t>(statistics->highestPrice);
msg.add<uint64_t>(statistics->lowestPrice);
}
else
{
msg.addByte(0x00);
}