better counts for excluded contracts
This commit is contained in:
39
index.ts
39
index.ts
@@ -107,7 +107,7 @@ function update() {
|
|||||||
let includedContracts = [];
|
let includedContracts = [];
|
||||||
let excludedContracts = [];
|
let excludedContracts = [];
|
||||||
for (const contract of contracts) {
|
for (const contract of contracts) {
|
||||||
if (isIncluded(contract)) {
|
if (isIncluded(contract, "")) {
|
||||||
includedContracts.push(contract);
|
includedContracts.push(contract);
|
||||||
} else {
|
} else {
|
||||||
excludedContracts.push(contract);
|
excludedContracts.push(contract);
|
||||||
@@ -117,18 +117,18 @@ function update() {
|
|||||||
for (const filter of costs) {
|
for (const filter of costs) {
|
||||||
let checkBox = document.getElementById(filter) as HTMLInputElement;
|
let checkBox = document.getElementById(filter) as HTMLInputElement;
|
||||||
if (checkBox.checked) {
|
if (checkBox.checked) {
|
||||||
setFilterCounts(includedContracts, "costs", filter);
|
setIncludedFilterCounts(includedContracts, "costs", filter);
|
||||||
} else {
|
} else {
|
||||||
setFilterCounts(excludedContracts, "costs", filter);
|
setExcludedFilterCounts(excludedContracts, "costs", filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const filter of rewards) {
|
for (const filter of rewards) {
|
||||||
let checkBox = document.getElementById(filter) as HTMLInputElement;
|
let checkBox = document.getElementById(filter) as HTMLInputElement;
|
||||||
if (checkBox.checked) {
|
if (checkBox.checked) {
|
||||||
setFilterCounts(includedContracts, "rewards", filter);
|
setIncludedFilterCounts(includedContracts, "rewards", filter);
|
||||||
} else {
|
} else {
|
||||||
setFilterCounts(excludedContracts, "rewards", filter);
|
setExcludedFilterCounts(excludedContracts, "rewards", filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ function update() {
|
|||||||
document.getElementById("excluded").innerHTML = excludedContractsHtml;
|
document.getElementById("excluded").innerHTML = excludedContractsHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFilterCounts(contracts: any[], subcategory:string, filterKey: string) {
|
function setIncludedFilterCounts(contracts: any[], subcategory: string, filterKey: string) {
|
||||||
let count: number = 0;
|
let count: number = 0;
|
||||||
let sum: number = 0;
|
let sum: number = 0;
|
||||||
for (const contract of contracts) {
|
for (const contract of contracts) {
|
||||||
@@ -160,6 +160,21 @@ function setFilterCounts(contracts: any[], subcategory:string, filterKey: string
|
|||||||
document.getElementById(filterKey + "Count").innerHTML = `(${sum} on ${count})`;
|
document.getElementById(filterKey + "Count").innerHTML = `(${sum} on ${count})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setExcludedFilterCounts(contracts: any[], subcategory: string, filterKey: string) {
|
||||||
|
let count: number = 0;
|
||||||
|
let sum: number = 0;
|
||||||
|
for (const contract of contracts) {
|
||||||
|
if (isIncluded(contract, filterKey)) {
|
||||||
|
let value = contract[subcategory][filterKey];
|
||||||
|
sum += value
|
||||||
|
if (value > 0) {
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById(filterKey + "Count").innerHTML = `(+${sum} on ${count})`;
|
||||||
|
}
|
||||||
|
|
||||||
function setDirectFilterCounts(contracts, filter: string) {
|
function setDirectFilterCounts(contracts, filter: string) {
|
||||||
let count: number = 0;
|
let count: number = 0;
|
||||||
for (const contract of contracts) {
|
for (const contract of contracts) {
|
||||||
@@ -171,21 +186,29 @@ function setDirectFilterCounts(contracts, filter: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isIncluded(contract) {
|
function isIncluded(contract, ignoredCriteria: string) {
|
||||||
let included = true;
|
let included = true;
|
||||||
for (const cost of costs) {
|
for (const cost of costs) {
|
||||||
|
if (cost == ignoredCriteria) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let checkBox = document.getElementById(cost) as HTMLInputElement;
|
let checkBox = document.getElementById(cost) as HTMLInputElement;
|
||||||
if (!checkBox.checked && (contract.costs[cost] > 0)) {
|
if (!checkBox.checked && (contract.costs[cost] > 0)) {
|
||||||
included = false;
|
included = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const reward of rewards) {
|
for (const reward of rewards) {
|
||||||
|
if (reward == ignoredCriteria) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let checkBox = document.getElementById(reward) as HTMLInputElement;
|
let checkBox = document.getElementById(reward) as HTMLInputElement;
|
||||||
if (!checkBox.checked && (contract.rewards[reward] > 0)) {
|
if (!checkBox.checked && (contract.rewards[reward] > 0)) {
|
||||||
included = false;
|
included = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(document.getElementById("discarded") as HTMLInputElement).checked && contract.discarded) {
|
if ("discarded" != ignoredCriteria
|
||||||
|
&& !(document.getElementById("discarded") as HTMLInputElement).checked
|
||||||
|
&& contract.discarded) {
|
||||||
included = false;
|
included = false;
|
||||||
}
|
}
|
||||||
return included;
|
return included;
|
||||||
|
|||||||
Reference in New Issue
Block a user