我在python烧瓶中有来自Postgres的一系列数据。看起来像这样
[4, datetime.datetime(2018, 6, 18, 22, 53, 0, 899493)]
[5, datetime.datetime(2018, 6, 18, 22, 54, 47, 899493)]
[3, datetime.datetime(2018, 6, 18, 22, 55, 0, 899493)]
[2, datetime.datetime(2018, 6, 19, 3, 53, 0, 899493)]
[1, datetime.datetime(2018, 6, 19, 3, 54, 0, 899493)]
[2, datetime.datetime(2018, 6, 19, 3, 54, 0, 899493)]
.
.
.
第一列的可能值为[1,2,3,4,5],第二列为UTC时间戳。
我有一个要计算的分数。它的公式是
score = ( no of records having first col values '4' or '5' / total no of records ) * 100
但是!!我也想对分数日期进行分组,以便在d3中进行绘制;三组
我期望的输出是
#First col is the score, Second column is timestamp in milliseconds.
#This is a 'day wise' grouped result
[
{'y': 50.0, 'x': 1529380380000},
{'y': 67.0, 'x': 1529380440000},
{'y': 46.0, 'x': 1529381700000},
{'y': 34.0, 'x': 1529381723000},
{'y': 65.0, 'x': 1529381723000},
{'y': 10.0, 'x': 1529381743000},
{'y': 90.0, 'x': 1529381940000}
]
我无法提出一种万无一失的方法来开发此方法。任何帮助,将不胜感激。