def __init__(self): # Begining: # Exit condition initialization self.running = True # Tempo initialization (Refresh rate) self.t = Tempo() self.fps = 30 self.delay = 1.0 / self.fps # Tempo initialization (Level words) self.t_w = Tempo() # Screen initialization self.scr = Screen() #self.scr.addWord(Word('Score: ', 1, -1, 0)) #self.scr.addWord(Word('Life: ', 15, -1, 0)) #self.scr.addWord(Word(name='video', speed=-0.02)) #self.scr.addWord(Word(name='shot', speed=-0.03, pos_x=15, pos_y=-3)) #self.scr.addWord(Word(name=':)', speed=-0.05, pos_x=22, pos_y=-3)) # Dynamics initialization #self.dyn = Dynamics() # Load levels self.lev = Level() #self.curr_lev = self.lev.loadLev('levels/debug.wrd') self.curr_lev = self.lev.loadLev('levels/rand.lex') # Main loop... self.mainLoop()
def get_tempo_recommendations(self, seed_tracks): seed_tracks_id = "" for seed_track in seed_tracks: seed_tracks_id += seed_track.id + "," seed_tracks_id = seed_tracks_id[:-1] url = f"https://api.spotify.com/v1/audio-features?ids={seed_tracks_id}" response = self._place_get_api_request(url) response_json = response.json() tempo_audio = [Tempo(tempo["tempo"]) for tempo in response_json["audio_features"]] return tempo_audio
from os import system from tempo import Tempo from time import sleep import random as rd tempo = Tempo() class Personagem(): def __init__(self): self.__energia = 100 self.__energiaMax = 100 self.__dinheiro = 100 self.__salario = 0 self.__expHtml = 0 self.__expJava = 0 self.__trabalhoDia = 0 self.nivel = "Sem experiência" self.trabalho = False self.__contaBanco = 0 self.carregamento = "[-----------------]" def __str__(self): return f'\nStatus do personagem:\n\nExperiência HTML: {self.expHtml}\nExperiência Java: {self.expJava}\nNÃvel: {self.nivel}' # ENCAPSULAMENTO @property def energia(self): return self.__energia @property def energiaMax(self):
class jTime(): def __init__ (self, config): self.config = config self.act = ActivityStream(config) self.tempo = Tempo(config) self.utils = JTUtils() # Build a summary per project from a list of ticket dicts # # tickets: ticket dicts # # returns: [{ # 'project': 'LBR', # 'time': '01:30:35' # }] def _get_project_summary(self,tickets): projects = [] for ticket in tickets: exists = self.utils.get_from_dict(projects,'project',ticket['project']) if exists is None: p = { 'project': ticket['project'], 'time': ticket['time'], 'tenrox_project_name': self._get_tenrox_project_name(ticket['project']), 'tenrox_comment': self._get_tenrox_comment(ticket) } projects.append(p) else: p = exists p['time'] += ticket['time'] p['tenrox_comment'] += self._get_tenrox_comment(ticket) # round up the tenrox time in each project for project in projects: project['tenrox_time'] = self._round_tenrox_time(project['time']) return projects # Sum the total time from a list of projects # # projects: list of project dicts # # return {total_time: '07:30:59', total_tenrox_time: '7.5'} def _get_total_summary(self, projects): time = timedelta() tenrox_time = 0.0 for project in projects: time += project['time'] tenrox_time += project['tenrox_time'] return { 'time': time, 'tenrox_time': tenrox_time } # derive the tenrox code from a project # # project: Jira project (LBR) # # returns: tenrox project name (LBR300) def _get_tenrox_project_name(self, project): try: code = self.config.get('tenrox_project_names',project) except ConfigParser.NoOptionError: code = project + '300 Investigation' return code # format a tenrox comment based on a ticket dict # # ticket: the ticket dict # # return: the tenrox comment ([LBR-12345|01:30:45]) def _get_tenrox_comment(self,ticket): comment = '[{0}|{1}]' return comment.format(ticket['ticket_id'],ticket['time']) # Round a datetime.timedelta object into tenrox time (4.25 instead of 04:15) # # time: timedelta obj # # return: rounded tenrox time (double) def _round_tenrox_time(self,time): spl = str(time).rsplit(':') hour = int(spl[0]) minute = int(spl[1]) second = int(spl[2]) up_from_zero = True # first round the minutes up or down as appropriate if second > 30: minute += 1 if hour > 0: up_from_zero = False minute = self._round_tenrox_minutes(minute,up_from_zero) # round up the hour if necessary if minute == 1.0: hour += 1 minute = 0.0 return hour + minute # Round (convert) standard clock minutes into tenrox values # # minutes: amount of minutes we're rounding # up_from_zero: do we want to round 0.00 to 0.25? # # return: tenrox minutes (15 minutes = 0.25) def _round_tenrox_minutes(self,minutes,up_from_zero=True): # return 0 minutes if not rounding 0 up if not up_from_zero and minutes <= 7: return 0 if minutes <= 22: return 0.25 elif minutes <= 37: return 0.5 elif minutes <= 52: return 0.75 return 1.0 # get tickets, projects and a summary for a given date # # username: jira username # password: jira password # date: datetime # # returns: { # 'tickets': tickets, # 'projects': projects, # 'summary': {total_time: '07:30:59', total_tenrox_time: '7.5'} # } def do(self, username, password, date): tickets = None try: tickets = self.tempo.get_tickets(username, password, date) except jTimeError as e: if e.code != 'NO_ACTIVITIES': raise e except HTTPUtilsError: raise jTimeError('HTTP_JIRA') # if we've got nothing from tempo, try the activity stream if tickets is None: no_act_retries = self.config.getint('activity_stream','no_act_retries') while no_act_retries >= 0: try: tickets = self.act.get_tickets(username, password, date) break except jTimeError as e: if e.code != 'NO_ACTIVITIES': raise e print 'retrying for no activities error',no_act_retries,'retries remaining' no_act_retries -= 1 # if we've got this far with no tickets, we should raise NO_ACTIVITIES if tickets is None: raise jTimeError('NO_ACTIVITIES') projects = self._get_project_summary(tickets) summary = self._get_total_summary(projects) return { 'tickets': tickets, 'projects': projects, 'summary': summary }
def __init__ (self, config): self.config = config self.act = ActivityStream(config) self.tempo = Tempo(config) self.utils = JTUtils()
# Set this variable to "threading", "eventlet" or "gevent" to test the # different async modes, or leave it set to None for the applicationlication to choose # the best option based on installed packages. async_mode = None application = Flask(__name__, static_folder='../build', static_url_path='/') application.config['SECRET_KEY'] = 'secret!' cors = CORS(application) application.config['CORS_HEADERS'] = "Content-Type" socketio = SocketIO(application, logger=True, binary=True, cors_allowed_origins="*") tempo_obj = Tempo() volume_obj = Volume() @application.route('/') def index(): return application.send_static_file('index.html') @socketio.on('connect', namespace="/test") def connect(): session['local_tempos'] = [] session['local_volumes'] = [] emit('server_response', {'data': 'connected'})
class Game: def __init__(self): # Begining: # Exit condition initialization self.running = True # Tempo initialization (Refresh rate) self.t = Tempo() self.fps = 30 self.delay = 1.0 / self.fps # Tempo initialization (Level words) self.t_w = Tempo() # Screen initialization self.scr = Screen() #self.scr.addWord(Word('Score: ', 1, -1, 0)) #self.scr.addWord(Word('Life: ', 15, -1, 0)) #self.scr.addWord(Word(name='video', speed=-0.02)) #self.scr.addWord(Word(name='shot', speed=-0.03, pos_x=15, pos_y=-3)) #self.scr.addWord(Word(name=':)', speed=-0.05, pos_x=22, pos_y=-3)) # Dynamics initialization #self.dyn = Dynamics() # Load levels self.lev = Level() #self.curr_lev = self.lev.loadLev('levels/debug.wrd') self.curr_lev = self.lev.loadLev('levels/rand.lex') # Main loop... self.mainLoop() def main(self): # Print current score #self.scr.addstr(1, 8, str(self.scr.score)) # Check input keys self.c = self.scr.getch() #if self.c != -1: if self.c >= 0 and self.c < 128: #self.scr.addstr(3, 3, chr(self.c)) self.key_res = self.scr.addKey(chr(self.c)) self.runCommand(self.key_res) self.scr.flushinp() def runCommand(self, comm): if comm: if comm == 'exit': self.running = False else: self.scr.scoreWord(comm) def mainLoop(self): while not self.scr.game_over: self.t.tick() self.main() # Level words if len(self.curr_lev) > 0: print "Entrei!" print "ELAPSED:", self.t_w.elapsed() print "ETA BEFORE IF:", self.curr_lev[0].eta if self.t_w.elapsed() >= self.curr_lev[0].eta: print "name", self.curr_lev[0].name print "yln", self.curr_lev[0].pos_y print "eta", self.curr_lev[0].eta print "life", self.scr.life print "elapsed:", self.t_w.elapsed() self.scr.addWord(self.curr_lev[0]) #print "WORDS", self.scr.words[3].name del self.curr_lev[0] print "blowup" print "length:", len(self.curr_lev) self.t_w.reset() elif len(self.scr.words) == 0: self.scr.game_over = True self.scr.init_pair(1, self.scr.COLOR_GREEN, self.scr.COLOR_BLACK) self.scr.addstr(11, 15, "Game Over!", self.scr.color_pair(1)) self.scr.refresh() sleep(3) print "Before dynPump" # Refresh dynamics self.scr.dynPump() print "Before drawPump" # Drawing refresh self.scr.drawPump() print "Before waitUntil" # Keep FPS value stable... self.t.waitUntilMultiple(self.delay)