func getDashboardFrom()

in Sources/XCMetricsBackendLib/UploadMetrics/Repository/PostgreSQLJobLogRepository.swift [48:70]


    func getDashboardFrom(_ from: Date, to: Date, using eventLoop: EventLoop) -> EventLoopFuture<JobDashboard> {
        return getCountByStatusFrom(from, to: to, using: eventLoop)
            .map { values -> JobDashboard in
                let failed: Int = values.filter { $0.key == JobLogStatus.failed.rawValue }.first?.value ?? 0
                let successful: Int = values.filter { $0.key == JobLogStatus.successful.rawValue }.first?.value ?? 0
                let running: Int = values.filter { $0.key == JobLogStatus.running.rawValue }.first?.value ?? 0
                let pending: Int = values.filter { $0.key == JobLogStatus.pending.rawValue }.first?.value ?? 0
                return JobDashboard(from: from,
                                    to: to,
                                    successful: successful,
                                    running: running,
                                    failed: failed,
                                    pending: pending,
                                    averageTime: 0.0)
            }.flatMap { jobDashboard -> EventLoopFuture<JobDashboard> in
                self.getAverageExecutionTimeFrom(from, to: to, using: eventLoop)
                    .map { jobDashboard.with(averageTime: $0?.result) }
            }.flatMap { jobDashboard -> EventLoopFuture<JobDashboard> in
                return self.getAveragesPerHour(from, to: to, using: eventLoop)
                    .and(self.getThroughputPerHours(from, to: to, using: eventLoop))
                    .map { jobDashboard.with(averageTimes: $0.0, throughput: $0.0) }
            }
    }