Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
|
epoger
2014/05/07 21:26:17
Reason for the CL: the fact that the rebaseline_se
borenet
2014/05/08 12:40:18
Top-level comment about parsing JSON: I really lik
epoger
2014/05/08 15:04:35
Thanks for pointing out this other way of living.
| |
| 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 ColumnHeaderFactory class (see class docstring for details) | 9 ColumnHeaderFactory class (see class docstring for details) |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import utils | |
| 13 | |
| 12 # Keys used within dictionary representation of each column header. | 14 # Keys used within dictionary representation of each column header. |
| 13 # NOTE: Keep these in sync with static/constants.js | 15 # NOTE: Keep these in sync with static/constants.js |
| 14 KEY__HEADER_TEXT = 'headerText' | 16 KEY__EXTRACOLUMNHEADERS = 'extraColumnHeaders' |
| 15 KEY__HEADER_URL = 'headerUrl' | 17 KEY__EXTRACOLUMNHEADERS__COUNTS = 'counts' |
|
epoger
2014/05/07 21:26:17
While I was at it, renamed these particular key co
| |
| 16 KEY__IS_FILTERABLE = 'isFilterable' | 18 KEY__EXTRACOLUMNHEADERS__HEADER_TEXT = 'headerText' |
| 17 KEY__IS_SORTABLE = 'isSortable' | 19 KEY__EXTRACOLUMNHEADERS__HEADER_URL = 'headerUrl' |
| 18 KEY__VALUES_AND_COUNTS = 'valuesAndCounts' | 20 KEY__EXTRACOLUMNHEADERS__IS_FILTERABLE = 'isFilterable' |
| 21 KEY__EXTRACOLUMNHEADERS__IS_SORTABLE = 'isSortable' | |
| 22 KEY__EXTRACOLUMNHEADERS__VALUES = 'values' | |
| 19 | 23 |
| 20 | 24 |
| 21 class ColumnHeaderFactory(object): | 25 class ColumnHeaderFactory(object): |
| 22 """Factory which assembles the header for a single column of data.""" | 26 """Factory which assembles the header for a single column of data.""" |
| 23 | 27 |
| 24 def __init__(self, header_text, header_url=None, | 28 def __init__(self, header_text, header_url=None, |
| 25 is_filterable=True, is_sortable=True, | 29 is_filterable=True, is_sortable=True, |
| 26 include_values_and_counts=True): | 30 include_values_and_counts=True): |
| 27 """ | 31 """ |
| 28 Args: | 32 Args: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 39 self._header_text = header_text | 43 self._header_text = header_text |
| 40 self._header_url = header_url | 44 self._header_url = header_url |
| 41 self._is_filterable = is_filterable | 45 self._is_filterable = is_filterable |
| 42 self._is_sortable = is_sortable | 46 self._is_sortable = is_sortable |
| 43 self._include_values_and_counts = include_values_and_counts | 47 self._include_values_and_counts = include_values_and_counts |
| 44 | 48 |
| 45 def create_as_dict(self, values_and_counts_dict=None): | 49 def create_as_dict(self, values_and_counts_dict=None): |
| 46 """Creates the header for this column, in dictionary form. | 50 """Creates the header for this column, in dictionary form. |
| 47 | 51 |
| 48 Creates the header for this column in dictionary form, as needed when | 52 Creates the header for this column in dictionary form, as needed when |
| 49 constructing the JSON representation. Uses the KEY__* constants as keys. | 53 constructing the JSON representation. Uses the KEY__EXTRACOLUMNHEADERS__* |
| 54 constants as keys. | |
| 50 | 55 |
| 51 Args: | 56 Args: |
| 52 values_and_counts_dict: dictionary mapping each possible column value | 57 values_and_counts_dict: dictionary mapping each possible column value |
| 53 to its count (how many entries in the column have this value), or | 58 to its count (how many entries in the column have this value), or |
| 54 None if this information is not available. | 59 None if this information is not available. |
| 55 """ | 60 """ |
| 56 asdict = { | 61 asdict = { |
| 57 KEY__HEADER_TEXT: self._header_text, | 62 KEY__EXTRACOLUMNHEADERS__HEADER_TEXT: self._header_text, |
| 58 KEY__IS_FILTERABLE: self._is_filterable, | 63 KEY__EXTRACOLUMNHEADERS__IS_FILTERABLE: self._is_filterable, |
| 59 KEY__IS_SORTABLE: self._is_sortable, | 64 KEY__EXTRACOLUMNHEADERS__IS_SORTABLE: self._is_sortable, |
| 60 } | 65 } |
| 61 if self._header_url: | 66 if self._header_url: |
| 62 asdict[KEY__HEADER_URL] = self._header_url | 67 asdict[KEY__EXTRACOLUMNHEADERS__HEADER_URL] = self._header_url |
| 63 if self._include_values_and_counts and values_and_counts_dict: | 68 if self._include_values_and_counts and values_and_counts_dict: |
| 64 asdict[KEY__VALUES_AND_COUNTS] = values_and_counts_dict | 69 values, counts = utils.unzip_dict(values_and_counts_dict) |
| 70 asdict[KEY__EXTRACOLUMNHEADERS__VALUES] = values | |
| 71 asdict[KEY__EXTRACOLUMNHEADERS__COUNTS] = counts | |
| 65 return asdict | 72 return asdict |
| OLD | NEW |