def test_time_get_mem(self): com_pool = ['menmodelblog'] #, "tnull", "potracheno", "roscosmos"] logging.info("Amount | Asyncio | OneThread") for com in com_pool: members_count = self.api.groups.getMembers(group_id=com).get( 'count', 0) t1 = 0 for i in range(TIMES): st = time.time() getters.get_members_asy(com, members_count) t1 += time.time() - st t1 /= TIMES t2 = 0 for i in range(TIMES): st = time.time() getters.get_members(com, members_count) t2 += time.time() - st t2 /= TIMES logging.debug("{0} | {1:.5f} | {2:.5f}".format( members_count, t1, t2))
def test_get_mem(self): members_count = self.api.groups.getMembers(group_id='bo0om_ru').get( 'count', 0) res1 = getters.get_members_asy('bo0om_ru', members_count) res2 = getters.get_members('bo0om_ru', members_count) self.assertEqual(res1, res2)
def age_data(self): age_data = getters.get_members(self.group_id, self.members_count, fields='sex, bdate') year = time.gmtime(time.time()).tm_year unknown = 0 ages_male = [] ages_female = [] for user in age_data: date = user.get('bdate', None) if date: date = date.split('.') if len(date) < 3: unknown += 1 continue else: date = date[-1] age = year - int(date) if age >= 80 or age < 10: unknown += 1 else: if user['sex'] == 1: ages_female.append(age) elif user['sex'] == 2: ages_male.append(age) else: unknown += 1 else: unknown += 1 if ages_female: age_female_max = max(ages_female) age_female_min = min(ages_female) else: age_female_max, age_female_min = 0, 0 if ages_male: age_male_max = max(ages_male) age_male_min = min(ages_female) else: age_male_max, age_male_min = 0, 0 age_num = len(ages_female) + len(ages_male) hist_step = 1 + floor(log(age_num, 2)) # age_data = {(a, a + hist_step): None for a in range(age_min, age_max, hist_step)} xbins_female = dict(start=age_female_min, end=age_female_max, size=hist_step) xbins_male = dict(start=age_male_min, end=age_male_max, size=hist_step) return ages_female, xbins_female, ages_male, xbins_male, unknown
def sex_data(self): sex_data = getters.get_members(self.group_id, self.members_count, fields="sex") woman = 0 man = 0 unknown = 0 for user in sex_data: if user['sex'] == 1: woman += 1 elif user['sex'] == 2: man += 1 else: unknown += 1 sex_dict = {"Woman": woman, "Man": man, "Unknown": unknown} return sex_dict
def platform_data(self): platform_data = getters.get_members(self.group_id, self.members_count, fields="last_seen") platform_count = [] for user in platform_data: index = None last = user.get('last_seen', None) if last is not None: index = last.get('platform', None) if index is not None: platform_count.append(index) index_dict = dict(Counter(platform_count)) platform_dict = {} for each in index_dict.keys(): platform_dict[settings.PLATFORM[each]] = index_dict[each] platform_dict.update( {'Apple': platform_dict['iPhone'] + platform_dict['iPad']}) platform_dict.pop('iPhone') platform_dict.pop('iPad') to_pop = platform_dict.get('Windows 10', 0) platform_dict['Web'] += to_pop if to_pop: platform_dict.pop('Windows 10') system_dict = dict.fromkeys(['Web', 'Mobile']) system_dict['Web'] = platform_dict['Web'] platform_dict.pop('Web') system_dict['Mobile'] = platform_dict['Mobile'] platform_dict.pop('Mobile') return platform_dict, system_dict