Auction Regions

Initial implementation of regions for auctions:
Added a region field to the auction. This includes updating the
databases functions (create, update) to handle the new field, the
auction route functions (update), and the front-end JS to pass the
region information to the backend.

A new validation function was created to validate the regions for
auctions. As well as, a new config field that allows the admin to create
whitelisted regions to be used. A region drop down was added to the
auction creation and update tool in both the admin and auctionEdit
pages. And the auction partial view was updated to show the region
information. Also, the history page and the admin page was updated to
region information at a glance.
Initial work on new region system for auctions

Implemented the new region object config in the config.js file. There is
now only one config variable for regions and it is an array of region
objects where each region has a name, an array of countries, and a
inclusive boolean.

Removed the top level slots property from the auction model. This was
removed in the validation.js file, the db.js file, the auction.js file,
the admin page, and the sblayout.ejs file. It still needs to be fully
removed from the auction edit page.

Created new validations for regions in both the front end js and in the
validation.js file. This validates that there is at least one region,
the region names are found in the config, and that the slots property in
each region is a valid number and is greater than zero.

Updated the <hr> dom element to be darker so it shows up on the page
better.

Optimized the time format code in the auction.js file and pulled in all
the region names from the config to be display on the admin page.

Also pulled the region names from the config into the auction.js file's
editAuction method so that that AuctionEdit page can also show all the
region names.

Added a region control to the auction creation tool on the admin page.
This needs to be replicated on the AuctionEdit page.

Updated the submit and update methods on the admin.ejs and sblayout.ejs
file respectively to reflect the above changes. (Removed slots and added
regions/region validations.)
Added ads start and end times, AuctionEdit updates

Syntax update in config file.

Added start and end times to the auction model. Created new validations
for the ads start and end time that also validate that the ads start
time is after auction end time. Also fixed a bug with the region
validation trying to validate that the region.slots is a number.

Added ads start and end times to the auction.js route file.

Updated the admin.ejs page with ads start and end datetimes. Refactored
the auctionEdit.ejs file to match the new auction creation tool on the
admin page.

Updated all the front end JS to account for and validate the new ads
start and end datetimes.

Loaded the new auction region and auction ads start and end datetimes
into the newly updated auction creation tool on the auctionEdit.ejs
file.
Added regional bids to the auction model

Sorted all bids by region and added to the auction model when the user
looks at an auction. This requires updating the DB methods that retrieve
an auction. Also updated the auction partial view to reflect the above
changes.
regions in bids, view updates, auction probabilities

Updated the bidPerSlot in the bidding algorithm to primarySlots. This
was changed in both the bidding algorithm and the db methods that use
the algorithm.

Updated the bid model to include a region. This affected the db.js file,
and the bid route files. A validation was also created to validate that
the region given is in the auction.

Updated the auction and sbindex views to with a bid per region tool.
Also optimized the auction view to need fewer variables to be passed
into the template. This includes splitting the auction partial view into
two different files for both the auction and the sbindex page. The one
used in the auction page includes the bid tool while the other doesn't.

Updated the auction.js and template file to find the lowest bid price
for all regions and attached that to the region object.

Created a file to figure out the probabilities for all slots in every
region of an auction. This file has been included and used in both the
sbindex and the auction page.
Delete regions from auction

Added the ability to remove a region from an auction as long as that
region does not already contain bids. This involves updating the UI on
both the admin and the auctionEdit pages.It required adding the bid
model to the auction.js route file and checking the regions in each bid.
If an auction region has a bid and the that region is deleted in the
input, that region is added back to the input before the auction is
processed.

This makes sure the validation exists in both the ui and the route but
not in the db file. The API routes will need to be updated to account
for this.
Regions in ads

Updated the ad model to use the new region design rather than just the
blacklisted regions. This involved updating the db.js file to define
regions in the ad model, the ads.js route file to remove the old
blacklistedCN and add the region property, and the front end views
(ad_upload.ejs and ads.ejs).
Added the antiSnipe minutes to the views

The antiSnipe minutes defined in the configs were not being shown in the
auction page correctly. This has been fixed.
Show bid tool for users with ads in that region

Updated the bid tool to only show up when the currently logged in user
is also registered with the system AND has a ad in the region they are
bidding in. An ad with a global region allows the user to bid in all
regions.
Removed Global bypass for regional bidding

Removed the mechanism that allows a user to bid on any region if they
have a Global ad.
Regions in auction close and bug fixes

Added region to the auction close event. This includes adding regions to
the AdsInRotation object (otherwise known as the reference object).
Re-routing the way winners are found over all the regions, while also
keeping the winners for each region, in the region object. Also added
regions to the lineitems for invoice as well so each lineitem in the
invoice can display which region it's for.

Fixes:
Fixed a bug where an in rotation ad still appears to be in rotation
after it is rejected. The inRotation Boolean is now reset on rejection.

Fixed the was Ads Start and End times are kept in the DB and eventually
displayed to the user. It was being stored as a string, but is now a
number in epoch time. This lead to a bug where Ads Start and End time
appeared invalid for auctions in the past.

Added an extra object check on the ad_upload page. This page broke on
new ads because it was looking for an ad that did not exist. It makes
sure that if there is no given ad, it gives up and the rest of the
checks.

Fixed a bug on the history page where the regions were not showing up
correctly. The regions are now shown as a list of region instead of as
an array of objects.
Region in random ad route and bug fixes

Fixes:
Fixed a bug in auction close that added more lineitems to each region
user than they originally had. It was a object reference issue. Also
cleaned up the regions objects so there's less duplicated data in the
DB.

Changed the region object in configs to use an exclusive boolean instead
of inclusive. This makes the list by default an inclusive list.

Updated the design doc for couchapp so that the system can retrieve a
list of AdsInRotation objects that have already started.

Updated the db.js file to use the new ddoc view to grab the
AdsInRotation object that have already started and sorted them by latest
end time. It then gives back only the latest ending object.

Re-wrote the ads.js file that contains the code for randomized ad
retrieval. It now takes into consideration regions in the AdsInRotation
object. The general idea is that the country code for the given ip and
the number of ads the caller wants is found. Then for each region in the
AdsInRotation object, all the winners are pulled, and a random set of
ads are found for each user until the number of slots they've won is
reached. This should equal to all the ads for each region. Then all the
ads from each region is put into one list and a random set of ads are
selected until the number of ads the caller wanted is reached. The ads
are cleaned and then sent to back to the caller.