def metaculus_via_api_keys(): load_dotenv() user_api_key = cast(str, os.getenv("METACULUS_USER_WWW_API_KEY")) org_api_key = cast(str, os.getenv("METACULUS_ORG_API_KEY")) if None in [user_api_key, org_api_key]: raise ValueError( ".env is missing METACULUS_ORG_API_KEY or METACULUS_USER_WWW_API_KEY" ) metaculus = ergo.Metaculus() metaculus.login_via_api_keys( user_api_key=user_api_key, org_api_key=org_api_key, ) return metaculus
def metaculus(): load_dotenv() uname = cast(str, os.getenv("METACULUS_USERNAME")) pwd = cast(str, os.getenv("METACULUS_PASSWORD")) user_id_str = cast(str, os.getenv("METACULUS_USER_ID")) if None in [uname, pwd, user_id_str]: raise ValueError( ".env is missing METACULUS_USERNAME, METACULUS_PASSWORD, or METACULUS_USER_ID" ) user_id = int(user_id_str) metaculus = ergo.Metaculus(uname, pwd) assert metaculus.user_id == user_id return metaculus
def metaculus(): load_dotenv() uname = METACULUS_USERNAME pwd = METACULUS_PASSWORD user_id_str = METACULUS_USER_ID if None in [uname, pwd, user_id_str]: raise ValueError( ".env is missing METACULUS_USERNAME, METACULUS_PASSWORD, or METACULUS_USER_ID" ) user_id = int(user_id_str) metaculus = ergo.Metaculus() metaculus.login_via_username_and_password(username=uname, password=pwd) assert metaculus.user_id == user_id return metaculus
def submit_recalibrated(qid, ir_model, session=None, username=USERNAME, password=PASSWORD, debug=False): if session is None: metaculus = ergo.Metaculus() metaculus.login_via_username_and_password(username=username, password=password) else: metaculus = session question = metaculus.get_question(qid) comm_cdf = get_histogram(question.data)['c'].cumsum() / 200 cdf = ir_model.predict(comm_cdf) lm = LogisticMixture() lm.fit(cdf) low_closed, high_closed = [not question.possibilities.get(side)=='tail' for side in ('low', 'high')] data = lm.get_prediction_data(low_closed, high_closed) if not debug and is_open(question): print(f"\t{question.name}") metaculus.predict(q_id=str(qid), data=data) return lm.func(np.linspace(0,1,len(cdf)), *lm.opt), cdf, comm_cdf.squeeze().values
def fetch_questions(search_query, qid_path=None, username=USERNAME, password=PASSWORD, n_pages=N_PAGES): metaculus = ergo.Metaculus() metaculus.login_via_username_and_password(username=username, password=password) if qid_path is not None: with open(qid_path, "r") as f: qids = [int(qid) for qid in f.readlines()] return [metaculus.get_question(qid) for qid in qids] qs = [] for cat in search_query: qs.extend(metaculus.get_questions(cat=cat, pages=n_pages)) return qs
def unauthenticated_metaculus(): return ergo.Metaculus()
if not dry_run: print("\tSubmitting") question.submit_from_samples(samples) else: comm_samples = np.array( [question.sample_community() for _ in range(n_samples)]) print("\tSaving to file...") np.save(f"samples/{question.id}", np.vstack([samples, comm_samples]).T) if __name__ == '__main__': # Login and load questions metaculus = ergo.Metaculus() metaculus.login_via_username_and_password(username=USERNAME, password=PASSWORD) print("Fetching questions...") qs = [] for cat in CATS: qs.extend(metaculus.get_questions(cat=cat, pages=N_PAGES)) print("Done!\n") # Submit for q in qs: print(f"{q.id}: {q.name}") if int(q.id) in MANUAL: print("\tSkipping...") try: