(messageHours: number[])
| 1900 | } |
| 1901 | |
| 1902 | function generateTimeOfDayChart(messageHours: number[]): string { |
| 1903 | if (messageHours.length === 0) return '<p class="empty">No time data</p>' |
| 1904 | |
| 1905 | // Group into time periods |
| 1906 | const periods = [ |
| 1907 | { label: 'Morning (6-12)', range: [6, 7, 8, 9, 10, 11] }, |
| 1908 | { label: 'Afternoon (12-18)', range: [12, 13, 14, 15, 16, 17] }, |
| 1909 | { label: 'Evening (18-24)', range: [18, 19, 20, 21, 22, 23] }, |
| 1910 | { label: 'Night (0-6)', range: [0, 1, 2, 3, 4, 5] }, |
| 1911 | ] |
| 1912 | |
| 1913 | const hourCounts: Record<number, number> = {} |
| 1914 | for (const h of messageHours) { |
| 1915 | hourCounts[h] = (hourCounts[h] || 0) + 1 |
| 1916 | } |
| 1917 | |
| 1918 | const periodCounts = periods.map(p => ({ |
| 1919 | label: p.label, |
| 1920 | count: p.range.reduce((sum, h) => sum + (hourCounts[h] || 0), 0), |
| 1921 | })) |
| 1922 | |
| 1923 | const maxVal = Math.max(...periodCounts.map(p => p.count)) || 1 |
| 1924 | |
| 1925 | const barsHtml = periodCounts |
| 1926 | .map( |
| 1927 | p => ` |
| 1928 | <div class="bar-row"> |
| 1929 | <div class="bar-label">${p.label}</div> |
| 1930 | <div class="bar-track"><div class="bar-fill" style="width:${(p.count / maxVal) * 100}%;background:#8b5cf6"></div></div> |
| 1931 | <div class="bar-value">${p.count}</div> |
| 1932 | </div>`, |
| 1933 | ) |
| 1934 | .join('\n') |
| 1935 | |
| 1936 | return `<div id="hour-histogram">${barsHtml}</div>` |
| 1937 | } |
| 1938 | |
| 1939 | function getHourCountsJson(messageHours: number[]): string { |
| 1940 | const hourCounts: Record<number, number> = {} |
no test coverage detected