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 import column | 12 import column |
13 | 13 |
14 # Keys used within dictionary representation of ImagePairSet. | 14 # Keys used within dictionary representation of ImagePairSet. |
15 # NOTE: Keep these in sync with static/constants.js | 15 # NOTE: Keep these in sync with static/constants.js |
16 KEY__EXTRACOLUMNHEADERS = 'extraColumnHeaders' | 16 KEY__EXTRACOLUMNHEADERS = 'extraColumnHeaders' |
17 KEY__IMAGEPAIRS = 'imagePairs' | 17 KEY__IMAGEPAIRS = 'imagePairs' |
18 KEY__IMAGESETS = 'imageSets' | 18 KEY__IMAGESETS = 'imageSets' |
19 KEY__IMAGESETS__BASE_URL = 'baseUrl' | 19 KEY__IMAGESETS__FIELD__BASE_URL = 'baseUrl' |
20 KEY__IMAGESETS__DESCRIPTION = 'description' | 20 KEY__IMAGESETS__FIELD__DESCRIPTION = 'description' |
21 KEY__IMAGESETS__SET__DIFFS = 'diffs' | |
22 KEY__IMAGESETS__SET__IMAGE_A = 'imageA' | |
23 KEY__IMAGESETS__SET__IMAGE_B = 'imageB' | |
24 KEY__IMAGESETS__SET__WHITEDIFFS = 'whiteDiffs' | |
21 | 25 |
22 DEFAULT_DESCRIPTIONS = ('setA', 'setB') | 26 DEFAULT_DESCRIPTIONS = ('setA', 'setB') |
23 | 27 |
24 | 28 |
25 class ImagePairSet(object): | 29 class ImagePairSet(object): |
26 """A collection of ImagePairs, representing two arbitrary sets of images. | 30 """A collection of ImagePairs, representing two arbitrary sets of images. |
27 | 31 |
28 These could be: | 32 These could be: |
29 - images generated before and after a code patch | 33 - images generated before and after a code patch |
30 - expected and actual images for some tests | 34 - expected and actual images for some tests |
31 - or any other pairwise set of images. | 35 - or any other pairwise set of images. |
32 """ | 36 """ |
33 | 37 |
34 def __init__(self, descriptions=None): | 38 def __init__(self, descriptions=None): |
35 """ | 39 """ |
36 Args: | 40 Args: |
37 descriptions: a (string, string) tuple describing the two image sets. | 41 descriptions: a (string, string) tuple describing the two image sets. |
38 If not specified, DEFAULT_DESCRIPTIONS will be used. | 42 If not specified, DEFAULT_DESCRIPTIONS will be used. |
39 """ | 43 """ |
40 self._column_header_factories = {} | 44 self._column_header_factories = {} |
41 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS | 45 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS |
42 self._extra_column_tallies = {} # maps column_id -> values | 46 self._extra_column_tallies = {} # maps column_id -> values |
43 # -> instances_per_value | 47 # -> instances_per_value |
44 self._image_pair_dicts = [] | 48 self._image_pair_dicts = [] |
49 self._image_base_url = None | |
50 self._diff_base_url = '/static/generated-images' | |
rmistry
2014/03/17 13:48:58
Can we make this a module level constant?
epoger
2014/03/17 14:21:36
Done.
| |
45 | 51 |
46 def add_image_pair(self, image_pair): | 52 def add_image_pair(self, image_pair): |
47 """Adds an ImagePair; this may be repeated any number of times.""" | 53 """Adds an ImagePair; this may be repeated any number of times.""" |
48 # Special handling when we add the first ImagePair... | 54 # Special handling when we add the first ImagePair... |
49 if not self._image_pair_dicts: | 55 if not self._image_pair_dicts: |
50 self._base_url = image_pair.base_url | 56 self._image_base_url = image_pair.base_url |
51 | 57 |
52 if image_pair.base_url != self._base_url: | 58 if image_pair.base_url != self._image_base_url: |
53 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( | 59 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( |
54 image_pair.base_url, self._base_url)) | 60 image_pair.base_url, self._image_base_url)) |
55 self._image_pair_dicts.append(image_pair.as_dict()) | 61 self._image_pair_dicts.append(image_pair.as_dict()) |
56 extra_columns_dict = image_pair.extra_columns_dict | 62 extra_columns_dict = image_pair.extra_columns_dict |
57 if extra_columns_dict: | 63 if extra_columns_dict: |
58 for column_id, value in extra_columns_dict.iteritems(): | 64 for column_id, value in extra_columns_dict.iteritems(): |
59 self._add_extra_column_value_to_summary(column_id, value) | 65 self._add_extra_column_value_to_summary(column_id, value) |
60 | 66 |
61 def set_column_header_factory(self, column_id, column_header_factory): | 67 def set_column_header_factory(self, column_id, column_header_factory): |
62 """Overrides the default settings for one of the extraColumn headers. | 68 """Overrides the default settings for one of the extraColumn headers. |
63 | 69 |
64 Args: | 70 Args: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 column_header_factory = self.get_column_header_factory(column_id) | 126 column_header_factory = self.get_column_header_factory(column_id) |
121 asdict[column_id] = column_header_factory.create_as_dict( | 127 asdict[column_id] = column_header_factory.create_as_dict( |
122 values_for_column) | 128 values_for_column) |
123 return asdict | 129 return asdict |
124 | 130 |
125 def as_dict(self): | 131 def as_dict(self): |
126 """Returns a dictionary describing this package of ImagePairs. | 132 """Returns a dictionary describing this package of ImagePairs. |
127 | 133 |
128 Uses the KEY__* constants as keys. | 134 Uses the KEY__* constants as keys. |
129 """ | 135 """ |
136 key_description = KEY__IMAGESETS__FIELD__DESCRIPTION | |
137 key_base_url = KEY__IMAGESETS__FIELD__BASE_URL | |
130 return { | 138 return { |
131 KEY__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), | 139 KEY__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), |
132 KEY__IMAGEPAIRS: self._image_pair_dicts, | 140 KEY__IMAGEPAIRS: self._image_pair_dicts, |
133 KEY__IMAGESETS: [{ | 141 KEY__IMAGESETS: { |
134 KEY__IMAGESETS__BASE_URL: self._base_url, | 142 KEY__IMAGESETS__SET__IMAGE_A: { |
135 KEY__IMAGESETS__DESCRIPTION: self._descriptions[0], | 143 key_description: self._descriptions[0], |
136 }, { | 144 key_base_url: self._image_base_url, |
137 KEY__IMAGESETS__BASE_URL: self._base_url, | 145 }, |
138 KEY__IMAGESETS__DESCRIPTION: self._descriptions[1], | 146 KEY__IMAGESETS__SET__IMAGE_B: { |
139 }], | 147 key_description: self._descriptions[1], |
148 key_base_url: self._image_base_url, | |
149 }, | |
150 KEY__IMAGESETS__SET__DIFFS: { | |
151 key_description: 'color difference per channel', | |
152 key_base_url: self._diff_base_url + '/diffs', | |
rmistry
2014/03/17 13:48:58
Use posixpath.join here instead? and below.
epoger
2014/03/17 14:21:36
Done.
| |
153 }, | |
154 KEY__IMAGESETS__SET__WHITEDIFFS: { | |
155 key_description: 'differing pixels in white', | |
156 key_base_url: ( | |
157 self._diff_base_url + '/whitediffs'), | |
158 }, | |
159 }, | |
140 } | 160 } |
OLD | NEW |