Minor improvements

This commit is contained in:
monosans
2024-02-04 16:58:45 +03:00
parent 419d9fc036
commit d57620cae4
2 changed files with 22 additions and 10 deletions
+2 -2
View File
@@ -82,9 +82,9 @@ def get_summary_table(
table.add_column("Working", style="magenta")
table.add_column("Total", style="green")
for proto in sort.PROTOCOL_ORDER:
if total := before.get(proto):
if (total := before.get(proto)) is not None:
working = after.get(proto, 0)
percentage = working / total
percentage = (working / total) if total else 0
table.add_row(
proto.name, f"{working} ({percentage:.1%})", str(total)
)
+20 -8
View File
@@ -26,17 +26,29 @@ class ProxyStorage:
def get_grouped(self) -> Dict[ProxyType, Tuple[Proxy, ...]]:
key = sort.protocol_sort_key
d: Dict[ProxyType, Tuple[Proxy, ...]] = {
proto: ()
for proto in sort.PROTOCOL_ORDER
if proto in self.enabled_protocols
return {
**{
proto: ()
for proto in sort.PROTOCOL_ORDER
if proto in self.enabled_protocols
},
**{
proto: tuple(v)
for (_, proto), v in itertools.groupby(
sorted(self, key=key), key=key
)
},
}
for (_, proto), v in itertools.groupby(sorted(self, key=key), key=key):
d[proto] = tuple(v)
return d
def get_count(self) -> Dict[ProxyType, int]:
return dict(Counter(proxy.protocol for proxy in self))
return {
**{
proto: 0
for proto in sort.PROTOCOL_ORDER
if proto in self.enabled_protocols
},
**Counter(proxy.protocol for proxy in self),
}
def __iter__(self) -> Iterator[Proxy]:
return iter(self._proxies)