Skip to content

Commit

Permalink
Fix for always returning dates
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Nov 25, 2024
1 parent bbd2317 commit 5fa06ba
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
18 changes: 18 additions & 0 deletions lib/Db/CallLogMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function getCallStatsByDateRange(\DateTime $from, \DateTime $to): array
{
$qb = $this->db->getQueryBuilder();

// Get the actual data from database
$qb->select(
$qb->createFunction('DATE(created) as date'),
$qb->createFunction('SUM(CASE WHEN status_code >= 200 AND status_code < 300 THEN 1 ELSE 0 END) as success'),
Expand All @@ -219,7 +220,24 @@ public function getCallStatsByDateRange(\DateTime $from, \DateTime $to): array

$result = $qb->execute();
$stats = [];

// Create DatePeriod to iterate through all dates
$period = new \DatePeriod(
$from,
new \DateInterval('P1D'),
$to->modify('+1 day')
);

// Initialize all dates with zero values
foreach ($period as $date) {
$dateStr = $date->format('Y-m-d');
$stats[$dateStr] = [
'success' => 0,
'error' => 0
];
}

// Fill in actual values where they exist
while ($row = $result->fetch()) {
$stats[$row['date']] = [
'success' => (int)$row['success'],
Expand Down
19 changes: 19 additions & 0 deletions lib/Db/JobLogMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ public function getJobStatsByDateRange(\DateTime $from, \DateTime $to): array
$result = $qb->execute();
$stats = [];

// Create DatePeriod to iterate through all dates
$period = new \DatePeriod(
$from,
new \DateInterval('P1D'),
$to->modify('+1 day')
);

// Initialize all dates with zero values
foreach ($period as $date) {
$dateStr = $date->format('Y-m-d');
$stats[$dateStr] = [
'info' => 0,
'warning' => 0,
'error' => 0,
'debug' => 0
];
}

// Fill in actual values where they exist
while ($row = $result->fetch()) {
$stats[$row['date']] = [
'info' => (int)$row['info'],
Expand Down
14 changes: 14 additions & 0 deletions lib/Db/SynchronizationContractLogMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ public function getSyncStatsByDateRange(\DateTime $from, \DateTime $to): array
$result = $qb->execute();
$stats = [];

// Create DatePeriod to iterate through all dates
$period = new \DatePeriod(
$from,
new \DateInterval('P1D'),
$to->modify('+1 day')
);

// Initialize all dates with zero values
foreach ($period as $date) {
$dateStr = $date->format('Y-m-d');
$stats[$dateStr] = 0;
}

// Fill in actual values where they exist
while ($row = $result->fetch()) {
$stats[$row['date']] = (int)$row['executions'];
}
Expand Down
29 changes: 20 additions & 9 deletions src/views/dashboard/DashboardIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,23 @@ export default {
xaxis: {
type: 'datetime',
labels: {
datetimeFormatter: {
year: 'yyyy',
month: 'MMM \'yy',
day: 'dd MMM',
},
format: 'dd MMM',
style: {
colors: '#000000'
}
}
},
colors: ['#28a745', '#dc3545'], // Green for success, red for errors
tooltip: {
x: {
format: 'dd MMM yyyy'
}
},
colors: [getTheme() === 'dark' ? '#28a745' : 'rgb(0, 103, 158)', '#dc3545'], // Nextcloud blue for light mode, green for dark mode
title: {
text: 'Daily Outgoing Calls',
align: 'left'
Expand Down Expand Up @@ -572,22 +583,22 @@ export default {
)
const { daily, hourly } = response.data
// Update daily stats
// Ensure dates are properly formatted for the chart
this.sourcesCalls.series = [
{
name: 'Successful Calls',
data: Object.entries(daily).map(([date, stats]) => ({
x: new Date(date).getTime(),
y: stats.success,
})),
x: new Date(date).getTime(), // Convert to timestamp
y: stats.success
})).sort((a, b) => a.x - b.x)
},
{
name: 'Failed Calls',
data: Object.entries(daily).map(([date, stats]) => ({
x: new Date(date).getTime(),
y: stats.error,
})),
},
x: new Date(date).getTime(), // Convert to timestamp
y: stats.error
})).sort((a, b) => a.x - b.x)
}
]
// Update hourly stats
Expand Down

0 comments on commit 5fa06ba

Please sign in to comment.