agentleFS
agentsdanceagentsdance/agentskills/skills/data-aggregator/SKILL.md

data-aggregator

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Aggregate and summarize data from multiple sources. Use when the user needs to combine data, calculate statistics, or create summary reports.

The file

Files
SKILL.md

Data Aggregator

Aggregate and summarize data from various sources.

JavaScript Aggregation

// Group and aggregate
function aggregate(data, groupBy, aggregations) {
  const groups = {};

  data.forEach(item => {
    const key = item[groupBy];
    if (!groups[key]) {
      groups[key] = { [groupBy]: key, items: [] };
    }
    groups[key].items.push(item);
  });

  return Object.values(groups).map(group => {
    const result = { [groupBy]: group[groupBy] };

    for (const [field, ops] of Object.entries(aggregations)) {
      const values = group.items.map(i => i[field]).filter(v => v != null);

      if (ops.includes('sum')) result[`${field}_sum`] = values.reduce((a, b) => a + b, 0);
      if (ops.includes('avg')) result[`${field}_avg`] = values.reduce((a, b) => a + b, 0) / values.length;
      if (ops.includes('min')) result[`${field}_min`] = Math.min(...values);
      if (ops.includes('max')) result[`${field}_max`] = Math.max(...values);
      if (ops.includes('count')) result[`${field}_count`] = values.length;
    }

    return result;
  });
}

// Usage
const sales = [
  { region: 'North', amount: 100, quantity: 5 },
  { region: 'North', amount: 200, quantity: 3 },
  { region: 'South', amount: 150, quantity: 4 },
];

aggregate(sales, 'region', {
  amount: ['sum', 'avg'],
  quantity: ['sum', 'count']
});

SQL Aggregation

SELECT
    region,
    DATE_TRUNC('month', sale_date) AS month,
    COUNT(*) AS total_orders,
    SUM(amount) AS total_revenue,
    AVG(amount) AS avg_order_value,
    MIN(amount) AS min_order,
    MAX(amount) AS max_order,
    PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY amount) AS median
FROM sales
GROUP BY region, DATE_TRUNC('month', sale_date)
HAVING SUM(amount) > 1000
ORDER BY month DESC, total_revenue DESC;

Pandas Aggregation

import pandas as pd

df = pd.read_csv('sales.csv')

# Multiple aggregations
summary = df.groupby('region').agg({
    'amount': ['sum', 'mean', 'min', 'max'],
    'quantity': 'sum',
    'order_id': 'count'
}).round(2)

# Pivot table
pivot = pd.pivot_table(
    df,
    values='amount',
    index='region',
    columns='category',
    aggfunc='sum',
    fill_value=0
)

# Rolling aggregation
df['rolling_avg'] = df.groupby('region')['amount'].transform(
    lambda x: x.rolling(7).mean()
)

MongoDB Aggregation

db.sales.aggregate([
  { $match: { status: 'completed' } },
  { $group: {
      _id: { region: '$region', month: { $month: '$date' } },
      totalAmount: { $sum: '$amount' },
      avgAmount: { $avg: '$amount' },
      count: { $sum: 1 }
  }},
  { $sort: { totalAmount: -1 } }
]);

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.