Created
September 2, 2022 18:31
-
-
Save a-churchill/81b00ea292c15eb8af9c164128e932c3 to your computer and use it in GitHub Desktop.
Runs `prepare_cow` against every model in the file `model_ids` and puts the results in a SQLite database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Runs 'prepare_cow' against every model in the file 'model_ids' and puts | |
# the results in a sqlite database. | |
# The first argument is the name of the run e.g. the branch name. These | |
# can be compared later. | |
# Written by: kevin@causal.app | |
# Modified by: andrew@causal.app | |
import os | |
import sqlite3 | |
import requests | |
import time | |
import sys | |
import subprocess | |
name = sys.argv[1] | |
token = os.getenv("CAUSAL_STAGING_HTTP_AUTH_TOKEN") | |
with open("model_ids", "r") as f: | |
model_ids = [i.strip() for i in f.readlines()] | |
db = sqlite3.connect("results.db") | |
db.execute( | |
"CREATE TABLE IF NOT EXISTS results (name text, model_id integer, completed text, status text, result text, time real);" | |
) | |
db.execute("DELETE FROM results WHERE name = ?", [name]) | |
print("flushing cache...") | |
subprocess.run(["redis-cli", "flushall"]) | |
try: | |
for model_id in model_ids: | |
print(model_id) | |
start = time.perf_counter() | |
response = requests.post( | |
"https://causal.vip/api/causal_models/prepare_cow/" + model_id, | |
headers={ | |
"Authorization": "Bearer " + token, | |
"Content-Type": "application/json", | |
}, | |
data='{"delta":"{}","return_all_variables":true,"return_all_models":true,"clearCache":false,"additional_affected_ids":[],"changed_dimension_ids":[],"dimensions_delta":[],"models_delta":{}}', | |
) | |
end = time.perf_counter() | |
db.execute( | |
"INSERT INTO results (name, model_id, completed, status, result, time) VALUES (?, ?, datetime('now'), ?, ?, ?)", | |
[name, model_id, response.status_code, response.content, end - start], | |
) | |
finally: | |
db.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment