예제 #1
0
파일: test.py 프로젝트: vitrun/santa
def _claim_all(num):
    total = 301
    envelope = Santa.create_envelope(1, total, num)
    cents = []
    for i in range(num):
        claim = Santa.claim_envelope(i, envelope.id, envelope.secret)
        cents.append(claim.cent)
    assert sum(cents) == total
예제 #2
0
파일: test.py 프로젝트: vitrun/santa
def test_claim_twice():
    """
    试图领两个应拋错
    """
    envelope = Santa.create_envelope(1, 300, 3)
    Santa.claim_envelope(1, envelope.id, envelope.secret)
    try:
        Santa.claim_envelope(1, envelope.id, envelope.secret)
    except Exception as e:
        assert type(e) == SimpleException
예제 #3
0
파일: test.py 프로젝트: vitrun/santa
def test_insufficient():
    """
    领光了应拋错
    """
    num = 5
    envelope = Santa.create_envelope(1, 300, num)
    for i in range(num):
        Santa.claim_envelope(i, envelope.id, envelope.secret)
    try:
        Santa.claim_envelope(num, envelope.id, envelope.secret)
    except Exception as e:
        assert type(e) == SimpleException
예제 #4
0
def enter():
    game_framework.reset_time()
    global map, player, house, background, avalanche, coin, snows, map_on_coins, game_over, santa, game_clear, distance, stones
    map = Map()
    player = Player()
    house = House()
    background = Background()
    avalanche = Avalanche()
    coin = Coin()
    game_over = Game_over()
    santa = Santa()
    game_clear = Game_clear()
    distance = Distance()
    map_on_coins = [Map_on_Coin() for i in range(200)]
    snows = [Snow() for i in range(20)]
    stones = [Stone() for i in range(10)]

    Player.x = 300.0
    Player.y = 300.0
    Player.unreal_x = 300.0
    Player.unreal_y = 0
    Player.jump_before_y = 0
    Map.map_move_y_minor = 0
    Avalanche.game_over = 0
    Game_clear.game_clear = 0
    Santa.game_clear = 0
예제 #5
0
 def post(self):
     #: TODO. get from auth token
     try:
         user_id = int(self.get_argument('user_id'))
         envelope_id = int(self.get_argument('envelope_id'))
         secret = self.get_argument('secret')
         claim = Santa.claim_envelope(user_id, envelope_id, secret)
         self.done(data=claim.dic)
     except Exception as e:
         self.done(msg=str(e))
예제 #6
0
 def post(self):
     #: TODO. get from auth token
     try:
         user_id = int(self.get_argument('user_id'))
         cent = int(float(self.get_argument('money')) * 100)
         num = int(self.get_argument('num'))
         #: TODO. more argument check
         if num > cent:
             self.done(msg='num too large')
             return
         envelope = Santa.create_envelope(user_id, cent, num)
         self.done(envelope.dic)
     except Exception as e:
         self.done(msg=str(e))
예제 #7
0
  def matrixToCompany(self, matrix):
    for n, p in matrix.items():
      pers = Santa(n)
      self.people[n] = pers

    # loop again to add the actual people
    for n, p in self.people.items():
      cs = matrix[n]['confirmedSanta']
      if cs != '':
        p.hasSanta = True
        p.confirmedSanta = self.people[cs]
      else: 
        for nn, pp, in self.people.items():
          if (pp.name != p.name) & (pp.name != cs):
            p.addToPotentialSantas(pp)

      cg = matrix[n]['confirmedGiftee']
      if cg != '':
        p.hasGiftee = True
        p.confirmedGiftee = self.people[cg]
      else: 
        for nn, pp, in self.people.items():
          if (pp.name != p.name) & (pp.name != cg):
            p.addToPotentialGiftees(pp)
예제 #8
0
  def addPeople(self, people):
    for pName in people:
      pers = Santa(pName)
      for n, p in self.people.items():
        p.addToPotentialSantas(pers)
        p.addToPotentialGiftees(pers)
        pers.addToPotentialSantas(p)
        pers.addToPotentialGiftees(p)     
      self.people[pName] = pers
    








       
예제 #9
0
################################################################################
# This the secret santa letter template that is used to send everyone the email.
# Note that {santa} and {recipient} are automatically replaced by the secret
# santa's name, and his/her recipient of their gift.
################################################################################
letter = Letter(from_name='Secret Santa',
                from_email=smtp_user,
                subject='Family Christmas',
                greeting="{santa}, you are {recipient}'s secret Santa!",
                body="")

################################################################################
# The complete list of all the secret santa's and their email addresses.
################################################################################
santas = [
    Santa('Jan', '*****@*****.**'),
    Santa('Alisha', '*****@*****.**'),
    Santa('Pam', '*****@*****.**'),
    Santa('Mark', '*****@*****.**'),
    Santa('Nick', '*****@*****.**'),
    Santa('Erica', '*****@*****.**'),
    Santa('Luke', '*****@*****.**'),
    Santa('Sidney', '*****@*****.**'),
    Santa('Brittany', '*****@*****.**'),
]

################################################################################
# This contains a list of people that you do NOT want to be paired together...
# for whatever reason (either because they're going to gossip to each other of
# who they have as their recipient, or they just plainly can't stand the thought
# of giving each other a gift).
예제 #10
0
def send_test_email():
    test_santa = Santa('Test Santa', config.smtp_user)
    test_recipient = Santa('Test Recipient', '*****@*****.**')
    test_santa.recipient = test_recipient
    config.letter.send(test_santa)
예제 #11
0
파일: test.py 프로젝트: ReyhaneAskari/santa
import torch
torch.manual_seed(1991)
from torch.optim import RMSprop, SGD, Adam
from santa import Santa
import matplotlib.pyplot as plt

device = torch.device('cpu')
theta = torch.randn(1, 1, device=device, requires_grad=True)
theta.data = torch.Tensor([[4.0]])

N = 5000
optimizer = Santa(
    [theta],
    lr=1e-1, alpha=0.99, eps=1e-8, weight_decay=0,
    momentum=0.0, centered=False, decay_grad=0.0,
    anne_rate=0.5, burnin=N / 2, N=N)
# optimizer = Adam([theta], lr=1e-2, betas=[0.99, 0.9])
thetas = []

for t in range(N):

    loss = (theta + 4) * (theta + 1) * (theta - 1) * (theta - 3) / 14 + 0.5
    thetas.append(theta.item())
    print(t, theta.item())

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

plt.plot(thetas)
# plt.ylim([-6, 4])
예제 #12
0
파일: test.py 프로젝트: vitrun/santa
def test_gen_secret():
    """
    红包口令
    """
    assert len(Santa.gen_secret(1)) == 1
    assert len(Santa.gen_secret(99)) == 99
예제 #13
0
from santa import Santa

if __name__ == "__main__":
    santa = Santa()

    with open("input.txt", "rb") as handle:
        while True:
            step = handle.read(1)
            if not step:
                break
            santa.move(step)
        print santa.first_deliveries
예제 #14
0
letter = Letter(from_name='Secret Santa',
                from_email=smtp_user,
                subject='Family Christmas',
                body="""
Ho Ho Ho!

{santa}, you are {recipient}'s secret Santa!

Merry Christmas!
""")

################################################################################
# The complete list of all the secret santa's and their email addresses.
################################################################################
santas = [
    Santa('Jan', '*****@*****.**'),
    Santa('Alisha', '*****@*****.**'),
    Santa('Pam', '*****@*****.**'),
    Santa('Mark', '*****@*****.**'),
    Santa('Nick', '*****@*****.**'),
    Santa('Erica', '*****@*****.**'),
    Santa('Luke', '*****@*****.**'),
    Santa('Sidney', '*****@*****.**'),
    Santa('Brittany', '*****@*****.**'),
]

################################################################################
# This contains a list of people that you do NOT want to be paired together...
# for whatever reason (either because they're going to gossip to each other of
# who they have as their recipient, or they just plainly can't stand the thought
# of giving each other a gift).
예제 #15
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#

import argparse

from santa import Santa


if __name__ == '__main__':
    arger = argparse.ArgumentParser(__file__)
    arger.add_argument('job', type=str)

    args = arger.parse_args()
    if args.job == 'refund':
        Santa.refund_job()
    elif args.job == 'claim':
        Santa.claim_job()
    else:
        print('Invalid job')