Skip to content

Commit

Permalink
Merge pull request #7 from pjrigali/dev
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
pjrigali authored Aug 25, 2021
2 parents 1e4b41a + bc9174a commit 10112bf
Show file tree
Hide file tree
Showing 10 changed files with 722 additions and 621 deletions.
16 changes: 8 additions & 8 deletions Classes/call_of_duty.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from credentials import user_inputs
from Classes.user import User
from Classes.squad import Squad
from Utils.build import evaluate_df, get_our_and_other_df, get_match_id_set
from Utils.build import _evaluate_df, _get_our_and_other_df, _get_match_id_set
from Utils.gun_dictionary import gun_dict


Expand All @@ -29,19 +29,19 @@ class CallofDuty:

def __init__(self, hacker_data: bool = False, squad_data: bool = False):
self._User = User(info=user_inputs)
self._whole: pd.DataFrame = evaluate_df(file_name=self._User.file_name, repo=self._User.repo)
self._whole: pd.DataFrame = _evaluate_df(file_name=self._User.file_name, repo=self._User.repo)
self._gun_dic = gun_dict
self._last_match_date_time = list(self._whole['startDateTime'])[-1]
self._name_uno_dict = get_match_id_set(data=self._whole)
self._name_uno_dict = _get_match_id_set(data=self._whole)
self._my_uno = self.name_uno_dict[self._User.gamertag]
self._our_df, self._other_df = get_our_and_other_df(data=self._whole, _my_uno=self._my_uno,
squad_name_lst=self._User.squad,
name_uno_dict=self._name_uno_dict)
self._our_df, self._other_df = _get_our_and_other_df(data=self._whole, _my_uno=self._my_uno,
squad_name_lst=self._User.squad,
name_uno_dict=self._name_uno_dict)
self._hacker_df = None
self._name_uno_dict_hacker = None
if hacker_data:
self._hacker_df = evaluate_df(file_name='hacker_df.csv', repo=self._User.repo)
self._name_uno_dict_hacker = get_match_id_set(data=self.hacker_df)
self._hacker_df = _evaluate_df(file_name='hacker_df.csv', repo=self._User.repo)
self._name_uno_dict_hacker = _get_match_id_set(data=self.hacker_df)

self._Squad = None
if squad_data:
Expand Down
126 changes: 90 additions & 36 deletions Classes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from typing import List, Union, Optional
from scipy import stats
from dataclasses import dataclass
import six


def insert_every(L, char, every):
'''generates items composed of L-items interweaved with char every-so-many items'''
"""generates items composed of L-items interweaved with char every-so-many items"""
for i in range(len(L)):
yield L[i]
if (i + 1) % every == 0:
Expand All @@ -23,6 +24,7 @@ def insert_every(L, char, every):

@dataclass
class Line:
"""Creates a Line Plot"""

def __init__(self,
data: pd.DataFrame,
Expand All @@ -44,7 +46,7 @@ def __init__(self,
title_size: Optional[str] = 'xx-large',
grid: Optional[bool] = True,
grid_alpha: Optional[float] = 0.75,
grid_dash_sequence: Optional[tuple] = (1, 3),
grid_dash_sequence: Optional[tuple] = (3, 3),
grid_lineweight: Optional[float] = 0.5,
legend_fontsize: Optional[str] = 'medium',
legend_transparency: Optional[float] = 0.75,
Expand Down Expand Up @@ -110,6 +112,7 @@ def ax(self):

@dataclass
class Scatter:
"""Creates a Scatter Plot"""

def __init__(self,
data: pd.DataFrame,
Expand All @@ -134,7 +137,7 @@ def __init__(self,
title_size: Optional[str] = 'xx-large',
grid: Optional[bool] = True,
grid_alpha: Optional[float] = 0.75,
grid_dash_sequence: Optional[tuple] = (1, 3),
grid_dash_sequence: Optional[tuple] = (3, 3),
grid_lineweight: Optional[float] = 0.5,
legend_fontsize: Optional[str] = 'medium',
legend_transparency: Optional[float] = 0.75,
Expand Down Expand Up @@ -216,6 +219,7 @@ def ax(self):

@dataclass
class Histogram:
"""Creates a Histogram Plot"""

def __init__(self,
data: pd.DataFrame,
Expand Down Expand Up @@ -243,7 +247,7 @@ def __init__(self,
title_size: Optional[str] = 'xx-large',
grid: Optional[bool] = True,
grid_alpha: Optional[float] = 0.75,
grid_dash_sequence: Optional[tuple] = (1, 3),
grid_dash_sequence: Optional[tuple] = (3, 3),
grid_lineweight: Optional[float] = 0.5,
legend_fontsize: Optional[str] = 'medium',
legend_transparency: Optional[float] = 0.75,
Expand Down Expand Up @@ -306,6 +310,88 @@ def ax(self):
return self._ax, self._ax1


@dataclass
class Table:
"""Creates a Table Plot"""

# import matplotlib
# matplotlib.colors.to_rgba(c, alpha=None)

def __init__(self,
data: pd.DataFrame,
label_lst: Optional[List[str]] = None,
fig_size: Optional[tuple] = (10, 10),
font_size: Optional[str] = 'medium',
col_widths: Optional[float] = 0.30,
row_colors: Optional[str] = None,
header_colors: Optional[str] = None,
edge_color: Optional[str] = 'w',
sequential_cells: Optional[bool] = None,
color_map: Optional[str] = 'Greens',
):
data['index'] = list(data.index)

if row_colors is None:
row_colors = ['#f1f1f2', 'w']
if type(row_colors) is str:
row_colors = [row_colors, 'w']
if header_colors is None:
header_colors = ['tab:blue', 'w']
if type(header_colors) is str:
header_colors = [header_colors, 'w']

if label_lst is None:
lst = list(data.columns)
lst.remove('index')
label_lst = ['index'] + lst
data = data[label_lst]
col_widths = [col_widths] * len(label_lst)
colours = None
if sequential_cells is not None:
color_lst = []
for col in label_lst:
if type(data[col].iloc[0]) != str and col != 'index':
_norm = plt.Normalize(np.min(data[col]) - 1, np.max(data[col]) + 1)
temp = plt.get_cmap(color_map)(_norm(data[col]))
elif type(data[col].iloc[0]) == str and col != 'index':
temp = [(1.0, 1.0, 1.0, 1.0), (0.945, 0.945, 0.949, 1.0)] * len(data)
else:
temp = [(0.121, 0.466, 0.705, 0.15), (0.121, 0.466, 0.705, 0.30)] * len(data)
temp_lst = []
for i in range(len(data)):
temp_lst.append(tuple(temp[i]))
color_lst.append(temp_lst)
colours = np.array(pd.DataFrame(color_lst).T)

fig, ax = plt.subplots(figsize=fig_size)
table = ax.table(cellText=data.values, colLabels=label_lst, colWidths=col_widths, loc='center',
cellLoc='center', cellColours=colours)
table.set_fontsize(font_size)

for k, cell in six.iteritems(table._cells):
r, c = k
cell.set_edgecolor(edge_color)
if r == 0:
cell.set_text_props(weight='bold', color=header_colors[1])
cell.set_facecolor(header_colors[0])
else:
if sequential_cells is None:
cell.set_facecolor(row_colors[r % len(row_colors)])

ax.axis('tight')
ax.axis('off')
fig.tight_layout()

self._ax = ax

def __repr__(self):
return 'Table Plot'

@property
def ax(self):
return self._ax


# @dataclass
# class BarChart:
#
Expand Down Expand Up @@ -376,35 +462,3 @@ def ax(self):
#
# def __repr__(self):
# return 'Bar Chart Plot'


# @dataclass
# class Plot:
#
# def __init__(self,
# doc_filter: DocumentFilter,
# col_lst: Union[str, List[str]],
# line: Optional[bool] = False,
# scat: Optional[bool] = False,
# histo: Optional[bool] = False,
# bar: Optional[bool] = False,
# ):
#
# self._data = doc_filter.df[col_lst]
# self._col_lst = col_lst
# self._line = line
# self._scat = scat
# self._histo = histo
# self._bar = bar
#
# if self._line:
# Line(data=self._data, label_lst=self._col_lst)
# if self._scat:
# Scatter(data=self._data, label_lst=self._col_lst)
# if self._histo:
# Histogram(data=self._data)
# if self._bar:
# BarChart(data=self._data)
#
# def __repr__(self):
# return 'Plot'
2 changes: 1 addition & 1 deletion Classes/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from statsmodels import regression
from statsmodels.tools import add_constant
from Classes.documnent_filter import DocumentFilter
from Classes.document_filter import DocumentFilter
from dataclasses import dataclass


Expand Down
Loading

0 comments on commit 10112bf

Please sign in to comment.