예제 #1
0
    def start(self, playerName):
        numString = self.sock.recv(4)
        assert numString.endswith('\n')

        numAttr = int(numString[:-1])
        self.numAttr = numAttr

        if playerName == 'person':
            self.player = Person(numAttr)
            self.startPersonIO()
        elif playerName == 'matchmaker':
            self.player = Matchmaker(numAttr)
            self.startMatchmakerIO()

        self.sock.close()
예제 #2
0
class TestMatchmaker(unittest.TestCase):
  def setUp(self):
    roster_data = {
                    "players" : [
                      {"name" : "Kalpesh Shah", "skill" : 3, "division": "West"},
                      {"name" : "Larry Ward", "skill" : 3, "division": "West"},
                      {"name" : "Trent Miller", "skill" : 3, "division": "West"},
                      {"name" : "Katrina Brinkley", "skill" : 2, "division": "West"},
                      {"name" : "Dan Doepner", "skill" : 2, "division": "West"},
                      {"name" : "Kevin Dahl", "skill" : 2, "division": "West"},
                      {"name" : "Doug Nufer", "skill" : 1, "division": "West"},
                      {"name" : "Bill Schaefermeyer", "skill" : 3, "division": "East"},
                      {"name" : "James Morris", "skill" : 3, "division": "East"},
                      {"name" : "Justin Long", "skill" : 3, "division": "East"},
                      {"name" : "Joe Au", "skill" : 2, "division": "East"},
                      {"name" : "Joseph Hoyal", "skill" : 2, "division": "East"},
                      {"name" : "Eric Prusse", "skill" : 2, "division": "East"},
                      {"name" : "Maria Bates", "skill" : 1, "division": "East"}
                    ]
                  }
    roster = Roster(roster_data)
    self.matchmaker = Matchmaker()
    self.teams = self.matchmaker.get_teams(roster)
    self.matches = self.matchmaker.get_matches(self.teams)
    self.optimized_matches = self.matchmaker.get_tournament_matches(roster)

  def tearDown(self):
    self.tourney = None

  def test_team_count(self):
    self.assertEqual(42, len(self.teams))

  def test_match_count(self):
    self.assertEqual(441, len(self.matches))

  def test_optimized_match_count(self):
    self.assertEqual(21, len(self.optimized_matches))

  def test_tourney_has_match(self):
    self.assertEqual("Bill Schaefermeyer James Morris,Kalpesh Shah Larry Ward", self.matches[0].id)
예제 #3
0
파일: test_auth.py 프로젝트: pbs/matchmaker
def test_auth():
	""" Tests the key validation stuff to make sure failing keys really fail """
	acct = GigyaStorage("asejifoa", "agoeuiau")
	auth = MemcachedStorage("127.0.0.1:11211")
	mm = Matchmaker(auth_storage=auth, acct_storage=acct)

	ids = [	
	# Working keys
		"fji39qp", 
		"fji32-", 
		"fjwo-=_", 
		"fjie1245", 
	# Failing keys
		"fjeiw%^&", 
		"!fjies'",
		"$asd",
		"'888'",
		"`qaz"
	]

	for id in ids:
		auth = mm.get_auth_code(id)
		print id, auth
예제 #4
0
 def setUp(self):
     roster_data = {
         "players": [
             {"name": "Kalpesh Shah", "skill": 3, "division": "West"},
             {"name": "Larry Ward", "skill": 3, "division": "West"},
             {"name": "Trent Miller", "skill": 3, "division": "West"},
             {"name": "Katrina Brinkley", "skill": 2, "division": "West"},
             {"name": "Dan Doepner", "skill": 2, "division": "West"},
             {"name": "Kevin Dahl", "skill": 2, "division": "West"},
             {"name": "Doug Nufer", "skill": 1, "division": "West"},
             {"name": "Bill Schaefermeyer", "skill": 3, "division": "East"},
             {"name": "James Morris", "skill": 3, "division": "East"},
             {"name": "Justin Long", "skill": 3, "division": "East"},
             {"name": "Joe Au", "skill": 2, "division": "East"},
             {"name": "Joseph Hoyal", "skill": 2, "division": "East"},
             {"name": "Eric Prusse", "skill": 2, "division": "East"},
             {"name": "Maria Bates", "skill": 1, "division": "East"},
         ]
     }
     roster = Roster(roster_data)
     matchmaker = Matchmaker()
     teams = matchmaker.get_teams(roster)
     matches = matchmaker.get_matches(teams)
     self.optimizer = Optimizer(matches)
예제 #5
0
def makeDonation():
    if not has_args(request.json, [
            'sender_first_name', 'sender_last_name', 'sender_email',
            'sender_address', 'city', 'state', 'zipcode', 'cardholder_name',
            'card_number', 'exp_date', 'cvc', 'dollars'
    ]):
        raise InvalidUsage('Missing paramenters')
        return 400
    # get matchmaker obj
    recipient = Matchmaker().get_recipientProfile()
    if recipient is None:
        return "Sorry there are no users to donate to at this time. Try again in a bit", 503
    purchase_status = False
    #fill out form
    full_name = request.json['sender_first_name'] + request.json[
        'sender_last_name']
    payment = DoorDash()
    if payment.preFill(dollars=request.json['dollars'],
                       recipient_name=recipient.get_first_name(),
                       recipient_email=recipient.get_email(),
                       sender_name=full_name) == True:
        sleep(randint(1, 2))
        # pay and deliver
        purchase_status = payment.purchase(
            sender_email=request.json['sender_email'],
            sender_address=request.json['sender_address'],
            city=request.json['city'],
            state=request.json['state'],
            zipcode=request.json['zipcode'],
            cardholder_name=request.json['cardholder_name'],
            card_number=request.json['card_number'],
            exp_date=request.json['exp_date'],
            cvc=request.json['cvc'])
        if purchase_status['status'] == True:
            # render template for donor:
            d2 = date.today().strftime("%B %d, %Y")
            template = env.get_template('billing.html')
            html = template.render(amount_donated=request.json["dollars"],
                                   invoice_number=1,
                                   Transaction_date=d2)
            # send confirm email to donor
            donor_confirm_email = send_donor_order_confirmation(
                donor_email=request.json["sender_email"], bodyContent=html)
            # render template for recipient:
            template = env.get_template('recipient_confirmation.html')
            html = template.render(recipient_name=recipient.get_first_name(),
                                   amount_donated=request.json["dollars"])
            recipient_confirm_email = send_recipient_order_confirmation(
                recipient_email=recipient.get_email(), bodyContent=html)
            # update User DB
            user_update_status = update_user_entry(recipient,
                                                   request.json["dollars"])
            # insert to Transactions DB
            timestamp_string = time.strftime(
                "%a, %d %b %Y %H:%M:%S +0000",
                datetime.fromtimestamp(int(time.time())).timetuple())
            donation_update_status = insert_donation(
                recipient, request.json["dollars"],
                request.json["sender_email"],
                request.json["sender_first_name"],
                request.json["sender_last_name"], timestamp_string,
                donor_confirm_email, recipient_confirm_email)

            return "Transaction Complete:" + str(
                purchase_status) + " | User Table Updated:" + str(
                    user_update_status
                ) + " | Transactions Table Inserted:" + str(
                    donation_update_status), 200
        else:
            return "Transaction Complete:" + str(
                purchase_status
            ) + " | User Table Updated:" + "False" + " | Transactions Table Inserted:" + "False", 400
    else:
        return "There was an error", 500
예제 #6
0
def get_next_recipient():
    recipient = Matchmaker().get_recipientProfile()
    profile_dict = get_recipient_profile(recipient.get_email())

    return jsonify(profile_dict), 200
예제 #7
0
파일: test_dict.py 프로젝트: pbs/matchmaker
def test_dict():
	user_ids = ["new_user_id", "test1", "test2", "test3", "test4"]
	devices = []
	
	print "DICTIONARY IMPLEMENTATION"
	auth = DictionaryAuth()
	acct = DictionaryAccount(user_ids)
	mm = Matchmaker(auth, acct, multi=ALLOW_MULTIPLE)

	print "ADDING, LINKING"
	for id in user_ids:
		device_id = uuid.uuid4().hex
		devices.append(device_id)
		new_auth = mm.get_auth_code(device_id)
		auth_code = new_auth['auth_code']
		reg_status = mm.link_device(auth_code, id)
		user_status = mm.get_user(device_id)

	for dev in devices:
		new_auth = mm.get_auth_code(dev)
		reg_status = mm.link_device(new_auth['auth_code'], user_ids[0])
		user_status = mm.get_user(dev)

	print mm.get_user(devices[0])
	print mm.get_user(devices[1])
	print mm.get_user(devices[2])
	pprint.pprint(vars(acct))
	print devices
	
	print "DELETING"
	for dev_id in devices:
		gone = mm.unlink_device(dev_id, user_ids[0])
		print gone

	print vars(acct)
예제 #8
0
class IO:
    def __init__(self, host, port):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect(('localhost', port))

    def start(self, playerName):
        numString = self.sock.recv(4)
        assert numString.endswith('\n')

        numAttr = int(numString[:-1])
        self.numAttr = numAttr

        if playerName == 'person':
            self.player = Person(numAttr)
            self.startPersonIO()
        elif playerName == 'matchmaker':
            self.player = Matchmaker(numAttr)
            self.startMatchmakerIO()

        self.sock.close()

    def startPersonIO(self):
        initialWeights = self.player.getValidWeights()
        idealCandidate = self.player.getIdealCandidate()
        antiIdealCandidate = self.player.getAntiIdealCandidate()

        self.sock.sendall(utils.floats_to_msg2(initialWeights))

        self.sock.sendall(utils.candidate_to_msg(idealCandidate))
        self.sock.sendall(utils.candidate_to_msg(antiIdealCandidate))


        for i in range(20):
            # 7 char weights + commas + exclamation
            data = self.sock.recv(8*self.numAttr)
            print('%d: Received guess = %r' % (i, data))
            assert data[-1] == '\n'
            self.sock.send(utils.floats_to_msg2(self.player.getNewWeights(data)))

    def startMatchmakerIO(self):
        candidates = []
        for i in range(20):
            # score digits + binary labels + commas + exclamation
            data = self.sock.recv(8 + 2*self.numAttr)
            print('Score = %s' % data[:8])
            assert data[-1] == '\n'
            candidates.append(utils.parseCandidateData(data))

        self.player.parseInitialData(candidates)

        # Set initial score higher than 1 so we know it is initial round
        score = 2
        candidate = []
        for i in range(20):
            candidate = self.player.guess(candidate, score, i)
            self.sock.sendall(utils.floats_to_msg4(candidate))

            data = self.sock.recv(8)
            assert data[-1] == '\n'
            score = float(data[:-1])

            # if np.isclose(score, 1):
            #     break

            print('i = %d score = %f' % (i, score))
예제 #9
0
# -*- coding: utf-8 -*-

from ethereum import tester
import os

from matchmaker import Matchmaker
from trader import Trader

state = tester.state()

# Create Market Contract
# TODO: remove gas
market = state.abi_contract('contracts/market.se', gas=10000000)

# Create Actors
match_maker = Matchmaker(state, market, name='MatchMaker')
buyer = Trader(state, market, name='Buyer')
seller = Trader(state, market, name='Seller')

# Setup our simple Buy and Sell tickets
buyer.new_ticket(5)
seller.new_ticket(-5)

# Run the Network!
state.mine(n=5)

# TODO:
# Traders Accept (or Decline )
# Matchmaker waits until accept window is over and collects fees?
# do they collect fees or do they get the option to add new sealed bids using the freed storage?
# depends if buyer or seller commit a fee for listing?