Skip to content

Commit 2b7eeb5

Browse files
committed
queries: added 'ratio' support (#47)
1 parent 8096ad2 commit 2b7eeb5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/pyrocore/util/matching.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class FieldFilter(Filter):
187187
#down = "=",
188188
# fno = "=",
189189
prio = "d.priority=",
190-
# ratio = "=",
190+
ratio = "d.ratio=",
191191
size = "d.size_bytes=",
192192
#up = "=",
193193
#uploaded = "=",
@@ -414,6 +414,19 @@ class FloatFilter(NumericFilterBase):
414414
""" Filter float values.
415415
"""
416416

417+
FIELD_SCALE = dict(
418+
ratio = 1000,
419+
)
420+
421+
def pre_filter(self):
422+
""" Return rTorrent condition to speed up data transfer.
423+
"""
424+
if self._name in self.PRE_FILTER_FIELDS:
425+
val = int(self._value * self.FIELD_SCALE.get(self._name, 1))
426+
return '"{}=value=${},value={}"'.format(
427+
self._rt_cmp, self.PRE_FILTER_FIELDS[self._name], val)
428+
return ''
429+
417430
def validate(self):
418431
""" Validate filter condition (template method).
419432
"""

0 commit comments

Comments
 (0)