Ejemplo n.º 1
0
// normalizeAppApk normalizes values in the "apk" section of App.
func normalizeAppApk(p *bspb.BatteryStats_App_Apk, totalTimeHour float64) *bspb.BatteryStats_App_Apk {
	norm := &bspb.BatteryStats_App_Apk{}

	// there's only one wakeups value per apk
	norm.Wakeups = proto.Float32(float32(roundToTwoDecimal(float64(p.GetWakeups()) / totalTimeHour)))
	norm.Service = normalizeRepeatedMessage(p.GetService(), totalTimeHour).Interface().([]*bspb.BatteryStats_App_Apk_Service)
	return norm
}
Ejemplo n.º 2
0
// subtractAppApk computes differences of "apk" in App. p2 will be subtracted from p1.
func subtractAppApk(p1, p2 *bspb.BatteryStats_App_Apk) *bspb.BatteryStats_App_Apk {
	d := &bspb.BatteryStats_App_Apk{}
	apkChanged := false
	// there's only one wakeups value per apk, compare wakeups separately
	if diffWakeups := p1.GetWakeups() - p2.GetWakeups(); diffWakeups != 0 {
		apkChanged = true
		d.Wakeups = proto.Float32(diffWakeups)
	}
	if diff := subtractRepeatedMessage(p1.GetService(), p2.GetService()); !diff.IsNil() {
		apkChanged = true
		d.Service = diff.Interface().([]*bspb.BatteryStats_App_Apk_Service)
	}
	if apkChanged {
		return d
	}
	return nil
}