Minor improvements
This commit is contained in:
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user