Class DutchAuction
source code
object --+
|
DutchAuction
The class DutchAuction
represents so-called Dutch
auctions in an electronic auction house. Each auction object represents
an auction for a single item that has been put up for sale. Please note
that in real life, the term "Dutch auction" is used for various
somewhat different purposes. The kind of Dutch auctions that this class
represents (as described below) are not identical to those featured in
the eBay online trading website, for instance.
Each Dutch auction has a starting price for the item being sold.
However, unlike in a typical auction where the price goes up from the
starting price, the price in a Dutch auction goes down until someone
decides to purchase the item. Every day, the price of the item is
decreased by a certain amount from the previous day's price, and the
first person who decides to buy the item gets it immediately at the
current price.
Upon creation, a starting price and a minimum price are set for the
auction. Every day, the method advance_one_day
must be
called to update the auction status and decrease the current price if
no-one has bought the item yet. The price of the item will never drop
below the preset minimum price. After the minimum price is reached, the
auction will remain open (at the minimum price) for a further three days.
If nobody still buys the item, the auction expires.
To summarize, a Dutch auction can be in any of the four stages
below.
-
decreasing price: the auction is open and the current price of
the auction keeps dropping daily from the until the minimum price is
reached or until someone buys the item.
-
stagnant: the auction is still open but its price no longer
decreases, and instead stays at the minimum price.
-
expired: after the price of the auction has been stagnant at
the minimum price for over three days (i.e., three additional full
days after reaching the minimum price), and still no-one has bought
the item, the auction expires and is no longer open.
-
bought: as soon as anyone chooses to buy the item, the auction
ceases to be open.
All prices and bid amounts are integers. Buyers are represented simply
by their names (strings).
|
__init__(self,
description,
starting_price,
decrement,
minimum_price)
Creates a new, open Dutch auction with the given attributes. |
source code
|
|
|
|
|
|
|
get_current_price(self)
Returns the price the item is currently available for (if the auction
is open) or used to be available for (if the auction is no longer
open). |
source code
|
|
|
|
|
|
|
|
|
is_open(self)
Determines if the auction is open, i.e., if the item can still be
bought. |
source code
|
|
|
|
|
|
|
buy(self,
buyer)
Buys the item for the given customer, thereby closing the auction. |
source code
|
|
|
matches_keyword(self,
keyword)
Determines if the auction matches a given search keyword, i.e., if
the auction description contains the given keyword. |
source code
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
description,
starting_price,
decrement,
minimum_price)
(Constructor)
| source code
|
Creates a new, open Dutch auction with the given attributes.
- Parameters:
description - a description of the auction and the item being sold
starting_price - the starting price for the auction
decrement - the daily decrement to the price
minimum_price - the minimum amount that the seller is willing to take
- Overrides:
object.__init__
|
Returns a description of the auction and the item being sold.
- Returns:
- auction description
|
Returns the starting price of the auction.
- Returns:
- starting price
|
Returns the price the item is currently available for (if the auction
is open) or used to be available for (if the auction is no longer
open).
- Returns:
- current item price
|
Returns the minimum price the seller is willing to accept.
- Returns:
- minimal item price
|
Returns a number indicating the relative "cheapness" of the
item. This is obtained by dividing the current price of the item by the
minimum price.
- Returns:
- price ratio
|
Records one day as having passed. For a Dutch auction, this means that
if the auction is still open, the current price of the auction is reduced
by the preset decrement, though only until the minimum price of the
auction. However, if the auction was already at the minimum price, then
the current price does not decrease at all instead the auction object
keeps track of how many days the price has remained stagnant at the
minimum level (this will eventually lead to auction expiration when this
method is called for the fourth time after the current price reached the
minimum price).
- See Also:
-
#is_expired(),
#is_open()
|
Determines if the auction is open, i.e., if the item can still be
bought. A Dutch auction is always open if no-one has yet bought the item
and the auction has not yet expired.
- Returns:
- a boolean value indicating if the auction is still open
|
Determines is the auction has expired. An Dutch auction expires if the
price remains stagnant at the minimum price level for over three days
without anyone byuing the item (not counting the day when the price
originally reached the minimum price).
(Note: Being expired implies that the auction is also closed. However,
not being expired does not guarantee that the auction is open. An auction
closes when either it expires or someone buys the item.)
- Returns:
- a boolean value indicating if the auction has expired
See Also:
#advance_one_day()
|
Returns the winner of the auction. That is, returns the person who
bought the item.
- Returns:
- the name of the buyer, or
None if no-one has bought
the item yet
|
Buys the item for the given customer, thereby closing the auction. The
item can only be bought if the auction is open.
- Parameters:
buyer - the buying customer
|
Determines if the auction matches a given search keyword, i.e., if the
auction description contains the given keyword. Upper and lowercase
letters are considered equal for the purposes of this matching
operation.
For instance, if the auction description is "Big golden
Rolex", then the keywords "rolex", "Rolex",
"GOLD", "olde" and "en r" match the
auction.
- Parameters:
keyword - a search string
- Returns:
- a boolean value indicating if the auction matches the keyword
|