Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: gm/rebaseline_server/results.py

Issue 59283006: rebaseline_server: add pixel diffs, and sorting by diff metrics (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: rename_selftest Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/rebaseline_server/imagediffdb_test.py ('k') | gm/rebaseline_server/server.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/rebaseline_server/results.py
===================================================================
--- gm/rebaseline_server/results.py (revision 12171)
+++ gm/rebaseline_server/results.py (working copy)
@@ -29,6 +29,7 @@
if GM_DIRECTORY not in sys.path:
sys.path.append(GM_DIRECTORY)
import gm_json
+import imagediffdb
IMAGE_FILENAME_RE = re.compile(gm_json.IMAGE_FILENAME_PATTERN)
IMAGE_FILENAME_FORMATTER = '%s_%s.png' # pass in (testname, config)
@@ -55,12 +56,15 @@
are immutable. If you want to update the results based on updated JSON
file contents, you will need to create a new Results object."""
- def __init__(self, actuals_root, expected_root):
+ def __init__(self, actuals_root, expected_root, generated_images_root):
"""
Args:
actuals_root: root directory containing all actual-results.json files
expected_root: root directory containing all expected-results.json files
+ generated_images_root: directory within which to create all pixels diffs;
+ if this directory does not yet exist, it will be created
"""
+ self._image_diff_db = imagediffdb.ImageDiffDB(generated_images_root)
self._actuals_root = actuals_root
self._expected_root = expected_root
self._load_actual_and_expected()
@@ -249,6 +253,36 @@
'for builders %s' % (
expected_builders_written, actual_builders_written))
+ def _generate_pixel_diffs_if_needed(self, test, expected_image, actual_image):
+ """If expected_image and actual_image both exist but are different,
+ add the image pair to self._image_diff_db and generate pixel diffs.
+
+ Args:
+ test: string; name of test
+ expected_image: (hashType, hashDigest) tuple describing the expected image
+ actual_image: (hashType, hashDigest) tuple describing the actual image
+ """
+ if expected_image == actual_image:
+ return
+
+ (expected_hashtype, expected_hashdigest) = expected_image
+ (actual_hashtype, actual_hashdigest) = actual_image
+ if None in [expected_hashtype, expected_hashdigest,
+ actual_hashtype, actual_hashdigest]:
+ return
+
+ expected_url = gm_json.CreateGmActualUrl(
+ test_name=test, hash_type=expected_hashtype,
+ hash_digest=expected_hashdigest)
+ actual_url = gm_json.CreateGmActualUrl(
+ test_name=test, hash_type=actual_hashtype,
+ hash_digest=actual_hashdigest)
+ self._image_diff_db.add_image_pair(
+ expected_image_locator=expected_hashdigest,
+ expected_image_url=expected_url,
+ actual_image_locator=actual_hashdigest,
+ actual_image_url=actual_url)
+
def _load_actual_and_expected(self):
"""Loads the results of all tests, across all builders (based on the
files within self._actuals_root and self._expected_root),
@@ -343,6 +377,9 @@
updated_result_type = result_type
(test, config) = IMAGE_FILENAME_RE.match(image_name).groups()
+ self._generate_pixel_diffs_if_needed(
+ test=test, expected_image=expected_image,
+ actual_image=actual_image)
results_for_this_test = {
'resultType': updated_result_type,
'builder': builder,
@@ -359,6 +396,26 @@
if expectations_per_test:
for field in FIELDS_PASSED_THRU_VERBATIM:
results_for_this_test[field] = expectations_per_test.get(field)
+
+ if updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON:
+ pass # no diff record to calculate at all
+ elif updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED:
+ results_for_this_test['percentDifferingPixels'] = 0
+ results_for_this_test['weightedDiffMeasure'] = 0
+ else:
+ try:
+ diff_record = self._image_diff_db.get_diff_record(
+ expected_image_locator=expected_image[1],
+ actual_image_locator=actual_image[1])
+ results_for_this_test['percentDifferingPixels'] = (
+ diff_record.get_percent_pixels_differing())
+ results_for_this_test['weightedDiffMeasure'] = (
+ diff_record.get_weighted_diff_measure())
+ except KeyError:
+ logging.warning('unable to find diff_record for ("%s", "%s")' %
+ (expected_image[1], actual_image[1]))
+ pass
+
Results._add_to_category_dict(categories_all, results_for_this_test)
data_all.append(results_for_this_test)
« no previous file with comments | « gm/rebaseline_server/imagediffdb_test.py ('k') | gm/rebaseline_server/server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698