"""Reproduce the citation-share example with Python 3.9+. All inputs are synthetic. Runs offline.""" import argparse import json def result(key, method, columns, rows, limits): return dict(key=key, method=method, columns=columns, rows=rows, limits=limits) def citation_share(): rows = [] for period, site, other in [('A',20,80),('B',24,136),('C',24,56),('D',0,0)]: total = site + other share = f'{100*site/total:g} %' if total else '∅' rows.append([period,f'{site} / {total}',share]) return result('citation-share', 'Use one hypothetical grounding query and four equal observation windows A through D ' 'with the same scope. Synthetic citation counts for this site and all other sites are ' '(20,80), (24,136), (24,56) and (0,0). Divide this site’s count by the sum across all ' 'sites in that window and multiply by 100. The middle column shows numerator and ' 'denominator, not two separate site counts. ∅ means the ratio is undefined.', ['Window', 'Site citations / all citations', 'Citation share'], rows, 'These are invented counts, not Bing data. The arithmetic does not establish what raw ' 'counts are available to a publisher or how Bing displays missing data. No competitor ' 'identity, ranking, click volume or traffic share can be inferred. Keep query, time ' 'window length, filters and scope comparable before interpreting a movement.') if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('case', nargs='?', choices=['citation-share']) parser.parse_args() print(json.dumps(citation_share(), indent=2, ensure_ascii=False))