-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontroller.js
More file actions
49 lines (42 loc) · 1.44 KB
/
controller.js
File metadata and controls
49 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const _ = require('lodash');
const criteria = require('./criteria');
const Controller = {};
function getMinMax(value) {
const hargaMin = _.minBy(value, 'harga');
const ramMax = _.maxBy(value, 'ram');
const memoryMax = _.maxBy(value, 'memory');
const processorMax = _.maxBy(value, 'processor');
const cameraMax = _.maxBy(value, 'camera');
return {
harga: hargaMin.harga,
ram: ramMax.ram,
memory: memoryMax.memory,
processor: processorMax.processor,
camera: cameraMax.camera
}
}
function normalisasi(matrix, maxmin) {
matrix.harga = maxmin.harga / matrix.harga;
matrix.ram = matrix.ram / maxmin.ram;
matrix.memory = matrix.memory / maxmin.memory;
matrix.processor = matrix.processor / maxmin.processor;
matrix.camera = matrix.camera /maxmin.camera;
return matrix;
}
function hitungPeringkat(nilai) {
const total = (nilai.harga * criteria.harga) + (nilai.ram * criteria.ram) + (nilai.memory * criteria.memory) + (nilai.processor * criteria.processor) + (nilai.camera * criteria.camera);
const result = {
nama: nilai.nama,
total: total
}
return result;
}
Controller.getRecomendation = (req, res) => {
const post = req.body;
const getNilaiBobot = post;
const getMaxMin = getMinMax(getNilaiBobot);
const normalisasiNilai = _.map(getNilaiBobot, nilai => normalisasi(nilai, getMaxMin));
const hitungBobotPeringkat = _.map(normalisasiNilai, nilai => hitungPeringkat(nilai));
res.json(hitungBobotPeringkat)
};
module.exports = Controller;