你好,我正在尝试对这个关注数据进行排序
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
bot = ChatBot('Test')
conv= open('chats.txt','r').readlines()
bot.set_trainer(ListTrainer)
bot.train(conv)
while True:
request = input("You: ")
response = bot.get_response(request)
print('Bot: ', response)
我需要按 2 个值对 [
{
"clockId": 27,
"clockResetId": 2,
"clockName": " clock1",
"station": "Byron",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 18,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 46,
"clockResetId": 2,
"clockName": "clock undenfiend",
"station": "Dresden",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 20,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 13,
"clockResetId": 1,
"clockName": " clock ",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "testing ",
"eventDate": "2020-04-28Z",
"totalDays": 22,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "tool",
"eventDescription": "testing ",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 13
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 43,
"clockResetId": 2,
"clockName": " clock1",
"station": "Braidwood",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 23,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#fe001c",
"textColor": "#ffffff"
},
{
"clockId": 42,
"clockResetId": 2,
"clockName": " clock1",
"station": "Clinton",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 28,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 49,
"clockResetId": 2,
"clockName": " clock undefiend",
"station": "Byron",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 28,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 41,
"clockResetId": 4,
"clockName": "clearance and tagging",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-18Z",
"totalDays": 32,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 41
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 44,
"clockResetId": 2,
"clockName": " clock1",
"station": "Dresden",
"department": "",
"owner": "",
"type": "Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 38,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 47,
"clockResetId": 2,
"clockName": " clock undenfiend",
"station": "Byron",
"department": "",
"owner": "",
"type": "",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-05-02Z",
"totalDays": 38,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 27
}
],
"backgroundColor": "#f6ea00",
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
},
{
"clockId": 55,
"clockResetId": 3,
"clockName": "configuration control",
"station": "Byron",
"department": "",
"owner": "",
"type": "Non-Discretionary",
"fleetClockGlobalRecordDays": null,
"clockLevel": "Fleet",
"clockDescription": "",
"eventDate": "2020-04-01Z",
"totalDays": 149,
"irNum": "123",
"observationNum": "",
"toolToPrevent": "123",
"eventDescription": "123",
"clockSetter": "sarahevelynn",
"resetHistory": [
{
"yearSubFour": 0,
"yearSubThree": 0,
"yearSubTwo": 0,
"yearSubOne": 0,
"maxTotalDays": 0,
"year": 1,
"clockId": 55
}
],
"backgroundColor": null,
"textColor": "#000000"
}
]
名称按字母顺序排序,然后在订购我的站名后,它需要订购我的 station
为升序
这是我目前拥有的
totalDays
答案 0 :(得分:5)
由于 station
是字符串而不是数字,因此 sort
回调中的以下表达式不会按预期工作:
a.station - b.station || a.totalDays - b.totalDays
表达式的前半部分将评估为 NaN
,因此后半部分始终是总评估的决定因素。
您需要以“字符串”方式进行比较:
a.station.localeCompare(b.station) || a.totalDays - b.totalDays