我正在尝试创建直方图,以识别存在大量同时具有“ CASTING”状态的“ ID”的情况。
您会注意到我存在一个等级列-我已经以多种方式尝试了此问题,最近一次是对ID进行分区,通过四舍五入然后将count_time列转换为最接近的15分钟间隔间隔为“ CASTING”状态的ID数。不幸的是,这并不能满足我的需要,因为它只包括状态更改实例的总和,而不是通过将特定时间间隔之前处于“铸造”的那些总和包括在内而得出的当前运行总电流。
对于如何生成两次之间的15分钟时间间隔的列表,我缺乏指导 14:00和17:30(如果有可能的话!!)-不太必要,因为我可以对它们进行硬编码,并可能执行某种加入列表的操作。
我认为我已经盯着这个问题已经很长时间了,以至于我看不到明显的解决方案...有谁能就我可以使用哪种方法来实现下面的预期效果提供高层次的概述?
这是一个测试数据集:
Date Count_at_casting
08/04/2019 14:00 1
08/04/2019 14:15 2
08/04/2019 14:30 2
08/04/2019 14:45 2
08/04/2019 15:00 3
08/04/2019 15:15 3
08/04/2019 15:30 3
08/04/2019 15:45 2
08/04/2019 16:00 2
08/04/2019 16:15 2
08/04/2019 16:30 2
08/04/2019 16:45 2
08/04/2019 17:00 2
08/04/2019 17:15 2
08/04/2019 17:30 2
Id loc status date START END
A 1 CASTING 08/04/2019 00:00 08/04/2019 14:09 08/04/2019 15:39
B 1 CASTING 08/04/2019 00:00 08/04/2019 13:52 08/04/2019 23:59
C 1 CASTING 08/04/2019 00:00 08/04/2019 14:59 08/04/2019 17:59
D 1 CASTING 08/04/2019 00:00 08/04/2019 12:59 08/04/2019 13:59
E 1 CASTING 08/04/2019 00:00 08/04/2019 18:59 08/04/2019 21:51
我的输出应如下所示:
from copy import deepcopy
class PersonInfo:
def __init__(self,name,age,height,hairColour):
self.name = name
self.age = age
self.height = height
self.hairColour = hairColour
x = PersonInfo("Mario",34,1.70,"blue")
print(x.height)//prints 1.70
x1 = deepcopy(x)
print(x1.age)
答案 0 :(得分:0)
您的输出与您的输入不匹配-我认为这只是一个示例。以下是针对oracle的。 oracle中的[from dual]是只选择1行,第一个是模拟输入。 Oracle to_char和to_date将字符串转换为日期。 sqlserver中提供了类似的函数以及datepart函数类型
[
with table1 as (
select 'A' id, 1 loc, 'READY' status, to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS') datetime, to_date('2019-08-04 15:39:00', 'YYYY-MM-DD HH24:MI:SS') event_time from dual union all
select 'A', 1, 'CASTING', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 14:09:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'A', 1, 'QUEUED', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 12:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'B', 1, 'READY', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 23:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'B', 1, 'CASTING', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 13:52:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'B', 1, 'QUEUED', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 13:44:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'C', 1, 'READY', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 17:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'C', 1, 'CASTING', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 14:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'C', 1, 'QUEUED', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 17:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'D', 1, 'READY', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 13:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'D', 1, 'CASTING', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 12:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'D', 1, 'QUEUED', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 11:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'E', 1, 'READY', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 21:51:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'E', 1, 'CASTING', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 18:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual union all
select 'E', 1, 'QUEUED', to_date('2019-08-04 00:00:00','YYYY-MM-DD HH24:MI:SS'), to_date('2019-08-04 11:59:00', 'YYYY-MM-DD HH24:MI:SS') from dual
),
table1_with_rounded_min as
(
select y.*,
to_date(to_char(event_time,'YYYYMMDDHH24') || ltrim(to_char(event_round_15)),'YYYYMMDDHH24MI') event_time_round15
from
(
select x.*,
trunc(x.event_min / 15)*15 event_round_15
from
(
select table1.*, to_char(event_time,'MI') event_min
from table1
) x
) y
)
select to_char(event_time_round15, 'MM/DD/YY HH24:MI') date1,
sum(case when status = 'CASTING' then 1 else 0 end) Count_at_casting
from table1_with_rounded_min
group by event_time_round15
order by 1
]