-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep
committed
Jul 11, 2023
1 parent
8e8a71b
commit 6876237
Showing
4 changed files
with
66 additions
and
2 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,23 @@ | ||
const pl = require("nodejs-polars"); | ||
|
||
|
||
const mcda = function(body){ | ||
if(body === undefined || !body instanceof Object) return {error: "body must be an array of ids"} | ||
if(!(body instanceof Array)) return {error: "body must be an array of ids"} | ||
|
||
let df = pl.readCSV("public/technologies.csv") | ||
|
||
wrong_ids = body.filter(e => !df['id'].toArray().includes(e)) | ||
if (wrong_ids.length > 0) return {error: "some ids are not valid"} | ||
|
||
df = df.filter(pl.col("id").isIn(body)) | ||
|
||
// TODO: Començar a calcular scores | ||
|
||
|
||
return(df.toRecords()) | ||
} | ||
|
||
module.exports = { | ||
mcda | ||
} |
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
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,25 @@ | ||
const expect = require("chai").expect | ||
const mcda = require("../lib/mcda").mcda | ||
|
||
describe('Test /mcda', () => { | ||
describe("Raise errors on data sanitation", () => { | ||
it('Returns error if no body', () => { | ||
expect(mcda()).to.have.key('error') | ||
}); | ||
it('Returns error if body is not an array', () => { | ||
expect(mcda({a: 'dsvsddf', b: 'aasdf'})).to.have.key('error') | ||
expect(mcda('dsvsddf')).to.have.key('error') | ||
expect(mcda(123)).to.have.key('error') | ||
}); | ||
it('Returns error if some ids are wrong', () => { | ||
result = mcda(['a', 'WW', 'French_CW']) | ||
expect(result).to.have.key("error") | ||
}) | ||
}); | ||
describe("Returns an array of technologies", () => { | ||
let result = mcda(['WW', 'French_CW', 'HSSF_CW']) | ||
it('result is an array', () => { | ||
expect(result).to.be.an('array') | ||
}) | ||
}) | ||
}) |