本文整理汇总了Python中score.Score类的典型用法代码示例。如果您正苦于以下问题:Python Score类的具体用法?Python Score怎么用?Python Score使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Score类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_game
def new_game(cls, player):
"""Creates and returns a new game"""
# 'player' is actually a user.key value for the
# relationship (KeyProperty) to the user entity
# pacific=timezone('US/Pacific')
now = datetime.datetime.now()
game = Game(player=player)
# print ('\nNew game object is :' + str(game) + '\n')
# set up the score record
game_key = game.put()
score = Score(
game_key=game_key,
player=player,
start_date=now,
end_date=now,
move_count=0,
parent=game.key)
score_key = score.put()
game.score_key = score_key
# set up the move records
move_record = (Move(game_key=game_key))
move_record_key = move_record.put()
# print move_record_key
move_record_keys = []
move_record_keys.append(move_record_key)
game.move_record_keys = move_record_keys
# set the game number
game.game_number = game.get_max_game_number(player) + 1
game.put()
return game
示例2: TestScore
class TestScore(unittest.TestCase):
def setUp(self):
self.score = Score()
def test_initial_score(self):
self.assertEqual(0, self.score.player1)
self.assertEqual(0, self.score.player2)
def test_inc_play2(self):
ball = Ball()
ball.position['x'] = -1
self.score.check_score(ball)
self.assertEqual(0, self.score.player1)
self.assertEqual(1, self.score.player2)
self.checkFinalPosition(ball)
def checkFinalPosition(self, ball):
final_position = constants.SCREEN_WIDTH / 2 - ball.dimension['width'] / 2
self.assertEqual(final_position, ball.position['x'])
def test_inc_play1(self):
ball = Ball()
ball.position['x'] = constants.SCREEN_WIDTH + 1
self.score.check_score(ball)
self.assertEqual(1, self.score.player1)
self.assertEqual(0, self.score.player2)
self.checkFinalPosition(ball)
示例3: testgetTimeScore
def testgetTimeScore(self):
'Test if getTimeScore will return the correct time score for 3 instances'
get1 = Score()
finish1 = True
time1 = 1000
self.assertEqual(get1.getTimeScore(time1,finish1),0)
get2 = Score()
time2 = 290
self.failIf(get2.getTimeScore(time2,finish1) == 0)
示例4: get_score_for_patient
def get_score_for_patient(p):
total = 0
count = 0
for m in Medicine.objects.filter(treatments__patient=p).distinct():
r = RecurringTreatment.objects.get(patient = p, medicine = m)
pt = PillTaken.objects.filter(patient = p, medicine = m)
s = Score()
total = total + s.translate(r, pt)
count = count + 1
total = ceil(total / count)if count > 0 else 0
return total
示例5: main
def main():
WINDOW_WIDTH = 640
WINDOW_HEIGHT = 480
bulletArray = []
enemyArray = []
pygame.init()
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('CARNAPITON')
pygame.mouse.set_visible(1)
clock = pygame.time.Clock()
clock.tick(60)
grass = pygame.image.load("images/FONDO2.png")
s = Score()
p = Player(WINDOW_WIDTH, WINDOW_HEIGHT)
ec = Controller(s)
while 1:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
return
p.manageEvent(event, bulletArray)
screen.blit(grass, (0, 0))
s.draw(screen)
p.update(clock.get_time())
for bullet in bulletArray:
if bullet.isDestroyed:
bulletArray.remove(bullet)
continue
bullet.update()
for bullet in bulletArray:
bullet.draw(screen)
for e in enemyArray:
e.update(p, clock.get_time())
for e in enemyArray:
e.draw(screen)
ec.execute(WINDOW_WIDTH, WINDOW_HEIGHT, enemyArray, bulletArray, clock.get_time())
p.draw(screen)
pygame.display.flip()
示例6: _setup_score
def _setup_score(self):
"""
Sets up the score object
"""
from score import Score
self.score = Score(self.background)
示例7: record_score
def record_score(self, aggregate_data):
score = Score.query().filter(Score.user == self.user).get()
if score:
score.score += aggregate_data[0]
score.num_correct += aggregate_data[1]
score.num_incorrect += aggregate_data[2]
score.clues_used += aggregate_data[3]
else:
score = Score(user=self.user,
score=aggregate_data[0],
num_correct=aggregate_data[1],
num_incorrect=aggregate_data[2],
clues_used=aggregate_data[3])
score.put()
return score
示例8: finish_game
def finish_game(self):
"""Finish the game - user successfully finished the game."""
self.finished = True
self.put()
# Update user score
user = self.user.get()
user.finished_game(self.score)
# Add the game to the score 'board'
score = Score(user=self.user,
date=date.today(),
attempts_done=self.attempts_done,
card_cnt=self.card_cnt,
score=self.score)
score.put()
示例9: __init__
def __init__(self):
super(MenuManager, self).__init__()
self.contentsDoc = None
self.assistantProcess = QtCore.QProcess()
self.helpRootUrl = ''
self.docDir = QtCore.QDir()
self.imgDir = QtCore.QDir()
self.info = {}
self.window = None
self.qmlRoot = None
self.declarativeEngine = None
self.ticker = None
self.tickerInAnim = None
self.upButton = None
self.downButton = None
self.helpEngine = None
self.score = Score()
self.currentMenu = "[no menu visible]"
self.currentCategory = "[no category visible]"
self.currentMenuButtons = "[no menu buttons visible]"
self.currentInfo = "[no info visible]"
self.currentMenuCode = -1
self.readXmlDocument()
self.initHelpEngine()
示例10: __init__
def __init__(self):
pygame.mixer.pre_init(48000,-16,2, 1024) #Sound Settings
pygame.init()
#sets the screen resolution for the game and sets a rect for the game screen
self.screen = pygame.display.set_mode((1024,768))
self.screen_rect = self.screen.get_rect()
#initializes a clock for the game
self.clock = pygame.time.Clock()
#initializes a menu object and HUD object and Score object
self.menu = Menu()
self.hud = Hud()
self.score = Score()
#sets a boolean for whether you are still in the menu or not
self.inMenu = True
#sets a camera for the world
self.camBorder = 32
self.cam = Camera(pygame.Rect(100, 100, 1024, 768), pygame.Rect(self.camBorder, self.camBorder, 2048 - self.camBorder, 1536 - self.camBorder))
self.camShakeFactor = 0 #Magnitude of shake
self.camShakeDecayFactor = 0.08 #Lerp Amount
#Timing
self.timer = pygame.time.get_ticks()
self.elapsed = 0
#Sound Controller
self.soundCon = SoundCon()
#Game Values
self.backgroundImg = pygame.image.load("Images/Arena/Arena2.png").convert_alpha()
self.backgroundImgRect = self.backgroundImg.get_rect()
self.player = Player( self.hud )
#Effects
self.effectInstances = []
self.spawnSound = pygame.mixer.Sound("Sounds/ShipRev.wav")
self.deathSound = pygame.mixer.Sound("Sounds/shipExplo.wav")
self.enemyExplo = pygame.mixer.Sound("Sounds/enemyExplo.wav")
self.clashSound = pygame.mixer.Sound("Sounds/clash.wav")
self.boostSound = pygame.mixer.Sound("Sounds/boostLow.wav")
#Game over fade out
self.fadeImage = pygame.image.load("Images/HUD/CrackedGlass.png").convert_alpha()
self.fadeRect = self.fadeImage.get_rect()
self.fadeSurface = pygame.Surface((1024, 768), pygame.SRCALPHA)
self.fadeSurfaceAlpha = 0
self.fadeSurfaceRate = 1
self.doFade = False
self.restartGame = False
#Enemies
self.enemyList = []
self.baseNumEnemies = 2
self.spawnTime = 10
self.currentSpawnTime = 30
示例11: __init__
def __init__(self, **kwargs):
"""Game class initializer. Initializes the temporary grid.
"""
super(Game, self).__init__()
self.grid = [[None for i in range(GRID_SIZE)] for j in range(GRID_SIZE)]
self.letter_grid = LetterGrid(GRID_SIZE)
self.score = Score()
self.level = Level()
self.io = MeowDatabase()
示例12: delete_duplicates
def delete_duplicates( self, control, location ):
scores = Score.all().filter( "control =", control )
if not location in ( config.LOCATION_WORLD, config.LOCATION_WEEK ):
scores = scores.filter( "location =", location )
elif location == config.LOCATION_WEEK:
scores = scores.filter( "new_week =", True )
elif location != config.LOCATION_WORLD:
logging.error( "CronJob.delete_duplicates: Got an invalid " \
+ "location \"%s\".", location )
return
fetched = scores.order( "-points" ).fetch( config.TOP_LIST_LENGTH )
fetched = sorted( fetched, key=lambda score: score.date )
to_remove = []
i = 0
while i < len( fetched ):
scorei = fetched[i]
j = i+1
while j < len( fetched ):
scorej = fetched[j]
if not scorei is scorej and scorei.equals( scorej ) \
and not scorej in to_remove:
to_remove.append( scorej )
j += 1
i += 1
have = [ score.to_dict() for score in fetched ]
logging.info( "Location: \"%s\" Have %d scores: %s", location,
len( have ), have )
would = [ score.to_dict() for score in to_remove ]
logging.info( "Location: \"%s\"Would remove %d scores: %s", location,
len( would ), would )
count1 = 0
for score in to_remove:
if score in fetched:
count1 += 1
count2 = 0
for score in fetched:
if score in to_remove:
count2 += 1
logging.info( "count1: %d, count2: %d", count1, count2 )
try:
db.delete( to_remove )
self.response.out.write(
"<br />all entities deleted successfully." )
except Exception, msg:
self.response.out.write( "<br />Got exception: '%s'." % msg \
+ "<br />Some or all deletes might have failed." )
示例13: ponderateFrequencyMatrix
def ponderateFrequencyMatrix(groups):
"""
Return the weighted matrix for the groups
"""
matrix = Score()
length = len(groups[0][0])
for i in range(length):
for iGroup, group in enumerate(groups):
for seq in group:
aa1 = seq[i]
for iOtherGroup, otherGroup in enumerate(groups):
if iGroup != iOtherGroup:
for otherSeq in otherGroup:
aa2 = otherSeq[i]
freq = (1 / len(group)) * (1 / len(otherGroup))
if aa1 == aa2:
freq = freq / 2
matrix[aa1, aa2] = matrix.get((aa1, aa2), 0) + freq
return matrix
示例14: score_game
def score_game(self, winner, penalty_winner, penalty_loser):
""" Set up Score for Game """
if winner == self.player_one:
loser = self.player_two
else:
loser = self.player_one
# Add the game to the score 'board'
score = Score(date=date.today(),
game=self.key,
winner=winner,
loser=loser,
penalty_winner=penalty_winner,
penalty_loser=penalty_loser)
score.put()
# Update the user models
winner.get().add_win()
loser.get().add_loss()
return
示例15: create_evaluation
def create_evaluation(self, reading_system):
"Create and return a new evaluation, along with an initialized set of result objects."
from test import Test
from score import Score
from result import Result
from category import Category
from testsuite import TestSuite
testsuite = TestSuite.objects.get_most_recent_testsuite()
print "Creating evaluation for testsuite {0}".format(testsuite.version_date)
tests = Test.objects.filter(testsuite = testsuite)
evaluation = self.create(
testsuite = testsuite,
last_updated = generate_timestamp(),
percent_complete = 0.00,
reading_system = reading_system
)
evaluation.save()
total_score = Score(category = None, evaluation = evaluation)
total_score.save()
# create results for this evaluation
for t in tests:
result = Result(test = t, evaluation = evaluation, result = RESULT_NOT_ANSWERED)
result.save()
# update the score once results have been created
total_score.update(evaluation.get_all_results())
# create category score entries for this evaluation
categories = Category.objects.filter(testsuite = evaluation.testsuite)
for cat in categories:
score = Score(
category = cat,
evaluation = evaluation
)
score.update(evaluation.get_category_results(cat))
score.save()
return evaluation