Skip to content

Commit

Permalink
chg: [website] The new table is sorted based on the number of sightin…
Browse files Browse the repository at this point in the history
…gs for the last 31 days,
  • Loading branch information
cedricbonhomme committed Dec 31, 2024
1 parent 88d9b26 commit b8fec62
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions website/web/static/js/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function drawVulnerabilityTable(sightings, containerId) {

// Process data into a structured format
const processedData = {};
const vulnerabilities = new Set();
const vulnerabilities = new Map(); // Map to store total sightings for sorting

// Get today's date and calculate the last 31 days
const today = new Date();
Expand All @@ -235,17 +235,22 @@ function drawVulnerabilityTable(sightings, containerId) {
const dateKey = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; // Format YYYY-MM-DD
const vuln = entry.vulnerability;

vulnerabilities.add(vuln);
if (!processedData[vuln]) {
processedData[vuln] = {};
vulnerabilities.set(vuln, 0); // Initialize total sightings count
}

if (!processedData[vuln]) processedData[vuln] = {};
if (!processedData[vuln][dateKey]) processedData[vuln][dateKey] = 0;

processedData[vuln][dateKey]++;
vulnerabilities.set(vuln, vulnerabilities.get(vuln) + 1); // Increment total sightings count
maxCount = Math.max(maxCount, processedData[vuln][dateKey]);
});

// Convert vulnerabilities to an array for consistent ordering
const vulnerabilitiesArray = Array.from(vulnerabilities).sort();
// Sort vulnerabilities by total sightings in descending order
const vulnerabilitiesArray = Array.from(vulnerabilities.entries())
.sort((a, b) => b[1] - a[1]) // Sort by total sightings
.map(entry => entry[0]); // Extract sorted vulnerability IDs

// Create table element
const table = document.createElement('table');
Expand Down

0 comments on commit b8fec62

Please sign in to comment.