【发布时间】:2013-08-07 16:16:34
【问题描述】:
我有一个看起来像这样的数据数组:
#API name, min, max, average
['findProductByPartNumber', '336.0', '336.0', '336.0']
['findProductByPartNumber', '336.0', '339.0', '337.5']
['findProductByPartNumber', '336.0', '339.0', '338.0']
['findProductByPartNumber', '336.0', '341.0', '338.75']
['findProductByPartNumber', '336.0', '353.0', '341.6']
['findProductById', '841.0', '841.0', '841.0']
['findProductByPartNumber', '336.0', '920.0', '438.0']
['findProductByPartNumber', '336.0', '944.0', '510.29']
['findProductByPartNumber', '336.0', '952.0', '565.5']
['findProductByPartNumber', '336.0', '975.0', '611.0']
['findProductsByCategory', '113.0', '113.0', '113.0']
['findProductById', '161.0', '841.0', '501.0']
['findProductByPartNumber', '255.0', '975.0', '575.4']
我想做的是,对于每个单独的 API,生成如下内容:
API, Min, Max, Average, 90th Percentile
findProductByPartNumber, 278.69, 770.25, 458.69, 565.5
findProductById, 373.0, 841.0, 571.67, 501.0
findProductsByCategory, 112.33, 187.17, 154.46, 167.75
这是上述每个 API 的汇总结果。在 Python 中执行此操作的最佳方法是什么?
编辑:
我有以下 Java 代码可以满足我的需求。 Java 是我最好的语言,我正在尝试学习 Python,但我不熟悉数据结构。
double[] apiValues = new double[3];
apiValues[0] = Double.valueOf(min);
apiValues[1] = Double.valueOf(max);
apiValues[2] = Double.valueOf(average);
parseAPILogs.registerAPI(name, apiValues);
...
...
private static void registerAPI(String apiName, double[] apiValues) {
if(!averagePerAPI.containsKey(apiName)) {
APIData data = new APIData();
data.addValues(apiValues);
averagePerAPI.put(apiName, data);
} else {
averagePerAPI.get(apiName).addValues(apiValues);
}
}
APIData Java 类在这里有点大,但你可以看到我的想法。
【问题讨论】:
-
你试过了吗?
-
我回答了,但您应该提供您以后尝试过的代码,以显示您的努力。
-
我已经编辑了包含执行此操作的 Java 代码,但我正在尝试学习 Python,但我想出的任何东西都没有真正做到这一点。我对 Python 数据结构不太熟悉,所以希望有一些示例代码可以开始。
标签: python arrays statistics metrics