Índice
Este script processa registos de tempo e gera estatísticas diárias de presença com horários de entrada e saída por funcionário.
Prerequisites
You need two tables:
- Time records: Contains columns
Name,Date, andTimewith the raw clocking data. - Statistics: Contains columns
Name,Date,Clock in, andClock outfor the results.
The complete script
const timeRecordsTable = base.getTableByName('Time records');
const statisticsTable = base.getTableByName('Statistics');
const view = base.getViewByName(timeRecordsTable, 'Default View');
const rows = base.getRows(timeRecordsTable, view);
// Group by date and name
const groups = {};
rows.forEach(row => {
const name = row['Name'] || '';
const date = row['Date'] || '';
const time = row['Time'] || '';
if (!name || !date || !time) return;
const key = date + '_' + name;
if (!groups[key]) {
groups[key] = {name: name, date: date, times: []};
}
groups[key].times.push(time);
});
// Create statistics entries
Object.keys(groups).forEach(key => {
const group = groups[key];
const sortedTimes = group.times.sort();
const clockIn = sortedTimes[0];
const clockOut = sortedTimes[sortedTimes.length - 1];
base.addRow(statisticsTable, {
'Name': group.name,
'Date': group.date,
'Clock in': clockIn,
'Clock out': clockOut
});
});
output.text('Attendance statistics computed.');
Adjust the table and column names to match your setup. The script always appends new rows to the statistics table – if you run it multiple times, you may want to clear the statistics table first.
For the complete function reference, visit the SeaTable Developer Manual .