How to use get_stats_diff method in autotest

Best Python code snippet using autotest_python

stats.py

Source:stats.py Github

copy

Full Screen

...42 diff = new - old43 if diff == 0:44 return None45 return f"+{diff}" if diff > 0 else f"{diff}"46def get_stats_diff(symbol, tokens, previous_stats):47 if not previous_stats:48 return ""49 previous_symbol_totals = previous_stats.get('all_holdings').get(symbol)50 diff = get_diff(previous_symbol_totals, tokens)51 if not diff:52 return ""53 return f"({diff})"54def get_holders_diff(previous_stats, current_holders, last_checked, last_checked_date):55 diff = get_diff(previous_stats.get('unique'), len(current_holders))56 if not last_checked or not diff:57 return None58 return f"({diff} since {last_checked_date.humanize()})"59def fetch_phunks_stats(should_tweet=True):60 print("Getting unique NFT owners...")61 try:62 previous_stats = get_latest_stats()63 created_at = previous_stats.get('created_at')64 created_at_arrow = arrow.get(created_at)65 time_diff = (arrow.utcnow() - created_at_arrow) # type: timedelta66 if time_diff.seconds < (120 * 60): # 2 hours in seconds67 print("trying to run too early, ignoring...")68 return69 except Exception as e:70 print(f"problem fetching previous stats {e}")71 previous_stats = {}72 holders = get_nft_unique_owners(settings.PHUNK_CONTRACT_ADDRESS)73 phunk_holders = copy.deepcopy(holders)74 print(f"Found {len(holders)}. Iterating through...")75 current_holder_addresses = list(holders.keys())76 sum_holdings = defaultdict(int)77 unique_holders = defaultdict(int)78 new_holders = holders_coll.find({"_id": {"$nin": current_holder_addresses}})79 if not list(new_holders) and not DEEP_FETCH:80 print("No new holders")81 sys.exit(0)82 new_holders_addresses = [h.get('_id') for h in list(new_holders)]83 total_holders = len(phunk_holders)84 counter = 085 for holder, token_ids in holders.items():86 counter += 187 print(f"Handling holder {holder} | {counter}/{total_holders}")88 new_holder = holder in new_holders_addresses89 db_holder = get_holder(holder)90 try:91 if not new_holder and not DEEP_FETCH and db_holder:92 curated_holdings = db_holder.get('holdings')93 else:94 curated_holdings = get_curated_nfts_holdings(holder, include_batch=False,95 curated_contracts=curated_contracts)96 except Exception as e:97 print(f"problems fetching holdings for {holder}: {e}")98 continue99 ch_tuples = []100 for curated_holding in curated_holdings:101 name = curated_holding.get('name')102 balance = curated_holding.get('balance')103 symbol = curated_holding.get('symbol')104 ch_tuples.append((symbol, balance))105 sum_holdings[symbol] += balance106 unique_holders[symbol] += 1107 if len(ch_tuples) > 0:108 print(f"{holder}: {ch_tuples}")109 try:110 if db_holder:111 update_holder(holder, {'token_ids': token_ids, 'holdings': curated_holdings})112 else:113 holder_data = {114 '_id': holder,115 'ens': get_ens_domain_for_address(holder),116 'token_ids': token_ids,117 'holdings': curated_holdings118 }119 save_holder(holder_data)120 except Exception as e:121 raise e122 print("\n\n## All holdings")123 sorted_holdings = dict(sorted(dict(sum_holdings).items(), key=operator.itemgetter(1), reverse=True))124 print(sorted_holdings)125 print("\n\n## Unique holders")126 sorted_holders = dict(sorted(dict(unique_holders).items(), key=operator.itemgetter(1), reverse=True))127 print(sorted_holders)128 try:129 save_stats({'results': sorted_holders, 'unique': len(phunk_holders), 'all_holdings': sorted_holdings})130 except Exception as e:131 print(f"problem storing stats: {e}")132 last_checked = None if not previous_stats else previous_stats.get('created_at')133 last_checked_date = arrow.get(last_checked) if last_checked else None134 print("\n\nCleaning up...")135 result = holders_coll.delete_many({"_id": {"$nin": current_holder_addresses}})136 print(f"deleted {result.deleted_count} old holders")137 print("\n\nTweeting holdings...")138 for addr, meta in curated_contracts.items():139 symbol = meta.get('symbol')140 if not meta.get('show_holdings', True):141 del sorted_holdings[symbol]142 unique_holdings = [f"- {no_tokens} {symbol} {get_stats_diff(symbol, no_tokens, previous_stats)}" for143 symbol, no_tokens in sorted_holdings.items()]144 unique_holdings_str = "\n".join(unique_holdings)145 holders_diff = get_holders_diff(previous_stats, phunk_holders, last_checked, last_checked_date)146 tweet_content = f"""Wallets holding PHUNKS also hold:147{unique_holdings_str}148{"" if not last_checked_date else f"(since {last_checked_date.humanize()})"}149"""150 print(tweet_content)151 if should_tweet:152 tweet(tweet_content)153 print("\n\nTweeting unique holders...")154 unique_owners = {}155 for addr, meta in curated_contracts.items():156 if not meta.get('show_flip', True):...

Full Screen

Full Screen

compare_perf_stats.py

Source:compare_perf_stats.py Github

copy

Full Screen

...32 print(header_template.format('App', 'Mem diff %', 'Time diff %'))33 def print_sep():34 print(header_template.format(*['-' * (width - 1) for width in col_widths]))35 print_sep()36 def get_stats_diff(slug, stat):37 stats_item1 = stats1[slug]38 if slug not in stats2:39 return 10040 stats_item2 = stats2[slug]41 diff = stats_item2[stat] - stats_item1[stat]42 percent = float(diff) / stats_item1[stat]43 return {44 '%': percent,45 'numerator': diff,46 'denominator': stats_item1[stat]47 }48 def get_all_diffs(name):49 return [get_stats_diff(slug, name) for slug in stats1]50 all_mem = get_all_diffs('mem')51 all_time = get_all_diffs('time')52 for slug, mem, time in zip(stats1.keys(), all_mem, all_time):53 print(row_template.format(54 slug,55 mem_cell_template.format(**mem),56 time_cell_template.format(**time)57 ))58 print_sep()59 print(row_template.format(60 'Average',61 mem_cell_template.format(**avg_dict(all_mem)),62 time_cell_template.format(**avg_dict(all_time)),63 ))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful