import numpy as np import matplotlib.pyplot as plt import json data = json.load(open('boardgames-2022.json', 'r')) data1 = list(filter(lambda v: v['plays'] == 1, data)) data2 = list(filter(lambda v: v['plays'] == 2, data)) data3 = list(filter(lambda v: v['plays'] == 3, data)) def plotx(xlambda, games, color, marker, plt): x = list(map(xlambda, games)) y = list(map(lambda v: v['weight'], games)) plt.grid(linestyle='dotted') plt.scatter(x, y, s=150, c=color, marker=marker, alpha=0.5) plt.set_ylim(0, 4.5) plt.set_xlim = plt.xlim plt.set_ylim = plt.ylim fig, ((ax1, ax2)) = plt.subplots(2, figsize=(7, 7)) ax1.set_xlim(1, 10) ax1.set_xlabel('BGG Score (1-10)') ax1.set_ylabel('Weight (1-5)') plotx(lambda v: v['score']['BGG'], data1, 'red', 'v', ax1) plotx(lambda v: v['score']['BGG'], data2, 'orange', ',', ax1) plotx(lambda v: v['score']['BGG'], data3, 'green', '^', ax1) ax2.set_xlim(0, 5) ax2.set_xlabel('Own Score (1-4)') ax2.set_ylabel('Weight (1-5)') plotx(lambda v: v['score']['W'], data1, 'red', 'v', ax2) plotx(lambda v: v['score']['W'], data2, 'orange', ',', ax2) plotx(lambda v: v['score']['W'], data3, 'green', '^', ax2) print("Correlations between BGG score and Own score") print(" \t -- PLAY 1") print(np.corrcoef(list(map(lambda v: v['score']['BGG'], data1)), list(map(lambda v: v['score']['W'], data1)))) print(" \t -- PLAY 2") print(np.corrcoef(list(map(lambda v: v['score']['BGG'], data2)), list(map(lambda v: v['score']['W'], data2)))) print(" \t -- PLAY 3") print(np.corrcoef(list(map(lambda v: v['score']['BGG'], data3)), list(map(lambda v: v['score']['W'], data3)))) print(" \t -- OVERALL") print(np.corrcoef(list(map(lambda v: v['score']['BGG'], data)), list(map(lambda v: v['score']['W'], data)))) print("\n\n") print("Correlation between weight and plays?") print(np.corrcoef(list(map(lambda v: v['score']['W'], data)), list(map(lambda v: v['weight'], data)))) def play(p): if p == 1: return "-" if p == 2: return "+" return "++" for e in data: print("| [" + e['name'] + "](" + e['link'] + ") | " + str(e['score']['BGG']) + " (" + str(e['score']['W']) + ") | " + str(e['weight']) + " | " + play(e['plays']) + " |") plt.show()