Best Python code snippet using ATX
battle_timers.py
Source:battle_timers.py
1# Python bytecode 2.7 (decompiled from Python 2.7)2# Embedded file name: scripts/client/gui/Scaleform/daapi/view/battle/shared/battle_timers.py3import SoundGroups4from gui.Scaleform.daapi.view.meta.BattleTimerMeta import BattleTimerMeta5from gui.Scaleform.daapi.view.meta.PrebattleTimerMeta import PrebattleTimerMeta6from gui.battle_control.battle_constants import COUNTDOWN_STATE7from gui.battle_control.controllers.period_ctrl import IAbstractPeriodView8from helpers import dependency9from helpers import i18n10from skeletons.gui.battle_session import IBattleSessionProvider11class _WWISE_EVENTS(object):12 BATTLE_ENDING_SOON = 'time_buzzer_02'13 COUNTDOWN_TICKING = 'time_countdown'14 STOP_TICKING = 'time_countdown_stop'15_BATTLE_END_TIME = 016_STATE_TO_MESSAGE = {COUNTDOWN_STATE.WAIT: i18n.makeString('#ingame_gui:timer/waiting'),17 COUNTDOWN_STATE.START: i18n.makeString('#ingame_gui:timer/starting'),18 COUNTDOWN_STATE.STOP: i18n.makeString('#ingame_gui:timer/started')}19class PreBattleTimer(PrebattleTimerMeta, IAbstractPeriodView):20 def updateBattleCtx(self, battleCtx):21 self.as_setWinConditionTextS(battleCtx.getArenaWinString())22 def setCountdown(self, state, timeLeft):23 self.as_setMessageS(_STATE_TO_MESSAGE[state])24 if state == COUNTDOWN_STATE.WAIT:25 self.as_hideTimerS()26 else:27 self.as_setTimerS(timeLeft)28 def hideCountdown(self, state, speed):29 self.as_setMessageS(_STATE_TO_MESSAGE[state])30 self.as_hideAllS(speed)31class BattleTimer(BattleTimerMeta, IAbstractPeriodView):32 sessionProvider = dependency.descriptor(IBattleSessionProvider)33 def __init__(self):34 super(BattleTimer, self).__init__()35 self.__isTicking = False36 self.__state = COUNTDOWN_STATE.UNDEFINED37 self.__roundLength = self.arenaVisitor.type.getRoundLength()38 self.__endingSoonTime = self.arenaVisitor.type.getBattleEndingSoonTime()39 self.__endWarningIsEnabled = self.__checkEndWarningStatus()40 self.__sounds = dict()41 def destroy(self):42 for sound in self.__sounds.values():43 sound.stop()44 self.__sounds.clear()45 super(BattleTimer, self).destroy()46 @property47 def arenaVisitor(self):48 return self.sessionProvider.arenaVisitor49 def setTotalTime(self, totalTime):50 minutes, seconds = divmod(int(totalTime), 60)51 if self.__endWarningIsEnabled and self.__state == COUNTDOWN_STATE.STOP:52 if _BATTLE_END_TIME < totalTime <= self.__endingSoonTime:53 if not self.__isTicking:54 self._startTicking()55 if totalTime == self.__endingSoonTime:56 self._callWWISE(_WWISE_EVENTS.BATTLE_ENDING_SOON)57 elif self.__isTicking:58 self.__stopTicking()59 self._sendTime(minutes, seconds)60 def setState(self, state):61 self.__state = state62 def hideTotalTime(self):63 self.as_showBattleTimerS(False)64 def showTotalTime(self):65 self.as_showBattleTimerS(True)66 def _sendTime(self, minutes, seconds):67 self.as_setTotalTimeS('{:02d}'.format(minutes), '{:02d}'.format(seconds))68 def _callWWISE(self, wwiseEventName):69 sound = SoundGroups.g_instance.getSound2D(wwiseEventName)70 if sound is not None:71 sound.play()72 self.__sounds[wwiseEventName] = sound73 return74 def _setColor(self):75 self.as_setColorS(self.__isTicking)76 def _startTicking(self):77 self._callWWISE(_WWISE_EVENTS.COUNTDOWN_TICKING)78 self.__isTicking = True79 self._setColor()80 def __stopTicking(self):81 self._callWWISE(_WWISE_EVENTS.STOP_TICKING)82 self.__isTicking = False83 self._setColor()84 def __validateEndingSoonTime(self):85 return 0 < self.__endingSoonTime < self.__roundLength86 def __checkEndWarningStatus(self):87 endingSoonTimeIsValid = self.__validateEndingSoonTime()...
pairprogramming.py
Source:pairprogramming.py
1import time2persons = []3ticking = -14start = time.time()5class Person:6 def __init__(self,id,name):7 self.id = id8 self.name=name9 self.friend = None10 self.time = 011 self.inQueue = False12 self.decoration = ""13 def friendName(self):14 if self.friend: return self.friend.name15 return ""16def display():17 for person in persons:18 print person.id, '{:>10}'.format(person.name) + ' {:<10}'.format(person.friendName()), "%.2f" % person.time, person.decoration19def decorate():20 queue = [person for person in persons if person.inQueue]21 arr = sorted(queue, key=lambda person: person.time)22 for person in persons:23 person.decoration = ""24 for i in range(len(arr)):25 person = arr[i]26 person.decoration = i+127 if ticking >= 0:28 persons[ticking].decoration = "*"29def debitera(id):30 seconds = time.time() - start31 if persons[id].friend==None:32 persons[id].time += seconds33 else:34 persons[id].time += seconds/235 persons[id].friend.time += seconds/236persons.append(Person(0,"Adam"))37persons.append(Person(1,"Bertil"))38persons.append(Person(2,"Cesar"))39persons.append(Person(3,"David"))40persons.append(Person(4,"Erik"))41persons.append(Person(5,"Filip"))42persons[0].friend = persons[2]43persons[2].friend = persons[0]44persons[0].time = 13.545persons[1].time = 12.246persons[2].time = 6.547persons[3].time = 18.948persons[4].time = 1749persons[5].time = 050persons[1].inQueue = True51persons[5].inQueue = True52#persons[1].friend = persons[2]53#persons[2].friend = persons[1]54ticking = -155while True:56 decorate()57 display()58 cmd = raw_input("Command:")59 if len(cmd) == 1: # ticking on/off60 id1 = "abcdef".index(cmd[0])61 if ticking == -1:62 start = time.time()63 ticking = id164 persons[ticking].inQueue=False65 elif ticking == id1: # samma person, stoppa66 debitera(id1)67 start = 068 ticking = -169 elif ticking != -1: # olika personer70 debitera(ticking)71 start = time.time()72 ticking = id173 persons[ticking].inQueue=False74 elif len(cmd) == 2:75 id1 = "abcdef".index(cmd[0])76 id2 = "abcdef".index(cmd[1])77 if id1 == id2:78 persons[id1].inQueue = not persons[id1].inQueue79 else:80 if persons[id1].friend == None and persons[id1].friend == None:81 persons[id1].friend = persons[id2]82 persons[id2].friend = persons[id1]83 else:84 friend = persons[id1].friend85 friend.friend = None...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!