Ran black on sources
This commit is contained in:
parent
5e5f3efc24
commit
db17ece61b
4 changed files with 73 additions and 45 deletions
|
|
@ -2653,10 +2653,12 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
try:
|
||||
# Try grabbing the actual min/max id values by database aggregation
|
||||
qs = ObjectDB.objects.values('id').aggregate(low=Min('id'), high=Max('id'))
|
||||
qs = ObjectDB.objects.values("id").aggregate(low=Min("id"), high=Max("id"))
|
||||
low, high = sorted(qs.values())
|
||||
if not (low and high):
|
||||
raise ValueError(f"{self.__class__.__name__}: Min and max ID not returned by aggregation; falling back to queryset slicing.")
|
||||
raise ValueError(
|
||||
f"{self.__class__.__name__}: Min and max ID not returned by aggregation; falling back to queryset slicing."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.log_trace(e)
|
||||
# If that doesn't work for some reason (empty DB?), guess the lower
|
||||
|
|
@ -2666,7 +2668,9 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
if self.rhs:
|
||||
try:
|
||||
# Check that rhs is either a valid dbref or dbref range
|
||||
bounds = tuple(sorted(dbref(x, False) for x in re.split('[-\s]+', self.rhs.strip())))
|
||||
bounds = tuple(
|
||||
sorted(dbref(x, False) for x in re.split("[-\s]+", self.rhs.strip()))
|
||||
)
|
||||
|
||||
# dbref() will return either a valid int or None
|
||||
assert bounds
|
||||
|
|
@ -2681,7 +2685,9 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
caller.msg("Invalid dbref range provided (not a number).")
|
||||
return
|
||||
except IndexError as e:
|
||||
logger.log_err(f"{self.__class__.__name__}: Error parsing upper and lower bounds of query.")
|
||||
logger.log_err(
|
||||
f"{self.__class__.__name__}: Error parsing upper and lower bounds of query."
|
||||
)
|
||||
logger.log_trace(e)
|
||||
|
||||
low = min(low, high)
|
||||
|
|
@ -2762,9 +2768,11 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
if any(x in switches for x in ("room", "exit", "char")):
|
||||
obj_ids = set()
|
||||
for obj in results:
|
||||
if ("room" in switches and inherits_from(obj, ROOM_TYPECLASS)) \
|
||||
or ("exit" in switches and inherits_from(obj, EXIT_TYPECLASS)) \
|
||||
or ("char" in switches and inherits_from(obj, CHAR_TYPECLASS)):
|
||||
if (
|
||||
("room" in switches and inherits_from(obj, ROOM_TYPECLASS))
|
||||
or ("exit" in switches and inherits_from(obj, EXIT_TYPECLASS))
|
||||
or ("char" in switches and inherits_from(obj, CHAR_TYPECLASS))
|
||||
):
|
||||
obj_ids.add(obj.id)
|
||||
|
||||
# Filter previous queryset instead of requesting another
|
||||
|
|
@ -2776,14 +2784,21 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
# still results after type filtering?
|
||||
if nresults:
|
||||
if nresults > 1: header = f'{nresults} Matches'
|
||||
else: header = 'One Match'
|
||||
if nresults > 1:
|
||||
header = f"{nresults} Matches"
|
||||
else:
|
||||
header = "One Match"
|
||||
|
||||
string = f"|w{header}|n(#{low}-#{high}{restrictions}):"
|
||||
res = None
|
||||
for res in results:
|
||||
string += f"\n |g{res.get_display_name(caller)} - {res.path}|n"
|
||||
if "loc" in self.switches and nresults == 1 and res and getattr(res, 'location', None):
|
||||
if (
|
||||
"loc" in self.switches
|
||||
and nresults == 1
|
||||
and res
|
||||
and getattr(res, "location", None)
|
||||
):
|
||||
string += f" (|wlocation|n: |g{res.location.get_display_name(caller)}|n)"
|
||||
else:
|
||||
string = f"|wNo Matches|n(#{low}-#{high}{restrictions}):"
|
||||
|
|
|
|||
|
|
@ -598,7 +598,11 @@ class CmdObjects(COMMAND_DEFAULT_CLASS):
|
|||
typetable.align = "l"
|
||||
dbtotals = ObjectDB.objects.get_typeclass_totals()
|
||||
for stat in dbtotals:
|
||||
typetable.add_row(stat.get('typeclass', '<error>'), stat.get('count', -1), "%.2f" % stat.get('percent', -1))
|
||||
typetable.add_row(
|
||||
stat.get("typeclass", "<error>"),
|
||||
stat.get("count", -1),
|
||||
"%.2f" % stat.get("percent", -1),
|
||||
)
|
||||
|
||||
# last N table
|
||||
objs = ObjectDB.objects.all().order_by("db_date_created")[max(0, nobjs - nlim) :]
|
||||
|
|
|
|||
|
|
@ -1044,7 +1044,10 @@ class TestBuilding(CommandTest):
|
|||
self.call(building.CmdFind(), "/exact Obj", "One Match")
|
||||
|
||||
# Test multitype filtering
|
||||
with mock.patch('evennia.commands.default.building.CHAR_TYPECLASS', 'evennia.objects.objects.DefaultCharacter'):
|
||||
with mock.patch(
|
||||
"evennia.commands.default.building.CHAR_TYPECLASS",
|
||||
"evennia.objects.objects.DefaultCharacter",
|
||||
):
|
||||
self.call(building.CmdFind(), "/char/room Obj", "No Matches")
|
||||
self.call(building.CmdFind(), "/char/room/exit Char", "2 Matches")
|
||||
self.call(building.CmdFind(), "/char/room/exit/startswith Cha", "2 Matches")
|
||||
|
|
|
|||
|
|
@ -495,17 +495,23 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
the percentage of objects associated with the typeclass.
|
||||
|
||||
"""
|
||||
return self.values('db_typeclass_path').distinct().annotate(
|
||||
# Get count of how many objects for each typeclass exist
|
||||
count=Count('db_typeclass_path')
|
||||
).annotate(
|
||||
# Rename db_typeclass_path field to something more human
|
||||
typeclass=F('db_typeclass_path'),
|
||||
# Calculate this class' percentage of total composition
|
||||
percent=ExpressionWrapper(
|
||||
((F('count') / float(self.count())) * 100.0), output_field=FloatField()
|
||||
),
|
||||
).values('typeclass', 'count', 'percent')
|
||||
return (
|
||||
self.values("db_typeclass_path")
|
||||
.distinct()
|
||||
.annotate(
|
||||
# Get count of how many objects for each typeclass exist
|
||||
count=Count("db_typeclass_path")
|
||||
)
|
||||
.annotate(
|
||||
# Rename db_typeclass_path field to something more human
|
||||
typeclass=F("db_typeclass_path"),
|
||||
# Calculate this class' percentage of total composition
|
||||
percent=ExpressionWrapper(
|
||||
((F("count") / float(self.count())) * 100.0), output_field=FloatField()
|
||||
),
|
||||
)
|
||||
.values("typeclass", "count", "percent")
|
||||
)
|
||||
|
||||
def object_totals(self):
|
||||
"""
|
||||
|
|
@ -518,8 +524,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
object having that typeclass set on themselves).
|
||||
|
||||
"""
|
||||
stats = self.get_typeclass_totals().order_by('typeclass')
|
||||
return {x.get('typeclass'):x.get('count') for x in stats}
|
||||
stats = self.get_typeclass_totals().order_by("typeclass")
|
||||
return {x.get("typeclass"): x.get("count") for x in stats}
|
||||
|
||||
def typeclass_search(self, typeclass, include_children=False, include_parents=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue