当前位置: 首页>>代码示例>>Golang>>正文


Golang BatteryStats.System方法代码示例

本文整理汇总了Golang中github.com/google/battery-historian/pb/batterystats_proto.BatteryStats.System方法的典型用法代码示例。如果您正苦于以下问题:Golang BatteryStats.System方法的具体用法?Golang BatteryStats.System怎么用?Golang BatteryStats.System使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/google/battery-historian/pb/batterystats_proto.BatteryStats的用法示例。


在下文中一共展示了BatteryStats.System方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NormalizeStats

// NormalizeStats takes in a proto and normalizes it by converting
// any absolute value to value/TotalTime.
func NormalizeStats(p *bspb.BatteryStats) (*bspb.BatteryStats, error) {
	totalTimeHour := roundToTwoDecimal(float64((p.GetSystem().GetBattery().GetBatteryRealtimeMsec()) / (3600 * 1000)))

	if totalTimeHour == 0 {
		return nil, errors.New("battery real time cannot be 0")
	}
	normApp := &bspb.BatteryStats{
		ReportVersion:   p.ReportVersion,
		AggregationType: p.AggregationType,
	}

	// Normalize the app data
	for _, a1 := range p.GetApp() {
		a := normalizeApp(a1, totalTimeHour)
		normApp.App = append(normApp.App, a)
	}

	// Normalize system data
	s1 := p.GetSystem()
	s := &bspb.BatteryStats_System{}

	if norm := normalizeMessage(s1.GetBattery(), totalTimeHour); norm != nil {
		s.Battery = norm.(*bspb.BatteryStats_System_Battery)
	}
	if norm := normalizeMessage(s1.GetBatteryDischarge(), totalTimeHour); norm != nil {
		s.BatteryDischarge = norm.(*bspb.BatteryStats_System_BatteryDischarge)
	}
	s.BatteryLevel = s1.GetBatteryLevel()
	if norm := normalizeRepeatedMessage(s1.GetBluetoothState(), totalTimeHour); !norm.IsNil() {
		s.BluetoothState = norm.Interface().([]*bspb.BatteryStats_System_BluetoothState)
	}
	if norm := normalizeRepeatedMessage(s1.GetDataConnection(), totalTimeHour); !norm.IsNil() {
		s.DataConnection = norm.Interface().([]*bspb.BatteryStats_System_DataConnection)
	}
	if norm := normalizeMessage(s1.GetGlobalNetwork(), totalTimeHour); norm != nil {
		s.GlobalNetwork = norm.(*bspb.BatteryStats_System_GlobalNetwork)
	}
	if norm := normalizeRepeatedMessage(s1.GetKernelWakelock(), totalTimeHour); !norm.IsNil() {
		s.KernelWakelock = norm.Interface().([]*bspb.BatteryStats_System_KernelWakelock)
	}
	if norm := normalizeMessage(s1.GetMisc(), totalTimeHour); norm != nil {
		s.Misc = norm.(*bspb.BatteryStats_System_Misc)
	}
	if norm := normalizeRepeatedMessage(s1.GetPowerUseItem(), totalTimeHour); !norm.IsNil() {
		s.PowerUseItem = norm.Interface().([]*bspb.BatteryStats_System_PowerUseItem)
	}
	if norm := normalizeMessage(s1.GetPowerUseSummary(), totalTimeHour); norm != nil {
		s.PowerUseSummary = norm.(*bspb.BatteryStats_System_PowerUseSummary)
	}
	if norm := normalizeRepeatedMessage(s1.GetScreenBrightness(), totalTimeHour); !norm.IsNil() {
		s.ScreenBrightness = norm.Interface().([]*bspb.BatteryStats_System_ScreenBrightness)
	}
	if norm := normalizeMessage(s1.GetSignalScanningTime(), totalTimeHour); norm != nil {
		s.SignalScanningTime = norm.(*bspb.BatteryStats_System_SignalScanningTime)
	}
	if norm := normalizeRepeatedMessage(s1.GetSignalStrength(), totalTimeHour); !norm.IsNil() {
		s.SignalStrength = norm.Interface().([]*bspb.BatteryStats_System_SignalStrength)
	}
	if norm := normalizeRepeatedMessage(s1.GetWakeupReason(), totalTimeHour); !norm.IsNil() {
		s.WakeupReason = norm.Interface().([]*bspb.BatteryStats_System_WakeupReason)
	}
	if norm := normalizeRepeatedMessage(s1.GetWifiState(), totalTimeHour); !norm.IsNil() {
		s.WifiState = norm.Interface().([]*bspb.BatteryStats_System_WifiState)
	}
	if norm := normalizeRepeatedMessage(s1.GetWifiSupplicantState(), totalTimeHour); !norm.IsNil() {
		s.WifiSupplicantState = norm.Interface().([]*bspb.BatteryStats_System_WifiSupplicantState)
	}
	p.System = s
	p.App = normApp.App
	return p, nil
}
开发者ID:mike69d,项目名称:battery-historian,代码行数:73,代码来源:checkin_normalize.go


注:本文中的github.com/google/battery-historian/pb/batterystats_proto.BatteryStats.System方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。