mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 14:41:39 +00:00
Improved delta values to support non-numerical values
Delta values now work for non-numerical values. Any column, when its value differs from its ref, becomes orange. A column that was already a "delta column" keeps its previous behavior (dupe cells for these columns are always displayed in orange). Sorting behavior, when Dupes Only and Delta Values are enabled at the same time, has also been extended to non-numerical values, making it easy to mass-mark dupe rows with orange values. Documentation was updated, unit tests were added. Fixes #213
This commit is contained in:
26
core/app.py
26
core/app.py
@@ -136,17 +136,25 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
||||
|
||||
#--- Private
|
||||
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
|
||||
if key == 'percentage':
|
||||
m = get_group().get_match_of(dupe)
|
||||
return m.percentage
|
||||
if key == 'dupe_count':
|
||||
return 0
|
||||
if key == 'marked':
|
||||
return self.results.is_marked(dupe)
|
||||
r = cmp_value(dupe, key)
|
||||
if delta and (key in self.result_table.DELTA_COLUMNS):
|
||||
r -= cmp_value(get_group().ref, key)
|
||||
return r
|
||||
if key == 'percentage':
|
||||
m = get_group().get_match_of(dupe)
|
||||
result = m.percentage
|
||||
elif key == 'dupe_count':
|
||||
result = 0
|
||||
else:
|
||||
result = cmp_value(dupe, key)
|
||||
if delta:
|
||||
refval = getattr(get_group().ref, key)
|
||||
if key in self.result_table.DELTA_COLUMNS:
|
||||
result -= refval
|
||||
else:
|
||||
# We use directly getattr() because cmp_value() does thing that we don't want to do
|
||||
# when we want to determine whether two values are exactly the same.
|
||||
same = getattr(dupe, key) == refval
|
||||
result = (same, result)
|
||||
return result
|
||||
|
||||
def _get_group_sort_key(self, group, key):
|
||||
if key == 'percentage':
|
||||
|
||||
@@ -21,6 +21,30 @@ class DupeRow(Row):
|
||||
self._dupe = dupe
|
||||
self._data = None
|
||||
self._data_delta = None
|
||||
self._delta_columns = None
|
||||
|
||||
def is_cell_delta(self, column_name):
|
||||
"""Returns whether a cell is in delta mode (orange color).
|
||||
|
||||
If the result table is in delta mode, returns True if the column is one of the "delta
|
||||
columns", that is, one of the columns that display a a differential value rather than an
|
||||
absolute value.
|
||||
|
||||
If not, returns True if the dupe's value is different from its ref value.
|
||||
"""
|
||||
if not self.table.delta_values:
|
||||
return False
|
||||
if self.isref:
|
||||
return False
|
||||
if self._delta_columns is None:
|
||||
# table.DELTA_COLUMNS are always "delta"
|
||||
self._delta_columns = self.table.DELTA_COLUMNS.copy()
|
||||
dupe_info = self.data
|
||||
ref_info = self._group.ref.get_display_info(group=self._group, delta=False)
|
||||
for key, value in dupe_info.items():
|
||||
if ref_info[key] != value:
|
||||
self._delta_columns.add(key)
|
||||
return column_name in self._delta_columns
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
|
||||
@@ -21,9 +21,6 @@ from jobprogress.job import Job
|
||||
from .base import DupeGuru, TestApp
|
||||
from .results_test import GetTestGroups
|
||||
from .. import app, fs, engine
|
||||
from ..gui.details_panel import DetailsPanel
|
||||
from ..gui.directory_tree import DirectoryTree
|
||||
from ..gui.result_table import ResultTable
|
||||
from ..scanner import ScanType
|
||||
|
||||
def add_fake_files_to_directories(directories, files):
|
||||
|
||||
@@ -62,15 +62,6 @@ class DupeGuru(DupeGuruBase):
|
||||
def __init__(self):
|
||||
DupeGuruBase.__init__(self, DupeGuruView(), '/tmp')
|
||||
|
||||
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
|
||||
r = cmp_value(dupe, key)
|
||||
if delta and (key in self.result_table.DELTA_COLUMNS):
|
||||
r -= cmp_value(get_group().ref, key)
|
||||
return r
|
||||
|
||||
def _get_group_sort_key(self, group, key):
|
||||
return cmp_value(group.ref, key)
|
||||
|
||||
def _prioritization_categories(self):
|
||||
return prioritize.all_categories()
|
||||
|
||||
|
||||
46
core/tests/result_table_test.py
Normal file
46
core/tests/result_table_test.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Created By: Virgil Dupras
|
||||
# Created On: 2013-07-28
|
||||
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
||||
#
|
||||
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.hardcoded.net/licenses/bsd_license
|
||||
|
||||
from .base import TestApp, GetTestGroups
|
||||
|
||||
def app_with_results():
|
||||
app = TestApp()
|
||||
objects, matches, groups = GetTestGroups()
|
||||
app.app.results.groups = groups
|
||||
app.rtable.refresh()
|
||||
return app
|
||||
|
||||
def test_delta_flags_delta_mode_off():
|
||||
app = app_with_results()
|
||||
# When the delta mode is off, we never have delta values flags
|
||||
app.rtable.delta_values = False
|
||||
# Ref file, always false anyway
|
||||
assert not app.rtable[0].is_cell_delta('size')
|
||||
# False because delta mode is off
|
||||
assert not app.rtable[1].is_cell_delta('size')
|
||||
|
||||
def test_delta_flags_delta_mode_on_delta_columns():
|
||||
# When the delta mode is on, delta columns always have a delta flag, except for ref rows
|
||||
app = app_with_results()
|
||||
app.rtable.delta_values = True
|
||||
# Ref file, always false anyway
|
||||
assert not app.rtable[0].is_cell_delta('size')
|
||||
# But for a dupe, the flag is on
|
||||
assert app.rtable[1].is_cell_delta('size')
|
||||
|
||||
def test_delta_flags_delta_mode_on_non_delta_columns():
|
||||
# When the delta mode is on, non-delta columns have a delta flag if their value differs from
|
||||
# their ref.
|
||||
app = app_with_results()
|
||||
app.rtable.delta_values = True
|
||||
# "bar bleh" != "foo bar", flag on
|
||||
assert app.rtable[1].is_cell_delta('name')
|
||||
# "ibabtu" row, but it's a ref, flag off
|
||||
assert not app.rtable[3].is_cell_delta('name')
|
||||
# "ibabtu" == "ibabtu", flag off
|
||||
assert not app.rtable[4].is_cell_delta('name')
|
||||
Reference in New Issue
Block a user