Example #1
0
 def count(self):
     """Count anything
     
     Returns:
         Chepy: The Chepy object. 
     """
     self.state = pydash.count_by(self.state)
     return self
Example #2
0
    def _validate_json(data):
        """ Internal method to validate resources.json content """
        counts = count_by(data, lambda obj: obj.get('id'))
        no_ids = filter_(counts.keys(), lambda key: key is None)
        if no_ids:
            raise ValueError('Invalid json, id property is missing')

        duplicates = filter_(counts.keys(), lambda key: counts[key] > 1)
        if duplicates:
            MODULE_LOGGER.warning('Duplicates: %s', duplicates)
            raise ValueError(f"Invalid json, duplicate ids in {duplicates}")
Example #3
0
 def agg(value):
     values = grouped_objects.get(value, [])
     result = {'cycle': value}
     total = len(values)
     yes_count_value = count_values[YES]
     no_count_value = count_values[NO]
     not_reporting_count_value = count_values[NOT_REPORTING]
     if total > 0:
         counts = pydash.count_by(values, get_count_key)
         yes_count = counts.get(yes_count_value, 0)
         no_count = counts.get(no_count_value, 0)
         not_reporting_count = counts.get(not_reporting_count_value, 0)
         result[keys[YES]] = (yes_count * 100 / float(total))
         result[keys[NO]] = (no_count * 100 / float(total))
         result[keys[NOT_REPORTING]] = (not_reporting_count * 100 / float(total))
     else:
         result[keys[YES]] = 0
         result[keys[NO]] = 0
         result[keys[NOT_REPORTING]] = 0
     return result
Example #4
0
 def agg(value):
     values = grouped_objects.get(value, [])
     result = {'cycle': value}
     total = len(values)
     yes_count_value = count_values[YES]
     no_count_value = count_values[NO]
     not_reporting_count_value = count_values[NOT_REPORTING]
     if total > 0:
         counts = pydash.count_by(values, get_count_key)
         yes_count = counts.get(yes_count_value, 0)
         no_count = counts.get(no_count_value, 0)
         not_reporting_count = counts.get(not_reporting_count_value, 0)
         result[keys[YES]] = (yes_count * 100 / float(total))
         result[keys[NO]] = (no_count * 100 / float(total))
         result[keys[NOT_REPORTING]] = (not_reporting_count * 100 /
                                        float(total))
     else:
         result[keys[YES]] = 0
         result[keys[NO]] = 0
         result[keys[NOT_REPORTING]] = 0
     return result
Example #5
0
def test_count_by(case, expected):
    assert _.count_by(*case) == expected