def extract_filters(kwargs): """ Pulls all the filtering options out of kwargs and returns dictionaries of filters, range filters and meta filters. """ filters = {} ranges = {} metas = {} if isinstance(kwargs.get('product'), int): metas['product'] = kwargs['product'] if kwargs.get('version'): filters['version'] = crc32(kwargs['version']) if kwargs.get('type'): metas['type'] = kwargs['type'] if kwargs.get('os'): metas['os'] = crc32(kwargs['os']) if kwargs.get('locale'): if kwargs['locale'] == 'unknown': filters['locale'] = crc32('') else: filters['locale'] = crc32(kwargs['locale']) if kwargs.get('date_end') and kwargs.get('date_start'): start = int(timegm(kwargs['date_start'].timetuple())) end_date = kwargs['date_end'] + timedelta(days=1) end = int(timegm(end_date.timetuple())) ranges['created'] = (start, end) return (filters, ranges, metas)
def _locale_meta(self, results, **kwargs): result = results[self.queries['locale']] if 'matches' in result: t = dict(((crc32(f), f) for f in product_details.languages)) return [dict(count=f['attrs']['count'], locale=t.get(f['attrs']['locale'])) for f in result['matches']]
def _platform_meta(self, results, **kwargs): result = results[self.queries['platform']] t = dict(((crc32(f.short), f.short) for f in PLATFORM_USAGE)) return [ dict(count=f['attrs']['count'], platform=t.get(f['attrs']['platform'])) for f in result['matches'] ]
def extract_filters(kwargs): """ Pulls all the filtering options out of kwargs and returns dictionaries of filters, range filters and meta filters. """ filters = {} ranges = {} metas = {} if isinstance(kwargs.get('product'), int): metas['product'] = kwargs['product'] if kwargs.get('version'): filters['version'] = crc32(kwargs['version']) if kwargs.get('type'): metas['type'] = kwargs['type'] for meta in ('platform', 'manufacturer', 'device'): val = kwargs.get(meta) if val and val.lower() == 'unknown': # In this situation 'unknown' usually means empty. metas[meta] = crc32('') elif val: metas[meta] = crc32(kwargs[meta]) if kwargs.get('locale'): if kwargs['locale'] == 'unknown': filters['locale'] = crc32('') else: filters['locale'] = crc32(kwargs['locale']) # TODO: We should allow infinite queries when we get hardware or ES many_days_ago = date.today() - timedelta(days=60) start = time_as_int(kwargs.get('date_start') or many_days_ago, utc=kwargs.get('utc')) end_date = (kwargs.get('date_end') or date.today()) + timedelta(days=1) end = time_as_int(end_date) ranges['created'] = (start, end) return (filters, ranges, metas)
def _device_meta(self, results, **kwargs): result = results[self.queries['device']] t = dict(((crc32(d), d) for d in KNOWN_DEVICES)) return collapsed(result['matches'], t, 'device')
def _manufacturer_meta(self, results, **kwargs): result = results[self.queries['manufacturer']] t = dict(((crc32(m), m) for m in KNOWN_MANUFACTURERS)) return collapsed(result['matches'], t, 'manufacturer')
def _platform_meta(self, results, **kwargs): result = results[self.queries['platform']] t = dict(((crc32(f.short), f.short) for f in PLATFORM_USAGE)) return [dict(count=f['attrs']['count'], platform=t.get(f['attrs']['platform'])) for f in result['matches']]
def _os_meta(self, results, **kwargs): result = results[self.queries['os']] t = dict(((crc32(f.short), f.short) for f in OS_USAGE)) return [dict(count=f['attrs']['count'], os=t.get(f['attrs']['os'])) for f in result['matches']]