public static function getChartDatasetDataForItem(Item $item, \ModelCriteria $q)
 {
     $data = array('raw' => array(), 'daily' => array(), 'weekly' => array(), 'monthly' => array());
     $listings = $q->select(array('listingDatetime'))->withColumn('SUM(quantity)', 'quantity')->withColumn('MIN(unit_price)', 'min_unit_price')->groupBy('listingDatetime')->filterByItemId($item->getDataId())->find();
     /*
      * use these 3 arrays to maintain the values over which we calculate the moving average
      *  every value is added to the array, but we pop off values older then the specified threshold (day, week, month)
      */
     $dailyCntValues = array();
     $dailyValues = array();
     $weeklyValues = array();
     $monthlyValues = array();
     foreach ($listings as $listingEntry) {
         $date = new DateTime("{$listingEntry['listingDatetime']}");
         $date->setTimezone(new DateTimeZone('UTC'));
         $timestamp = $date->getTimestamp();
         $dailyCntValues[$timestamp] = $listingEntry['quantity'];
         $dailyValues[$timestamp] = $listingEntry['min_unit_price'];
         $weeklyValues[$timestamp] = $listingEntry['min_unit_price'];
         $monthlyValues[$timestamp] = $listingEntry['min_unit_price'];
         $listingEntry['min_unit_price'] = round($listingEntry['min_unit_price'], 2);
         foreach ($dailyCntValues as $keyTimestamp => $value) {
             if ($timestamp - $keyTimestamp > 86400) {
                 unset($dailyCntValues[$keyTimestamp]);
             } else {
                 break;
             }
         }
         foreach ($dailyValues as $keyTimestamp => $value) {
             if ($timestamp - $keyTimestamp > 86400) {
                 unset($dailyValues[$keyTimestamp]);
             } else {
                 break;
             }
         }
         foreach ($weeklyValues as $keyTimestamp => $value) {
             if ($timestamp - $keyTimestamp > 604800) {
                 unset($weeklyValues[$keyTimestamp]);
             } else {
                 break;
             }
         }
         foreach ($monthlyValues as $keyTimestamp => $value) {
             if ($timestamp - $keyTimestamp > 18144000) {
                 unset($monthlyValues[$keyTimestamp]);
             } else {
                 break;
             }
         }
         $data['raw'][] = array($timestamp * 1000, $listingEntry['min_unit_price']);
         $data['daily'][] = array($timestamp * 1000, round(array_sum($dailyValues) / count($dailyValues), 2));
         $data['weekly'][] = array($timestamp * 1000, round(array_sum($weeklyValues) / count($weeklyValues), 2));
         $data['monthly'][] = array($timestamp * 1000, round(array_sum($monthlyValues) / count($monthlyValues), 2));
         $data['cnt'][] = array($timestamp * 1000, (int) $listingEntry['quantity']);
         $data['daily_cnt'][] = array($timestamp * 1000, round(array_sum($dailyCntValues) / count($dailyCntValues), 2));
     }
     return $data;
 }
Example #2
0
 public function getItemVolumeDataset(Item $item, $type)
 {
     $cacheKey = "item_v_{$item->getDataId()}_{$type}";
     $dataset = $this->cache->get($cacheKey);
     if (!$this->useCache || !$dataset) {
         $dataset = new ItemVolumeDataset($item->getDataId(), $type);
     }
     $dataset->updateDataset();
     $this->cache->set($cacheKey, $dataset);
     return $dataset;
 }
/**
 * @param $API_JSON
 * @param $offset
 */
function processApiData($API_JSON, $offset)
{
    $APIItems = APIItemV2::getMultipleItemsByJSON($API_JSON);
    try {
        $itemCount = $offset;
        foreach ($APIItems as $APIItem) {
            $itemCount++;
            if ($APIItem == null) {
                print "Skipped item {$itemCount} on page {$offset}.\n";
                continue;
            }
            echo "{$itemCount}: {$APIItem->getName()} (ID: {$APIItem->getItemId()})\n";
            $itemData = array('TypeId' => getOrCreateTypeID($APIItem->getMarketType()), 'DataId' => $APIItem->getItemId(), 'Name' => $APIItem->getName(), 'RestrictionLevel' => $APIItem->getLevel(), 'Rarity' => getRarityID($APIItem->getRarity()), 'VendorSellPrice' => $APIItem->getVendorValue(), 'Img' => $APIItem->getImageURL(), 'RarityWord' => $APIItem->getRarity(), 'UnsellableFlag' => $APIItem->isUnsellable());
            $item = ItemQuery::create()->findPK($APIItem->getItemId());
            if ($item === null) {
                $item = new Item();
            }
            $item->fromArray($itemData);
            $itemType = ItemTypeQuery::create()->findPk($itemData['TypeId']);
            if ($itemType !== null) {
                if ($APIItem->getSubType() !== null) {
                    $itemSubType = ItemSubTypeQuery::create()->findOneByTitle($APIItem->getDBSubType());
                    if ($itemSubType === null) {
                        //All of the below types are known to not exist in the market data with an ID (by this name).
                        //Rune/Sigil/Utility/Gem/Booze/Halloween/LargeBundle/RentableContractNpc/ContractNPC/UnlimitedConsumable
                        //TwoHandedToy/AppearanceChange/Immediate/Unknown
                        $itemSubTypes = ItemSubTypeQuery::create()->filterByMainTypeId($itemData['TypeId'])->withColumn('MAX(id)', 'MAXid')->find();
                        $SubTypeID = $itemSubTypes[0]->getMAXid() + 1;
                        $itemSubType = new ItemSubType();
                        $itemSubType->fromArray(array('Id' => $SubTypeID, 'MainTypeId' => $itemData['TypeId'], 'Title' => $APIItem->getDBSubType()));
                        $itemSubType->save();
                        $itemType->addSubType($itemSubType);
                        $item->setItemSubType($itemSubType);
                    }
                    $itemType->addSubType($itemSubType);
                    $item->setItemSubType($itemSubType);
                }
                $item->setItemType($itemType);
            }
            $item->save();
        }
    } catch (Exception $e) {
        echo "failed [[ {$e->getMessage()} ]] .. \n";
    }
}
Example #4
0
 /**
  * Declares an association between this object and a Item object.
  *
  * @param                  Item $v
  * @return                 Recipe The current object (for fluent API support)
  * @throws PropelException
  */
 public function setResultItem(Item $v = null)
 {
     if ($v === null) {
         $this->setResultItemId(NULL);
     } else {
         $this->setResultItemId($v->getDataId());
     }
     $this->aResultItem = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Item object, it will not be re-added.
     if ($v !== null) {
         $v->addResultOfRecipe($this);
     }
     return $this;
 }
 /**
  * Filter the query by a related Item object
  *
  * @param   Item|PropelObjectCollection $item The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return   BuyListingQuery The current query, for fluid interface
  * @throws   PropelException - if the provided filter is invalid.
  */
 public function filterByItem($item, $comparison = null)
 {
     if ($item instanceof Item) {
         return $this->addUsingAlias(BuyListingPeer::ITEM_ID, $item->getDataId(), $comparison);
     } elseif ($item instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(BuyListingPeer::ITEM_ID, $item->toKeyValue('PrimaryKey', 'DataId'), $comparison);
     } else {
         throw new PropelException('filterByItem() only accepts arguments of type Item or PropelCollection');
     }
 }
 /**
  * Filter the query by a related Item object
  *
  * @param   Item|PropelObjectCollection $item  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return   ItemSubTypeQuery The current query, for fluid interface
  * @throws   PropelException - if the provided filter is invalid.
  */
 public function filterByItem($item, $comparison = null)
 {
     if ($item instanceof Item) {
         return $this->addUsingAlias(ItemSubTypePeer::ID, $item->getItemSubTypeId(), $comparison);
     } elseif ($item instanceof PropelObjectCollection) {
         return $this->useItemQuery()->filterByPrimaryKeys($item->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByItem() only accepts arguments of type Item or PropelCollection');
     }
 }
Example #7
0
 /**
  * Exclude object from result
  *
  * @param   Item $item Object to remove from the list of results
  *
  * @return ItemQuery The current query, for fluid interface
  */
 public function prune($item = null)
 {
     if ($item) {
         $this->addUsingAlias(ItemPeer::DATA_ID, $item->getDataId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #8
0
 /**
  * @param	Item $item The item object to add.
  */
 protected function doAddItem($item)
 {
     $this->collItems[] = $item;
     $item->setItemType($this);
 }
Example #9
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Item $obj A Item object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getDataId();
         }
         // if key === null
         ItemPeer::$instances[$key] = $obj;
     }
 }
 protected function updateTrending(Item $item)
 {
     $onehourago = new DateTime();
     $onehourago->sub(new \DateInterval('PT1H'));
     $q = SellListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC);
     $oneHourAgoSellListing = $q->findOne();
     if (!$oneHourAgoSellListing || $oneHourAgoSellListing->getUnitPrice() <= 0 || $item->getMinSaleUnitPrice() <= 0) {
         $item->setSalePriceChangeLastHour(0);
     } else {
         $item->setSalePriceChangeLastHour(($item->getMinSaleUnitPrice() - $oneHourAgoSellListing->getUnitPrice()) / $oneHourAgoSellListing->getUnitPrice() * 100);
     }
     $q = BuyListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC);
     $oneHourAgoBuyListing = $q->findOne();
     if (!$oneHourAgoBuyListing || $oneHourAgoBuyListing->getUnitPrice() <= 0 || $item->getMaxOfferUnitPrice() <= 0) {
         $item->setOfferPriceChangeLastHour(0);
     } else {
         $item->setOfferPriceChangeLastHour(($item->getMaxOfferUnitPrice() - $oneHourAgoBuyListing->getUnitPrice()) / $oneHourAgoBuyListing->getUnitPrice() * 100);
     }
     $item->save();
 }