-2
鉴于在酒店人的逗留天以下JSON对象每三个月:如何计算连续事件?
[{u'month': u'7', u'stay_days': {u'value': 1.0}},
{u'month': u'8', u'stay_days': {u'value': 1.0}},
{u'month': u'9', u'stay_days': {u'value': 1.0}}]
我应该检查,如果人在最近3个月连续2个月参观了酒店,每月至少一次。
我被检查连续访问卡住了。
arr = '''[ {
"stay_days": {
"value": 1.0
},
"month": "1"
},
{
"stay_days": {
"value": 1.0
},
"month": "2"
},
{
"stay_days": {
"value": 1.0
},
"month": "3"
}]'''
json_object = json.loads(arr)
dt = datetime.strptime(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f'), "%Y-%m-%dT%H:%M:%S.%f")
month = dt.month
months = []
for line in json_object:
months.append(line["key"])
months
if (int(month) - int(max(months))) > 0 and (int(month) - int(max(months))) <= 3:
for line in json_object:
# ???