Last active
July 5, 2021 12:42
-
-
Save saikumar-everest/6b0dc534c5b96692e093a35ecf967684 to your computer and use it in GitHub Desktop.
provider selection rb file for debug purpose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ProviderSelectorStrategy | |
class ProviderSelection | |
def initialize(express_service, selector_data) | |
@express_service = express_service | |
@selector_data = selector_data | |
end | |
def find | |
available_providers = @express_service.subscriptions.available.joins(:provider) | |
.where(users: { provider_state: Provider::Machine::States::APPROVED }) | |
ids = available_providers.map(&:provider_id) | |
users_vector = UserVector.new(ids) | |
strategies = [ | |
Strategies::MyItemsOnly.new(users_vector, available_providers), | |
Strategies::RoundRobin.new(users_vector, available_providers), | |
Strategies::AvailableNow.new(users_vector) | |
] | |
strategies.unshift(Strategies::FirstDibs.new(users_vector, @selector_data)) if Feature::MarketApi.new.active? | |
final_vector = strategies.inject(users_vector) { |vector, strategy| vector + strategy.vector } | |
winner = final_vector.winner | |
p @express_service | |
p "final_vector:", final_vector | |
p "final_vector.vector:", final_vector.vector | |
p "winner:", winner | |
p "available_providers.size:", available_providers.size | |
p "strategies.size:", strategies.size | |
p "strategies[0].vector:", strategies[0].vector | |
p "strategies[1].vector:", strategies[1].vector | |
p "strategies[2].vector:", strategies[2].vector | |
available_providers.select { |p| p.provider_id == winner }.first.provider | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment