Skip to content

Commit

Permalink
do not render hz if no messages (#1006)
Browse files Browse the repository at this point in the history
### Public-Facing Changes

For `mcap info`, removes channel hz display if there are no or one
messages in a channel. This avoids displaying an ugly `NaN` or `Inf`.

Before:
```
j@192-168-1-108 python % mcap info ~/this.mcap                                
library:   python mcap 1.1.1                                        
profile:                                                            
messages:  1                                                        
duration:  0s                                                       
start:     2023-11-02T05:34:10.165983+11:00 (1698863650.165983000)  
end:       2023-11-02T05:34:10.165983+11:00 (1698863650.165983000)  
compression:
        zstd: [1/1 chunks] [234.00 B/153.00 B (34.62%)] 
channels:
        (1) sample_topic  0 msgs (NaN Hz)    : sample [jsonschema]  
        (2) sample_topic  1 msgs (+Inf Hz)   : sample [jsonschema]  
attachments: 0
metadata: 0
```

After:
```
j@192-168-1-108 mcap % ./bin/mcap info ~/this.mcap                          
library:   python mcap 1.1.1                                        
profile:                                                            
messages:  1                                                        
duration:  0s                                                       
start:     2023-11-02T05:34:10.165983+11:00 (1698863650.165983000)  
end:       2023-11-02T05:34:10.165983+11:00 (1698863650.165983000)  
compression:
        zstd: [1/1 chunks] [234.00 B/153.00 B (34.62%)] 
channels:
        (1) sample_topic  0 msgs   : sample [jsonschema]  
        (2) sample_topic  1 msgs   : sample [jsonschema]  
attachments: 0
metadata: 0
```
  • Loading branch information
james-rms authored Nov 1, 2023
1 parent 526626f commit 4ab424e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions go/cli/mcap/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ func printInfo(w io.Writer, info *mcap.Info) error {
}
if info.Statistics != nil {
channelMessageCount := info.Statistics.ChannelMessageCounts[chanID]
frequency := 1e9 * float64(channelMessageCount) / float64(end-start)
row = append(row, fmt.Sprintf("%*d msgs (%.2f Hz)", maxCountWidth, channelMessageCount, frequency))
if channelMessageCount > 1 {
frequency := 1e9 * float64(channelMessageCount) / float64(end-start)
row = append(row, fmt.Sprintf("%*d msgs (%.2f Hz)", maxCountWidth, channelMessageCount, frequency))
} else {
row = append(row, fmt.Sprintf("%*d msgs", maxCountWidth, channelMessageCount))
}
}
switch {
case schema != nil:
Expand Down

0 comments on commit 4ab424e

Please sign in to comment.