Average Command

The Average command is the command that handles calculating the statistical average of the specified item.
average.calculate_average(plat_list: list[int], statistic: Literal['geometric', 'mean', 'median', 'mode'], ndigits: int = config.DEFAULT_NDIGITS) float

Calculate the specified statistic for a list of prices.

Given a list of integers of prices associated with an item, calculate and return the desired statistic, rounded to the specified number of decimal places.

Parameters:
  • plat_list – Prices in platinum of each order.

  • statistic – Statistic to be calculated.

  • ndigits – Number of decimals to which the calculated statistic should be rounded, defaults to config.DEFAULT_NDIGITS.

Raises:

errors.NoListingsFoundError – If plat_list has no contents.

Returns:

Desired statistic of the specified item.

average.in_time_range(last_updated: str, current_time: datetime, time_range: int = config.DEFAULT_TIME) bool

Check if order is younger than time_range days.

Subtract last_updated field from current_time to check if the difference in days is less than or equal to time_range.

Parameters:
  • last_updated – ISO-8601 timestamp of when the order was last updated.

  • current_time – Current UTC time.

  • time_range – Maximum age, in days, that an order can be to be accepted, defaults to config.DEFAULT_TIME.

Returns:

True if last_updated time_range, False if last_updated > time_range.

average.check_mod_arcane_rank(order_rank: int | None, item_max_rank: int | None, *, use_maxrank: bool) bool

Check if an order’s rank matches user-specified rank level.

Check if an order’s rank equals the rank specified by the user. If the item isn’t a mod or arcane, order_rank and item_max_rank should both be None. If either order_rank or item_max_rank is None, then True will be returned.

Parameters:
  • order_rank – Rank of the order.

  • item_max_rank – Maximum possible rank for the item.

  • use_maxrank – User-specified rank of mod or arcane. If True, the maximum potential rank of the item will be use. If False, the unranked item will be used.

Returns:

True if the order_rank is None, if item_max_rank is None, or if order’s rank matches item_max_rank * use_maxrank, False otherwise.

average.check_relic_subtype(subtype: str | None, use_radiant: Literal['intact', 'radiant']) bool

Check if an order’s subtype matches user-specified refinement level.

Check if an order’s subtype equals the refinement level specified by the user. If the item isn’t a relic, subtype should be None.

Parameters:
  • subtype – Subtype of the order.

  • use_radiant – User-specified refinement level to compare against. Can be either “radiant” or “intact”.

Returns:

True if the order’s subtype matches use_radiant or if subtype is None, False otherwise.

average.filter_order(order: OrderWithUser, item_info: Item, current_time: datetime, args: Namespace) bool

Check if an order meets all user-specified criteria.

Check if an order meets all user-defined conditions:

  • Whether the order’s last update is within args.timerange days.

  • Whether the order is of “buy” or “sell” type, depending on

    args.use_buyers.

  • If the item is a mod or arcane, whether its rank is unranked or

    the maximum rank, based on args.maxrank.

  • If the item is a relic, whether its refinement is intact or

    radiant, based on args.radiant.

Parameters:
  • order – Order to be checked.

  • item_info – Details about the item.

  • current_time – Current time.

  • args – Command-line arguments provided by the user. Must have the fields use_buyers, maxrank, radiant, and timerange.

Returns:

True if all specified conditions are met, False otherwise.

average.filtered_plat_list(order_data: list[OrderWithUser], item_info: Item, current_time: datetime, args: Namespace) list[int]

Construct a list of prices using a filter.

Return a filtered list of platinum prices given a list of schema.OrderWithUser, a schema.Item, and the user’s command-line arguments.

Parameters:
  • order_data – List of schema.OrderWithUser containing information about each individual order.

  • item_info – Object containing information about the item.

  • current_time – Current time.

  • args – User-given command line arguments. Must have the fields statistic, item, porcelain, and timerange.

Returns:

List of the platinum prices from the filtered listings.

average.format_output(stat: float, plat_list: list[int], args: Namespace) str

Format the calculated statistic along with additional information.

Format the calculated statistic, along with the maximum and minimum prices of the orders, and the total number of orders that match the search criteria. If args.porcelain is True, separate the fields with a single colon.

Parameters:
  • stat – Statistic of the item that was found.

  • plat_list – List of prices of the item.

  • args – User-given command line arguments. Must have the fields statistic, item, porcelain, and timerange.

Returns:

Return appropriately formatted string.

average.get_required_data(item: str, http_headers: dict[str, str]) tuple[ItemResponse, OrderResponse]

Retrieve the orders and metadata for an item.

Parameters:
  • item – Item to retrieve.

  • http_headers – Headers to be used in the HTTP request.

Returns:

The item’s metadata and the orders associated with it.

average.process_data(args: Namespace, http_headers: dict[str, str], current_time: datetime) str

Calculate average price of an item from warframe.market.

Parameters:
  • args – Parsed command-line args. Must have the fields statistic, item, porcelain, radiant, use_buyers, maxrank, and timerange.

  • http_headers – Headers to be used in the HTTP request.

  • current_time – Current time.

Returns:

Calculated statistic.