feat: support postgres autonomy runtime
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const os = require('os');
|
||||
const https = require('https');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { calculateOutcome } = require('../src/autonomy/outcomes');
|
||||
|
||||
@@ -33,7 +33,7 @@ async function history(symbol) {
|
||||
}
|
||||
|
||||
async function resolveAutonomyOutcomes({ intelligencePath, workerId = `outcome-${os.hostname()}-${process.pid}`, pollMs = 60000 } = {}) {
|
||||
const db = new Database(intelligencePath);
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(db);
|
||||
@@ -56,9 +56,18 @@ async function resolveAutonomyOutcomes({ intelligencePath, workerId = `outcome-$
|
||||
continue;
|
||||
}
|
||||
db.prepare(`
|
||||
INSERT OR REPLACE INTO autonomy_outcomes
|
||||
INSERT INTO autonomy_outcomes
|
||||
(prediction_id, price_0, price_horizon, benchmark_0, benchmark_horizon, excess_return, direction_correct, error_type)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(prediction_id) DO UPDATE SET
|
||||
price_0=excluded.price_0,
|
||||
price_horizon=excluded.price_horizon,
|
||||
benchmark_0=excluded.benchmark_0,
|
||||
benchmark_horizon=excluded.benchmark_horizon,
|
||||
excess_return=excluded.excess_return,
|
||||
direction_correct=excluded.direction_correct,
|
||||
error_type=excluded.error_type,
|
||||
evaluated_at=datetime('now')
|
||||
`).run(prediction.id, result.price0, result.priceHorizon, result.benchmark0, result.benchmarkHorizon,
|
||||
result.excessReturn, result.directionCorrect, result.directionCorrect ? null : 'direction_error');
|
||||
db.prepare("UPDATE autonomy_predictions SET status = 'resolved' WHERE id = ?").run(prediction.id);
|
||||
|
||||
Reference in New Issue
Block a user