Esempio n. 1
0
def load_increments():
    with open('increments.csv', 'rb') as incfile:
        reader = csv.reader(incfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        for row in reader:
            inc = StoredIncrement(*row)
            shared.auction_to_increments[inc.auction].append(inc)
Esempio n. 2
0
def read_bids():
	with open('clean_bids.csv', 'rb') as bidsfile:
		reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
		skip(reader, 1)
		c = 0
		prev_bid = None
		for row in reader:
			c += 1
			if c % 1e6 == 0:
				print "Read bids progress: %s" % c

			bid = Bid(*row)
			ct = None
			if bid.is_human:
				ct = country_to_time
			if bid.is_robot:
				ct = rbo_country_to_time
			if ct is None:
				continue

            u = float(52631.578)
            t = bid.time
            d = datetime.today()
            td = timedelta(seconds=(t/u))
			dt = d + td
			ct[bid.country].append(dt.hour)
Esempio n. 3
0
 def test_delete_user_in_backends_by_email(self):
     """ Delete a user previously registered user by email
     """
     # first, create a user and register it with services
     try:
         self.msu.create_user('josh', 'homme', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('josh', 'homme', config.GATEWAY_URL)
     # make sure user is in redmine and gerrit
     self.assertEqual('*****@*****.**',
                      self.gu.get_account('josh').get('email'))
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         users = [u for u in users if u.firstname == 'josh']
         self.assertEqual(1, len(users))
         user = users[0]
         self.assertEqual('*****@*****.**', user.mail)
     # now suppress it
     del_url = config.GATEWAY_URL +\
         'manage/services_users/[email protected]'
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     # make sure the user does not exist anymore
     self.assertEqual(False, self.gu.get_account('josh'))
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         self.assertEqual(0,
                          len([u for u in users if u.firstname == 'josh']))
Esempio n. 4
0
 def test_delete_in_backend_and_recreate(self):
     """Make sure we can recreate a user but as a different one"""
     # first, create a user and register it with services
     try:
         self.msu.create_user('freddie', 'mercury', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('freddie', 'mercury', config.GATEWAY_URL)
     gerrit_id = self.gu.get_account('freddie').get('_account_id')
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         user = [u for u in users if u.firstname == 'freddie'][0]
         redmine_id = user.id
     del_url = config.GATEWAY_URL +\
         'manage/services_users/[email protected]'
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     self.assertEqual(False, self.gu.get_account('freddie'))
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         self.assertEqual(
             0, len([u for u in users if u.firstname == 'freddie']))
     # recreate the user in the backends
     time.sleep(5)
     self.logout()
     self.login('freddie', 'mercury', config.GATEWAY_URL)
     new_gerrit_id = self.gu.get_account('freddie').get('_account_id')
     self.assertTrue(gerrit_id != new_gerrit_id)
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         user = [u for u in users if u.firstname == 'freddie'][0]
         new_redmine_id = user.id
         self.assertTrue(redmine_id != new_redmine_id)
Esempio n. 5
0
def read_bidders(filename):
    with open('clean_%s' % filename, 'wb') as cbfile:
        fieldnames = [
            'bidder_id', 'pmt_type', 'pmt_account', 'addr_1', 'addr_2'
        ]
        if 'train' in filename:
            fieldnames.append('outcome')
        writer = csv.DictWriter(cbfile, fieldnames=fieldnames)
        writer.writeheader()
        with open(filename, 'rb') as bidsfile:
            reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
            skip(reader, 1)
            for row in reader:
                b = Bidder(row[0], row[1], row[2],
                           row[3] if len(row) > 3 else None)
                bidders[b.bidder_id] = b
                mrow = {
                    'bidder_id': b.bidder_id,
                    'pmt_type': b.get_payment_type(),
                    'pmt_account': b.get_payment_acct(),
                    'addr_1': b.get_addr_1(),
                    'addr_2': b.get_addr_2(),
                }
                if 'train' in filename:
                    mrow['outcome'] = b.outcome
                writer.writerow(mrow)
Esempio n. 6
0
 def test_delete_user_in_backends_by_username(self):
     """ Delete a user previously registered user by username
     """
     # first, create a user and register it with services
     try:
         self.msu.create_user('bootsy', 'collins', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('bootsy', 'collins', config.GATEWAY_URL)
     # make sure user is in gerrit
     self.assertEqual('*****@*****.**',
                      self.gu.get_account('bootsy').get('email'))
     # now suppress it
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/?username=bootsy'
     # try with a a non-admin user, it should not work ...
     auth_cookie = get_cookie('user5', config.ADMIN_PASSWORD)
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(400 < int(d.status_code) < 500)
     # try with an admin ...
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     # make sure the user does not exist anymore
     self.assertEqual(False, self.gu.get_account('bootsy'))
Esempio n. 7
0
 def test_delete_user_in_backends_by_email(self):
     """ Delete a user previously registered user by email
     """
     # first, create a user and register it with services
     try:
         self.msu.create_user('josh', 'homme', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('josh', 'homme', config.GATEWAY_URL)
     # make sure user is in redmine and gerrit
     self.assertEqual('*****@*****.**',
                      self.gu.get_account('josh').get('email'))
     if has_issue_tracker():
         users = self.rm.active_users()
         users = [u for u in users if u[0] == 'josh']
         self.assertEqual(1, len(users))
         user = users[0]
         self.assertEqual('*****@*****.**',
                          user[1])
     # now suppress it
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/[email protected]'
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url,
                         cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     # make sure the user does not exist anymore
     self.assertEqual(False,
                      self.gu.get_account('josh'))
     if has_issue_tracker():
         users = self.rm.active_users()
         self.assertEqual(0,
                          len([u for u in users if u[0] == 'josh']))
Esempio n. 8
0
 def test_delete_in_backend_and_recreate(self):
     """Make sure we can recreate a user but as a different one"""
     # first, create a user and register it with services
     try:
         self.msu.create_user('freddie', 'mercury', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('freddie', 'mercury', config.GATEWAY_URL)
     gerrit_id = self.gu.get_account('freddie').get('_account_id')
     if has_issue_tracker():
         tracker_id = self.rm.get_user_id_by_username('freddie')
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/[email protected]'
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url,
                         cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     self.assertEqual(False,
                      self.gu.get_account('freddie'))
     if has_issue_tracker():
         users = self.rm.active_users()
         self.assertEqual(0,
                          len([u for u in users
                               if u[0] == 'freddie']))
     # recreate the user in the backends
     time.sleep(5)
     self.logout()
     self.login('freddie', 'mercury', config.GATEWAY_URL)
     new_gerrit_id = self.gu.get_account('freddie').get('_account_id')
     self.assertTrue(gerrit_id != new_gerrit_id)
     if has_issue_tracker():
         new_tracker_id = self.rm.get_user_id_by_username('freddie')
         self.assertTrue(tracker_id != new_tracker_id)
Esempio n. 9
0
def read_country_to_time():
    ctt = dict()
    with open('country_to_time.csv', 'rb') as cfile:
        reader = csv.reader(cfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        for row in reader:
            ctt[row[0]] = map(float, row[1:])

    return ctt
 def test_create_local_user_and_login(self):
     try:
         self.msu.create_user('Flea', 'RHCP', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     url = config.GATEWAY_URL + "redmine/projects"
     quoted_url = urllib2.quote(url, safe='')
     response = self.login('Flea', 'RHCP', quoted_url)
     self.assertEqual(url, response.url)
 def test_create_local_user_and_login(self):
     try:
         self.msu.create_user('Flea', 'RHCP', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     time.sleep(10)
     response = self.login('Flea', 'RHCP',
                           'http%3a%2f%2ftests.dom%2fredmine%2fprojects')
     expect_url = "http://{}/redmine/projects".format(config.GATEWAY_HOST)
     self.assertEqual(expect_url, response.url)
Esempio n. 12
0
 def test_create_local_user_and_login(self):
     """ Try to create a local user then login
     """
     try:
         self.msu.create_user('Flea', 'RHCP', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     url = config.GATEWAY_URL + "/dashboard/"
     quoted_url = urllib2.quote(url, safe='')
     response = self.login('Flea', 'RHCP', quoted_url)
     self.assertEqual(url, response.url)
Esempio n. 13
0
def read_bids():
    with open('bids.csv', 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        c = 0
        prev_bid = None
        for row in reader:
            c += 1
            if c % 1e6 == 0:
                print "Read bids progress: %s" % c

            bid = Bid(*row)
            bids.append(bid)

        print "Bids read done: %s" % len(bids)
Esempio n. 14
0
def read_bids():
    with open('bids.csv', 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        c = 0
        prev_bid = None
        for row in reader:
            c += 1
            if c % 1e6 == 0:
                print "Read bids progress: %s" % c

            bid = Bid(*row)
            bids.append(bid)

        print "Bids read done: %s" % len(bids)
Esempio n. 15
0
 def test_unicode_user(self):
     """ Try to create a local user with unicode charset, login, delete
     """
     # /!\ redmine does not support non-ASCII chars in usernames.
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     try:
         self.msu.create_user('naruto', 'rasengan', '*****@*****.**',
                              fullname=u'うずまきナルト')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     except UnicodeEncodeError:
         # TODO the CLI works but I can't find what is wrong with
         # python's handling of unicode in subprocess.
         warnings.warn('Cannot run shell command with unicode chars for '
                       'whatever reason, retrying with a direct REST '
                       'API call ...',
                       UnicodeWarning)
         create_url = config.GATEWAY_URL + "/manage/user/naruto"
         headers = {'Content-Type': 'application/json; charset=utf8'}
         data = {'email': '*****@*****.**',
                 'fullname': u'うずまきナルト'.encode('utf8'),
                 'password': '******'}
         create_user = requests.post(create_url,
                                     headers=headers,
                                     data=json.dumps(data),
                                     cookies={'auth_pubtkt': auth_cookie})
         self.assertEqual(201,
                          int(create_user.status_code))
     self.logout()
     url = config.GATEWAY_URL + "/dashboard/"
     quoted_url = urllib2.quote(url, safe='')
     response = self.login('naruto',
                           'rasengan', quoted_url)
     self.assertEqual(url, response.url)
     naru_gerrit = self.gu.get_account('naruto')
     self.assertEqual(u'うずまきナルト',
                      naru_gerrit.get('name'))
     # TODO this should be tested in the tracker as well
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/[email protected]'
     d = requests.delete(del_url,
                         cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     self.assertEqual(False,
                      self.gu.get_account('naruto'))
Esempio n. 16
0
 def test_unicode_user(self):
     """ Try to create a local user with unicode charset, login, delete
     """
     # /!\ redmine does not support non-ASCII chars in usernames.
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     try:
         self.msu.create_user('naruto',
                              'rasengan',
                              '*****@*****.**',
                              fullname=u'うずまきナルト')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     except UnicodeEncodeError:
         # TODO the CLI works but I can't find what is wrong with
         # python's handling of unicode in subprocess.
         warnings.warn(
             'Cannot run shell command with unicode chars for '
             'whatever reason, retrying with a direct REST '
             'API call ...', UnicodeWarning)
         create_url = config.GATEWAY_URL + "/manage/user/naruto"
         headers = {'Content-Type': 'application/json; charset=utf8'}
         data = {
             'email': '*****@*****.**',
             'fullname': u'うずまきナルト'.encode('utf8'),
             'password': '******'
         }
         create_user = requests.post(create_url,
                                     headers=headers,
                                     data=json.dumps(data),
                                     cookies={'auth_pubtkt': auth_cookie})
         self.assertEqual(201, int(create_user.status_code))
     self.logout()
     url = config.GATEWAY_URL + "/sf/welcome.html"
     quoted_url = urllib2.quote(url, safe='')
     response = self.login('naruto', 'rasengan', quoted_url)
     self.assertEqual(url, response.url)
     naru_gerrit = self.gu.get_account('naruto')
     self.assertEqual(u'うずまきナルト', naru_gerrit.get('name'))
     # TODO this should be tested in the tracker as well
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/[email protected]'
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     self.assertEqual(False, self.gu.get_account('naruto'))
Esempio n. 17
0
 def test_delete_user_in_backends_by_username(self):
     """ Delete a user previously registered user by username
     """
     # first, create a user and register it with services
     try:
         self.msu.create_user('bootsy', 'collins', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('bootsy', 'collins', config.GATEWAY_URL)
     # make sure user is in redmine and gerrit
     self.assertEqual('*****@*****.**',
                      self.gu.get_account('bootsy').get('email'))
     if has_issue_tracker():
         users = self.rm.active_users()
         users = [u for u in users if u[0] == 'bootsy']
         self.assertEqual(1, len(users))
         user = users[0]
         self.assertEqual('*****@*****.**',
                          user[1])
     # now suppress it
     del_url = config.GATEWAY_URL +\
         '/manage/services_users/?username=bootsy'
     # try with a a non-admin user, it should not work ...
     auth_cookie = get_cookie(config.GATEWAY_HOST,
                              'user5', config.ADMIN_PASSWORD)
     d = requests.delete(del_url,
                         cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(400 < int(d.status_code) < 500)
     # try with an admin ...
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url,
                         cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     # make sure the user does not exist anymore
     self.assertEqual(False,
                      self.gu.get_account('bootsy'))
     if has_issue_tracker():
         users = self.rm.active_users()
         self.assertEqual(0,
                          len([u for u in users
                               if u[0] == 'bootsy']))
Esempio n. 18
0
def read_bidders(filename):
    with open(filename, 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        for row in reader:
            b = Bidder(row[0], row[1], row[2],
                       row[3] if len(row) > 3 else None)
            #if b.bidder_id in ['f5b2bbad20d1d7ded3ed960393bec0f40u6hn', 'e90e4701234b13b7a233a86967436806wqqw4']:
            #    b.outcome = 1

            add_bidder(b)

            shared.addr_1[b.get_addr_1()].add(b.bidder_id)
            shared.addr_2[b.get_addr_2()].add(b.bidder_id)

            shared.pmt_type[b.get_payment_type()].add(b.bidder_id)
            shared.pmt_accnt[b.get_payment_acct()].add(b.bidder_id)

        print "%s data done" % filename
        rc = sum([1 for i in shared.bidders.values() if utils.is_robot(i)])
        hc = sum([1 for i in shared.bidders.values() if utils.is_human(i)])
        uc = sum([1 for i in shared.bidders.values() if i.outcome is None])
        print "Found %s robots, %s humans, %s unknown" % (rc, hc, uc)
Esempio n. 19
0
def read_bidders(filename):
    with open('clean_%s' % filename, 'wb') as cbfile:
        fieldnames = ['bidder_id', 'pmt_type', 'pmt_account', 'addr_1', 'addr_2']
        if 'train' in filename:
            fieldnames.append('outcome')
        writer = csv.DictWriter(cbfile, fieldnames=fieldnames)
        writer.writeheader()
        with open(filename, 'rb') as bidsfile:
            reader = csv.reader(bidsfile,  delimiter=',',  quotechar='|')
            skip(reader, 1)
            for row in reader:
                b = Bidder(row[0], row[1], row[2], row[3] if len(row) > 3 else None)
                bidders[b.bidder_id] = b
                mrow = {
                    'bidder_id': b.bidder_id,
                    'pmt_type': b.get_payment_type(),
                    'pmt_account': b.get_payment_acct(),
                    'addr_1': b.get_addr_1(),
                    'addr_2': b.get_addr_2(),
                }
                if 'train' in filename:
                    mrow['outcome'] = b.outcome
                writer.writerow(mrow)
Esempio n. 20
0
 def test_delete_user_in_backends_by_username(self):
     """ Delete a user previously registered user by username
     """
     # first, create a user and register it with services
     try:
         self.msu.create_user('bootsy', 'collins', '*****@*****.**')
     except NotImplementedError:
         skip("user management not supported in this version of managesf")
     self.logout()
     self.login('bootsy', 'collins', config.GATEWAY_URL)
     # make sure user is in redmine and gerrit
     self.assertEqual('*****@*****.**',
                      self.gu.get_account('bootsy').get('email'))
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         users = [u for u in users if u.firstname == 'bootsy']
         self.assertEqual(1, len(users))
         user = users[0]
         self.assertEqual('*****@*****.**', user.mail)
     # now suppress it
     del_url = config.GATEWAY_URL + 'manage/services_users/?username=bootsy'
     # try with a a non-admin user, it should not work ...
     auth_cookie = get_cookie(config.GATEWAY_HOST, 'user5',
                              config.ADMIN_PASSWORD)
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertEqual(401, int(d.status_code))
     # try with an admin ...
     auth_cookie = config.USERS[config.ADMIN_USER]['auth_cookie']
     d = requests.delete(del_url, cookies={'auth_pubtkt': auth_cookie})
     self.assertTrue(int(d.status_code) < 400, d.status_code)
     # make sure the user does not exist anymore
     self.assertEqual(False, self.gu.get_account('bootsy'))
     if is_present("SFRedmine"):
         users = self.rm.r.user.filter(limit=20)
         self.assertEqual(
             0, len([u for u in users if u.firstname == 'bootsy']))
Esempio n. 21
0
									if D: self.debug("discarded")
								except:
									if D: self.debug("discarded")
						if D: self.debug("returning '%s' objects: '%s'",len(nodeList),nodeList)
						return nodeList
					snd=exe(node[2])
					typefst=type(fst)
					if typefst in [tuple]+ITER_TYPES+STR_TYPES:
						typesnd=type(snd)
						# nodes[N]
						if typesnd in NUM_TYPES or typesnd is str and snd.isdigit():
							n=int(snd)
							if D: self.debug("getting %sth element from '%s'",n,snd)
							if typefst in (generator,chain):
								if n>0:
									return skip(fst,n)
								elif n==0:
									return fst.next()
								else:
									fst=list(fst)
							else:
								try:
									return fst[n]
								except:
									return None
						# $.*['string']==$.string
						return exe((".",fst,snd))
					else:
						try:
							if D: self.debug("returning '%s'",fst[snd])
							return fst[snd]
Esempio n. 22
0
def read_bids(filename):
    country_to_time = read_country_to_time()
    skip_bids_count = 0
    skip_aucs = set()
    # time_user = dict()
    shared.price_threshold = 2000

    with open(filename, 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        c = 0
        prev_bid = None

        days = [
            [
                sys.maxint, 0, sys.maxint, 0, 0
            ],  # min, max, min diff in a day, max diff in a day, last seen time
            [sys.maxint, 0, sys.maxint, 0, 0],
            [sys.maxint, 0, sys.maxint, 0, 0]
        ]

        for row in reader:
            c += 1
            if c % 1e6 == 0:
                print "Read bids progress: %s" % c

            bidder_id = row[1]

            if bidder_id not in shared.bidders:  # or (shared.bidders[bidder_id].outcome is None and fit) or (shared.bidders[bidder_id].outcome is not None and not fit):
                continue

            bid = Bid(*row)

            # if bid.time not in time_user:
            #     time_user[bid.time] = defaultdict(list)
            # time_user[bid.time][bid.bidder_id].append(bid)

            shared.bids.append(bid)

            # time_prob = 0

            # if bid.country in country_to_time:
            #     time_prob = country_to_time[bid.country][time_to_hour(bid.time)]

            shared.auctions_to_products[bid.auction] = bid.merchandise
            shared.products.add(bid.merchandise)
            shared.countries.add(bid.country)

            shared.bidders[bidder_id].update(bid, 0)  # Ahutng!

            shared.auction_to_bids[bid.auction].append(bid)

            if bid.is_human or bid.is_robot:
                # gather stats on ip
                pref_ip = bid.ip_pref
                if pref_ip not in shared.ip_to_bidder:
                    shared.ip_to_bidder[pref_ip] = [0, 0]
                shared.ip_to_bidder[pref_ip][0 if bid.is_human else 1] += 1

            prev_bid = bid

    print "Sim bidders"
    sim_bidders()

    print "Bids stats"
    print "Total bids: %s, total auctions: %s" % (len(
        shared.bids), len(shared.auction_to_bids))

    for auc, bids in shared.auction_to_bids.iteritems():
        if not bids:
            continue
        all_unique = set()
        c = defaultdict(int)
        q = deque()
        u = 0
        first_bid = bids[0]
        last_bid = bids[-1]
        prev = None
        l = float(last_bid.time - first_bid.time)
        for bid in bids:
            if bid.bidder_id not in c:
                u += 1

            c[bid.bidder_id] += 1
            q.append(bid.bidder_id)
            all_unique.add(bid.bidder_id)

            if len(q) > 50:
                rid = q.popleft()
                c[rid] -= 1
                if not c[rid]:
                    u -= 1

            bid.prev_unique = len(all_unique)
            bid.prev_unique_50 = u
            bid.time_from_start = bid.time - first_bid.time
            bid.time_to_end = last_bid.time - bid.time
            bid.auc_length = l

            if prev:
                bid.time_to_prev_bid = bid.time - prev.time
            prev = bid

    print "Time stats"

    h = []
    r = []
    bins = [i for i in xrange(0, 265000, 5000)]
    for auc, bids in shared.auction_to_bids.iteritems():
        for bid in bids:
            j = bisect.bisect_left(bins, bid.time)
            if j >= len(bins):
                print j, bid.time
            if bid.is_human:
                h.append(bins[j])
            elif bid.is_robot:
                r.append(bins[j])

    shared.human_hist, shared.human_hist_bins = np.histogram(h,
                                                             bins,
                                                             density=True)
    joblib.dump(shared.human_hist, 'human_hist.pkl', compress=3)
    joblib.dump(shared.human_hist_bins, 'human_hist_bins.pkl', compress=3)

    #shared.human_hist = joblib.load('human_hist.pkl')
    #shared.human_hist_bins = joblib.load('human_hist_bins.pkl')
    print "Human hist prob"
    print shared.human_hist
    print shared.human_hist_bins

    analyze_time()

    print "Determine increments"
    save_increments()
    #print "Load increments"
    #load_increments()
    increments_per_bidder_per_auction()
    calc_auction_rank()

    shared.countries = list(shared.countries)
    shared.countries.sort()

    #print "Search group patterns in increments"
    #search_group_patterns(shared.auction_to_increments)
    #print "Search group patterns in bids"
    #search_group_patterns(shared.auction_to_bids)
    #print "done search group patterns"
    # save_bidders_sets()
    # sys.exit()

    print "Determine country rank"
    n = len(shared.countries)
    rc = [0 for i in xrange(n)]
    hc = [0 for i in xrange(n)]
    for auc, increments in shared.auction_to_bids.iteritems():
        for inc in increments:
            if inc.is_robot:
                rc[shared.countries.index(inc.country)] += 1
            elif inc.is_human:
                hc[shared.countries.index(inc.country)] += 1

    for i in xrange(n):
        c = shared.countries[i]
        if (rc[i] + hc[i]):
            shared.country_rank[c] = float(rc[i]) / (rc[i] + hc[i])

    print "Calculate median price per product"

    for auc, bids in shared.auction_to_bids.iteritems():
        human_prices = [
            bid.price for bid in bids if bid.is_human and bid.is_last
        ]
        robot_prices = [
            bid.price for bid in bids if bid.is_robot and bid.is_last
        ]

        shared.human_median_price_per_auction[auc] = np.median(
            human_prices) if human_prices else 0
        shared.robot_median_price_per_auction[auc] = np.median(
            robot_prices) if robot_prices else 0

    shared.human_median_price_per_product, shared.human_std_price_per_product = get_median_price_per_product(
        shared.human_median_price_per_auction)
    shared.robot_median_price_per_product, shared.robot_std_price_per_product = get_median_price_per_product(
        shared.robot_median_price_per_auction)

    print "Draw graphs"
    utils.plot_median_price_per_product(shared.human_median_price_per_product,
                                        shared.human_std_price_per_product,
                                        shared.robot_median_price_per_product,
                                        shared.robot_std_price_per_product)

    utils.draw_auctions_bids(shared.auction_to_bids, 100)
    utils.draw_bids_time_hist(19011)
    utils.draw_bids_unique(19011)
    # for auc in ['2dfh7_2', 'nys0k_2', 'oqlkh_1', 'qj8uk_2']:
    #     utils.draw_auction(auc)
    #sys.exit()
    """
    utils.draw_robots_country()
    utils.plot_price_per_product_per_bucket(shared.auction_to_increments, shared.price_threshold)

    utils.draw_bidder_to_increments_time(shared.auction_to_increments, 'is_human', 'human_to_increment_time.png')
    utils.draw_bidder_to_increments_time(shared.auction_to_increments, 'is_robot', 'robot_to_increment_time.png')


    """
    print "Total auctions %s" % (len(shared.auction_to_bids))
Esempio n. 23
0
def read_set0(filename):
    with open(filename, 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        for row in reader:
            shared.set0.add(row[0])
Esempio n. 24
0
									if D: self.debug("discarded")
								except:
									if D: self.debug("discarded")
						if D: self.debug("returning '%s' objects: '%s'",len(nodeList),nodeList)
						return nodeList
					snd=exe(node[2])
					typefst=type(fst)
					if typefst in [tuple]+ITER_TYPES+STR_TYPES:
						typesnd=type(snd)
						# nodes[N]
						if typesnd in NUM_TYPES or typesnd is str and snd.isdigit():
							n=int(snd)
							if D: self.debug("getting %sth element from '%s'",n,snd)
							if typefst in (generator,chain):
								if n>0:
									return skip(fst,n)
								elif n==0:
									return fst.next()
								else:
									fst=list(fst)
							else:
								try:
									return fst[n]
								except:
									return None
						# $.*['string']==$.string
						return exe((".",fst,snd))
					else:
						try:
							if D: self.debug("returning '%s'",fst[snd])
							return fst[snd]