| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2013 Google Inc. | 4 Copyright 2013 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 | 8 |
| 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. | 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. |
| 10 """ | 10 """ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 Once this object has been constructed, the results (in self._results[]) | 55 Once this object has been constructed, the results (in self._results[]) |
| 56 are immutable. If you want to update the results based on updated JSON | 56 are immutable. If you want to update the results based on updated JSON |
| 57 file contents, you will need to create a new Results object.""" | 57 file contents, you will need to create a new Results object.""" |
| 58 | 58 |
| 59 def __init__(self, actuals_root, expected_root, generated_images_root): | 59 def __init__(self, actuals_root, expected_root, generated_images_root): |
| 60 """ | 60 """ |
| 61 Args: | 61 Args: |
| 62 actuals_root: root directory containing all actual-results.json files | 62 actuals_root: root directory containing all actual-results.json files |
| 63 expected_root: root directory containing all expected-results.json files | 63 expected_root: root directory containing all expected-results.json files |
| 64 generated_images_root: directory within which to create all pixels diffs; | 64 generated_images_root: directory within which to create all pixel diffs; |
| 65 if this directory does not yet exist, it will be created | 65 if this directory does not yet exist, it will be created |
| 66 """ | 66 """ |
| 67 self._image_diff_db = imagediffdb.ImageDiffDB(generated_images_root) | 67 self._image_diff_db = imagediffdb.ImageDiffDB(generated_images_root) |
| 68 self._actuals_root = actuals_root | 68 self._actuals_root = actuals_root |
| 69 self._expected_root = expected_root | 69 self._expected_root = expected_root |
| 70 self._load_actual_and_expected() | 70 self._load_actual_and_expected() |
| 71 self._timestamp = int(time.time()) | 71 self._timestamp = int(time.time()) |
| 72 | 72 |
| 73 def get_timestamp(self): | 73 def get_timestamp(self): |
| 74 """Return the time at which this object was created, in seconds past epoch | 74 """Return the time at which this object was created, in seconds past epoch |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 # FIELDS_PASSED_THRU_VERBATIM that may be overwritten below... | 393 # FIELDS_PASSED_THRU_VERBATIM that may be overwritten below... |
| 394 gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE: False, | 394 gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE: False, |
| 395 } | 395 } |
| 396 if expectations_per_test: | 396 if expectations_per_test: |
| 397 for field in FIELDS_PASSED_THRU_VERBATIM: | 397 for field in FIELDS_PASSED_THRU_VERBATIM: |
| 398 results_for_this_test[field] = expectations_per_test.get(field) | 398 results_for_this_test[field] = expectations_per_test.get(field) |
| 399 | 399 |
| 400 if updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON: | 400 if updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON: |
| 401 pass # no diff record to calculate at all | 401 pass # no diff record to calculate at all |
| 402 elif updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED: | 402 elif updated_result_type == gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED: |
| 403 results_for_this_test['numDifferingPixels'] = 0 |
| 403 results_for_this_test['percentDifferingPixels'] = 0 | 404 results_for_this_test['percentDifferingPixels'] = 0 |
| 404 results_for_this_test['weightedDiffMeasure'] = 0 | 405 results_for_this_test['weightedDiffMeasure'] = 0 |
| 406 results_for_this_test['maxDiffPerChannel'] = 0 |
| 405 else: | 407 else: |
| 406 try: | 408 try: |
| 407 diff_record = self._image_diff_db.get_diff_record( | 409 diff_record = self._image_diff_db.get_diff_record( |
| 408 expected_image_locator=expected_image[1], | 410 expected_image_locator=expected_image[1], |
| 409 actual_image_locator=actual_image[1]) | 411 actual_image_locator=actual_image[1]) |
| 412 results_for_this_test['numDifferingPixels'] = ( |
| 413 diff_record.get_num_pixels_differing()) |
| 410 results_for_this_test['percentDifferingPixels'] = ( | 414 results_for_this_test['percentDifferingPixels'] = ( |
| 411 diff_record.get_percent_pixels_differing()) | 415 diff_record.get_percent_pixels_differing()) |
| 412 results_for_this_test['weightedDiffMeasure'] = ( | 416 results_for_this_test['weightedDiffMeasure'] = ( |
| 413 diff_record.get_weighted_diff_measure()) | 417 diff_record.get_weighted_diff_measure()) |
| 418 results_for_this_test['maxDiffPerChannel'] = ( |
| 419 diff_record.get_max_diff_per_channel()) |
| 414 except KeyError: | 420 except KeyError: |
| 415 logging.warning('unable to find diff_record for ("%s", "%s")' % | 421 logging.warning('unable to find diff_record for ("%s", "%s")' % |
| 416 (expected_image[1], actual_image[1])) | 422 (expected_image[1], actual_image[1])) |
| 417 pass | 423 pass |
| 418 | 424 |
| 419 Results._add_to_category_dict(categories_all, results_for_this_test) | 425 Results._add_to_category_dict(categories_all, results_for_this_test) |
| 420 data_all.append(results_for_this_test) | 426 data_all.append(results_for_this_test) |
| 421 | 427 |
| 422 # TODO(epoger): In effect, we have a list of resultTypes that we | 428 # TODO(epoger): In effect, we have a list of resultTypes that we |
| 423 # include in the different result lists (data_all and data_failures). | 429 # include in the different result lists (data_all and data_failures). |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 category_dict: category dict-of-dicts to modify | 476 category_dict: category dict-of-dicts to modify |
| 471 category_name: category name, as a string | 477 category_name: category name, as a string |
| 472 category_values: list of values we want to make sure are represented | 478 category_values: list of values we want to make sure are represented |
| 473 for this category | 479 for this category |
| 474 """ | 480 """ |
| 475 if not category_dict.get(category_name): | 481 if not category_dict.get(category_name): |
| 476 category_dict[category_name] = {} | 482 category_dict[category_name] = {} |
| 477 for category_value in category_values: | 483 for category_value in category_values: |
| 478 if not category_dict[category_name].get(category_value): | 484 if not category_dict[category_name].get(category_value): |
| 479 category_dict[category_name][category_value] = 0 | 485 category_dict[category_name][category_value] = 0 |
| OLD | NEW |