Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
5
Indexable
Never
 
function generateDailyData(numDocs) {
  const data = [];
  const today = new Date();
  today.setHours(0, 0, 0, 0);
 
  for (let i = 0; i < numDocs; i++) {
    const docId = `doc_${i}`;
    const docAdded = new Date(today);
    docAdded.setDate(today.getDate() - Math.floor(Math.random() * 10));
    const docStatusOptions = ["pending", "completed", "unclassified"];
    const docStatus = docStatusOptions[Math.floor(Math.random() * docStatusOptions.length)];
    
    data.push({ docId, docAdded, docStatus });
  }
 
  return data;
}
 
// Example usage
const dailyData = generateDailyData(20);
dailyData.forEach(row => console.log(row));
 
 
function groupByDateWithStatusCounts(dailyData) {
  const trends = {};
 
  dailyData.forEach(row => {
    const { docStatus, docAdded } = row;
    const dateStr = docAdded.toISOString().slice(0, 10); // Get the date part in YYYY-MM-DD format
 
    if (!trends[dateStr]) {
      trends[dateStr] = {};
    }
 
    if (!trends[dateStr][docStatus]) {
      trends[dateStr][docStatus] = 0;
    }
 
    trends[dateStr][docStatus]++;
  });
 
  return trends;
}
 
// Example usage
 
const trends = groupByDateWithStatusCounts(dailyData);
console.log(trends);
 
 
console.log(Object.keys(trends))
 
Leave a Comment