OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 """ | 3 """ |
4 Copyright 2014 Google Inc. | 4 Copyright 2014 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 ImagePairSet class; see its docstring below. | 9 ImagePairSet class; see its docstring below. |
10 """ | 10 """ |
11 | 11 |
12 # System-level imports | 12 # System-level imports |
13 import posixpath | 13 import posixpath |
14 | 14 |
15 # Local imports | 15 # Local imports |
16 import column | 16 import column |
17 import imagediffdb | 17 import imagediffdb |
18 | 18 |
19 # Keys used within dictionary representation of ImagePairSet. | 19 # Keys used within dictionary representation of ImagePairSet. |
20 # NOTE: Keep these in sync with static/constants.js | 20 # NOTE: Keep these in sync with static/constants.js |
21 KEY__ROOT__EXTRACOLUMNHEADERS = 'extraColumnHeaders' | 21 KEY__ROOT__EXTRACOLUMNHEADERS = 'extraColumnHeaders' |
| 22 KEY__ROOT__EXTRACOLUMNORDER = 'extraColumnOrder' |
22 KEY__ROOT__HEADER = 'header' | 23 KEY__ROOT__HEADER = 'header' |
23 KEY__ROOT__IMAGEPAIRS = 'imagePairs' | 24 KEY__ROOT__IMAGEPAIRS = 'imagePairs' |
24 KEY__ROOT__IMAGESETS = 'imageSets' | 25 KEY__ROOT__IMAGESETS = 'imageSets' |
25 KEY__IMAGESETS__FIELD__BASE_URL = 'baseUrl' | 26 KEY__IMAGESETS__FIELD__BASE_URL = 'baseUrl' |
26 KEY__IMAGESETS__FIELD__DESCRIPTION = 'description' | 27 KEY__IMAGESETS__FIELD__DESCRIPTION = 'description' |
27 KEY__IMAGESETS__SET__DIFFS = 'diffs' | 28 KEY__IMAGESETS__SET__DIFFS = 'diffs' |
28 KEY__IMAGESETS__SET__IMAGE_A = 'imageA' | 29 KEY__IMAGESETS__SET__IMAGE_A = 'imageA' |
29 KEY__IMAGESETS__SET__IMAGE_B = 'imageB' | 30 KEY__IMAGESETS__SET__IMAGE_B = 'imageB' |
30 KEY__IMAGESETS__SET__WHITEDIFFS = 'whiteDiffs' | 31 KEY__IMAGESETS__SET__WHITEDIFFS = 'whiteDiffs' |
31 | 32 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 129 |
129 def _column_headers_as_dict(self): | 130 def _column_headers_as_dict(self): |
130 """Returns all column headers as a dictionary.""" | 131 """Returns all column headers as a dictionary.""" |
131 asdict = {} | 132 asdict = {} |
132 for column_id, values_for_column in self._extra_column_tallies.iteritems(): | 133 for column_id, values_for_column in self._extra_column_tallies.iteritems(): |
133 column_header_factory = self.get_column_header_factory(column_id) | 134 column_header_factory = self.get_column_header_factory(column_id) |
134 asdict[column_id] = column_header_factory.create_as_dict( | 135 asdict[column_id] = column_header_factory.create_as_dict( |
135 values_for_column) | 136 values_for_column) |
136 return asdict | 137 return asdict |
137 | 138 |
138 def as_dict(self): | 139 def as_dict(self, column_ids_in_order=None): |
139 """Returns a dictionary describing this package of ImagePairs. | 140 """Returns a dictionary describing this package of ImagePairs. |
140 | 141 |
141 Uses the KEY__* constants as keys. | 142 Uses the KEY__* constants as keys. |
| 143 |
| 144 Params: |
| 145 column_ids_in_order: A list of all extracolumn IDs in the desired display |
| 146 order. If unspecified, they will be displayed in alphabetical order. |
| 147 If specified, this list must contain all the extracolumn IDs! |
| 148 (It may contain extra column IDs; they will be ignored.) |
142 """ | 149 """ |
| 150 all_column_ids = set(self._extra_column_tallies.keys()) |
| 151 if column_ids_in_order == None: |
| 152 column_ids_in_order = sorted(all_column_ids) |
| 153 else: |
| 154 # Make sure the caller listed all column IDs, and throw away any extras. |
| 155 specified_column_ids = set(column_ids_in_order) |
| 156 forgotten_column_ids = all_column_ids - specified_column_ids |
| 157 assert not forgotten_column_ids, ( |
| 158 'column_ids_in_order %s missing these column_ids: %s' % ( |
| 159 column_ids_in_order, forgotten_column_ids)) |
| 160 column_ids_in_order = [c for c in column_ids_in_order |
| 161 if c in all_column_ids] |
| 162 |
143 key_description = KEY__IMAGESETS__FIELD__DESCRIPTION | 163 key_description = KEY__IMAGESETS__FIELD__DESCRIPTION |
144 key_base_url = KEY__IMAGESETS__FIELD__BASE_URL | 164 key_base_url = KEY__IMAGESETS__FIELD__BASE_URL |
145 return { | 165 return { |
146 KEY__ROOT__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), | 166 KEY__ROOT__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), |
| 167 KEY__ROOT__EXTRACOLUMNORDER: column_ids_in_order, |
147 KEY__ROOT__IMAGEPAIRS: self._image_pair_dicts, | 168 KEY__ROOT__IMAGEPAIRS: self._image_pair_dicts, |
148 KEY__ROOT__IMAGESETS: { | 169 KEY__ROOT__IMAGESETS: { |
149 KEY__IMAGESETS__SET__IMAGE_A: { | 170 KEY__IMAGESETS__SET__IMAGE_A: { |
150 key_description: self._descriptions[0], | 171 key_description: self._descriptions[0], |
151 key_base_url: self._image_base_url, | 172 key_base_url: self._image_base_url, |
152 }, | 173 }, |
153 KEY__IMAGESETS__SET__IMAGE_B: { | 174 KEY__IMAGESETS__SET__IMAGE_B: { |
154 key_description: self._descriptions[1], | 175 key_description: self._descriptions[1], |
155 key_base_url: self._image_base_url, | 176 key_base_url: self._image_base_url, |
156 }, | 177 }, |
157 KEY__IMAGESETS__SET__DIFFS: { | 178 KEY__IMAGESETS__SET__DIFFS: { |
158 key_description: 'color difference per channel', | 179 key_description: 'color difference per channel', |
159 key_base_url: posixpath.join( | 180 key_base_url: posixpath.join( |
160 self._diff_base_url, imagediffdb.RGBDIFFS_SUBDIR), | 181 self._diff_base_url, imagediffdb.RGBDIFFS_SUBDIR), |
161 }, | 182 }, |
162 KEY__IMAGESETS__SET__WHITEDIFFS: { | 183 KEY__IMAGESETS__SET__WHITEDIFFS: { |
163 key_description: 'differing pixels in white', | 184 key_description: 'differing pixels in white', |
164 key_base_url: posixpath.join( | 185 key_base_url: posixpath.join( |
165 self._diff_base_url, imagediffdb.WHITEDIFFS_SUBDIR), | 186 self._diff_base_url, imagediffdb.WHITEDIFFS_SUBDIR), |
166 }, | 187 }, |
167 }, | 188 }, |
168 } | 189 } |
OLD | NEW |