0

我正在研究一个能源应用,我们正在监控工厂的柴油发电机和电表。

我们在数据库中有这些数据。以下是数据库中存在的一些记录。

ip           meter_id   device_time
===========================================
100.74.61.93    s1  r1  2018-11-01 09:02:42
100.74.61.93    s1  r1  2018-11-01 09:02:57
100.74.61.93    s1  r1  2018-11-01 09:03:12
100.74.61.93    s1  r1  2018-11-01 09:03:27
100.74.61.93    s1  r1  2018-11-01 09:03:42
100.74.61.93    s1  r1  2018-11-01 09:03:57
100.74.61.93    s1  r1  2018-11-01 09:04:17
100.74.61.93    s1  r1  2018-11-01 09:04:27
100.74.61.93    s1  r1  2018-11-01 09:04:47
100.74.61.93    s1  r1  2018-11-01 09:04:57
100.74.61.93    s1  r1  2018-11-01 09:05:12
100.74.61.93    s1  r1  2018-11-01 09:05:27
100.74.61.93    s1  r1  2018-11-01 09:05:47
100.74.61.93    s1  r1  2018-11-01 09:05:57
100.74.61.93    s1  r1  2018-11-01 09:06:12
100.74.61.93    s1  r1  2018-11-01 09:06:27
100.74.61.93    s1  r1  2018-11-01 09:06:42
100.74.61.93    s1  r1  2018-11-01 09:06:57
100.74.61.93    s1  r1  2018-11-01 09:07:12
100.74.61.93    s1  r1  2018-11-01 09:07:27
100.74.61.93    s1  r1  2018-11-01 09:07:42
100.74.61.93    s1  r1  2018-11-01 09:07:57
100.74.61.93    s1  r1  2018-11-01 09:08:12
100.74.61.93    s1  r1  2018-11-01 09:08:27
100.74.61.93    s1  r1  2018-11-01 09:08:47
100.74.61.93    s1  r1  2018-11-01 09:08:57
100.74.61.93    s1  r1  2018-11-01 09:09:12
100.74.61.93    s1  r1  2018-11-01 09:09:27
100.74.61.93    s1  r1  2018-11-01 09:09:42
100.74.61.93    s1  r1  2018-11-01 09:09:57
100.74.61.93    s1  r1  2018-11-01 09:10:12
100.74.61.93    s1  r1  2018-11-01 09:10:27
100.74.61.93    s1  r1  2018-11-01 09:10:42
100.74.61.93    s1  r1  2018-11-01 09:10:57
100.74.61.93    s1  r1  2018-11-01 09:11:12
100.74.61.93    s1  r1  2018-11-01 09:11:27
100.74.61.93    s1  r1  2018-11-01 09:11:42
100.74.61.93    s1  r1  2018-11-01 09:11:57
100.74.61.93    s1  r1  2018-11-01 09:12:12
100.74.61.93    s1  r1  2018-11-01 09:12:27
100.74.61.93    s1  r1  2018-11-01 09:12:42
100.74.61.93    s1  r1  2018-11-01 09:12:57
100.74.61.93    s1  r1  2018-11-01 09:13:12
100.74.61.93    s1  r1  2018-11-01 09:13:27
100.74.61.93    s1  r1  2018-11-01 11:15:42
100.74.61.93    s1  r1  2018-11-01 09:13:42
100.74.61.93    s1  r1  2018-11-01 09:13:57
100.74.61.93    s1  r1  2018-11-01 11:15:58
100.74.61.93    s1  r1  2018-11-01 11:16:12
100.74.61.93    s1  r1  2018-11-01 11:13:42
100.74.61.93    s1  r1  2018-11-01 11:13:57
100.74.61.93    s1  r1  2018-11-01 11:14:12
100.74.61.93    s1  r1  2018-11-01 11:14:27
100.74.61.93    s1  r1  2018-11-01 11:14:42
100.74.61.93    s1  r1  2018-11-01 11:14:57
100.74.61.93    s1  r1  2018-11-01 11:15:12
100.74.61.93    s1  r1  2018-11-01 11:15:27
100.74.61.93    s1  r1  2018-11-01 11:16:27
100.74.61.93    s1  r1  2018-11-01 11:16:42
100.74.61.93    s1  r1  2018-11-01 11:16:57
100.74.61.93    s1  r1  2018-11-01 11:17:13
100.74.61.93    s1  r1  2018-11-01 11:17:27
100.74.61.93    s1  r1  2018-11-01 11:17:42
100.74.61.93    s1  r1  2018-11-01 11:17:57
100.74.61.93    s1  r1  2018-11-01 11:18:12
100.74.61.93    s1  r1  2018-11-01 11:18:28
100.74.61.93    s1  r1  2018-11-01 11:18:42
100.74.61.93    s1  r1  2018-11-01 11:18:58
100.74.61.93    s1  r1  2018-11-01 11:19:12
100.74.61.93    s1  r1  2018-11-01 11:19:27
100.74.61.93    s1  r1  2018-11-01 11:19:42
100.74.61.93    s1  r1  2018-11-01 11:19:58
100.74.61.93    s1  r1  2018-11-01 11:20:13
100.74.61.93    s1  r1  2018-11-01 11:20:27
100.74.61.93    s1  r1  2018-11-01 11:20:43
100.74.61.93    s1  r1  2018-11-01 11:20:58
100.74.61.93    s1  r1  2018-11-01 11:21:13
100.74.61.93    s1  r1  2018-11-01 11:21:28
100.74.61.93    s1  r1  2018-11-01 11:21:43
100.74.61.93    s1  r1  2018-11-01 11:21:58
100.74.61.93    s1  r1  2018-11-01 11:48:58
100.74.61.93    s1  r1  2018-11-01 11:49:13
100.74.61.93    s1  r1  2018-11-01 11:49:28
100.74.61.93    s1  r1  2018-11-01 11:49:43
100.74.61.93    s1  r1  2018-11-01 11:49:58
100.74.61.93    s1  r1  2018-11-01 11:50:13
100.74.61.93    s1  r1  2018-11-01 11:50:28
100.74.61.93    s1  r1  2018-11-01 11:50:43
100.74.61.93    s1  r1  2018-11-01 11:50:58
100.74.61.93    s1  r1  2018-11-01 11:51:13
100.74.61.93    s1  r1  2018-11-01 11:51:28
100.74.61.93    s1  r1  2018-11-01 11:51:43
100.74.61.93    s1  r1  2018-11-01 11:51:58
100.74.61.93    s1  r1  2018-11-01 11:52:13
100.74.61.93    s1  r1  2018-11-01 11:52:28
100.74.61.93    s1  r1  2018-11-01 11:52:43
100.74.61.93    s1  r1  2018-11-01 11:52:58
100.74.61.93    s1  r1  2018-11-01 11:53:13
100.74.61.93    s1  r1  2018-11-01 11:53:28
100.74.61.93    s1  r1  2018-11-01 11:53:43
100.74.61.93    s1  r1  2018-11-01 11:53:58
100.74.61.93    s1  r1  2018-11-01 11:54:13
100.74.61.93    s1  r1  2018-11-01 11:54:28
100.74.61.93    s1  r1  2018-11-01 11:54:43
100.74.61.93    s1  r1  2018-11-01 11:54:58
100.74.61.93    s1  r1  2018-11-01 11:55:13
100.74.61.93    s1  r1  2018-11-01 11:55:28
100.74.61.93    s1  r1  2018-11-01 11:55:43
100.74.61.93    s1  r1  2018-11-01 11:55:58
100.74.61.93    s1  r1  2018-11-01 11:56:13
100.74.61.93    s1  r1  2018-11-01 11:56:28

正如您可以从数据库中检查上述记录,每一行都具有device_time这意味着当时柴油发电机正在运行。

现在我想以这样的格式计算时间,01 days, 2 hours, 10 min它会告诉我它运行了多少总时间?

我写了给我结果的查询。

select
    count(device_timestamp) * '1 minute'::interval as operatingtime
from
    (
    select
        time_bucket('1 min',
        device_time at time zone 'Asia/Kolkata') as device_timestamp
    from
        public.schneider_new
    where
        meter_id in ('s1')
        and device_time >= '2018-11-01T00:00:00.000'
        and device_time <= now()
    group by
        device_timestamp
    order by
        device_timestamp as ) as tab

输出:

0 年 0 月 0 天 30 小时 28 分钟 0.00 秒

这给了我结果,但我不想0 years 0 mons 0 secs在上面的输出中。

而且,如果小时数大于 24 小时,即在这种情况下为 30 小时,则结果应为1 day 6 hours 28 mins

我哪里错了?或者有没有其他方法可以计算 DG 在给定时间段内运行的时间?

更新:

我用这个尝试了查询

(count(device_timestamp)::numeric/60)/24 * '1 day'::interval as operatingtime

输出:

0 年 0 月 1 天 6 小时 28 分钟 0.00 秒

我得到了正确的输出,即1 days 6 hours 28 mins,我现在唯一要寻找的是删除另一个0 years 0 mons 0.00 secs

4

0 回答 0