From aea653e349f64a9e97aa5f614b8701fa2b89788b Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 17:27:12 -0300 Subject: [PATCH] feat: creating CalculateNodeReputationTask --- .../tasks/CalculateNodeReputationTask.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/reputation/node/tasks/CalculateNodeReputationTask.java diff --git a/src/main/java/reputation/node/tasks/CalculateNodeReputationTask.java b/src/main/java/reputation/node/tasks/CalculateNodeReputationTask.java new file mode 100644 index 0000000..1a2b6e8 --- /dev/null +++ b/src/main/java/reputation/node/tasks/CalculateNodeReputationTask.java @@ -0,0 +1,46 @@ +package reputation.node.tasks; + +import dlt.client.tangle.hornet.model.transactions.Transaction; +import java.util.List; +import java.util.TimerTask; +import reputation.node.models.Node; +import reputation.node.reputation.IReputation; + +/** + * Task para calcular a reputação atual do nó. + * + * @author Allan Capistrano + * @version 1.0.0 + */ +public class CalculateNodeReputationTask extends TimerTask { + + private final Node node; + private final IReputation reputation; + + /** + * Método construtor. + * @param node Node - O nó que verificará a própria reputação. + * @param reputation IReputation - Objeto para calcular a reputação. + */ + public CalculateNodeReputationTask(Node node, IReputation reputation) { + this.node = node; + this.reputation = reputation; + } + + @Override + public void run() { + List evaluationTransactions = + this.node.getLedgerConnector() + .getLedgerReader() + .getTransactionsByIndex(this.node.getNodeType().getNodeId(), false); + + double reputationValue = + this.reputation.calculate( + evaluationTransactions, + this.node.isUseLatestCredibility(), + this.node.isUseCredibility() + ); + + this.node.setReputationValue(reputationValue); + } +}