a few more dashboard updates

This commit is contained in:
2025-07-31 10:59:22 -06:00
parent d775dea0dc
commit c0811de8fa
5 changed files with 222 additions and 13 deletions

View File

@@ -5,20 +5,36 @@ const config = require('../config');
class DashboardController {
async getStats(req, res) {
try {
// Get all locations for support level stats
const locationsResponse = await nocodbService.getAll(config.nocodb.tableId);
// Get all locations using the paginated method
const locationsResponse = await nocodbService.getAllPaginated(config.nocodb.tableId);
const locations = locationsResponse.list || [];
logger.info(`Processing ${locations.length} locations for dashboard stats`);
// Calculate support level distribution
const supportLevels = { '1': 0, '2': 0, '3': 0, '4': 0 };
let signRequests = 0;
let signDelivered = 0;
// Track sign sizes for requested signs
const signSizes = { 'Regular': 0, 'Large': 0, 'Unsure': 0 };
locations.forEach(loc => {
// Support levels
if (loc['Support Level']) {
supportLevels[loc['Support Level']]++;
}
// Signs delivered (where Sign checkbox is checked)
if (loc.Sign || loc.sign) {
signRequests++;
signDelivered++;
}
// Sign sizes for requested signs (count all with sign size, regardless of delivery)
if (loc['Sign Size']) {
const size = loc['Sign Size'];
if (signSizes.hasOwnProperty(size)) {
signSizes[size]++;
}
}
});
@@ -28,9 +44,15 @@ class DashboardController {
supportLevels['3'] * 2 + supportLevels['4'] * 1) /
(totalResponses || 1);
// Get user stats
const usersResponse = await nocodbService.getAll(config.nocodb.loginSheetId);
const users = usersResponse.list || [];
// Get all users using the paginated method
let users = [];
if (config.nocodb.loginSheetId) {
const usersResponse = await nocodbService.getAllPaginated(config.nocodb.loginSheetId);
users = usersResponse.list || [];
logger.info(`Processing ${users.length} users for dashboard stats`);
} else {
logger.warn('Login sheet ID not configured, skipping user stats');
}
// Get daily entry counts for the last 30 days
const thirtyDaysAgo = new Date();
@@ -38,8 +60,8 @@ class DashboardController {
const dailyEntries = {};
locations.forEach(loc => {
const createdAt = new Date(loc.CreatedAt || loc.created_at);
if (createdAt >= thirtyDaysAgo) {
const createdAt = new Date(loc.CreatedAt || loc.created_at || loc.createdAt);
if (!isNaN(createdAt.getTime()) && createdAt >= thirtyDaysAgo) {
const dateKey = createdAt.toISOString().split('T')[0];
dailyEntries[dateKey] = (dailyEntries[dateKey] || 0) + 1;
}
@@ -49,7 +71,8 @@ class DashboardController {
success: true,
data: {
supportLevels,
signRequests,
signDelivered,
signSizes,
totalLocations: locations.length,
overallScore: weightedScore.toFixed(2),
totalUsers: users.length,