cli2 writes CredResult as cred.json (#1833)
This commit modifies the cli2 score command so that instead of writing the output format described in #1773, it instead writes the new CredResult format added in #1830. This is a much better engineered format, and will be useful for building a new frontend as well as for analysis by third parties (although we will need to provide client code for parsing it). Test plan: On a cli2 instance, run `sc2 score` and inspect the resulting cred.json file.
This commit is contained in:
parent
cb1d612f1f
commit
f615ec89a3
|
@ -8,13 +8,8 @@ import type {Command} from "./command";
|
||||||
import {loadInstanceConfig} from "./common";
|
import {loadInstanceConfig} from "./common";
|
||||||
import {fromJSON as weightedGraphFromJSON} from "../core/weightedGraph";
|
import {fromJSON as weightedGraphFromJSON} from "../core/weightedGraph";
|
||||||
import {defaultParams} from "../analysis/timeline/params";
|
import {defaultParams} from "../analysis/timeline/params";
|
||||||
import {TimelineCred} from "../analysis/timeline/timelineCred";
|
|
||||||
import {LoggingTaskReporter} from "../util/taskReporter";
|
import {LoggingTaskReporter} from "../util/taskReporter";
|
||||||
import {
|
import {compute, toJSON as credResultToJSON} from "../analysis/credResult";
|
||||||
fromTimelineCredAndPlugins,
|
|
||||||
COMPAT_INFO as OUTPUT_COMPAT_INFO,
|
|
||||||
} from "../analysis/output";
|
|
||||||
import {toCompat} from "../util/compat";
|
|
||||||
|
|
||||||
function die(std, message) {
|
function die(std, message) {
|
||||||
std.err("fatal: " + message);
|
std.err("fatal: " + message);
|
||||||
|
@ -40,15 +35,10 @@ const scoreCommand: Command = async (args, std) => {
|
||||||
// TODO: Support loading params from config.
|
// TODO: Support loading params from config.
|
||||||
const params = defaultParams();
|
const params = defaultParams();
|
||||||
|
|
||||||
const tc = await TimelineCred.compute({
|
const credResult = await compute(graph, params, declarations);
|
||||||
weightedGraph: graph,
|
const credJSON = stringify(credResultToJSON(credResult));
|
||||||
params,
|
const outputPath = pathJoin(baseDir, "output", "credResult.json");
|
||||||
plugins: declarations,
|
await fs.writeFile(outputPath, credJSON);
|
||||||
});
|
|
||||||
const output = fromTimelineCredAndPlugins(tc, declarations);
|
|
||||||
const outputJSON = stringify(toCompat(OUTPUT_COMPAT_INFO, output));
|
|
||||||
const outputPath = pathJoin(baseDir, "output", "cred.json");
|
|
||||||
await fs.writeFile(outputPath, outputJSON);
|
|
||||||
taskReporter.finish("score");
|
taskReporter.finish("score");
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue