Skip to content

Commit

Permalink
Remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Aug 29, 2023
1 parent 6121890 commit ba4691e
Show file tree
Hide file tree
Showing 5 changed files with 500 additions and 549 deletions.
7 changes: 0 additions & 7 deletions rich_tables/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class Review(Content):
state: str
threads: t.List[ReviewThread]

def make(self):
return self["id"]


@dataclass
class PullRequest:
Expand Down Expand Up @@ -245,10 +242,6 @@ def make_info_subpanel(self, attr: str) -> Panel:
def repo(self) -> str:
return wrap(self.repository, f"b {predictably_random_color(self.repository)}")

@property
def dates(self) -> t.Tuple[str, str]:
return self.createdAt, self.updatedAt

@property
def pr_state(self) -> str:
return "MERGED" if self.state == "MERGED" else self.reviewDecision
Expand Down
29 changes: 0 additions & 29 deletions rich_tables/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,6 @@ def report_sql_query(data: JSONDict) -> None:
return utils.FIELDS_MAP["sql"](data)


def get_duplicates(queries: JSONDict) -> JSONDict:
data = [{f: q[f] for f in ("operation", "tables", "joins")} for q in queries]
table_groups = groupby(sorted(data, key=lambda q: q["tables"]))
with_counts = [{**data, "count": len(list(it))} for data, it in table_groups]
return sorted(
filter(lambda q: q["count"] > 1, with_counts), key=lambda q: q["count"]
)


def report_queries(queries: List[JSONDict]) -> None:
queries = list(filter(lambda q: q.get("tables"), queries))
if queries:
# duplicates = get_duplicates(queries)
for query in queries:
span = float(query["span"])
query["time"] = "{:>7.2f}".format(round(query["time"] + span, 2))
query["span"] = utils.wrap(
f"{span:>5.2f}",
"green" if span < 1 else "yellow" if span < 10 else "red",
)

# if duplicates:

# console.print(
# Rule(utils.wrap("Duplicate queries", "bold"), style="dim cyan")
# )
# console.print(utils.simple_panel(duplicates, expand=True))


def sql_table(data: List[JSONDict]) -> utils.NewTable:
return utils.list_table(
(utils._get_val(item["sql"], "sql") for idx, item in enumerate(data))
Expand Down
17 changes: 2 additions & 15 deletions rich_tables/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ def colnames(self) -> List[str]:
"""Provide a mapping between columns names / ids and columns."""
return [str(c.header) for c in self.columns]

@property
def colmap(self) -> Dict[str, int]:
"""Provide a mapping between columns names / ids and columns."""
return {str(c.header): c._index for c in self.columns if c.header}

def add_dict_item(
self,
item: JSONDict,
Expand Down Expand Up @@ -249,10 +244,6 @@ def _colored_split(strings: List[str]) -> str:
return " ".join(map(format_with_color, strings))


def unsorted_colored_split(string: str) -> str:
return _colored_split(SPLIT_PAT.split(string))


def colored_split(string: str) -> str:
return _colored_split(sorted(SPLIT_PAT.split(string)))

Expand Down Expand Up @@ -284,12 +275,12 @@ def get_val(obj: Union[JSONDict, object], field: str) -> Any:


@get_val.register
def get_val_from_dict(obj: dict, field: str) -> Any:
def _(obj: dict, field: str) -> Any:
return _get_val(obj.get(field), field)


@get_val.register
def get_val_from_object(obj: object, field: str) -> Any:
def _(obj: object, field: str) -> Any:
return _get_val(getattr(obj, field, None), field)


Expand Down Expand Up @@ -345,10 +336,6 @@ def timestamp2datetime(timestamp: Union[str, int, float, None]) -> datetime:
return datetime.fromtimestamp(int(float(timestamp or 0)), tz=timezone.utc)


def timestamp2datetimestr(timestamp: Union[str, int, float, None]) -> str:
return timestamp2datetime(timestamp).strftime("%F %T")


def timestamp2timestr(timestamp: Union[str, int, float, None]) -> str:
return timestamp2datetime(timestamp).strftime("%T")

Expand Down
Loading

0 comments on commit ba4691e

Please sign in to comment.