Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.3 kB
2
Indexable
Never
const knownOffensesDetails = require("../../Repository/Offenses.json");

// Checking the offenses individually 
async function filterOffenses(data) {
    const filtered_offenses = [];
    let filtered_offenses_count = 0;

    for (const item of data) {
        if (
            !knownOffensesDetails.filteredOffensesDetails.descriptions.includes(item.description.trim()) &&
            !knownOffensesDetails.filteredOffensesDetails.offense_sources.includes(item.offense_source.trim()) &&
            !threeHoursOld(item.last_updated_time)
        ) { 
            // Add filtered data to a new array
            filtered_offenses.push(item);

            // Count the offenses
            filtered_offenses_count++;
        }
    }

    return { filtered_offenses, filtered_offenses_count };
}

function threeHoursOld(last_updated_time) {
    // Convert Unix timestamp to milliseconds
    const lastUpdatedTimeMillis = last_updated_time * 1000;

    // Implement the logic to check if last_updated_time is within the last three hours
    const currentTime = new Date().getTime();
    const threeHoursAgo = currentTime - 3 * 60 * 60 * 1000; // 3 hours in milliseconds

    return lastUpdatedTimeMillis >= threeHoursAgo;
}

module.exports = { filterOffenses, threeHoursOld };
Leave a Comment