Skip to content

Commit

Permalink
queries: added 'ratio' support (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Apr 9, 2017
1 parent 8096ad2 commit 2b7eeb5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/pyrocore/util/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class FieldFilter(Filter):
#down = "=",
# fno = "=",
prio = "d.priority=",
# ratio = "=",
ratio = "d.ratio=",
size = "d.size_bytes=",
#up = "=",
#uploaded = "=",
Expand Down Expand Up @@ -414,6 +414,19 @@ class FloatFilter(NumericFilterBase):
""" Filter float values.
"""

FIELD_SCALE = dict(
ratio = 1000,
)

def pre_filter(self):
""" Return rTorrent condition to speed up data transfer.
"""
if self._name in self.PRE_FILTER_FIELDS:
val = int(self._value * self.FIELD_SCALE.get(self._name, 1))
return '"{}=value=${},value={}"'.format(
self._rt_cmp, self.PRE_FILTER_FIELDS[self._name], val)
return ''

def validate(self):
""" Validate filter condition (template method).
"""
Expand Down

0 comments on commit 2b7eeb5

Please sign in to comment.