当前位置: 首页>>代码示例>>Python>>正文


Python randgen.generate_prize函数代码示例

本文整理汇总了Python中tracker.randgen.generate_prize函数的典型用法代码示例。如果您正苦于以下问题:Python generate_prize函数的具体用法?Python generate_prize怎么用?Python generate_prize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了generate_prize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_correct_prize_amount_with_split_tickets

 def test_correct_prize_amount_with_split_tickets(self):
     prize0 = randgen.generate_prize(
         self.rand, event=self.event, sumDonations=True, randomDraw=True, ticketDraw=True)
     prize0.maximumbid = None
     prize0.save()
     prize1 = randgen.generate_prize(
         self.rand, event=self.event, sumDonations=True, randomDraw=True, ticketDraw=True)
     prize1.maximumbid = None
     prize1.save()
     donor = self.donorList[0]
     donation = randgen.generate_donation(
         self.rand, donor=donor, event=self.event, minAmount=prize0.minimumbid + prize1.minimumbid)
     donation.save()
     prize0Eligible = prize0.eligible_donors()
     self.assertEqual(0, len(prize0Eligible))
     prize1Eligible = prize1.eligible_donors()
     self.assertEqual(0, len(prize1Eligible))
     models.PrizeTicket.objects.create(
         donation=donation, prize=prize0, amount=donation.amount * Decimal('2.0'))
     models.PrizeTicket.objects.create(
         donation=donation, prize=prize1, amount=donation.amount * Decimal('2.0'))
     prize0Eligible = prize0.eligible_donors()
     self.assertEqual(1, len(prize0Eligible))
     prize1Eligible = prize1.eligible_donors()
     self.assertEqual(1, len(prize1Eligible))
开发者ID:DreadWingKnight,项目名称:donation-tracker,代码行数:25,代码来源:test_prizetickets.py

示例2: testWinMultiPrizeLowerThanMaxWin

 def testWinMultiPrizeLowerThanMaxWin(self):
     donor = randgen.generate_donor(self.rand)
     donor.save()
     prize = randgen.generate_prize(self.rand)
     prize.event = self.event
     prize.maxwinners = 3
     prize.maxmultiwin = 2
     prize.save()
     models.DonorPrizeEntry.objects.create(donor=donor, prize=prize)
     prizeWinner = models.PrizeWinner.objects.create(
         winner=donor, prize=prize, pendingcount=1, declinecount=1)
     result, msg = viewutil.draw_prize(prize)
     self.assertFalse(result)
     donor2 = randgen.generate_donor(self.rand)
     donor2.save()
     models.DonorPrizeEntry.objects.create(donor=donor2, prize=prize)
     result, msg = viewutil.draw_prize(prize)
     self.assertTrue(result)
     prizeWinner = models.PrizeWinner.objects.get(
         winner=donor2, prize=prize)
     self.assertEquals(1, prizeWinner.pendingcount)
     result, msg = viewutil.draw_prize(prize)
     self.assertTrue(result)
     result, msg = viewutil.draw_prize(prize)
     self.assertFalse(result)
开发者ID:uraniumanchor,项目名称:sda-donation-tracker-2-read-only,代码行数:25,代码来源:test_prize.py

示例3: test_accept_deadline_offset

    def test_accept_deadline_offset(self):
        # 10 days in the future
        self.event.prize_accept_deadline_delta = 10
        # TODO: it should not take this much set-up to draw a single donor to a single prize
        amount = Decimal('50.0')
        targetPrize = randgen.generate_prize(
            self.rand, event=self.event, sumDonations=False, randomDraw=False, minAmount=amount, maxAmount=amount, maxwinners=1)
        targetPrize.save()
        winner = randgen.generate_donor(self.rand)
        winner.save()
        winningDonation = randgen.generate_donation(
            self.rand, donor=winner, minAmount=amount, maxAmount=amount, event=self.event)
        winningDonation.save()
        self.assertEqual(1, len(targetPrize.eligible_donors()))
        self.assertEqual(winner.id, targetPrize.eligible_donors()[0]['donor'])
        self.assertEqual(
            0, len(prizeutil.get_past_due_prize_winners(self.event)))
        currentDate = datetime.date.today()
        result, status = prizeutil.draw_prize(targetPrize)
        prizeWin = models.PrizeWinner.objects.get(prize=targetPrize)
        self.assertEqual(prizeWin.accept_deadline_date(), currentDate +
                         datetime.timedelta(days=self.event.prize_accept_deadline_delta))

        prizeWin.acceptdeadline = datetime.datetime.utcnow().replace(
            tzinfo=pytz.utc) - datetime.timedelta(days=2)
        prizeWin.save()
        self.assertEqual(0, len(targetPrize.eligible_donors()))
        pastDue = prizeutil.get_past_due_prize_winners(self.event)
        self.assertEqual(
            1, len(prizeutil.get_past_due_prize_winners(self.event)))
        self.assertEqual(prizeWin, pastDue[0])
开发者ID:TipoftheHats,项目名称:donation-tracker,代码行数:31,代码来源:test_prize.py

示例4: test_decline_prize_single

 def test_decline_prize_single(self):
   amount = Decimal('50.0')
   targetPrize = randgen.generate_prize(self.rand,event=self.event,sumDonations=False,randomDraw=False,minAmount=amount,maxAmount=amount,maxwinners=1)
   targetPrize.save()
   self.assertEqual(0, len(targetPrize.eligible_donors()))
   donorA = randgen.generate_donor(self.rand)
   donorA.save()
   donorB = randgen.generate_donor(self.rand)
   donorB.save()
   donationA = randgen.generate_donation(self.rand,donor=donorA,minAmount=amount,maxAmount=amount,event=self.event)
   donationA.save()
   self.assertEqual(1, len(targetPrize.eligible_donors()))
   self.assertEqual(donorA.id, targetPrize.eligible_donors()[0]['donor'])
   viewutil.draw_prize(targetPrize)
   self.assertEqual(donorA, targetPrize.get_winner())
   self.assertEqual(0, len(targetPrize.eligible_donors()))
   donationB = randgen.generate_donation(self.rand,donor=donorB,minAmount=amount,maxAmount=amount,event=self.event)
   donationB.save()
   self.assertEqual(1, len(targetPrize.eligible_donors()))
   self.assertEqual(donorB.id, targetPrize.eligible_donors()[0]['donor'])
   prizeWinnerEntry = targetPrize.prizewinner_set.filter(winner=donorA)[0]
   prizeWinnerEntry.acceptstate = 'DECLINED';
   prizeWinnerEntry.save()
   self.assertEqual(1, len(targetPrize.eligible_donors()))
   self.assertEqual(donorB.id, targetPrize.eligible_donors()[0]['donor'])
   viewutil.draw_prize(targetPrize)
   self.assertEqual(donorB, targetPrize.get_winner())
   self.assertEqual(1, len(targetPrize.get_winners()))
   self.assertEqual(0, len(targetPrize.eligible_donors()))
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:29,代码来源:tests.py

示例5: test_draw_prize_multiple_donors_norandom_sum

 def test_draw_prize_multiple_donors_norandom_sum(self):
     startRun = self.runsList[5]
     endRun = self.runsList[9]
     prize = randgen.generate_prize(
         self.rand, event=self.event, sumDonations=True, randomDraw=False, startRun=startRun, endRun=endRun)
     prize.save()
     donationDonors = {}
     for donor in self.donorList:
         numDonations = self.rand.getrandbits(4)
         redHerrings = self.rand.getrandbits(4)
         donationDonors[donor.id] = {
             'donor': donor, 'amount': Decimal('0.00')}
         for i in range(0, numDonations):
             donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                 '0.01'), maxAmount=Decimal('100.00'), minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
             donation.save()
             donationDonors[donor.id]['amount'] += donation.amount
         # toss in a few extras to keep the drawer on its toes
         for i in range(0, redHerrings):
             donation = None
             if self.rand.getrandbits(1) == 0:
                 donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                     '1000.01'), maxAmount=Decimal('2000.00'), maxTime=prize.start_draw_time() - datetime.timedelta(seconds=1))
             else:
                 donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                     '1000.01'), maxAmount=prize.minimumbid - Decimal('2000.00'), minTime=prize.end_draw_time() + datetime.timedelta(seconds=1))
             donation.save()
     maxDonor = max(donationDonors.items(), key=lambda x: x[1]['amount'])[1]
     eligibleDonors = prize.eligible_donors()
     self.assertEqual(1, len(eligibleDonors))
     self.assertEqual(maxDonor['donor'].id, eligibleDonors[0]['donor'])
     self.assertEqual(1.0, eligibleDonors[0]['weight'])
     self.assertEqual(maxDonor['amount'], eligibleDonors[0]['amount'])
     for seed in [9524, 373, 747]:
         prize.prizewinner_set.all().delete()
         prize.save()
         result, message = viewutil.draw_prize(prize, seed)
         self.assertTrue(result)
         self.assertEqual(maxDonor['donor'].id, prize.get_winner().id)
     oldMaxDonor = maxDonor
     del donationDonors[oldMaxDonor['donor'].id]
     maxDonor = max(donationDonors.items(), key=lambda x: x[1]['amount'])[1]
     diff = oldMaxDonor['amount'] - maxDonor['amount']
     newDonor = maxDonor['donor']
     newDonation = randgen.generate_donation(self.rand, donor=newDonor, event=self.event, minAmount=diff + Decimal(
         '0.01'), maxAmount=diff + Decimal('100.00'), minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
     newDonation.save()
     maxDonor['amount'] += newDonation.amount
     prize = models.Prize.objects.get(id=prize.id)
     eligibleDonors = prize.eligible_donors()
     self.assertEqual(1, len(eligibleDonors))
     self.assertEqual(maxDonor['donor'].id, eligibleDonors[0]['donor'])
     self.assertEqual(1.0, eligibleDonors[0]['weight'])
     self.assertEqual(maxDonor['amount'], eligibleDonors[0]['amount'])
     for seed in [9524, 373, 747]:
         prize.prizewinner_set.all().delete()
         prize.save()
         result, message = viewutil.draw_prize(prize, seed)
         self.assertTrue(result)
         self.assertEqual(maxDonor['donor'].id, prize.get_winner().id)
开发者ID:uraniumanchor,项目名称:sda-donation-tracker-2-read-only,代码行数:60,代码来源:test_prize.py

示例6: test_prize_range_single

 def test_prize_range_single(self):
   run = self.runs[18]
   prize = randgen.generate_prize(self.rand, event=self.event, startRun=run, endRun=run)
   prizeRuns = prize.games_range()
   self.assertEqual(1, prizeRuns.count())
   self.assertEqual(run.id, prizeRuns[0].id)
   return
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:7,代码来源:tests.py

示例7: test_draw_prize_multiple_donors_random_sum

 def test_draw_prize_multiple_donors_random_sum(self):
   startRun = self.runsList[41]
   endRun = self.runsList[46]
   prize = randgen.generate_prize(self.rand, event=self.event, sumDonations=True, randomDraw=True, startRun=startRun, endRun=endRun)
   prize.save()
   donationDonors = {}
   for donor in self.donorList:
     numDonations = self.rand.getrandbits(4)
     redHerrings = self.rand.getrandbits(4)
     donationDonors[donor.id] = { 'donor': donor, 'amount': Decimal('0.00') }
     for i in range(0, numDonations):
       donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal('0.01'), maxAmount=prize.minimumbid - Decimal('0.10'), minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
       donation.save()
       donationDonors[donor.id]['amount'] += donation.amount
     # toss in a few extras to keep the drawer on its toes
     for i in range(0, redHerrings):
       donation = None
       if self.rand.getrandbits(1) == 0:
         donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal('0.01'), maxAmount=prize.minimumbid - Decimal('0.10'), maxTime=prize.start_draw_time() - datetime.timedelta(seconds=1))
       else:
         donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal('0.01'), maxAmount=prize.minimumbid - Decimal('0.10'), minTime=prize.end_draw_time() + datetime.timedelta(seconds=1))
       donation.save()
     if donationDonors[donor.id]['amount'] < prize.minimumbid:
       del donationDonors[donor.id]
   eligibleDonors = prize.eligible_donors()
   self.assertEqual(len(donationDonors.keys()), len(eligibleDonors))
   for eligibleDonor in eligibleDonors:
     found = False
     if eligibleDonor['donor'] in donationDonors:
       entry = donationDonors[eligibleDonor['donor']]
       donor = entry['donor']
       if entry['amount'] >= prize.minimumbid:
         donations = donor.donation_set.filter(timereceived__gte=prize.start_draw_time(), timereceived__lte=prize.end_draw_time())
         countAmount = Decimal('0.00')
         for donation in donations:
           countAmount += donation.amount
         self.assertEqual(entry['amount'], eligibleDonor['amount'])
         self.assertEqual(countAmount, eligibleDonor['amount'])
         self.assertAlmostEqual(min(prize.maximumbid / prize.minimumbid, entry['amount'] / prize.minimumbid), Decimal(eligibleDonor['weight']))
         found = True
   self.assertTrue(found and "Could not find the donor in the list")
   winners = []
   for seed in [51234, 235426, 62363245]:
     result, message = viewutil.draw_prize(prize, seed)
     self.assertTrue(result)
     self.assertIn(prize.get_winner().id, donationDonors)
     winners.append(prize.get_winner())
     current = prize.get_winner()
     prize.prizewinner_set.all().delete()
     prize.save()
     result, message = viewutil.draw_prize(prize, seed)
     self.assertTrue(result)
     self.assertEqual(current, prize.get_winner())
     prize.prizewinner_set.all().delete()
     prize.save()
   self.assertNotEqual(winners[0], winners[1])
   self.assertNotEqual(winners[1], winners[2])
   self.assertNotEqual(winners[0], winners[2])
   return
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:59,代码来源:tests.py

示例8: test_prize_range_gap

 def test_prize_range_gap(self):
   runsSlice = self.runs[24:34]
   prize = randgen.generate_prize(self.rand, event=self.event, startRun=runsSlice[0], endRun=runsSlice[-1])
   prizeRuns = prize.games_range()
   self.assertEqual(len(runsSlice), prizeRuns.count())
   for i in range(0, len(runsSlice)):
     self.assertEqual(runsSlice[i].id, prizeRuns[i].id)
   return
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:8,代码来源:tests.py

示例9: test_draw_prize_with_tickets_no_donations

 def test_draw_prize_with_tickets_no_donations(self):
   prize = randgen.generate_prize(self.rand, event=self.event, sumDonations=True, randomDraw=True, ticketDraw=True)
   prize.save()
   eligibleDonors = prize.eligible_donors()
   self.assertEqual(0, len(eligibleDonors))
   result, message = viewutil.draw_prize(prize)
   self.assertFalse(result)
   self.assertEqual(None, prize.get_winner())
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:8,代码来源:tests.py

示例10: test_prize_range_pair

 def test_prize_range_pair(self):
   startRun = self.runs[44]
   endRun = self.runs[45]
   prize = randgen.generate_prize(self.rand, event=self.event, startRun=startRun, endRun=endRun)
   prizeRuns = prize.games_range()
   self.assertEqual(2, prizeRuns.count())
   self.assertEqual(startRun.id, prizeRuns[0].id)
   self.assertEqual(endRun.id, prizeRuns[1].id)
   return
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:9,代码来源:tests.py

示例11: test_time_prize_no_range

 def test_time_prize_no_range(self):
   timeA = randgen.random_time(self.rand, self.eventStart, self.eventEnd)
   timeB = randgen.random_time(self.rand, self.eventStart, self.eventEnd)
   randomStart = min(timeA, timeB)
   randomEnd = max(timeA, timeB)
   prize = randgen.generate_prize(self.rand, event=self.event, startTime=randomStart, endTime=randomEnd)
   prizeRuns = prize.games_range()
   self.assertEqual(0, prizeRuns.count())
   return
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:9,代码来源:tests.py

示例12: test_draw_prize_one_donor

 def test_draw_prize_one_donor(self):
     startRun = self.runsList[14]
     endRun = self.runsList[28]
     for useRandom in [True, False]:
         for useSum in [True, False]:
             for donationSize in ['top', 'bottom', 'above', 'below', 'within']:
                 prize = randgen.generate_prize(
                     self.rand, event=self.event, sumDonations=useSum, randomDraw=useRandom, startRun=startRun, endRun=endRun)
                 prize.save()
                 donor = randgen.pick_random_element(
                     self.rand, self.donorList)
                 donation = randgen.generate_donation(
                     self.rand, donor=donor, event=self.event, minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
                 if donationSize == 'above':
                     donation.amount = prize.maximumbid + Decimal('5.00')
                 elif donationSize == 'top':
                     donation.amount = prize.maximumbid
                 elif donationSize == 'within':
                     donation.amount = randgen.random_amount(
                         self.rand, rounded=False, minAmount=prize.minimumbid, maxAmount=prize.maximumbid)
                 elif donationSize == 'bottom':
                     donation.amount = prize.minimumbid
                 elif donationSize == 'below':
                     donation.amount = max(
                         Decimal('0.00'), prize.minimumbid - Decimal('5.00'))
                 donation.save()
                 eligibleDonors = prize.eligible_donors()
                 if donationSize == 'below' and prize.randomdraw:
                     self.assertEqual(0, len(eligibleDonors))
                 else:
                     self.assertEqual(1, len(eligibleDonors))
                     self.assertEqual(donor.id, eligibleDonors[0]['donor'])
                     self.assertEqual(
                         donation.amount, eligibleDonors[0]['amount'])
                     if prize.sumdonations and prize.randomdraw:
                         if donationSize == 'top' or donationSize == 'above':
                             expectedRatio = float(
                                 prize.maximumbid / prize.minimumbid)
                         else:
                             expectedRatio = float(
                                 donation.amount / prize.minimumbid)
                         self.assertAlmostEqual(
                             expectedRatio, eligibleDonors[0]['weight'])
                     else:
                         self.assertEqual(1.0, eligibleDonors[0]['weight'])
                 result, message = viewutil.draw_prize(prize)
                 if donationSize != 'below' or not prize.randomdraw:
                     self.assertTrue(result)
                     self.assertEqual(donor, prize.get_winner())
                 else:
                     self.assertFalse(result)
                     self.assertEqual(None, prize.get_winner())
                 donation.delete()
                 prize.prizewinner_set.all().delete()
                 prize.delete()
     return
开发者ID:uraniumanchor,项目名称:sda-donation-tracker-2-read-only,代码行数:56,代码来源:test_prize.py

示例13: test_prize_range_pair

 def test_prize_range_pair(self):
     runs = randgen.generate_runs(self.rand, self.event, 5, True)
     startRun = runs[2]
     endRun = runs[3]
     prize = randgen.generate_prize(
         self.rand, event=self.event, startRun=startRun, endRun=endRun)
     prizeRuns = prize.games_range()
     self.assertEqual(2, prizeRuns.count())
     self.assertEqual(startRun.id, prizeRuns[0].id)
     self.assertEqual(endRun.id, prizeRuns[1].id)
开发者ID:TipoftheHats,项目名称:donation-tracker,代码行数:10,代码来源:test_prize.py

示例14: test_draw_prize_multiple_donors_norandom_nosum

 def test_draw_prize_multiple_donors_norandom_nosum(self):
     startRun = self.runsList[25]
     endRun = self.runsList[34]
     prize = randgen.generate_prize(
         self.rand, event=self.event, sumDonations=False, randomDraw=False, startRun=startRun, endRun=endRun)
     prize.save()
     largestDonor = None
     largestAmount = Decimal('0.00')
     for donor in self.donorList:
         numDonations = self.rand.getrandbits(4)
         redHerrings = self.rand.getrandbits(4)
         for i in range(0, numDonations):
             donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                 '0.01'), maxAmount=Decimal('1000.00'), minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
             donation.save()
             if donation.amount > largestAmount:
                 largestDonor = donor
                 largestAmount = donation.amount
         # toss in a few extras to keep the drawer on its toes
         for i in range(0, redHerrings):
             donation = None
             if self.rand.getrandbits(1) == 0:
                 donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                     '1000.01'), maxAmount=Decimal('2000.00'), maxTime=prize.start_draw_time() - datetime.timedelta(seconds=1))
             else:
                 donation = randgen.generate_donation(self.rand, donor=donor, event=self.event, minAmount=Decimal(
                     '1000.01'), maxAmount=prize.minimumbid - Decimal('2000.00'), minTime=prize.end_draw_time() + datetime.timedelta(seconds=1))
             donation.save()
     eligibleDonors = prize.eligible_donors()
     self.assertEqual(1, len(eligibleDonors))
     self.assertEqual(largestDonor.id, eligibleDonors[0]['donor'])
     self.assertEqual(1.0, eligibleDonors[0]['weight'])
     self.assertEqual(largestAmount, eligibleDonors[0]['amount'])
     for seed in [9524, 373, 747]:
         prize.prizewinner_set.all().delete()
         prize.save()
         result, message = viewutil.draw_prize(prize, seed)
         self.assertTrue(result)
         self.assertEqual(largestDonor.id, prize.get_winner().id)
     newDonor = randgen.generate_donor(self.rand)
     newDonor.save()
     newDonation = randgen.generate_donation(self.rand, donor=newDonor, event=self.event, minAmount=Decimal(
         '1000.01'), maxAmount=Decimal('2000.00'), minTime=prize.start_draw_time(), maxTime=prize.end_draw_time())
     newDonation.save()
     eligibleDonors = prize.eligible_donors()
     self.assertEqual(1, len(eligibleDonors))
     self.assertEqual(newDonor.id, eligibleDonors[0]['donor'])
     self.assertEqual(1.0, eligibleDonors[0]['weight'])
     self.assertEqual(newDonation.amount, eligibleDonors[0]['amount'])
     for seed in [9524, 373, 747]:
         prize.prizewinner_set.all().delete()
         prize.save()
         result, message = viewutil.draw_prize(prize, seed)
         self.assertTrue(result)
         self.assertEqual(newDonor.id, prize.get_winner().id)
开发者ID:uraniumanchor,项目名称:sda-donation-tracker-2-read-only,代码行数:55,代码来源:test_prize.py

示例15: testSingleEntry

 def testSingleEntry(self):
   donor = randgen.generate_donor(self.rand)
   donor.save()
   prize = randgen.generate_prize(self.rand,event=self.event)
   prize.save()
   entry = tracker.models.DonorPrizeEntry(donor=donor,prize=prize)
   entry.save()
   eligible = prize.eligible_donors()
   self.assertEqual(1, len(eligible))
   self.assertEqual(donor.pk, eligible[0]['donor'])
   self.assertEqual(entry.weight, eligible[0]['weight'])
开发者ID:quinox,项目名称:sda-donation-tracker-2,代码行数:11,代码来源:tests.py


注:本文中的tracker.randgen.generate_prize函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。