Exemplo n.º 1
0
def proj_vs_actual(start_date, end_date):
    compare = None
    days = (end_date - start_date).days
    for offset in range(days + 1):
        cur_date = start_date + dt.timedelta(days = offset)
        try:
            stats = pd.read_csv(format_fpath('stat', cur_date))
        except:
            continue
        stats.loc[:,'Starters'] = stats.Starters.apply(lambda x: format_name(x))
        lineups = pd.read_csv(format_fpath('line',cur_date))
        lineups.loc[:,'Name'] = lineups.Name.apply(lambda x: format_name(x))
        combo = lineups.join(stats.set_index('Starters').FP.rename('actual'), on = 'Name').sort_values('Name').set_index('Name')
        combo['date'] = cur_date
        mapper = player_team_map()
        listed = combo.index.to_series().apply(lambda x: x in mapper.index)
        combo['PTeam'] = 'UNK'
        combo.loc[listed, 'PTeam'] = combo[listed].index.to_series().apply(lambda x: mapper.loc[x]).values
        combo['Loc'] = combo.apply(lambda x: 'Home' if x.PTeam == x.Team else 'Away', axis = 1)
        combo['Name'] = combo.index.values
        combo.index = range(len(combo))
        away = combo[combo.Loc == 'Away'].index
        temp = combo.loc[away,'Team'] 
        combo.loc[away,'Team'] = combo.loc[away,'Opp'] 
        combo.loc[away,'Opp'] = temp
        combo.set_index('Name')
        compare = combo if compare is None else compare.append(combo)
        compare.loc[:,'date'] = pd.to_datetime(compare.date)
    return compare
Exemplo n.º 2
0
    def get_force_confirm_payments_keyboard(bill_id, creditor_id, trans):
        unpaid = trans.get_unpaid_payments(bill_id, creditor_id)

        kb = []
        for payment in unpaid:
            btn = InlineKeyboardButton(
                text='✅ {}  {}{:.2f}'.format(
                    utils.format_name(payment[5], payment[3], payment[4]),
                    const.EMOJI_MONEY_BAG,
                    payment[1],
                ),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_FORCE_CONFIRM_PAYMENT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_PAYMENT_ID: payment[0]
                    }))
            kb.append([btn])

        back_btn = InlineKeyboardButton(
            text="🔙 Back",
            callback_data=utils.get_action_callback_data(
                MODULE_ACTION_TYPE, ACTION_REFRESH_BILL,
                {const.JSON_BILL_ID: bill_id}))
        kb.append([back_btn])
        return InlineKeyboardMarkup(kb)
Exemplo n.º 3
0
    def get_payment_buttons(bill_id, user_id, trans, debts=None):
        kb = []
        if debts is None:
            debts, __ = utils.calculate_remaining_debt(bill_id, trans)
        for debt in debts:
            text = '💸 Pay '
            for debtor in debt['debtors']:
                if (debtor['debtor'][0] == user_id
                        and debtor['status'] == '(Pending)'):
                    text = '💰 Unpay '
                    break

            credtr = debt['creditor']
            refresh_btn = InlineKeyboardButton(
                text="🔄 Refresh Bill",
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_REFRESH_BILL,
                    {const.JSON_BILL_ID: bill_id}))
            pay_btn = InlineKeyboardButton(
                text=text + utils.format_name(credtr[3], credtr[1], credtr[2]),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_PAY_DEBT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_CREDITOR_ID: credtr[0]
                    }))
            kb.append([refresh_btn])
            kb.append([pay_btn])

        return kb
Exemplo n.º 4
0
    def get_confirm_payments_keyboard(bill_id, creditor_id, trans):
        pending = trans.get_pending_payments(bill_id, creditor_id)

        kb = []
        for payment in pending:
            btn = InlineKeyboardButton(
                text='{}  {}{:.4f}'.format(
                    utils.format_name(payment[4], payment[2], payment[3]),
                    const.EMOJI_MONEY_BAG,
                    payment[1],
                ),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_CONFIRM_BILL_PAYMENT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_PAYMENT_ID: payment[0]
                    }))
            kb.append([btn])

        back_btn = InlineKeyboardButton(
            text="Back",
            callback_data=utils.get_action_callback_data(
                MODULE_ACTION_TYPE, ACTION_REFRESH_BILL,
                {const.JSON_BILL_ID: bill_id}))
        kb.append([back_btn])
        return InlineKeyboardMarkup(kb)
Exemplo n.º 5
0
def basic_data_formatting():
    # read relevant columns from csv and filter out players with under 10 games played
    col_list1 = ['Player', 'G', 'DRtg']
    col_list2 = ['SHOT_NUMBER', 'SHOT_CLOCK', 'DRIBBLES', 'TOUCH_TIME', 'SHOT_DIST', 'SHOT_RESULT',
                    'CLOSEST_DEFENDER', 'CLOSE_DEF_DIST', 'FGM', 'PTS']
    per100_df = pd.read_csv('per100.csv', usecols=col_list1).astype({ 'G': 'int32', 'DRtg': 'int32'})
    per100_df.query('G > 9', inplace=True)

    # reformat player name to match the shot logs
    per100_df['Player'] = per100_df['Player'].apply(lambda x: "{}".format(x.split('\\')[0]))
    per100_df['Player'] = per100_df['Player'].apply(lambda x: format_name(x))

    # sort by Defensive Rating and make a 20 / 80 split
    per100_df.sort_values(by='DRtg', inplace=True)
    split_index = int(len(per100_df.index) * SPLIT)
    quality_df = per100_df.head(split_index).copy()
    regular_df = per100_df.tail(len(per100_df.index) - split_index).copy()

    # tag players by defensive rating, concat and create a dictionary of tags
    quality_df['Q_defender'] = 1
    regular_df['Q_defender'] = 0
    tagged_players_df = pd.concat([quality_df, regular_df]) #
    tagged_players_df.drop(['G', 'DRtg'], axis='columns', inplace=True)
    tagged_dict = dict(tagged_players_df.values)

    # read shot logs and add tags
    shotlogs_df = pd.read_csv('shot_logs.csv', usecols=col_list2)
    shotlogs_df['T'] = shotlogs_df['CLOSEST_DEFENDER'].map(tagged_dict)
    shotlogs_df['T'].fillna(value=0, inplace=True)
    shotlogs_df.rename(columns={'SHOT_RESULT': 'Y'}, inplace=True)
    shotlogs_df['Y'] = shotlogs_df['Y'].apply(lambda x: 1 if x == 'made' else 0)
    shotlogs_df['FG_PERCENTAGE'] = shotlogs_df.apply(lambda x: x['FGM']/x['SHOT_NUMBER'], axis=1)
    shotlogs_df.drop(['CLOSEST_DEFENDER', 'FGM', 'SHOT_NUMBER'], axis='columns', inplace=True)

    return shotlogs_df
Exemplo n.º 6
0
 def process_get_student_profile(self, query):
     profile = []
     for student in query:
         profile.append({
             'full_name':
             utils.format_name(student['first_name'], student['last_name']),
             'sex':
             utils.get_sex(student['sex']),
             'date_of_birth':
             utils.to_mm_dd_yyyy(student['date_of_birth']),
             'phone_number':
             utils.format_phone_number(student['phone_number']),
             'age':
             str(student['age']),
             'id':
             str(student['id']),
             'address_zip_code':
             str(student['address_zip_code']),
             'username':
             student['username'],
             'address_street':
             student['address_street'],
             'address_city':
             student['address_city'],
             'address_state':
             student['address_state'],
             'email':
             student['email']
         })
     return profile[0]
Exemplo n.º 7
0
    def run(self):
        self.cursor = self.connection.cursor()
        self.cursor.execute(
            """SELECT * FROM Application AS App INNER JOIN Benchmark AS BM
                            WHERE App.benchmark = BM._id_""")

        db_list = []

        for row in self.cursor.fetchall():
            print "Profiling " + row['name'] + " Kernel: " + row["acronym"]
            cmd = os.environ[row['environment']] + row["binary"] + " " + (
                row["parameters"] or " ")
            db_name = format_name(DEVICE_NAME) + "_" + format_name(
                row['name']) + "_" + format_name(row["acronym"]) + ".db"

            cur_path = os.getcwd()
            os.chdir(os.environ[row['environment']] +
                     row["binary"][:-len(row["binary"].split('/')[-1])])

            nvprof_cmd = os.environ[
                "CUDA_DIR"] + "/bin/nvprof -f -o " + cur_path + "/" + db_name + " " + cmd
            LOG.info("Calling: " + nvprof_cmd)
            _env = os.environ.copy()
            _env['CUDA_VISIBLE_DEVICES'] = str(DEVICE_IDX)
            _env['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'  #CUDA VERSION >=7.0
            p = Popen(nvprof_cmd,
                      env=_env,
                      shell=True,
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=PIPE,
                      close_fds=True)
            output, errors = p.communicate()

            os.chdir(cur_path)

            if p.returncode:  #or errors:
                print errors
            else:
                db_list.append((db_name, row['_id_']))

        self.cursor.close()
        return db_list
Exemplo n.º 8
0
def map_team_names(name_sheet: worksheet) -> dict:
    """
    Mapeia os nomes dos times e suas variações
    """
    row = 0
    names = {}
    last_row = name_sheet.max_row

    while True:
        row += 1
        next_row = row + 1
        team = name_sheet.cell(row, 1).value
        variation = name_sheet.cell(next_row, 1).value

        if row > last_row:
            # Para quando chega à última linha
            break

        if not team:
            continue

        team = format_name(team)

        names[team] = {
            'wins': 0,
            'losses': 0,
            'draws': 0,
            'total_games': 0,
            'points': 0,
            'variations': []
        }

        while variation:
            variation = format_name(variation)
            if variation not in names[team]['variations']:
                names[team]['variations'].append(variation)

            next_row += 1
            variation = name_sheet.cell(next_row, 1).value
            row = next_row

    return names
Exemplo n.º 9
0
def EPISODES(url):
    link = get_html(url)
    matchurl = re.compile('<div class="ep_block">\s*<a href="(.*)">').findall(
        link)
    matchthumb = re.compile(
        '<div class="ep_block">\s*<a href=".*?">\s*<img src="(.*?[.jpg|.png])".*>'
    ).findall(link)
    matchname = re.compile(
        '<td class="episode-name">\s*(.*?)\s*</td>').findall(link)
    for urlc, thumb, name in zip(matchurl, matchthumb, matchname):
        add_item(X=1,
                 name=format_name(name, urlc),
                 url=urlc,
                 mode='l',
                 thumb='http:' + thumb)
Exemplo n.º 10
0
    def get_payment_buttons(bill_id, trans, debts=None):
        kb = []
        if debts is None:
            debts, __ = utils.calculate_remaining_debt(bill_id, trans)
        for debt in debts:
            credtr = debt['creditor']
            pay_btn = InlineKeyboardButton(
                text='Pay ' +
                utils.format_name(credtr[3], credtr[1], credtr[2]),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_PAY_DEBT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_CREDITOR_ID: credtr[0]
                    }))
            kb.append([pay_btn])

        return kb
Exemplo n.º 11
0
def get_proj(date):
    df = pd.read_csv(format_fpath('proj', date))
    df.loc[:, 'Name'] = df.Name.apply(lambda x: format_name(x))
    mapper = player_team_map()
    listed = df.Name.apply(lambda x: x in mapper.index)
    df['PTeam'] = 'UNK'
    df.loc[listed,
           'PTeam'] = df.loc[listed].Name.apply(lambda x: mapper.loc[x]).values
    df['Loc'] = df.apply(lambda x: 'Home' if x.PTeam == x.Team else 'Away',
                         axis=1)
    df['Name'] = df.index.values
    df.index = range(len(df))
    away = df[df.Loc == 'Away'].index
    temp = df.loc[away, 'Team']
    df.loc[away, 'Team'] = df.loc[away, 'Opp']
    df.loc[away, 'Opp'] = temp
    df.set_index('Name')
    return df
Exemplo n.º 12
0
 def send_confirmation(self, bot, cbq, bill_id, payment_id, trans):
     self.set_session(cbq.message.chat_id,
                      cbq.from_user,
                      self.action_type,
                      self.action_id,
                      0,
                      trans,
                      data={
                          const.JSON_BILL_ID: bill_id,
                          const.JSON_PAYMENT_ID: payment_id
                      })
     amt, fname, lname, uname = trans.get_payment(payment_id)
     cbq.answer()
     bot.sendMessage(chat_id=cbq.message.chat_id,
                     text=REQUEST_FORCE_PAY_CONFIRMATION.format(
                         utils.escape_html(
                             utils.format_name(uname, fname, lname)),
                         const.EMOJI_MONEY_BAG, amt),
                     parse_mode=ParseMode.HTML)
Exemplo n.º 13
0
	def process_section_query(self, sections):
		processed_sections = []
		for item in sections:
			processed_sections.append({
				'meet_day': utils.get_meet_day(item['meet_day']),
				'meet_time': utils.concat_start_end_time(
					item['meet_time_start'], item['meet_time_end']),
				'meet_date': utils.concat_start_end_date(
					item['start_date'], item['end_date']),
				'section_type': utils.get_section_type(
					item['type']),
				'course': utils.get_section_str(
					item['name'], item['title'], item['number']),
				'instructor': utils.format_name(
					item['first_name'], item['last_name'], True),
				'meet_location': item['meet_location'],
				'term': item['term']
			})
		return processed_sections
Exemplo n.º 14
0
def format_and_map_games_data(games_sheet: worksheet,
                              teams_dict: dict) -> dict:
    games = {}
    last_row_games = games_sheet.max_row

    for row in range(2, last_row_games):
        game_id = games_sheet.cell(row, 1).value

        home_team = games_sheet.cell(row, 7).value
        home_score = games_sheet.cell(row, 9).value

        away_team = games_sheet.cell(row, 12).value
        away_score = games_sheet.cell(row, 11).value

        game_date = games_sheet.cell(row, 2).value
        championship_name = format_name(games_sheet.cell(
            row, 15).value) if games_sheet.cell(row, 15).value else None

        if not away_team or not home_team:
            print(
                f'JOGO NÃO MAPEADO: O jogo "{game_id}" não tem os nomes das duas equipes.'
            )
            continue

        home_team = format_name(home_team)
        away_team = format_name(away_team)

        if home_team not in teams_dict.keys():
            this_name = away_team
            home_team = find_official_name(home_team, teams_dict)

            if not home_team:
                print(
                    f'JOGO NÃO MAPEADO: O time "{this_name}" não está na lista de nomes.'
                )
                continue

        if away_team not in teams_dict.keys():
            this_name = away_team
            away_team = find_official_name(away_team, teams_dict)

            if not away_team:
                print(
                    f'JOGO NÃO MAPEADO: O time "{this_name}" não está na lista de nomes.'
                )
                continue

        if str(home_score) == 'None' or str(away_score) == 'None':
            print(
                f'JOGO NÃO MAPEADO: O jogo "{game_id}" não tem pontuação das duas equipes.'
            )
            continue

        if not game_date or not isinstance(game_date, date):
            # Pula caso o jogo não tenha data ou data não esteja bem formatada
            print(
                f'JOGO NÃO MAPEADO: O jogo "{game_id}" não tem data ou a data está mal formatada.'
            )
            continue

        if home_score > away_score:
            winner = 'home'

        elif home_score < away_score:
            winner = 'away'

        else:
            winner = 'draw'

        games[game_id] = {
            'game_date':
            game_date,
            'game_time':
            games_sheet.cell(row, 3).value,
            'game_class':
            games_sheet.cell(row, 4).value,
            'genre':
            games_sheet.cell(row, 5).value,
            'home_team':
            home_team,
            'home_team_state':
            games_sheet.cell(row, 8).value,
            'home_score':
            home_score,
            'away_score':
            away_score,
            'away_team':
            away_team,
            'away_team_state':
            games_sheet.cell(row, 13).value,
            'game_location':
            games_sheet.cell(row, 14).value,
            'championship':
            championship_name,
            'game_city':
            games_sheet.cell(row, 16).value,
            'game_state':
            games_sheet.cell(row, 17).value,

            # Campos calculados
            'row':
            row,
            'winner':
            winner,
            'double_points':
            True if championship_name
            and 'CAMPEONATO BRASILEIRO - SÉRIE A' in championship_name else
            False,
            '15+':
            True if (home_score - away_score) >= 15 or
            (home_score - away_score) <= -15 else False,
        }

    return games
Exemplo n.º 15
0
    def run(self):
        cursor1 = self.connection.cursor()
        cursor2 = self.connection.cursor()

        cursor1.execute(
            """SELECT K.mangledName,B.environment,App.binary,App.parameters
                        FROM Kernels AS K INNER JOIN Application AS App ON K.application = App._id_
                        INNER JOIN Benchmark AS B ON App.benchmark=B._id_
                        WHERE K.cluster=1 ORDER BY K.ranking LIMIT 5;""")

        cursor2.execute(
            """SELECT K.mangledName,B.environment,App.binary,App.parameters
                        FROM Kernels AS K INNER JOIN Application AS App ON K.application = App._id_
                        INNER JOIN Benchmark AS B ON App.benchmark=B._id_
                        WHERE K.cluster=2 ORDER BY K.ranking LIMIT 5;""")

        #cursor1.execute("select K.name,B.environment,App.binary,App.parameters from Kernels as K inner join Application as App on K.application = App._id_ and K._id_=128 inner join Benchmark as B on App.benchmark=B._id_;")
        #cursor2.execute("select K.name,B.environment,App.binary,App.parameters from Kernels as K inner join Application as App on K.application = App._id_ and K._id_=129 inner join Benchmark as B on App.benchmark=B._id_;")

        rows1 = cursor1.fetchall()
        rows2 = cursor2.fetchall()

        start = 0

        print "Got " + str(len(rows1)) + " <- -> " + str(len(rows2))
        for row1 in rows1:
            for row2 in rows2:
                print "Running: " + row1['mangledName'] + " with " + row2[
                    'mangledName']

                env1 = os.environ.copy()
                env2 = os.environ.copy()

                env1['LD_PRELOAD'] = "./cuHook/libcuhook.so.0"
                env2['LD_PRELOAD'] = "./cuHook/libcuhook.so.1"

                env1['CU_HOOK_DEBUG'] = env2['CU_HOOK_DEBUG'] = '1'

                seed = str(randint(1, 50000))
                env1['RANDOM_SEED'] = env2['RANDOM_SEED'] = seed
                print "SEED: " + seed

                env1['KERNEL_NAME_0'] = row1['mangledName']
                env2['KERNEL_NAME_1'] = row2['mangledName']

                prof = Runner(
                    "nvprof --profile-all-processes -o " + LOG_DIR +
                    format_name(DEVICE_NAME) + ".output.%p.db",
                    os.environ.copy())
                app1 = Runner(
                    os.environ[row1['environment']] + row1["binary"] + " " +
                    (row1["parameters"] or " "), env1)
                app2 = Runner(
                    os.environ[row2['environment']] + row2["binary"] + " " +
                    (row2["parameters"] or " "), env2)
                prof.start()
                time.sleep(2)  #nvprof load overhead

                app1.start()
                app2.start()

                app1.join()
                app2.join()

                print app1.stdout
                print app2.stdout
                print app1.stderr
                print app2.stderr

                prof.quit()
                prof.join()

                print prof.stdout
                print prof.stderr

                time.sleep(3)  #storing db overhead

                path = os.getcwd() + "/" + LOG_DIR
                print 'Path: ' + path

                list_files = [f for f in os.listdir(path) if f.endswith(".db")]
                files = sorted(list_files, key=lambda x: (x.split('.')[-2]))

                print files

                kernel1 = files[-2]
                kernel2 = files[-1]

                try:
                    if (start == 0):
                        self.evaluateConcurrency(path + kernel1,
                                                 path + kernel2,
                                                 row1['mangledName'],
                                                 row2['mangledName'], False)
                    else:
                        self.evaluateConcurrency(path + kernel1,
                                                 path + kernel2,
                                                 row1['mangledName'],
                                                 row2['mangledName'], True)

                except Exception as e:
                    print str(e)

                os.rename(path + kernel1, path + 'histo/' + kernel1)
                os.rename(path + kernel2, path + 'histo/' + kernel2)

                start += 1

                self.check_order(path + 'histo/' + kernel1,
                                 path + 'histo/' + kernel2,
                                 row1['mangledName'], row2['mangledName'])