Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyzer-ng #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
"type": "node",
"request": "launch",
"name": "analyzer-ng",
"program": "${workspaceFolder}/scripts/analyzer-ng.js"
"program": "${workspaceFolder}/scripts/analyzer-ng.js",
"args": [
"--begin", "foo",
"--end", "bar"
]
}
]
}
6 changes: 3 additions & 3 deletions app/persistence/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class Database {
});
}

findMostRecent(filter, failIfEmpty) {
findMostRecent(filter, failIfEmpty=true) {
return new Promise((resolve, reject) => {
this.db.find(filter).sort({ date: -1 }).limit(1).exec( (err, docs) => {
if (err) {
reject(err);
} else {
if (docs === null && failIfEmpty) {
reject(`No document found ${JSON.stringify(filter)}`);
if (failIfEmpty && (docs === null || docs.length === 0) ) {
reject(`No document found for filter ${JSON.stringify(filter)}`);
}
resolve(docs[0]);
}
Expand Down
40 changes: 40 additions & 0 deletions scripts/analyzer-ng.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/env node
"use strict";

const analyzerUtils = require("../app/core/analyzer-utils.js");
const cli = require("cli");
const { Database } = require("../app/persistence/db.js");

const cliArgs = cli.parse({
criteria: [ "c", "Criteria to be used for filtering/ordering", "string", "pe" ], //--criteria STRING
begin: [ "b", "First date", "date"],
end: [ "e", "End date", "date"],
threshold: [ "t", "Threshold", "int", 0], // --threshold 5, to display only changes higher than 5%
});

const checkCliArguments = (cliArgs) => {
let result = true;
if (!cliArgs.begin) {
cli.error("--begin date required");
result = false;
}

if (!cliArgs.end) {
cli.error("--end date required");
result = false;
}
return result;
};

let dates = [cliArgs.begin, cliArgs.end];
let securities = ["My security"];
const criteria = cliArgs.criteria;

if (checkCliArguments(cliArgs) ) {
const securitiesDb = new Database("securities.db");
Promise.all(dates
.map((x) => securitiesDb.findOne( {key: securities[0], valueDate: x} ) ))
.then(res => analyzerUtils.computeChangesEtf(res, criteria))
.then(res => analyzerUtils.displayResults(res, criteria, cliArgs.threshold))
.catch(cli.error);
}