本文整理汇总了Golang中github.com/google/battery-historian/pb/batterystats_proto.BatteryStats.GetApp方法的典型用法代码示例。如果您正苦于以下问题:Golang BatteryStats.GetApp方法的具体用法?Golang BatteryStats.GetApp怎么用?Golang BatteryStats.GetApp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/battery-historian/pb/batterystats_proto.BatteryStats
的用法示例。
在下文中一共展示了BatteryStats.GetApp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseAppStats
func parseAppStats(checkin *bspb.BatteryStats) []*bspb.BatteryStats_App {
var as []*bspb.BatteryStats_App
unknown := 1
for _, a := range checkin.GetApp() {
if a.GetName() == "" {
a.Name = proto.String("UNKNOWN_" + strconv.Itoa(unknown))
unknown++
}
as = append(as, a)
}
// Sort by name so that we can display the apps in alphabetical order in the dropdown.
sort.Sort(byName(as))
return as
}
示例2: parseAppStats
func parseAppStats(checkin *bspb.BatteryStats, sensors map[int32]bugreportutils.SensorInfo) []AppStat {
var as []AppStat
bCapMah := checkin.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah()
for _, app := range checkin.GetApp() {
a := AppStat{
DevicePowerPrediction: 100 * float32(app.GetPowerUseItem().GetComputedPowerMah()) / bCapMah,
RawStats: app,
}
if app.GetName() == "" {
app.Name = proto.String(fmt.Sprintf("UNKNOWN_%d", app.GetUid()))
}
// Only add it to AppStat if the CPU field exists and is therefore populated.
if app.Cpu != nil {
a.CPUPowerPrediction = 100 * (app.Cpu.GetPowerMaMs() / (1000 * 60 * 60)) / bCapMah
}
for _, u := range app.GetUserActivity() {
a.UserActivity = append(a.UserActivity, userActivity{
Type: u.GetName().String(),
Count: u.GetCount(),
})
}
for _, s := range app.GetSensor() {
sensor, ok := sensors[s.GetNumber()]
if !ok {
sensor = bugreportutils.SensorInfo{
Name: fmt.Sprintf("unknown sensor (#%d)", s.GetNumber()),
Number: s.GetNumber(),
}
}
sensor.TotalTimeMs = int64(s.GetTotalTimeMsec())
sensor.Count = s.GetCount()
a.Sensor = append(a.Sensor, sensor)
}
as = append(as, a)
}
// Sort by name so that we can display the apps in alphabetical order in the dropdown.
sort.Sort(byName(as))
return as
}
示例3: 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
}