首页
关于本站
友情链接
全站统计
Search
1
中华人民共和国网络安全法
26 阅读
2
python爬取抖音作者主页视频
24 阅读
3
每日60秒早报 读懂时间
21 阅读
4
《极限竞速:地平线5顶级版》联机版
20 阅读
5
Python3 零基础完全入门 小白到程序猿进化 (80课全)
20 阅读
实验室
生活圈
咖啡屋
破碎代码
闲言碎语
登录
Search
标签搜索
情书
安卓
漏洞
诗词
是小刘同学
累计撰写
24
篇文章
累计收到
4
条评论
首页
栏目
实验室
生活圈
咖啡屋
破碎代码
闲言碎语
页面
关于本站
友情链接
全站统计
搜索到
6
篇与
的结果
2022-11-29
15行代码实现获取本机所有wifi密码
import subprocess获取wifi列表output = subprocess.run(['netsh', 'wlan', 'show', 'profiles'], capture_output=True).stdout.decode('gbk').split('\n')wifis = line.split(':')[1 for line in output if "所有用户配置文件" in line]查看每个wifi对应的密码for wifi in wifis:results = subprocess.run(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear'], capture_output=True).stdout.decode('gbk', errors='ignore').split('\n') results = [line.split(':')[1][1:-1] for line in results if "关键内容" in line] try: print(f'wifi名:{wifi},密码:{results[0]}') except IndexError: print(f'wifi名:{wifi},密码:无法提取')input('按enter确认并退出')
2022年11月29日
5 阅读
0 评论
0 点赞
2022-11-26
Python模拟预测2022卡塔尔世界杯结果
一、前言在逛github的时候看到一个大佬发布了模拟2022世界杯的程序,在我试验了以后发现最终模拟的结果是巴西会夺冠。这应该符合很多人的想法猜测吧,哈哈哈哈。声明:本贴仅供学习交流使用,如存在侵权行为请告知我立即删帖。github原作者【QuarterTime】 --反正我是在他那里找到的,至于他是不是原作者我也就不清楚了。二、程序代码# -*- coding:utf-8 -*- # Wan Jiongming @Copyright 2022 import cv2 import numpy as np from PIL import Image, ImageDraw, ImageFont with open("country_name.txt", "r", encoding="utf-8") as f: info = f.readlines() info = list(map(lambda x:x.strip(), info)) English_name = info[:32] Chinese_name = info[32:] country_name = {} for each in zip(English_name, Chinese_name): country_name[each[0]] = each[1] def cv2AddChineseText(img, text, position, textColor=(0, 255, 0), textSize=30): if (isinstance(img, np.ndarray)): # 判断是否OpenCV图片类型 img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) # 创建一个可以在给定图像上绘图的对象 draw = ImageDraw.Draw(img) # 字体的格式 fontStyle = ImageFont.truetype( "simsun.ttc", textSize, encoding="utf-8") # 绘制文本 draw.text(position, text, textColor, font=fontStyle) # 转换回OpenCV格式 return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR) def save_res(a, b, winner, prob, save_name): img = np.zeros((520, 850, 3), np.uint8) a_img_path = "./world_cup/" + country_name[a] + ".png" a_img = cv2.imdecode(np.fromfile(a_img_path, dtype = np.uint8), -1) a_img_h, a_img_w, _ = a_img.shape b_img_path = "./world_cup/" + country_name[b] + ".png" b_img = cv2.imdecode(np.fromfile(b_img_path, dtype = np.uint8), -1) b_img_h, b_img_w, _ = b_img.shape winner_img_path = "./world_cup/" + country_name[winner] + ".png" winner_img = cv2.imdecode(np.fromfile(winner_img_path, dtype = np.uint8), -1) winner_img_h, winner_img_w, _ = winner_img.shape img[10: 10 + a_img_h, 10: 10 + a_img_w] = a_img[:, :, :3] img[110 + a_img_h: 110 + a_img_h + b_img_h, 10: 10 + b_img_w] = b_img[:,:,:3] img = cv2AddChineseText(img, country_name[a] + "(" + a + ")", (10, 20 + a_img_h),(255, 255, 255), 30) img = cv2AddChineseText(img, country_name[b] + "(" + b + ")", (10, 20 + 100 + a_img_h + b_img_h), (255, 255, 255), 30) point1 = (10 + a_img_w, 10 + (a_img_h) // 2) point2 = (10 + a_img_w + 100, 10 + (a_img_h) // 2) cv2.line(img, point1, point2, (255, 255, 255), 10) point3 = (10 + a_img_w, 10 + 100 + a_img_h + (b_img_h) // 2) point4 = (10 + b_img_w + 100, 10 + 100 + a_img_h + (b_img_h) // 2) cv2.line(img, point3, point4, (255, 255, 255), 10) cv2.line(img, point2, point4, (255, 255, 255), 10) point5 = (10 + a_img_w + 100, 10 + 50 + a_img_h) point6 = (10 + a_img_w + 300, 10 + 50 + a_img_h) cv2.line(img, point5, point6, (255, 255, 255), 10) img = cv2AddChineseText(img, "胜率:{}".format(prob), (10 + a_img_w + 100 + 20, 10 + 50 + a_img_h - 40),(255, 255, 255), 30) img[10 + 50 + a_img_h - winner_img_h // 2: 10 + 50 + a_img_h + winner_img_h // 2, 10 + a_img_w + 300 : 10 + a_img_w + 300 + winner_img_w] = winner_img[:,:,:3] img = cv2AddChineseText(img, country_name[winner] + "(" + winner + ")", (10 + a_img_w + 300, 10 + 50 + a_img_h + winner_img_h // 2 + 10), (255, 255, 255), 30) cv2.imwrite(save_name, img) def save_res_draw(a, b, winner, prob, save_name): img = np.zeros((520, 850, 3), np.uint8) a_img_path = "./world_cup/" + country_name[a] + ".png" a_img = cv2.imdecode(np.fromfile(a_img_path, dtype = np.uint8), -1) a_img_h, a_img_w, _ = a_img.shape b_img_path = "./world_cup/" + country_name[b] + ".png" b_img = cv2.imdecode(np.fromfile(b_img_path, dtype = np.uint8), -1) b_img_h, b_img_w, _ = b_img.shape winner_img_path = "./world_cup/" + country_name[winner] + ".png" winner_img = cv2.imdecode(np.fromfile(winner_img_path, dtype = np.uint8), -1) winner_img_h, winner_img_w, _ = winner_img.shape img[10: 10 + a_img_h, 10: 10 + a_img_w] = a_img[:, :, :3] img[110 + a_img_h: 110 + a_img_h + b_img_h, 10: 10 + b_img_w] = b_img[:,:,:3] img = cv2AddChineseText(img, country_name[a] + "(" + a + ")", (10, 20 + a_img_h),(255, 255, 255), 30) img = cv2AddChineseText(img, country_name[b] + "(" + b + ")", (10, 20 + 100 + a_img_h + b_img_h), (255, 255, 255), 30) point1 = (10 + a_img_w, 10 + (a_img_h) // 2) point2 = (10 + a_img_w + 100, 10 + (a_img_h) // 2) cv2.line(img, point1, point2, (255, 255, 255), 10) point3 = (10 + a_img_w, 10 + 100 + a_img_h + (b_img_h) // 2) point4 = (10 + b_img_w + 100, 10 + 100 + a_img_h + (b_img_h) // 2) cv2.line(img, point3, point4, (255, 255, 255), 10) cv2.line(img, point2, point4, (255, 255, 255), 10) point5 = (10 + a_img_w + 100, 10 + 50 + a_img_h) point6 = (10 + a_img_w + 300, 10 + 50 + a_img_h) cv2.line(img, point5, point6, (255, 255, 255), 10) img = cv2AddChineseText(img, "胜率:{}".format(prob), (10 + a_img_w + 100 + 20, 10 + 50 + a_img_h - 40),(255, 255, 255), 30) # img[10 + 50 + a_img_h - winner_img_h // 2: 10 + 50 + a_img_h + winner_img_h // 2, 10 + a_img_w + 300 : 10 + a_img_w + 300 + winner_img_w] = winner_img[:,:,:3] # img = cv2AddChineseText(img, country_name[winner] + "(" + winner + ")", (10 + a_img_w + 300, 10 + 50 + a_img_h + winner_img_h // 2 + 10), (255, 255, 255), 30) cv2.imwrite(save_name, img) if __name__ == "__main__": save_res_draw("Switzerland", "Cameroon", "Switzerland", 0.62, "tmp.png")这里是第二部分代码,程序运行的主代码# -*- coding:utf-8 -*- # Wan Jiongming @Copyright 2022 import numpy as np import pandas as pd from operator import itemgetter from save_res import save_res, save_res_draw import time df = pd.read_csv("./kaggle/results.csv") df["date"] = pd.to_datetime(df["date"]) df.dropna(inplace=True) df = df[(df["date"] >= "2018-8-1")].reset_index(drop=True) rank = pd.read_csv("./kaggle/fifa_ranking-2022-10-06.csv") rank["rank_date"] = pd.to_datetime(rank["rank_date"]) rank = rank[(rank["rank_date"] >= "2018-8-1")].reset_index(drop=True) rank["country_full"] = rank["country_full"].str.replace("IR Iran", "Iran").str.replace("Korea Republic", "South Korea").str.replace("USA", "United States") rank = rank.set_index(['rank_date']).groupby(['country_full'], group_keys=False).resample('D').first().fillna(method='ffill').reset_index() df_wc_ranked = df.merge(rank[["country_full", "total_points", "previous_points", "rank", "rank_change", "rank_date"]], left_on=["date", "home_team"], right_on=["rank_date", "country_full"]).drop(["rank_date", "country_full"], axis=1) df_wc_ranked = df_wc_ranked.merge(rank[["country_full", "total_points", "previous_points", "rank", "rank_change", "rank_date"]], left_on=["date", "away_team"], right_on=["rank_date", "country_full"], suffixes=("_home", "_away")).drop(["rank_date", "country_full"], axis=1) df = df_wc_ranked # print(df[(df_wc_ranked.home_team == "Brazil") | (df.away_team == "Brazil")].tail(10)) def result_finder(home, away): if home > away: return pd.Series([0, 3, 0]) if home < away: return pd.Series([1, 0, 3]) else: return pd.Series([2, 1, 1]) results = df.apply(lambda x: result_finder(x["home_score"], x["away_score"]), axis=1) df[["result", "home_team_points", "away_team_points"]] = results # print(df[(df_wc_ranked.home_team == "Brazil") | (df.away_team == "Brazil")].tail(10)) import seaborn as sns import matplotlib.pyplot as plt # plt.figure(figsize=(15, 10)) # sns.heatmap(df[["total_points_home", "rank_home", "total_points_away", "rank_away"]].corr()) # plt.show() df["rank_dif"] = df["rank_home"] - df["rank_away"] df["sg"] = df["home_score"] - df["away_score"] df["points_home_by_rank"] = df["home_team_points"]/df["rank_away"] df["points_away_by_rank"] = df["away_team_points"]/df["rank_home"] home_team = df[["date", "home_team", "home_score", "away_score", "rank_home", "rank_away","rank_change_home", "total_points_home", "result", "rank_dif", "points_home_by_rank", "home_team_points"]] away_team = df[["date", "away_team", "away_score", "home_score", "rank_away", "rank_home","rank_change_away", "total_points_away", "result", "rank_dif", "points_away_by_rank", "away_team_points"]] home_team.columns = [h.replace("home_", "").replace("_home", "").replace("away_", "suf_").replace("_away", "_suf") for h in home_team.columns] away_team.columns = [a.replace("away_", "").replace("_away", "").replace("home_", "suf_").replace("_home", "_suf") for a in away_team.columns] team_stats = home_team.append(away_team)#.sort_values("date") team_stats_raw = team_stats.copy() stats_val = [] for index, row in team_stats.iterrows(): team = row["team"] date = row["date"] past_games = team_stats.loc[(team_stats["team"] == team) & (team_stats["date"] < date)].sort_values(by=['date'], ascending=False) last5 = past_games.head(5) goals = past_games["score"].mean() goals_l5 = last5["score"].mean() goals_suf = past_games["suf_score"].mean() goals_suf_l5 = last5["suf_score"].mean() rank = past_games["rank_suf"].mean() rank_l5 = last5["rank_suf"].mean() if len(last5) > 0: points = past_games["total_points"].values[0] - past_games["total_points"].values[-1]#qtd de pontos ganhos points_l5 = last5["total_points"].values[0] - last5["total_points"].values[-1] else: points = 0 points_l5 = 0 gp = past_games["team_points"].mean() gp_l5 = last5["team_points"].mean() gp_rank = past_games["points_by_rank"].mean() gp_rank_l5 = last5["points_by_rank"].mean() stats_val.append([goals, goals_l5, goals_suf, goals_suf_l5, rank, rank_l5, points, points_l5, gp, gp_l5, gp_rank, gp_rank_l5]) stats_cols = ["goals_mean", "goals_mean_l5", "goals_suf_mean", "goals_suf_mean_l5", "rank_mean", "rank_mean_l5", "points_mean", "points_mean_l5", "game_points_mean", "game_points_mean_l5", "game_points_rank_mean", "game_points_rank_mean_l5"] stats_df = pd.DataFrame(stats_val, columns=stats_cols) full_df = pd.concat([team_stats.reset_index(drop=True), stats_df], axis=1, ignore_index=False) home_team_stats = full_df.iloc[:int(full_df.shape[0]/2),:] away_team_stats = full_df.iloc[int(full_df.shape[0]/2):,:] home_team_stats = home_team_stats[home_team_stats.columns[-12:]] away_team_stats = away_team_stats[away_team_stats.columns[-12:]] home_team_stats.columns = ['home_'+str(col) for col in home_team_stats.columns] away_team_stats.columns = ['away_'+str(col) for col in away_team_stats.columns] match_stats = pd.concat([home_team_stats, away_team_stats.reset_index(drop=True)], axis=1, ignore_index=False) full_df = pd.concat([df, match_stats.reset_index(drop=True)], axis=1, ignore_index=False) def find_friendly(x): if x == "Friendly": return 1 else: return 0 full_df["is_friendly"] = full_df["tournament"].apply(lambda x: find_friendly(x)) full_df = pd.get_dummies(full_df, columns=["is_friendly"]) base_df = full_df[["date", "home_team", "away_team", "rank_home", "rank_away","home_score", "away_score","result", "rank_dif", "rank_change_home", "rank_change_away", 'home_goals_mean', 'home_goals_mean_l5', 'home_goals_suf_mean', 'home_goals_suf_mean_l5', 'home_rank_mean', 'home_rank_mean_l5', 'home_points_mean', 'home_points_mean_l5', 'away_goals_mean', 'away_goals_mean_l5', 'away_goals_suf_mean', 'away_goals_suf_mean_l5', 'away_rank_mean', 'away_rank_mean_l5', 'away_points_mean', 'away_points_mean_l5','home_game_points_mean', 'home_game_points_mean_l5', 'home_game_points_rank_mean', 'home_game_points_rank_mean_l5','away_game_points_mean', 'away_game_points_mean_l5', 'away_game_points_rank_mean', 'away_game_points_rank_mean_l5', 'is_friendly_0', 'is_friendly_1']] base_df_no_fg = base_df.dropna() df = base_df_no_fg def no_draw(x): if x == 2: return 1 else: return x df["target"] = df["result"].apply(lambda x: no_draw(x)) def create_db(df): columns = ["home_team", "away_team", "target", "rank_dif", "home_goals_mean", "home_rank_mean", "away_goals_mean", "away_rank_mean", "home_rank_mean_l5", "away_rank_mean_l5", "home_goals_suf_mean", "away_goals_suf_mean", "home_goals_mean_l5", "away_goals_mean_l5", "home_goals_suf_mean_l5", "away_goals_suf_mean_l5", "home_game_points_rank_mean", "home_game_points_rank_mean_l5", "away_game_points_rank_mean", "away_game_points_rank_mean_l5","is_friendly_0", "is_friendly_1"] base = df.loc[:, columns] base.loc[:, "goals_dif"] = base["home_goals_mean"] - base["away_goals_mean"] base.loc[:, "goals_dif_l5"] = base["home_goals_mean_l5"] - base["away_goals_mean_l5"] base.loc[:, "goals_suf_dif"] = base["home_goals_suf_mean"] - base["away_goals_suf_mean"] base.loc[:, "goals_suf_dif_l5"] = base["home_goals_suf_mean_l5"] - base["away_goals_suf_mean_l5"] base.loc[:, "goals_per_ranking_dif"] = (base["home_goals_mean"] / base["home_rank_mean"]) - (base["away_goals_mean"] / base["away_rank_mean"]) base.loc[:, "dif_rank_agst"] = base["home_rank_mean"] - base["away_rank_mean"] base.loc[:, "dif_rank_agst_l5"] = base["home_rank_mean_l5"] - base["away_rank_mean_l5"] base.loc[:, "dif_points_rank"] = base["home_game_points_rank_mean"] - base["away_game_points_rank_mean"] base.loc[:, "dif_points_rank_l5"] = base["home_game_points_rank_mean_l5"] - base["away_game_points_rank_mean_l5"] model_df = base[["home_team", "away_team", "target", "rank_dif", "goals_dif", "goals_dif_l5", "goals_suf_dif", "goals_suf_dif_l5", "goals_per_ranking_dif", "dif_rank_agst", "dif_rank_agst_l5", "dif_points_rank", "dif_points_rank_l5", "is_friendly_0", "is_friendly_1"]] return model_df model_db = create_db(df) X = model_db.iloc[:, 3:] y = model_db[["target"]] from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier from sklearn.model_selection import train_test_split, GridSearchCV X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= 0.2, random_state=1) gb = GradientBoostingClassifier(random_state=5) params = {"learning_rate": [0.01, 0.1, 0.5], "min_samples_split": [5, 10], "min_samples_leaf": [3, 5], "max_depth":[3,5,10], "max_features":["sqrt"], "n_estimators":[100, 200] } gb_cv = GridSearchCV(gb, params, cv = 3, n_jobs = -1, verbose = False) gb_cv.fit(X_train.values, np.ravel(y_train)) gb = gb_cv.best_estimator_ params_rf = {"max_depth": [20], "min_samples_split": [10], "max_leaf_nodes": [175], "min_samples_leaf": [5], "n_estimators": [250], "max_features": ["sqrt"], } rf = RandomForestClassifier(random_state=1) rf_cv = GridSearchCV(rf, params_rf, cv = 3, n_jobs = -1, verbose = False) rf_cv.fit(X_train.values, np.ravel(y_train)) rf = rf_cv.best_estimator_ # from sklearn.metrics import confusion_matrix, roc_curve, roc_auc_score # def analyze(model): # fpr, tpr, _ = roc_curve(y_test, model.predict_proba(X_test.values)[:,1]) #test AUC # plt.figure(figsize=(15,10)) # plt.plot([0, 1], [0, 1], 'k--') # plt.plot(fpr, tpr, label="test") # fpr_train, tpr_train, _ = roc_curve(y_train, model.predict_proba(X_train.values)[:,1]) #train AUC # plt.plot(fpr_train, tpr_train, label="train") # auc_test = roc_auc_score(y_test, model.predict_proba(X_test.values)[:,1]) # auc_train = roc_auc_score(y_train, model.predict_proba(X_train.values)[:,1]) # plt.legend() # plt.title('AUC score is %.2f on test and %.2f on training'%(auc_test, auc_train)) # plt.show() # plt.figure(figsize=(15, 10)) # cm = confusion_matrix(y_test, model.predict(X_test.values)) # sns.heatmap(cm, annot=True, fmt="d") # analyze(gb) with open("country_name.txt", "r", encoding="utf-8") as f: info = f.readlines() info = list(map(lambda x:x.strip(), info)) English_name = info[:32] Chinese_name = info[32:] country_name = {} for each in zip(English_name, Chinese_name): country_name[each[0]] = each[1] table = {'A': [['Qatar', 0, []], ['Ecuador', 0, []], ['Senegal', 0, []], ['Netherlands', 0, []]], 'B': [['England', 0, []], ['Iran', 0, []], ['United States', 0, []], ['Wales', 0, []]], 'C': [['Argentina', 0, []], ['Saudi Arabia', 0, []], ['Mexico', 0, []], ['Poland', 0, []]], 'D': [['France', 0, []], ['Australia', 0, []], ['Denmark', 0, []], ['Tunisia', 0, []]], 'E': [['Spain', 0, []], ['Costa Rica', 0, []], ['Germany', 0, []], ['Japan', 0, []]], 'F': [['Belgium', 0, []], ['Canada', 0, []], ['Morocco', 0, []], ['Croatia', 0, []]], 'G': [['Brazil', 0, []], ['Serbia', 0, []], ['Switzerland', 0, []], ['Cameroon', 0, []]], 'H': [['Portugal', 0, []], ['Ghana', 0, []], ['Uruguay', 0, []], ['South Korea', 0, []]]} groups = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] group_count = 7 matches = [('A', 'Qatar', 'Ecuador'), ('A', 'Senegal', 'Netherlands'), ('A', 'Qatar', 'Senegal'), ('A', 'Netherlands', 'Ecuador'), ('A', 'Ecuador', 'Senegal'), ('A', 'Netherlands', 'Qatar'), ('B', 'England', 'Iran'), ('B', 'United States', 'Wales'), ('B', 'Wales', 'Iran'), ('B', 'England', 'United States'), ('B', 'Wales', 'England'), ('B', 'Iran', 'United States'), ('C', 'Argentina', 'Saudi Arabia'), ('C', 'Mexico', 'Poland'), ('C', 'Poland', 'Saudi Arabia'), ('C', 'Argentina', 'Mexico'), ('C', 'Poland', 'Argentina'), ('C', 'Saudi Arabia', 'Mexico'), ('D', 'Denmark', 'Tunisia'), ('D', 'France', 'Australia'), ('D', 'Tunisia', 'Australia'), ('D', 'France', 'Denmark'), ('D', 'Australia', 'Denmark'), ('D', 'Tunisia', 'France'), ('E', 'Germany', 'Japan'), ('E', 'Spain', 'Costa Rica'), ('E', 'Japan', 'Costa Rica'), ('E', 'Spain', 'Germany'), ('E', 'Japan', 'Spain'), ('E', 'Costa Rica', 'Germany'), ('F', 'Morocco', 'Croatia'), ('F', 'Belgium', 'Canada'), ('F', 'Belgium', 'Morocco'), ('F', 'Croatia', 'Canada'), ('F', 'Croatia', 'Belgium'), ('F', 'Canada', 'Morocco'), ('G', 'Switzerland', 'Cameroon'), ('G', 'Brazil', 'Serbia'), ('G', 'Cameroon', 'Serbia'), ('G', 'Brazil', 'Switzerland'), ('G', 'Serbia', 'Switzerland'), ('G', 'Cameroon', 'Brazil'), ('H', 'Uruguay', 'South Korea'), ('H', 'Portugal', 'Ghana'), ('H', 'South Korea', 'Ghana'), ('H', 'Portugal', 'Uruguay'), ('H', 'Ghana', 'Uruguay'), ('H', 'South Korea', 'Portugal')] def find_stats(team_1): #team_1 = "Qatar" past_games = team_stats_raw[(team_stats_raw["team"] == team_1)].sort_values("date") last5 = team_stats_raw[(team_stats_raw["team"] == team_1)].sort_values("date").tail(5) team_1_rank = past_games["rank"].values[-1] team_1_goals = past_games.score.mean() team_1_goals_l5 = last5.score.mean() team_1_goals_suf = past_games.suf_score.mean() team_1_goals_suf_l5 = last5.suf_score.mean() team_1_rank_suf = past_games.rank_suf.mean() team_1_rank_suf_l5 = last5.rank_suf.mean() team_1_gp_rank = past_games.points_by_rank.mean() team_1_gp_rank_l5 = last5.points_by_rank.mean() return [team_1_rank, team_1_goals, team_1_goals_l5, team_1_goals_suf, team_1_goals_suf_l5, team_1_rank_suf, team_1_rank_suf_l5, team_1_gp_rank, team_1_gp_rank_l5] def find_features(team_1, team_2): rank_dif = team_1[0] - team_2[0] goals_dif = team_1[1] - team_2[1] goals_dif_l5 = team_1[2] - team_2[2] goals_suf_dif = team_1[3] - team_2[3] goals_suf_dif_l5 = team_1[4] - team_2[4] goals_per_ranking_dif = (team_1[1]/team_1[5]) - (team_2[1]/team_2[5]) dif_rank_agst = team_1[5] - team_2[5] dif_rank_agst_l5 = team_1[6] - team_2[6] dif_gp_rank = team_1[7] - team_2[7] dif_gp_rank_l5 = team_1[8] - team_2[8] return [rank_dif, goals_dif, goals_dif_l5, goals_suf_dif, goals_suf_dif_l5, goals_per_ranking_dif, dif_rank_agst, dif_rank_agst_l5, dif_gp_rank, dif_gp_rank_l5, 1, 0] advanced_group = [] last_group = "" for k in table.keys(): for t in table[k]: t[1] = 0 t[2] = [] for idx, teams in enumerate(matches): draw = False team_1 = find_stats(teams[1]) team_2 = find_stats(teams[2]) features_g1 = find_features(team_1, team_2) features_g2 = find_features(team_2, team_1) probs_g1 = gb.predict_proba([features_g1]) probs_g2 = gb.predict_proba([features_g2]) team_1_prob_g1 = probs_g1[0][0] team_1_prob_g2 = probs_g2[0][1] team_2_prob_g1 = probs_g1[0][1] team_2_prob_g2 = probs_g2[0][0] team_1_prob = (probs_g1[0][0] + probs_g2[0][1])/2 team_2_prob = (probs_g2[0][0] + probs_g1[0][1])/2 if ((team_1_prob_g1 > team_2_prob_g1) & (team_2_prob_g2 > team_1_prob_g2)) | ((team_1_prob_g1 < team_2_prob_g1) & (team_2_prob_g2 < team_1_prob_g2)): draw=True for i in table[teams[0]]: if i[0] == teams[1] or i[0] == teams[2]: i[1] += 1 elif team_1_prob > team_2_prob: winner = teams[1] winner_proba = team_1_prob for i in table[teams[0]]: if i[0] == teams[1]: i[1] += 3 elif team_2_prob > team_1_prob: winner = teams[2] winner_proba = team_2_prob for i in table[teams[0]]: if i[0] == teams[2]: i[1] += 3 for i in table[teams[0]]: #adding criterio de desempate (probs por jogo) if i[0] == teams[1]: i[2].append(team_1_prob) if i[0] == teams[2]: i[2].append(team_2_prob) if last_group != teams[0]: if last_group != "": print("\n") print("小组 %s 排名: "%(last_group)) for i in table[last_group]: #adding crieterio de desempate i[2] = np.mean(i[2]) final_points = table[last_group] final_table = sorted(final_points, key=itemgetter(1, 2), reverse = True) advanced_group.append([final_table[0][0], final_table[1][0]]) for i in final_table: print("%s -------- %d"%(country_name[i[0]] + "(" + i[0] + ")", i[1])) print("\n") print("-"*10+" 开始分析小组 %s "%(teams[0])+"-"*10) if draw == False: print("小组 %s - %s vs. %s: %s 获胜,胜率: %.2f"%(teams[0], country_name[teams[1]] + "(" + teams[1] + ")", country_name[teams[2]] + "(" + teams[2] + ")", country_name[winner] + "(" + winner + ")", winner_proba)) save_res(teams[1], teams[2], winner, winner_proba, "{}-{}.png".format(teams[0], idx)) else: print("小组 %s - %s vs. %s: Draw"%(teams[0], teams[1], teams[2])) save_res_draw(teams[1], teams[2], teams[2], 0.5, "{}-{}.png".format(teams[0], idx)) last_group = teams[0] print("\n") print("小组 %s 排名: "%(last_group)) for i in table[last_group]: #adding crieterio de desempate i[2] = np.mean(i[2]) final_points = table[last_group] final_table = sorted(final_points, key=itemgetter(1, 2), reverse = True) advanced_group.append([final_table[0][0], final_table[1][0]]) for i in final_table: print("%s -------- %d"%(country_name[i[0]] + "(" + i[0] + ")", i[1])) advanced = advanced_group playoffs = {"16 强": [], "四分之一决赛": [], "半决赛": [], "决赛": []} for p in playoffs.keys(): playoffs[p] = [] actual_round = "" next_rounds = [] for p in playoffs.keys(): if p == "16 强": control = [] for a in range(0, len(advanced*2), 1): if a < len(advanced): if a % 2 == 0: control.append((advanced*2)[a][0]) else: control.append((advanced*2)[a][1]) else: if a % 2 == 0: control.append((advanced*2)[a][1]) else: control.append((advanced*2)[a][0]) playoffs[p] = [[control[c], control[c+1]] for c in range(0, len(control)-1, 1) if c%2 == 0] for i in range(0, len(playoffs[p]), 1): game = playoffs[p][i] home = game[0] away = game[1] team_1 = find_stats(home) team_2 = find_stats(away) features_g1 = find_features(team_1, team_2) features_g2 = find_features(team_2, team_1) probs_g1 = gb.predict_proba([features_g1]) probs_g2 = gb.predict_proba([features_g2]) team_1_prob = (probs_g1[0][0] + probs_g2[0][1])/2 team_2_prob = (probs_g2[0][0] + probs_g1[0][1])/2 if actual_round != p: print("-"*10) print("开始模拟 %s"%(p)) print("-"*10) print("\n") if team_1_prob < team_2_prob: print("%s vs. %s: %s 晋级,概率: %.2f"%(country_name[home] + "(" + home + ")", country_name[away] + "(" + away + ")", country_name[away] + "(" + away + ")", team_2_prob)) save_res(home, away, away, team_2_prob, "%s.png" % str(time.time()).replace(".", "_")) next_rounds.append(away) else: print("%s vs. %s: %s 晋级,概率: %.2f"%(country_name[home] + "(" + home + ")", country_name[away] + "(" + away + ")", country_name[home] + "(" + home + ")", team_1_prob)) save_res(home, away, home, team_1_prob, "%s.png" % str(time.time()).replace(".", "_")) next_rounds.append(home) game.append([team_1_prob, team_2_prob]) playoffs[p][i] = game actual_round = p else: playoffs[p] = [[next_rounds[c], next_rounds[c+1]] for c in range(0, len(next_rounds)-1, 1) if c%2 == 0] next_rounds = [] for i in range(0, len(playoffs[p])): game = playoffs[p][i] home = game[0] away = game[1] team_1 = find_stats(home) team_2 = find_stats(away) features_g1 = find_features(team_1, team_2) features_g2 = find_features(team_2, team_1) probs_g1 = gb.predict_proba([features_g1]) probs_g2 = gb.predict_proba([features_g2]) team_1_prob = (probs_g1[0][0] + probs_g2[0][1])/2 team_2_prob = (probs_g2[0][0] + probs_g1[0][1])/2 if actual_round != p: print("-"*10) print("开始模拟 %s"%(p)) print("-"*10) print("\n") if team_1_prob < team_2_prob: print("%s vs. %s: %s 晋级,概率: %.2f"%(country_name[home] + "(" + home + ")", country_name[away] + "(" + away + ")", country_name[away] + "(" + away + ")", team_2_prob)) save_res(home, away, away, team_2_prob, "%s.png" % str(time.time()).replace(".", "_")) next_rounds.append(away) else: print("%s vs. %s: %s 晋级,概率: %.2f"%(country_name[home] + "(" + home + ")", country_name[away] + "(" + away + ")", country_name[home] + "(" + home + ")", team_1_prob)) save_res(home, away, home, team_1_prob, "%s.png" % str(time.time()).replace(".", "_")) next_rounds.append(home) game.append([team_1_prob, team_2_prob]) playoffs[p][i] = game actual_round = p
2022年11月26日
9 阅读
0 评论
0 点赞
2022-11-18
使用c++SDK写个钢琴,加上自动演奏外挂
钢琴买不起,可以自己码一个。来个C++ Piano,码砖累了还可以即兴演奏一首。主要用到SDK知识,文件流,字符转,程序之间消息传送,window运行程序遍历等音源和乐谱在压缩包中,一并奉上,望大佬多多指教实现播放本地音乐:在项目中添加音乐文件,如果在vs中运行即以main数所在文件夹为当前文件夹,如果运行的是exe文件,则是以exe文件所在的文件夹为当前文件夹。导入Windows.h头文件,#pragma comment(lib,"winmm.lib"),需要使用micString(),该函数用于将mci(媒体控制设备)有关指令发送到设备上。该函数有两种版本A版和W版,是否可以使用通用版?函数如果成功返回0失败则返回其他。MCIERROR mciSendString( LPCTSTR lpszCommand, //发送给MCI的指令 LPTSTR lpszReturnString, //返回的结果 UINT cchReturn, //返回结果大小 HANDLE hwndCallback //如果在命令字符串中指定了“通知”标志,则返回回调窗口的hwndCallback句柄 );新建一个loadmusic函数导入所有音乐并设置别名mciSendStringA(("open sound\start.mp3 alias START"), temp, 255, 0);这里alias是别名指令,将start.mp3打开为别名START。新建一个PlayMusic函数用于播放已经打开的音乐,mciSendStringA("seek START to start", NULL, 0, 0);mciSendStringA("play START", NULL, 0, 0);实现窗口对按键的反应在窗口的回调函数中判断 Msg 如果是WM_CHAR消息,则获取wParam的值,以该值作为索引找出对应的音乐。按下不同的按键就会打开对应音乐。实现外挂读取文件包含windows,使用GetDesktopWindow()得到桌面句柄,使用GetWindow得到屏幕上第一个子窗口句柄,通过while循环和GetNextWindow遍历所有窗口,找到Piano程序,得到其句柄。创建SendOpern函数发送曲谱,参数为句柄,第一步打开文件获取数据,使用ofstream读取文本文件。(无法读取空格)将读取到的字符通过sendmessage发送给Pinao窗口,第一个参数为句柄,第二个参数为发送消息类型,第三个参数为wParam,第四个参数为lParam。 SendMessage( hd,WM_CHAR,k, 0)。贴上源代码Piano#include<Windows.h> #include<tchar.h>//为通用提供映射 #include< conio.h > #include<stdio.h> //该链接库用于音乐播放 #pragma comment(lib,"winmm.lib") LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void LoadMusic(); int APIENTRY _tWinMain( HINSTANCE hinstance, //实例句柄 HINSTANCE hPrevInstance, LPTSTR lpCmdLine, //命令行参数 int nCmdShow //显示方式 ) { //1.设计窗口类 WNDCLASS ws = {}; //窗口类名 ws.lpszClassName = _T("Music"); //窗口回调函数 ws.lpfnWndProc = WndProc; //背景颜色 ws.hbrBackground = CreateSolidBrush(RGB(255, 180, 255)); //光标图标菜单, ws.hInstance = hinstance; //2.注册窗口类 RegisterClass(&ws); //3.创建窗口 HWND hWnd = CreateWindow( _T("Music"), //窗口类名 _T("Piano"), //窗口名 WS_OVERLAPPEDWINDOW,//窗口风格 100, 100, //窗口左上角的位置,以屏幕左上角为参考点 600, 800, //窗口的宽度和高度 NULL, //父窗口句柄 NULL, //菜单句柄 hinstance, //实例句柄 NULL //附加参数 ); //4.更新显示窗口 ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); LoadMusic(); //5.消息循环 MSG msg = {}; //GetMessage //第一个是消息结构体 //第二个是窗口句柄,如果填0就是所有窗口的消息 //第三个是最小消息数量 //第四个是最大消息数量 while (GetMessage(&msg, 0, 0, 0)) { //将消息分发给回调函数 TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_CHAR: { char szBuf[100] = { 0 }; char szBuf1[100] = { 0 }; sprintf_s(szBuf, sizeof(szBuf), "seek %c to start", wParam); sprintf_s(szBuf1, sizeof(szBuf1), "play %c", wParam); mciSendStringA(szBuf, NULL, 0, 0); mciSendStringA(szBuf1, NULL, 0, 0); }break; case WM_KEYDOWN: { //MessageBox(0, buff, 0, 0); }break; case WM_CLOSE: PostQuitMessage(0); break; default: break; } //如果不想要处理的消息类型,就让他返回默认的处理函数 return DefWindowProc(hWnd, Msg, wParam, lParam); } void LoadMusic() { char A = 'A'; for (int i = 1; i < 26; i++) { char szBuf[100] = { 0 }; sprintf_s(szBuf, sizeof(szBuf), "open sound\\Sound_%c.wav alias %c", A, A);//写入 A++; mciSendStringA(szBuf, NULL, 0, 0); } }辅助,读取琴谱自动演奏#include <Windows.h> #include <stdio.h> #include <tchar.h> #include <string.h> #include <iostream> #include<fstream> void SendOpern(HWND hd); void SendOpern2(HWND hd); using namespace std; int main() { HWND hd = GetDesktopWindow(); //得到桌面窗口 hd = GetWindow(hd, GW_CHILD); //得到屏幕上第一个子窗口 char s[200] = {0}; int num = 1; while (hd != NULL) //循环得到所有的子窗口 { //memset(s, 0,200); GetWindowTextA(hd, s, 200); //cout << num++ << ": " << s <<sizeof(s) << endl; //由于字符串数组之间无法比较,所以需要转换为字符串 std::string a(&s[0], &s[strlen(s)]); if (a == "Piano") { SendOpern2(hd); printf("演奏成功"); break; } hd = GetNextWindow(hd, GW_HWNDNEXT); } SendOpern(hd); getchar(); return 0; } void SendOpern(HWND hd) { ifstream Opern; Opern.open("Sound.txt", ios::in); char k; while (Opern >> k) { Sleep(800); //此处空格和"\n"都被>>吃掉了 SendMessage( hd, WM_CHAR, k, 0 ); printf("%c\n", k); } } void SendOpern2(HWND hd) { ifstream Opern; Opern.open("Sound.txt", ios::in); string k; while (Opern >> k) { for (auto ele : k) { Sleep(1000); SendMessage( hd, WM_CHAR, ele, 0 ); printf("%c\n", ele); } Sleep(1000); } }
2022年11月18日
7 阅读
0 评论
0 点赞
2022-11-15
程序员必做50题第1题
题目有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?代码#include <stdio.h> #include <stdlib.h> int main() { int n; int i,j,k; for(i=1;i<5;i++) { for(j=1;j<5;j++) { for(k=1;k<5;k++) { if(i!=j&&i!=k&&j!=k) { printf("%d%d%d\n",i,j,k); n++; } } } } printf("一共有:%d组\n",n); return 0; }运行结果
2022年11月15日
7 阅读
0 评论
1 点赞
2022-11-15
程序员必做50题第2题
题目企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%; 20 万到40万之间时,高于20万元的部分,可提成5%; 40万到60万之间时高于40万元的部分,可提成3%; 60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数?代码#include <stdio.h> int main() { double profit,bonus1,bonus2,bonus4,bonus6,bonus10,bonus; printf("请输入企业利润(单位元):"); scanf("%lf",&profit); //计算每个利润段的奖励基数。 bonus1 = 100000 * 0.1; //利润低于或等于10万元时,将近课提10% bonus2 = bonus1 + 100000 * 0.075; //利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分可提成7.5% bonus4 = bonus2 + 200000 * 0.05; //20万到40万之间时,高于20万元的部分可提成5% bonus6 = bonus4 + 200000 * 0.03; //40万到60万之间时,高于40万的部分可提成3% bonus10 = bonus6 + 400000 * 0.015; //60万到100万之间时,高于60万的部分,可提成1.5% if (profit <= 100000) bonus = profit * 0.1; else if (profit <= 200000) bonus = bonus1 + (profit - 100000) * 0.075; else if (profit <= 400000) bonus = bonus2 + (profit - 200000) * 0.05; else if (profit <= 6000000) bonus = bonus4 + (profit - 400000) * 0.03; else if (profit <= 1000000) bonus = bonus6 + (profit - 600000) * 0.015; else if (profit > 1000000) bonus = bonus10 + (profit - 1000000) * 0.01; printf("提成为:bonus=%lf\n",bonus); }运行结果
2022年11月15日
6 阅读
0 评论
0 点赞
1
2
")
首页
复制
搜索
前进
后退
重载网页
和我当邻居
给我留言吧