Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Module that outputs an JSON summary containing the comparision of images.""" | 6 """Module that outputs an JSON summary containing the comparision of images.""" |
| 7 | 7 |
| 8 import csv | |
| 8 import imp | 9 import imp |
| 9 import json | 10 import json |
| 10 import optparse | 11 import optparse |
| 11 import os | 12 import os |
| 12 import posixpath | 13 import posixpath |
| 13 import sys | 14 import sys |
| 14 | 15 |
| 15 sys.path.append( | 16 sys.path.append( |
| 16 os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) | 17 os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) |
| 17 import json_summary_constants | 18 import json_summary_constants |
| 18 | 19 |
| 19 | 20 |
| 20 def WriteJsonSummary(img_root, nopatch_json, nopatch_img_dir_name, | 21 def WriteJsonSummary(img_root, nopatch_json, nopatch_img_dir_name, |
| 21 withpatch_json, withpatch_img_dir_name, output_file_path, | 22 withpatch_json, withpatch_img_dir_name, output_file_path, |
| 22 gs_output_dir, gs_skp_dir, slave_num, gm_json_path, | 23 gs_output_dir, gs_skp_dir, slave_num, gm_json_path, |
| 23 imagediffdb_path): | 24 imagediffdb_path, skpdiff_output_csv): |
| 24 """Outputs the JSON summary of image comparisions. | 25 """Outputs the JSON summary of image comparisions. |
| 25 | 26 |
| 26 Args: | 27 Args: |
| 27 img_root: (str) The root directory on local disk where we store all images. | 28 img_root: (str) The root directory on local disk where we store all images. |
| 28 nopatch_json: (str) Location of the nopatch render_pictures JSON summary | 29 nopatch_json: (str) Location of the nopatch render_pictures JSON summary |
| 29 file. | 30 file. |
| 30 nopatch_img_dir_name: (str) Name of the directory within img_root that | 31 nopatch_img_dir_name: (str) Name of the directory within img_root that |
| 31 contains all nopatch images. | 32 contains all nopatch images. |
| 32 withpatch_json: (str) Location of the withpatch render_pictures JSON summary | 33 withpatch_json: (str) Location of the withpatch render_pictures JSON summary |
| 33 file. | 34 file. |
| 34 withpatch_img_dir_name: (str) Name of the directory within img_root that | 35 withpatch_img_dir_name: (str) Name of the directory within img_root that |
| 35 contains all withpatch images. | 36 contains all withpatch images. |
| 36 output_file_path: (str) The local path to the JSON file that will be | 37 output_file_path: (str) The local path to the JSON file that will be |
| 37 created by this function which will contain a summary of all file | 38 created by this function which will contain a summary of all file |
| 38 differences for this slave. | 39 differences for this slave. |
| 39 gs_output_dir: (str) The directory the JSON summary file and images will be | 40 gs_output_dir: (str) The directory the JSON summary file and images will be |
| 40 outputted to in Google Storage. | 41 outputted to in Google Storage. |
| 41 gs_skp_dir: (str) The Google Storage directory that contains the SKPs of | 42 gs_skp_dir: (str) The Google Storage directory that contains the SKPs of |
| 42 this cluster telemetry slave. | 43 this cluster telemetry slave. |
| 43 slave_num: (str) The number of the cluster telemetry slave that is running | 44 slave_num: (str) The number of the cluster telemetry slave that is running |
| 44 this script. | 45 this script. |
| 45 gm_json_path: (str) Local complete path to gm_json.py in Skia trunk. | 46 gm_json_path: (str) Local complete path to gm_json.py in Skia trunk. |
| 46 imagediffdb_path: (str) Local complete path to imagediffdb.py in Skia trunk. | 47 imagediffdb_path: (str) Local complete path to imagediffdb.py in Skia trunk. |
| 48 skpdiff_output_csv: (str) Local complete path to the CSV output of skpdiff. | |
| 47 """ | 49 """ |
| 48 | 50 |
| 49 assert os.path.isfile(gm_json_path), 'Must specify a valid path to gm_json.py' | 51 assert os.path.isfile(gm_json_path), 'Must specify a valid path to gm_json.py' |
| 50 gm_json_mod = imp.load_source(gm_json_path, gm_json_path) | 52 gm_json_mod = imp.load_source(gm_json_path, gm_json_path) |
| 51 assert os.path.isfile(imagediffdb_path), ( | 53 assert os.path.isfile(imagediffdb_path), ( |
| 52 'Must specify a valid path to imagediffdb.py') | 54 'Must specify a valid path to imagediffdb.py') |
| 53 imagediffdb_mod = imp.load_source(imagediffdb_path, imagediffdb_path) | 55 imagediffdb_mod = imp.load_source(imagediffdb_path, imagediffdb_path) |
| 54 | 56 |
| 55 files_to_checksums1 = GetFilesAndChecksums(nopatch_json, gm_json_mod) | 57 files_to_checksums1 = GetFilesAndChecksums(nopatch_json, gm_json_mod) |
| 56 files_to_checksums2 = GetFilesAndChecksums(withpatch_json, gm_json_mod) | 58 files_to_checksums2 = GetFilesAndChecksums(withpatch_json, gm_json_mod) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 70 json_summary_constants.JSONKEY_FILES_LOCATION_WITHPATCH: posixpath.join( | 72 json_summary_constants.JSONKEY_FILES_LOCATION_WITHPATCH: posixpath.join( |
| 71 gs_output_dir, 'slave%s' % slave_num, 'withpatch-images'), | 73 gs_output_dir, 'slave%s' % slave_num, 'withpatch-images'), |
| 72 json_summary_constants.JSONKEY_FILES_LOCATION_DIFFS: posixpath.join( | 74 json_summary_constants.JSONKEY_FILES_LOCATION_DIFFS: posixpath.join( |
| 73 gs_output_dir, 'slave%s' % slave_num, 'diffs'), | 75 gs_output_dir, 'slave%s' % slave_num, 'diffs'), |
| 74 json_summary_constants.JSONKEY_FILES_LOCATION_WHITE_DIFFS: posixpath.join( | 76 json_summary_constants.JSONKEY_FILES_LOCATION_WHITE_DIFFS: posixpath.join( |
| 75 gs_output_dir, 'slave%s' % slave_num, 'whitediffs') | 77 gs_output_dir, 'slave%s' % slave_num, 'whitediffs') |
| 76 } | 78 } |
| 77 json_summary = { | 79 json_summary = { |
| 78 'slave%s' % slave_num: slave_dict | 80 'slave%s' % slave_num: slave_dict |
| 79 } | 81 } |
| 82 # Read the skpdiff CSV output. | |
| 83 page_to_perceptual_similarity = {} | |
| 84 for row in csv.DictReader(open(skpdiff_output_csv, 'r')): | |
| 85 page_to_perceptual_similarity[row['key']] = float( | |
| 86 row[' perceptual'].strip()) | |
| 87 | |
| 80 for file1 in files_to_checksums1: | 88 for file1 in files_to_checksums1: |
| 81 algo1, checksum1 = files_to_checksums1[file1] | 89 algo1, checksum1 = files_to_checksums1[file1] |
| 82 algo2, checksum2 = files_to_checksums2[file1] | 90 algo2, checksum2 = files_to_checksums2[file1] |
| 83 assert algo1 == algo2, 'Different algorithms found' | 91 assert algo1 == algo2, 'Different algorithms found' |
| 84 if checksum1 != checksum2: | 92 if checksum1 != checksum2: |
| 85 # Call imagediffdb and then the diffs and metrics. | 93 # Call imagediffdb and then the diffs and metrics. |
| 86 image_diff = imagediffdb_mod.DiffRecord( | 94 image_diff = imagediffdb_mod.DiffRecord( |
| 87 storage_root=img_root, | 95 storage_root=img_root, |
| 88 expected_image_url=None, # Do not need to download any img. | 96 expected_image_url=None, # Do not need to download any img. |
| 89 expected_image_locator=os.path.splitext(file1)[0], | 97 expected_image_locator=os.path.splitext(file1)[0], |
| 90 actual_image_url=None, # Do not need to download any img. | 98 actual_image_url=None, # Do not need to download any img. |
| 91 actual_image_locator=os.path.splitext(file1)[0], | 99 actual_image_locator=os.path.splitext(file1)[0], |
| 92 expected_images_subdir=nopatch_img_dir_name, | 100 expected_images_subdir=nopatch_img_dir_name, |
| 93 actual_images_subdir=withpatch_img_dir_name) | 101 actual_images_subdir=withpatch_img_dir_name) |
| 94 file_differences.append({ | 102 file_differences.append({ |
| 95 json_summary_constants.JSONKEY_FILE_NAME: file1, | 103 json_summary_constants.JSONKEY_FILE_NAME: file1, |
| 96 json_summary_constants.JSONKEY_SKP_LOCATION: posixpath.join( | 104 json_summary_constants.JSONKEY_SKP_LOCATION: posixpath.join( |
| 97 gs_skp_dir, GetSkpFileName(file1)), | 105 gs_skp_dir, GetSkpFileName(file1)), |
| 98 json_summary_constants.JSONKEY_NUM_PIXELS_DIFFERING: | 106 json_summary_constants.JSONKEY_NUM_PIXELS_DIFFERING: |
| 99 image_diff.get_num_pixels_differing(), | 107 image_diff.get_num_pixels_differing(), |
| 100 json_summary_constants.JSONKEY_PERCENT_PIXELS_DIFFERING: | 108 json_summary_constants.JSONKEY_PERCENT_PIXELS_DIFFERING: |
| 101 image_diff.get_percent_pixels_differing(), | 109 image_diff.get_percent_pixels_differing(), |
| 102 json_summary_constants.JSONKEY_WEIGHTED_DIFF_MEASURE: | 110 json_summary_constants.JSONKEY_WEIGHTED_DIFF_MEASURE: |
| 103 image_diff.get_weighted_diff_measure(), | 111 image_diff.get_weighted_diff_measure(), |
| 104 json_summary_constants.JSONKEY_MAX_DIFF_PER_CHANNEL: | 112 json_summary_constants.JSONKEY_MAX_DIFF_PER_CHANNEL: |
| 105 image_diff.get_max_diff_per_channel() | 113 image_diff.get_max_diff_per_channel(), |
| 114 json_summary_constants.JSONKEY_PERCEPTUAL_SIMILARITY: | |
| 115 page_to_perceptual_similarity[file1], | |
| 106 }) | 116 }) |
| 107 if file_differences: | 117 if file_differences: |
| 108 slave_dict[json_summary_constants.JSONKEY_FAILED_FILES_COUNT] = len( | 118 slave_dict[json_summary_constants.JSONKEY_FAILED_FILES_COUNT] = len( |
| 109 file_differences) | 119 file_differences) |
| 110 with open(output_file_path, 'w') as f: | 120 with open(output_file_path, 'w') as f: |
| 111 f.write(json.dumps(json_summary, indent=4, sort_keys=True)) | 121 f.write(json.dumps(json_summary, indent=4, sort_keys=True)) |
| 112 | 122 |
| 113 | 123 |
| 114 def GetSkpFileName(img_file_name): | 124 def GetSkpFileName(img_file_name): |
| 115 """Determine the SKP file name from the image's file name.""" | 125 """Determine the SKP file name from the image's file name.""" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 option_parser.add_option( | 173 option_parser.add_option( |
| 164 '', '--slave_num', | 174 '', '--slave_num', |
| 165 help='The number of the cluster telemetry slave that is running this ' | 175 help='The number of the cluster telemetry slave that is running this ' |
| 166 'script.') | 176 'script.') |
| 167 option_parser.add_option( | 177 option_parser.add_option( |
| 168 '', '--gm_json_path', | 178 '', '--gm_json_path', |
| 169 help='Local complete path to gm_json.py in Skia trunk.') | 179 help='Local complete path to gm_json.py in Skia trunk.') |
| 170 option_parser.add_option( | 180 option_parser.add_option( |
| 171 '', '--imagediffdb_path', | 181 '', '--imagediffdb_path', |
| 172 help='Local complete path to imagediffdb.py in Skia trunk.') | 182 help='Local complete path to imagediffdb.py in Skia trunk.') |
| 183 option_parser.add_option( | |
| 184 '', '--skpdiff_output_csv', | |
| 185 help='Local complete path to the CSV output of skpdiff.') | |
| 173 options, unused_args = option_parser.parse_args() | 186 options, unused_args = option_parser.parse_args() |
| 174 if (not options.nopatch_json or not options.withpatch_json | 187 if (not options.nopatch_json or not options.withpatch_json |
| 175 or not options.output_file_path or not options.gs_output_dir | 188 or not options.output_file_path or not options.gs_output_dir |
| 176 or not options.gs_skp_dir or not options.slave_num | 189 or not options.gs_skp_dir or not options.slave_num |
| 177 or not options.gm_json_path or not options.img_root | 190 or not options.gm_json_path or not options.img_root |
|
epoger
2014/02/03 21:17:13
I think an automated check of all required_params
| |
| 178 or not options.nopatch_img_dir_name or not options.withpatch_img_dir_name | 191 or not options.nopatch_img_dir_name or not options.withpatch_img_dir_name |
| 179 or not options.imagediffdb_path): | 192 or not options.imagediffdb_path or not options.skpdiff_output_csv): |
| 180 option_parser.error( | 193 option_parser.error( |
| 181 'Must specify img_root, nopatch_json, nopatch_img_dir_name, ' | 194 'Must specify img_root, nopatch_json, nopatch_img_dir_name, ' |
| 182 'withpatch_json, withpatch_img_dir_name, output_file_path, ' | 195 'withpatch_json, withpatch_img_dir_name, output_file_path, ' |
| 183 'gs_output_dir, gs_skp_dir, slave_num, gm_json_path and ' | 196 'gs_output_dir, gs_skp_dir, slave_num, gm_json_path, ' |
| 184 'imagediffdb_path.') | 197 'imagediffdb_path and skpdiff_output_csv.') |
| 185 | 198 |
| 186 WriteJsonSummary(options.img_root, options.nopatch_json, | 199 WriteJsonSummary(options.img_root, options.nopatch_json, |
| 187 options.nopatch_img_dir_name, options.withpatch_json, | 200 options.nopatch_img_dir_name, options.withpatch_json, |
| 188 options.withpatch_img_dir_name, options.output_file_path, | 201 options.withpatch_img_dir_name, options.output_file_path, |
| 189 options.gs_output_dir, options.gs_skp_dir, options.slave_num, | 202 options.gs_output_dir, options.gs_skp_dir, options.slave_num, |
| 190 options.gm_json_path, options.imagediffdb_path) | 203 options.gm_json_path, options.imagediffdb_path, |
| 204 options.skpdiff_output_csv) | |
| OLD | NEW |