Skip to content

Commit

Permalink
Add model.bin to file system
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed May 28, 2024
1 parent bed267e commit 33eadb1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/project/project-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,24 @@ export class ProjectActions {
const data = JSON.parse(json) as ActionData[];
this.setModelData(data);
const actionNames = data.map((action) => action.name);
await this.fs.write(
"model.py",
modelModule(JSON.stringify(actionNames)),
VersionAction.INCREMENT
);
const model = await trainModel(data);
const result = compileModel(model, {});
const modelAsHexString = Array.from(result.machineCode, (i) =>
i.toString(16).padStart(2, "0")
).join("");
console.log(modelAsHexString);
// TODO: Remove if not needed.
// const modelAsHexString = Array.from(result.machineCode, (i) =>
// i.toString(16).padStart(2, "0")
// ).join("");
Promise.all([
await this.fs.write(
"model.py",
modelModule(JSON.stringify(actionNames)),
VersionAction.INCREMENT
),
await this.fs.write(
"model.bin",
result.machineCode,
VersionAction.INCREMENT
),
]);
}
};

Expand Down

0 comments on commit 33eadb1

Please sign in to comment.