如何计算百分位数? [英] How to calculate the percentile?
问题描述
我将以下访问日志存储在mongodb实例中:
I have access logs such as below stored in a mongodb instance:
Time Service Latency
[27/08/2013:11:19:22 +0000] "POST Service A HTTP/1.1" 403
[27/08/2013:11:19:24 +0000] "POST Service B HTTP/1.1" 1022
[27/08/2013:11:22:10 +0000] "POST Service A HTTP/1.1" 455
Oracle中是否有像PERCENTILE_DISC
这样的分析功能来计算百分位数?
Is there an analytics function like PERCENTILE_DISC
in Oracle to calculate the percentile?
我想计算一段时间内的延迟百分比.
I would like to calculate latency percentiles over a period of time.
推荐答案
似乎还没有原生方法来计算百分位数,但是通过组合一些聚合运算符,您可以获得相同的结果.
There still appears to be no native way to calculate percentiles but by combining a few aggregate operators you can get the same result.
db.items.aggregate([
{'$group': {
'_id': {
'league': '$league',
'base': '$base',
'type': '$type'
},
'value': {'$push': '$chaosequiv'}
}},
{'$unwind': '$value'},
{'$sort': {'value': 1}},
{'$group': {'_id': '$_id', 'value': {'$push': '$value'}}},
{'$project': {
'_id': 1,
'value': {'$arrayElemAt': ['$value', {'$floor': {'$multiply': [0.25, {'$size': '$value'}]}}]}
}}
], allowDiskUse=True)
请注意,我用pymongo编写了我的原始代码,该问题需要将第一组中的3个字段分组,因此这可能比单个字段所需的更为复杂.我会针对此问题编写解决方案,但我认为没有足够的具体信息.
Note I wrote my original code in pymongo for a problem that needed to group on 3 fields in the first group so this may be more complex than necessary for a single field. I would write a solution specific to this question but I don't think there is enough specific information.
这篇关于如何计算百分位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!