需要得到单个业务线集群一天中的QPS峰值,但是如果出现毛刺点,如正常的峰值是12,突然有一分钟因秒杀活动或爬虫,峰值被顶到了100,这时候取100会导致误差大(实际扫描中,导致判断业务线峰值能承受的比较大,从而扫多了)。
于是现在需要将pv数据去掉毛刺。
0X01 原理
1) 原始数据图,x轴为升序时间戳(一分钟一个x),y轴为x分钟时的平均qps
2) 我们算出每一个所有差值,也即前后两个时间戳的qps差值。以差值为x、同一差值的数量 画图,可以得出如下。
大部分的流量波动范围不大,所以差值范围集中在一个正常的范围中,但有的点突然波动,差值会变得极大、且数量极少。
所以我们只需要去除掉这部分 差值大、数量极小的差值对应的 时间戳pv就好了。
这里我们根据斜率来计算,比较直观,斜率开始突增45°(计算时用x y在其轴中的比例,保证45°可用)和斜率结束突降45°的点,以这两个点为根据,其他范围是不要的。
如,算出来突增突降点是 (-3, 3),则差值大于等于3、小于等于-3的可以不要,设置成旁边其他时间戳的pv。
3) 过滤后的数据图
4) 数据图的差值图
固然到了这里还可以再跑一次,不过再跑一次图就变得太平滑了,我们只是想去掉两个毛刺而已。
0X02 DEMO代码
"""
目的
输入 数据字典
输出 过滤毛刺后的数据字典
"""
import copy
import matplotlib.pyplot as plt
def my_draw(my_dic, title):
# 将字典k, v 按照key 升序的方式展示成图
keys = list(my_dic.keys())
keys.sort()
values = []
for key in keys:
values.append(my_dic[key])
plt.plot(keys, values, 'g-s')
plt.title(title)
plt.show()
def normal_distribution_filter(my_dic):
"""
:param my_dic:
:return: 将差值表斜率化(微分思想),返回斜率突增开始和突降结束的点,毛刺点的差值范围
"""
# 对照差值表
keys = list(my_dic.keys())
keys.sort()
key_point = dict()
x_total = keys[-1] - keys[0]
y_total = max(my_dic.values()) - min(my_dic.values())
for key_index in range(1, len(keys)):
x_len = (keys[key_index] - keys[key_index - 1]) / x_total
y_len = (my_dic[keys[key_index]] - my_dic[keys[key_index - 1]]) / y_total
# tan大于1,说明角度大于45%,是差值正态分布突增开始的点
if y_len/x_len > 1:
print("差值正态分布突增点", end="==>")
print(keys[key_index-1])
key_point["rise_point"] = keys[key_index-1]
break
for key_index in range(len(keys)-1, 0, -1):
x_len = (keys[key_index] - keys[key_index - 1]) / x_total
y_len = (my_dic[keys[key_index]] - my_dic[keys[key_index - 1]]) / y_total
# tan小于-1,说明角度大于45%,是差值正态分布突降结束的点
if y_len/x_len < -1:
print("差值正态分布突降点", end="==>")
print(keys[key_index])
key_point["down_point"] = keys[key_index]
break
return key_point
def qumaoci(rep_data, key_point):
"""
懒得起名了
:param rep_data: 数据字典
:param key_point: 数据字典中 value可用范围
:return:
"""
new_data = copy.deepcopy(rep_data)
my_keys = list(new_data.keys())
for index in range(1, len(my_keys)):
diffe = new_data[my_keys[index]] - new_data[my_keys[index-1]]
if diffe > key_point["down_point"]:
new_value = new_data[my_keys[index-1]]
# 同时因为值改变了,后面连着的毛刺柱会一连串的跟着改变
elif diffe < key_point["rise_point"]:
new_value = new_data[my_keys[index]]
new_data[my_keys[index-1]] = new_value
else:
new_value = new_data[my_keys[index]]
new_data[my_keys[index]] = new_value
return new_data
def get_diffe(rep_data):
"""
返回 以差值为横坐标、数量为纵坐标的字典
:param rep_data:
:return:
"""
diffe_dic = dict()
last_key = ""
for k, v in rep_data.items():
last_key = last_key if last_key else k
last_qps = int(rep_data[last_key])
qps = int(v)
diffe = qps - last_qps
if diffe in diffe_dic:
diffe_dic[diffe] += 1
else:
diffe_dic[diffe] = 1
last_key = k
return diffe_dic
def my_req():
rep_data = {'1587927540': 0.167, '1587927600': 0.567, '1587927660': 0.033, '1587927720': 0.017, '1587927780': 0, '1587927840': 0, '1587927900': 0.383, '1587927960': 0, '1587928020': 0, '1587928080': 0, '1587928140': 0.067, '1587928200': 0.433, '1587928260': 0.083, '1587928320': 0, '1587928380': 0, '1587928440': 0.083, '1587928500': 0.45, '1587928560': 0.1, '1587928620': 0.033, '1587928680': 0, '1587928740': 0, '1587928800': 0.417, '1587928860': 0, '1587928920': 0, '1587928980': 0, '1587929040': 0.017, '1587929100': 0.383, '1587929160': 0, '1587929220': 0.017, '1587929280': 0, '1587929340': 0, '1587929400': 0.4, '1587929460': 0.05, '1587929520': 0.033, '1587929580': 0.033, '1587929640': 0, '1587929700': 0.383, '1587929760': 0, '1587929820': 0, '1587929880': 0.017, '1587929940': 0.017, '1587930000': 0.383, '1587930060': 0, '1587930120': 0, '1587930180': 0.067, '1587930240': 0.183, '1587930300': 0.383, '1587930360': 0, '1587930420': 0, '1587930480': 0.017, '1587930540': 0, '1587930600': 0.383, '1587930660': 0, '1587930720': 0, '1587930780': 0, '1587930840': 0.017, '1587930900': 0.383, '1587930960': 0, '1587931020': 0.05, '1587931080': 0.033, '1587931140': 0.267, '1587931200': 18.083000000000002, '1587931260': 0.217, '1587931320': 0.083, '1587931380': 0.033, '1587931440': 0, '1587931500': 0.383, '1587931560': 0.033, '1587931620': 0.067, '1587931680': 0, '1587931740': 0.017, '1587931800': 0.417, '1587931860': 0.033, '1587931920': 0, '1587931980': 0, '1587932040': 0, '1587932100': 0.383, '1587932160': 0, '1587932220': 0.017, '1587932280': 0, '1587932340': 0, '1587932400': 0.4, '1587932460': 0, '1587932520': 0.017, '1587932580': 0, '1587932640': 0, '1587932700': 0.383, '1587932760': 0, '1587932820': 0.017, '1587932880': 0.033, '1587932940': 0, '1587933000': 0.417, '1587933060': 0, '1587933120': 0.017, '1587933180': 0, '1587933240': 0.017, '1587933300': 0.383, '1587933360': 0, '1587933420': 0.033, '1587933480': 0.017, '1587933540': 0, '1587933600': 0.383, '1587933660': 0, '1587933720': 0, '1587933780': 0, '1587933840': 0, '1587933900': 0.383, '1587933960': 0, '1587934020': 0, '1587934080': 0, '1587934140': 0, '1587934200': 0.383, '1587934260': 0, '1587934320': 0, '1587934380': 0, '1587934440': 0.033, '1587934500': 0.383, '1587934560': 0, '1587934620': 0, '1587934680': 0, '1587934740': 0, '1587934800': 0.467, '1587934860': 0.233, '1587934920': 0.017, '1587934980': 0.017, '1587935040': 0, '1587935100': 0.383, '1587935160': 0.017, '1587935220': 0, '1587935280': 0, '1587935340': 0, '1587935400': 0.433, '1587935460': 0.017, '1587935520': 0.017, '1587935580': 0, '1587935640': 0, '1587935700': 0.4, '1587935760': 0, '1587935820': 0.017, '1587935880': 0.033, '1587935940': 0, '1587936000': 0.4, '1587936060': 0, '1587936120': 0, '1587936180': 0, '1587936240': 0, '1587936300': 0.383, '1587936360': 0.017, '1587936420': 0.017, '1587936480': 0.017, '1587936540': 0, '1587936600': 0.383, '1587936660': 0.017, '1587936720': 0.017, '1587936780': 0, '1587936840': 0, '1587936900': 0.383, '1587936960': 0.017, '1587937020': 0.05, '1587937080': 0.017, '1587937140': 0.017, '1587937200': 0.383, '1587937260': 0.017, '1587937320': 0, '1587937380': 0.033, '1587937440': 0, '1587937500': 0.383, '1587937560': 0.017, '1587937620': 0, '1587937680': 0.017, '1587937740': 0, '1587937800': 0.383, '1587937860': 0, '1587937920': 0, '1587937980': 0, '1587938040': 0.017, '1587938100': 0.4, '1587938160': 0, '1587938220': 0, '1587938280': 0, '1587938340': 0.033, '1587938400': 0.467, '1587938460': 0.083, '1587938520': 0.033, '1587938580': 0, '1587938640': 0.033, '1587938700': 0.417, '1587938760': 0.017, '1587938820': 0, '1587938880': 0.05, '1587938940': 0.05, '1587939000': 0.467, '1587939060': 0, '1587939120': 0, '1587939180': 0.017, '1587939240': 0.05, '1587939300': 0.383, '1587939360': 0.067, '1587939420': 0.083, '1587939480': 0.033, '1587939540': 0.017, '1587939600': 0.4, '1587939660': 0.017, '1587939720': 0, '1587939780': 0.033, '1587939840': 0.167, '1587939900': 0.5, '1587939960': 0.117, '1587940020': 0.2, '1587940080': 0.267, '1587940140': 0.033, '1587940200': 0.417, '1587940260': 0.017, '1587940320': 0.05, '1587940380': 0.05, '1587940440': 0.017, '1587940500': 0.433, '1587940560': 0.05, '1587940620': 0.05, '1587940680': 0, '1587940740': 0.067, '1587940800': 0.417, '1587940860': 0.083, '1587940920': 0.033, '1587940980': 0.033, '1587941040': 0.083, '1587941100': 0.45, '1587941160': 0.067, '1587941220': 0.05, '1587941280': 0.033, '1587941340': 0.1, '1587941400': 0.483, '1587941460': 0.133, '1587941520': 0.067, '1587941580': 0.083, '1587941640': 0.05, '1587941700': 0.533, '1587941760': 0.033, '1587941820': 0.05, '1587941880': 0.083, '1587941940': 0.117, '1587942000': 0.517, '1587942060': 0.25, '1587942120': 0.133, '1587942180': 0.1, '1587942240': 0.017, '1587942300': 0.467, '1587942360': 0.217, '1587942420': 0.083, '1587942480': 0.083, '1587942540': 0.133, '1587942600': 0.5, '1587942660': 0.083, '1587942720': 0.067, '1587942780': 0.083, '1587942840': 0.133, '1587942900': 0.567, '1587942960': 0.167, '1587943020': 0.2, '1587943080': 0.217, '1587943140': 0.017, '1587943200': 0.667, '1587943260': 0.05, '1587943320': 0.067, '1587943380': 0.133, '1587943440': 0.05, '1587943500': 0.45, '1587943560': 0.133, '1587943620': 0.167, '1587943680': 0.117, '1587943740': 0.083, '1587943800': 0.667, '1587943860': 0.183, '1587943920': 0.167, '1587943980': 0.083, '1587944040': 0.117, '1587944100': 0.483, '1587944160': 0.117, '1587944220': 0.117, '1587944280': 0.183, '1587944340': 0.2, '1587944400': 0.55, '1587944460': 0.2, '1587944520': 0.3, '1587944580': 0.283, '1587944640': 0.25, '1587944700': 0.717, '1587944760': 0.317, '1587944820': 0.15, '1587944880': 0.517, '1587944940': 0.233, '1587945000': 0.783, '1587945060': 0.483, '1587945120': 0.3, '1587945180': 0.45, '1587945240': 0.383, '1587945300': 0.917, '1587945360': 0.717, '1587945420': 0.6, '1587945480': 0.767, '1587945540': 1.017, '1587945600': 1.733, '1587945660': 0.75, '1587945720': 0.917, '1587945780': 1.05, '1587945840': 1.367, '1587945900': 1.433, '1587945960': 1.317, '1587946020': 1.233, '1587946080': 1.717, '1587946140': 1.25, '1587946200': 2.25, '1587946260': 1.633, '1587946320': 1.75, '1587946380': 2.367, '1587946440': 2.467, '1587946500': 2.633, '1587946560': 2.783, '1587946620': 2.8, '1587946680': 2.85, '1587946740': 3, '1587946800': 3.733, '1587946860': 3.867, '1587946920': 4.667, '1587946980': 5.517, '1587947040': 5.017, '1587947100': 5.85, '1587947160': 5.717, '1587947220': 5.8, '1587947280': 6.2, '1587947340': 7.15, '1587947400': 6.667, '1587947460': 5.517, '1587947520': 5, '1587947580': 4.566999999999999, '1587947640': 5.15, '1587947700': 5.433000000000001, '1587947760': 4.85, '1587947820': 4.917, '1587947880': 5.733, '1587947940': 5.483, '1587948000': 5.833, '1587948060': 6, '1587948120': 6.467, '1587948180': 5.35, '1587948240': 6.867, '1587948300': 7.5, '1587948360': 6.45, '1587948420': 7.2, '1587948480': 7.316999999999999, '1587948540': 8.367, '1587948600': 7.917, '1587948660': 7.5, '1587948720': 7.467, '1587948780': 7.933000000000001, '1587948840': 8.283, '1587948900': 9.65, '1587948960': 9.55, '1587949020': 9.233, '1587949080': 10.117, '1587949140': 10.6, '1587949200': 10.4, '1587949260': 10.6, '1587949320': 11.55, '1587949380': 11.5, '1587949440': 11.483, '1587949500': 14.1, '1587949560': 9.567, '1587949620': 10.35, '1587949680': 10.867, '1587949740': 9.217, '1587949800': 9.317, '1587949860': 8.583, '1587949920': 9.4, '1587949980': 9.2, '1587950040': 11.65, '1587950100': 9.6, '1587950160': 8.367, '1587950220': 8.433, '1587950280': 9.333, '1587950340': 8.283, '1587950400': 7.917, '1587950460': 9.733, '1587950520': 9.433, '1587950580': 9.2, '1587950640': 8.367, '1587950700': 8.8, '1587950760': 8.75, '1587950820': 7.517, '1587950880': 8.317, '1587950940': 9.517, '1587951000': 9.633, '1587951060': 8.033, '1587951120': 6.3, '1587951180': 7.233, '1587951240': 8.367, '1587951300': 8.5, '1587951360': 8.15, '1587951420': 8.567, '1587951480': 7.667, '1587951540': 8.733, '1587951600': 9.3, '1587951660': 7.633, '1587951720': 7.783, '1587951780': 8.233, '1587951840': 8.033, '1587951900': 8.2, '1587951960': 9.483, '1587952020': 9.933, '1587952080': 7.533, '1587952140': 8.483, '1587952200': 8.067, '1587952260': 6.933000000000001, '1587952320': 7.7, '1587952380': 8.2, '1587952440': 7.683000000000001, '1587952500': 8.8, '1587952560': 7.983, '1587952620': 6.733, '1587952680': 8.083, '1587952740': 9.383, '1587952800': 10.717, '1587952860': 8.133, '1587952920': 8.683, '1587952980': 7.467, '1587953040': 8.35, '1587953100': 7.667, '1587953160': 8.783, '1587953220': 7.583, '1587953280': 7.917, '1587953340': 8.483, '1587953400': 7.167, '1587953460': 7.9, '1587953520': 7.8, '1587953580': 9.533, '1587953640': 7.983, '1587953700': 8.183, '1587953760': 8.2, '1587953820': 7.8, '1587953880': 7.183000000000001, '1587953940': 7.267, '1587954000': 7.717, '1587954060': 7.4, '1587954120': 7.65, '1587954180': 6.85, '1587954240': 7.183000000000001, '1587954300': 8.85, '1587954360': 6.533, '1587954420': 6.533, '1587954480': 6.233, '1587954540': 7.3, '1587954600': 7.1, '1587954660': 6.367, '1587954720': 6.767, '1587954780': 5.783, '1587954840': 6.5, '1587954900': 6.683000000000001, '1587954960': 6.333, '1587955020': 5.583, '1587955080': 5.917, '1587955140': 7.05, '1587955200': 7.333, '1587955260': 6.217, '1587955320': 5.3, '1587955380': 6.433000000000001, '1587955440': 6.55, '1587955500': 6.733, '1587955560': 6.233, '1587955620': 7.45, '1587955680': 6.833, '1587955740': 5.767, '1587955800': 6.217, '1587955860': 6.033, '1587955920': 6.267, '1587955980': 6.233, '1587956040': 6.65, '1587956100': 6.733, '1587956160': 5.867, '1587956220': 5.85, '1587956280': 6.7, '1587956340': 5.517, '1587956400': 6.217, '1587956460': 5.933000000000001, '1587956520': 6.816999999999999, '1587956580': 6.4, '1587956640': 7.633, '1587956700': 6.7, '1587956760': 4.967, '1587956820': 5.633, '1587956880': 5.383, '1587956940': 5.75, '1587957000': 6.033, '1587957060': 5.733, '1587957120': 6.017, '1587957180': 6.183000000000001, '1587957240': 6.133, '1587957300': 5.917, '1587957360': 6.267, '1587957420': 6.65, '1587957480': 7, '1587957540': 6.117, '1587957600': 6.533, '1587957660': 5.217, '1587957720': 5.267, '1587957780': 5.583, '1587957840': 5.2, '1587957900': 5.65, '1587957960': 4.8, '1587958020': 5.217, '1587958080': 5.033, '1587958140': 5.467, '1587958200': 5.85, '1587958260': 5.833, '1587958320': 5.183000000000001, '1587958380': 5.5, '1587958440': 5.65, '1587958500': 5.733, '1587958560': 4.917, '1587958620': 5.183000000000001, '1587958680': 4.967, '1587958740': 5.267, '1587958800': 5.8, '1587958860': 5.95, '1587958920': 6.6, '1587958980': 5.4, '1587959040': 6.25, '1587959100': 5.583, '1587959160': 4.35, '1587959220': 4.883, '1587959280': 5.65, '1587959340': 5.783, '1587959400': 5.217, '1587959460': 5.15, '1587959520': 4.517, '1587959580': 5.1, '1587959640': 4.8, '1587959700': 5.1, '1587959760': 3.233, '1587959820': 2.867, '1587959880': 3.817, '1587959940': 4.45, '1587960000': 3.617, '1587960060': 2.517, '1587960120': 1.967, '1587960180': 1.833, '1587960240': 1.483, '1587960300': 2.35, '1587960360': 1.633, '1587960420': 1.15, '1587960480': 1.267, '1587960540': 1.65, '1587960600': 1.85, '1587960660': 1.267, '1587960720': 1.233, '1587960780': 1.5, '1587960840': 1.117, '1587960900': 1.6, '1587960960': 0.8830000000000001, '1587961020': 0.75, '1587961080': 0.9, '1587961140': 0.8830000000000001, '1587961200': 1.167, '1587961260': 0.817, '1587961320': 0.667, '1587961380': 0.967, '1587961440': 0.767, '1587961500': 1.15, '1587961560': 0.8669999999999999, '1587961620': 1.067, '1587961680': 1.033, '1587961740': 0.967, '1587961800': 1.383, '1587961860': 0.8, '1587961920': 0.55, '1587961980': 0.8669999999999999, '1587962040': 0.6, '1587962100': 0.917, '1587962160': 0.817, '1587962220': 0.683, '1587962280': 0.683, '1587962340': 0.8669999999999999, '1587962400': 1.483, '1587962460': 0.8669999999999999, '1587962520': 0.6, '1587962580': 0.767, '1587962640': 0.783, '1587962700': 1.25, '1587962760': 0.733, '1587962820': 0.933, '1587962880': 0.767, '1587962940': 0.567, '1587963000': 1.25, '1587963060': 0.767, '1587963120': 0.95, '1587963180': 0.933, '1587963240': 0.717, '1587963300': 1.367, '1587963360': 0.933, '1587963420': 0.6169999999999999, '1587963480': 0.783, '1587963540': 1, '1587963600': 1.45, '1587963660': 0.917, '1587963720': 1.567, '1587963780': 1.733, '1587963840': 1.267, '1587963900': 2.15, '1587963960': 1.717, '1587964020': 1.917, '1587964080': 1.817, '1587964140': 1.833, '1587964200': 2.283, '1587964260': 1.733, '1587964320': 2.183, '1587964380': 1.6, '1587964440': 1.583, '1587964500': 1.7, '1587964560': 1.767, '1587964620': 2.083, '1587964680': 2.15, '1587964740': 2.817, '1587964800': 2.85, '1587964860': 2.733, '1587964920': 3.217, '1587964980': 3.683, '1587965040': 4.95, '1587965100': 3.617, '1587965160': 2.783, '1587965220': 3.25, '1587965280': 2.833, '1587965340': 2.65, '1587965400': 3.45, '1587965460': 2.85, '1587965520': 2.717, '1587965580': 2.817, '1587965640': 3.85, '1587965700': 4.183, '1587965760': 2.55, '1587965820': 3.9, '1587965880': 4.483, '1587965940': 4.183, '1587966000': 4.733, '1587966060': 4.417, '1587966120': 4.45, '1587966180': 4, '1587966240': 4.417, '1587966300': 5.5, '1587966360': 4.566999999999999, '1587966420': 5.367, '1587966480': 5.267, '1587966540': 5.367, '1587966600': 5.033, '1587966660': 4.65, '1587966720': 4.45, '1587966780': 4.633, '1587966840': 4.833, '1587966900': 6.083, '1587966960': 5.033, '1587967020': 6.767, '1587967080': 5, '1587967140': 5.733, '1587967200': 6.25, '1587967260': 5.867, '1587967320': 6.316999999999999, '1587967380': 5.967, '1587967440': 5.816999999999999, '1587967500': 6.45, '1587967560': 5.983, '1587967620': 5.75, '1587967680': 4.533, '1587967740': 5.833, '1587967800': 5.433000000000001, '1587967860': 5.65, '1587967920': 5, '1587967980': 5.283, '1587968040': 5.533, '1587968100': 6.25, '1587968160': 6.383, '1587968220': 6.633, '1587968280': 7.316999999999999, '1587968340': 6.667, '1587968400': 5.683000000000001, '1587968460': 5.1, '1587968520': 5.65, '1587968580': 5.2, '1587968640': 5.617, '1587968700': 5.967, '1587968760': 23, '1587968820': 25.916999999999998, '1587968880': 40.65, '1587968940': 5.917, '1587969000': 6.617, '1587969060': 5.433000000000001, '1587969120': 5.717, '1587969180': 5.717, '1587969240': 6.7, '1587969300': 6.267, '1587969360': 6.9, '1587969420': 5.883, '1587969480': 5.617, '1587969540': 6.15, '1587969600': 5.417, '1587969660': 4.883, '1587969720': 5.783, '1587969780': 6.933000000000001, '1587969840': 6.533, '1587969900': 5.95, '1587969960': 6.467, '1587970020': 7.017, '1587970080': 5.3, '1587970140': 5.4, '1587970200': 6.5, '1587970260': 6.65, '1587970320': 6.033, '1587970380': 6.333, '1587970440': 7.5, '1587970500': 6.816999999999999, '1587970560': 6.4, '1587970620': 6.983, '1587970680': 6.55, '1587970740': 7.883, '1587970800': 7.217, '1587970860': 7.45, '1587970920': 7.3, '1587970980': 6.983, '1587971040': 6.867, '1587971100': 7.883, '1587971160': 6.5, '1587971220': 7.05, '1587971280': 7.133, '1587971340': 6.033, '1587971400': 6.267, '1587971460': 4.95, '1587971520': 5.3, '1587971580': 5.8, '1587971640': 5.833, '1587971700': 6.717, '1587971760': 5.8, '1587971820': 5.983, '1587971880': 5.066999999999999, '1587971940': 6.017, '1587972000': 5.783, '1587972060': 6.3, '1587972120': 7.566999999999999, '1587972180': 7.633, '1587972240': 6.816999999999999, '1587972300': 8.85, '1587972360': 8.2, '1587972420': 6.917, '1587972480': 6.683000000000001, '1587972540': 6.066999999999999, '1587972600': 7.017, '1587972660': 7.133, '1587972720': 6.617, '1587972780': 5.566999999999999, '1587972840': 6.9, '1587972900': 6.183000000000001, '1587972960': 5.333, '1587973020': 6.533, '1587973080': 6.483, '1587973140': 6.533, '1587973200': 7.167, '1587973260': 6.983, '1587973320': 7.733, '1587973380': 8.583, '1587973440': 7.467, '1587973500': 7.267, '1587973560': 7.517, '1587973620': 5.983, '1587973680': 7.2, '1587973740': 5.816999999999999, '1587973800': 6.883, '1587973860': 5.7, '1587973920': 6.433000000000001, '1587973980': 5.617, '1587974040': 7.033, '1587974100': 6.217, '1587974160': 7.066999999999999, '1587974220': 5.85, '1587974280': 8.367, '1587974340': 7.15, '1587974400': 6.433000000000001, '1587974460': 6.183000000000001, '1587974520': 5.183000000000001, '1587974580': 5.367, '1587974640': 5.133, '1587974700': 7.433000000000001, '1587974760': 6.233, '1587974820': 9.667, '1587974880': 6.733, '1587974940': 6.383, '1587975000': 6.816999999999999, '1587975060': 6.217, '1587975120': 6.017, '1587975180': 6.933000000000001, '1587975240': 11.317, '1587975300': 7.683000000000001, '1587975360': 5.717, '1587975420': 5.967, '1587975480': 7.933000000000001, '1587975540': 6.25, '1587975600': 6.2, '1587975660': 6.917, '1587975720': 6.233, '1587975780': 6.15, '1587975840': 6.55, '1587975900': 6.433000000000001, '1587975960': 7.867, '1587976020': 6.583, '1587976080': 7.233, '1587976140': 6.483, '1587976200': 7.6, '1587976260': 7.917, '1587976320': 6.083, '1587976380': 7.267, '1587976440': 7.35, '1587976500': 7.033, '1587976560': 5.033, '1587976620': 6.217, '1587976680': 7.133, '1587976740': 6.967, '1587976800': 6, '1587976860': 7.083, '1587976920': 6, '1587976980': 5.8, '1587977040': 6.2, '1587977100': 5.883, '1587977160': 5.667, '1587977220': 7.267, '1587977280': 5.433000000000001, '1587977340': 6.217, '1587977400': 6.183000000000001, '1587977460': 6.867, '1587977520': 6.517, '1587977580': 5.933000000000001, '1587977640': 6.117, '1587977700': 6.633, '1587977760': 5.467, '1587977820': 7.083, '1587977880': 5.517, '1587977940': 5.083, '1587978000': 6.983, '1587978060': 7, '1587978120': 7.867, '1587978180': 7.633, '1587978240': 7.183000000000001, '1587978300': 7.633, '1587978360': 7.55, '1587978420': 6.417, '1587978480': 5.917, '1587978540': 6, '1587978600': 6.75, '1587978660': 7.767, '1587978720': 5.6, '1587978780': 5.7, '1587978840': 6.65, '1587978900': 6.6, '1587978960': 5.483, '1587979020': 5.566999999999999, '1587979080': 5.9, '1587979140': 6.083, '1587979200': 7.55, '1587979260': 7.417, '1587979320': 6.533, '1587979380': 6.467, '1587979440': 7.7, '1587979500': 5.967, '1587979560': 6.667, '1587979620': 7.316999999999999, '1587979680': 7.233, '1587979740': 6.566999999999999, '1587979800': 7.95, '1587979860': 7.75, '1587979920': 6.75, '1587979980': 7.066999999999999, '1587980040': 6.35, '1587980100': 7.233, '1587980160': 5.566999999999999, '1587980220': 5.833, '1587980280': 5.316999999999999, '1587980340': 4.967, '1587980400': 5.7, '1587980460': 6.1, '1587980520': 7.25, '1587980580': 7.233, '1587980640': 6.017, '1587980700': 6.783, '1587980760': 6.617, '1587980820': 6.833, '1587980880': 5.117, '1587980940': 5.7, '1587981000': 6.933000000000001, '1587981060': 5.767, '1587981120': 6.433000000000001, '1587981180': 7.233, '1587981240': 5.95, '1587981300': 6.117, '1587981360': 6.4, '1587981420': 6.033, '1587981480': 7.517, '1587981540': 5.717, '1587981600': 6.15, '1587981660': 5.316999999999999, '1587981720': 5.117, '1587981780': 5.05, '1587981840': 4.233, '1587981900': 4.9, '1587981960': 4.267, '1587982020': 3.733, '1587982080': 3.767, '1587982140': 4.05, '1587982200': 4.5, '1587982260': 3.7, '1587982320': 3.983, '1587982380': 3.667, '1587982440': 3.25, '1587982500': 3.2, '1587982560': 2.85, '1587982620': 13.15, '1587982680': 3, '1587982740': 3.133, '1587982800': 3.3, '1587982860': 3.25, '1587982920': 3.017, '1587982980': 2.633, '1587983040': 2.633, '1587983100': 3.467, '1587983160': 2.783, '1587983220': 2.767, '1587983280': 3.017, '1587983340': 2.717, '1587983400': 3.15, '1587983460': 3.7, '1587983520': 2.4, '1587983580': 2.45, '1587983640': 2.667, '1587983700': 3.2, '1587983760': 2.033, '1587983820': 2.633, '1587983880': 2.517, '1587983940': 2.367, '1587984000': 2.983, '1587984060': 2.483, '1587984120': 2.633, '1587984180': 2.3, '1587984240': 2.517, '1587984300': 2.667, '1587984360': 2.133, '1587984420': 2.7, '1587984480': 2.95, '1587984540': 2.533, '1587984600': 3.2, '1587984660': 2.9, '1587984720': 2.333, '1587984780': 2.333, '1587984840': 2.633, '1587984900': 3.733, '1587984960': 2.383}
# 画出原始数据图
my_draw(rep_data, "source data")
print("数据长度 " + str(len(rep_data)))
# 返回 以差值为横坐标、数量为纵坐标的字典
diffe_dic = get_diffe(rep_data)
# 展示
my_draw(diffe_dic, "diffe")
# 根据突增突降斜率 45° 得到两个点, 45°为调控值
key_point = normal_distribution_filter(diffe_dic)
"""根据两个点去毛刺
深度copy字典,直接去掉突增并且连贯的毛刺柱子
另外的做法:
新建一个字典存储数据,每一次丢进函数里只去毛刺单点,即三个连续的毛刺点,只去左右
"""
new_data = qumaoci(rep_data, key_point)
my_draw(new_data, "new_data")
# 新差值 - 差值正态分布计算
diffe_dic = get_diffe(new_data)
# 展示
my_draw(diffe_dic, "new_diffe")
if __name__ == '__main__':
my_req()