Open strubled opened 4 years ago
what if the algorithm put the names of the winners in an array, and we count the array to see if it's greater than 3. if it is, look at values for top categories.
top grocery: Capital One $250
top gas: Chase $100
top dining: Costco $400
top hotel: Citi $200
top other: Capital One $300
maxhash [[capital one $250],[chase $100],[costco $400],[citi $200],[capital one $300]] return k,v for top 3 values
[[capital one $250],[costco $400],[capitalone $300]] => [capital one 2, costco 1]
if count < 3, create hash with top 4 values
[[capital one $250, [costco $400], [capital one $300], [citi $200]]
if count < 3, create hash with top 5 values
if count < 3, create hash with top 6 values
[[capital one 2], [costco 1], [citi 1]] - there are three winners...now need to find categories they won
@winners = array of keys from maxhash
@cards2 = Cards.all where name = @winners[0], @winners[1], @winners[2]
@cards2.each do |card|
@groceryhash[card.name] = (card.grocery_cash_rate * @grocery / 100) +
(card.grocery_points_multi * @grocery / 100) -
(card.annual_fee / @countnil)
@gashash[card.name] = (card.gas_cash_rate * @gas / 100) +
(card.gas_points_multi * @gas / 100) -
(card.annual_fee / @countnil)
@dininghash[card.name] = (card.dining_cash_rate * @dining / 100) +
(card.dining_point_multi * @dining / 100) -
(card.annual_fee / @countnil)
@hotelhash[card.name] = (card.hotel_cash_rate * @hotel / 100) +
(card.hotel_points_multi * @hotel /100) -
(card.annual_fee / @countnil)
@airfarehash[card.name] = (card.airfare_cash_rate * @airfare / 100) +
(card.airfare_points_multi * @airfare / 100) -
(card.annual_fee / @countnil)
@otherhash[card.name] = (card.other_cash_rate * @other / 100) +
(card.other_points_multi * @other / 100) -
(card.annual_fee / @countnil)
end
@topgrocery = @groceryhash.max_by{|k,v| v}[0]
@topgas = @gashash.max_by{|k,v| v}[0]
@topdining = @dininghash.max_by{|k,v| v}[0]
@tophotel = @hotelhash.max_by{|k,v| v}[0]
@topairfare = @airfarehash.max_by{|k,v| v}[0]
@topother = @otherhash.max_by{|k,v| v}[0]
argh i basically did all of this and am realizing now the annual fee is rearing it's ugly head. basically it said a card should win for a specific category but only that category, but that was based on only applying 1/6th of the annual fee to the value of that category due to 6 categories being entered. once you remove the full annual fee from the value of that category spend, it loses.
idea (tl;dr this won't work)..what if for any card that has an annual fee, we create up to 6 different values based on if 6 categories are entered. so for example, card a value would look like:
annual fee $100 card a.1.grocery = 100 - 100 card a.2.grocery = 100 - 50 card a.3.grocery = 100 - 33 card a.4.grocery = 100 - 25 card a.5.grocery = 100 - 20 card a.6.grocery = 100 - 16
now when calculating the top 3, card a.6.grocery would win with $84 of value.
if we find that a.6 wins, we'd have to find out if it won any other categories, if it did, we'd have to replace it's value with a.1-a.5, then re-evaluate that categories winner. if that new winner also has an annual fee, we'd have to find out if it won any other categories, it if did, we'd have to replace it's value with a.1-a.5, then re-evaluate that categories winner. this idea is not going to work. each category will have this problem and if anything changes you'd have to go back to the original category winner and re-evaluate.
first step is creating a reco for up to 3 cards. we'll put in 4 cards and make sure the system is returning at most 3. once that works we'll add an option on form submit for how many cards does the user want to use at most.
let's say the following happens on user input:
top grocery: card A - $250 top gas: card B - $100 top dining: card C - $400 top other: card D - $300
we'd need the system to say you should use card c, d and a for the winning categories, and then find whatever card has the highest in gas to recommend for that spend (card c maybe has $95).
one way to do this is to count the winners, and if it's 3 or less, just return those. if it's 4+, you then use the top 3 as the winning cards, and then compare those top 3 cards values for the categories they didn't win to find the new winner.