from remote_util import latest, day_of, uniq DS = 'Lilambd/world-pulse-daily' LICENSE = 'CC BY-SA 4.0' STR = {} KEYS = {} SH = 'World Pulse Daily' # table -> list of (where-col, value-col, phrase) lookups keyed by `key` SPEC = { 'fx_ecb': [('rate', 'what is the ECB reference rate of EUR to {name}')], 'arxiv': [('submitted', 'how many arXiv submissions are counted for category {name}')], 'stablecoins': [('circulating', 'what circulating stablecoin amount (USD) is recorded for {name}')], 'hackernews_front': [('score', 'what score does the Hacker News front-page story ranked {name} have'), ('title', 'what is the title of the Hacker News front-page story ranked {name}')], 'wikipedia_size': [('articles', 'how many articles does the {name} Wikipedia have'), ('activeusers', 'how many active users does the {name} Wikipedia have')], 'docker_official_images': [('pulls', 'how many pulls does the Docker official image {name} have'), ('stars', 'how many stars does the Docker official image {name} have')], 'stackoverflow_tags': [('questions', 'how many questions are counted for the Stack Overflow key {name}')], 'ai_sdk_downloads': [('downloads', 'how many downloads are recorded for the AI SDK package key {name}')], 'crossref': [('dois', 'how many DOIs are counted for the Crossref facet key {name}')], 'zenodo': [('records', 'how many records are counted for the Zenodo facet key {name}')], 'hf_daily_papers': [('upvotes', 'how many upvotes does the Hugging Face daily paper with key {name} have')], 'github_new_repos': [('repos', 'how many new GitHub repos are counted for the key {name}')], 'crates_io': [('downloads', 'how many downloads does the crates.io key {name} show')], 'wikipedia_top': [('article', 'which article holds the Wikipedia top-views key {name}'), ('views', 'how many views does the Wikipedia top-views key {name} have')], 'appstore_charts': [('name', 'which app holds the App Store chart position key {name}')], } def build(B): root = B.store.root for t, specs in SPEC.items(): f = latest(root, f'{t}/*.csv') if not f: continue KEYS[f] = ['key'] d = B.store[f] day = day_of(f) du = uniq(d, 'key') n = 30 if t in ('appstore_charts', 'wikipedia_top', 'stablecoins') else 14 for r in du.loc[B.sample(du.index, n)].to_dict('records'): col, phrase = B.rng.choice(specs) if col not in r or r[col] != r[col] or r[col] is None: continue nm = r['key'] if t not in ('fx_ecb',) else r['key'] B.add('lookup', f'In {SH} ({t}, fetched {day}), {phrase.format(name=nm)}?', {'op': 'lookup', 'file': f, 'where': [['key', '==', r['key']]], 'col': col}, tol={'rel': 0.0001}, skills=['table_lookup', 'fresh_data']) num = [c for c in ('submitted', 'circulating', 'score', 'articles', 'pulls', 'questions', 'downloads', 'dois', 'records', 'upvotes', 'repos', 'views') if c in d.columns] for c in num[:1]: B.add('rank', f'In {SH} ({t}, fetched {day}), which key has the highest {c}?', {'op': 'argmax', 'file': f, 'col': c, 'return': 'key'}, difficulty=2, skills=['ranking', 'fresh_data']) B.add('rank', f'In {SH} ({t}, fetched {day}), list the 3 keys with the highest {c}, highest first.', {'op': 'topk', 'k': 3, 'file': f, 'col': c, 'return': 'key'}, difficulty=2, skills=['ranking', 'fresh_data'], answer_format='JSON list') B.add('count', f'In {SH}, how many rows does the {t} table have for fetch date {day}?', {'op': 'count', 'file': f}, skills=['count', 'fresh_data']) f = latest(root, 'appstore_charts/*.csv') if f: a = B.store[f] for c in B.sample(sorted(a.country.dropna().unique()), 25): ch = B.rng.choice(sorted(a.chart.dropna().unique())) B.add('lookup', f'In {SH} App Store charts fetched {day_of(f)}, which app is #1 on the {ch} chart in country "{c}"?', {'op': 'lookup', 'file': f, 'where': [['country', '==', c], ['chart', '==', ch], ['rank', '==', 1]], 'col': 'name'}, skills=['table_lookup', 'fresh_data', 'multilingual_entity']) for dev in list(a.developer.dropna().value_counts().index)[:12]: B.add('count', f'In {SH} App Store charts fetched {day_of(f)}, how many chart entries (all countries, all charts) belong to the developer "{dev}"?', {'op': 'count', 'file': f, 'where': [['developer', '==', dev]]}, difficulty=2, skills=['filter', 'count', 'fresh_data']) f = latest(root, 'wikipedia_top/*.csv') if f: w = B.store[f] for lg in B.sample(sorted(w.lang.dropna().unique()), 15): rk = B.rng.choice([3, 4, 5, 10]) B.add('lookup', f'In {SH} Wikipedia top views fetched {day_of(f)}, which article is ranked #{rk} in the "{lg}" Wikipedia?', {'op': 'lookup', 'file': f, 'where': [['lang', '==', lg], ['rank', '==', rk]], 'col': 'article'}, skills=['table_lookup', 'fresh_data', 'multilingual_entity']) f = latest(root, 'fx_ecb/*.csv') if f: for cur in ['XYZ', 'LIL']: B.add('unanswerable', f'In {SH} ECB rates fetched {day_of(f)}, what is the EUR rate for the currency code {cur}? If not listed, answer null.', {'op': 'absent', 'file': f, 'where': [['currency', '==', cur]]}, skills=['abstention'])