-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC allow to launch a recice from cli
- Loading branch information
Showing
4 changed files
with
121 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
import DatePeriods from "../src/support/DatePeriods"; | ||
import JSONApi from "../src/support/JSONApi"; | ||
import XlsxPopulate from "../src/support/XlsxPopulateOpenAsBlob" | ||
import Dhis2 from "../src/support/Dhis2"; | ||
import * as turf from "@turf/turf"; | ||
import papaparse from 'papaparse' | ||
import DataSets from "../src/support/DataSets"; | ||
|
||
|
||
const recipe = { | ||
id: "D5a1DVMw7F1", | ||
name: "empty", | ||
editable: true, | ||
code: ` | ||
const api = await dhis2.api(); | ||
const ou = await api.get("organisationUnits", { | ||
fields: "id,name,ancestors[id,name],geometry" | ||
}); | ||
|
||
return _.flattenObjects(ou.organisationUnits, ["geometry"]); | ||
`, | ||
} | ||
|
||
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor; | ||
|
||
|
||
const startup = async () => { | ||
const dhis2 = new Dhis2(); | ||
const parameters = {} | ||
const report = new DataSets() | ||
|
||
|
||
const workbook = await XlsxPopulate.fromFileAsync(process.argv[2]) | ||
console.log(workbook.sheets().map(s => s.name())) | ||
|
||
|
||
const body = recipe.code.includes("return ") | ||
? recipe.code | ||
: "return " + recipe.code; | ||
const libs = [ | ||
{ identifier: "dhis2", entryPoint: async () => dhis2 }, | ||
|
||
{ | ||
identifier: "_", | ||
entryPoint: async () => { | ||
const lodash = await import("../src/support/lodash"); | ||
return lodash.default; | ||
}, | ||
}, | ||
{ | ||
identifier: "turf", | ||
entryPoint: async () => { | ||
return turf.default; | ||
}, | ||
}, | ||
{ | ||
identifier: "Fuse", | ||
entryPoint: async () => { | ||
const Fuse = await import("fuse.js"); | ||
return Fuse.default; | ||
}, | ||
}, | ||
|
||
{ identifier: "XlsxPopulate", entryPoint: async () => XlsxPopulate }, | ||
{ identifier: "DatePeriods", entryPoint: async () => DatePeriods }, | ||
{ identifier: "parameters", entryPoint: async () => parameters }, | ||
{ identifier: "report", entryPoint: async () => report }, | ||
{ identifier: "JSONApi", entryPoint: async () => JSONApi }, | ||
]; | ||
const entryPoints = []; | ||
for (let entryPoint of libs.map((l) => l.entryPoint)) { | ||
entryPoints.push(await entryPoint()); | ||
} | ||
|
||
|
||
console.log(body) | ||
const results = await new AsyncFunction( | ||
...libs.map((l) => l.identifier), | ||
body | ||
)(...entryPoints); | ||
console.log(results) | ||
|
||
} | ||
console.log("hello", process.argv) | ||
|
||
startup() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class DataSets { | ||
constructor() { | ||
this.registeredCount = 0; | ||
this.datasets = {}; | ||
} | ||
register(datasetName, data) { | ||
this.datasets[datasetName] = data; | ||
this.registeredCount += 1; | ||
return this; | ||
} | ||
reset(mode) { | ||
for (var member in this.datasets) { | ||
delete this.datasets[member]; | ||
} | ||
this.registeredCount = 0; | ||
if (mode == "run" && this.reRun) { | ||
this.reRun(); | ||
} | ||
if (mode == "clear" && this.clearResults) { | ||
this.clearResults(); | ||
} | ||
} | ||
|
||
asVars() { | ||
return this.datasets; | ||
} | ||
} | ||
|
||
export default DataSets |
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