func listAllValues(store *storage.Storage, tx *storage.Tx, showCount, onePerLine bool) error { log.Info(2, "retrieving all values.") if showCount { count, err := store.ValueCount(tx) if err != nil { return fmt.Errorf("could not retrieve value count: %v", err) } fmt.Println(count) } else { values, err := store.Values(tx) if err != nil { return fmt.Errorf("could not retrieve values: %v", err) } if onePerLine { for _, value := range values { fmt.Println(escape(value.Name)) } } else { valueNames := make([]string, len(values)) for index, value := range values { valueNames[index] = escape(value.Name) } terminal.PrintColumns(valueNames) } } return nil }
func showStatistics(store *storage.Storage, tx *storage.Tx, colour bool) error { tagCount, err := store.TagCount(tx) if err != nil { return fmt.Errorf("could not retrieve tag count: %v", err) } valueCount, err := store.ValueCount(tx) if err != nil { return fmt.Errorf("could not retrieve value count: %v", err) } fileCount, err := store.FileCount(tx) if err != nil { return fmt.Errorf("could not retrieve file count: %v", err) } fileTagCount, err := store.FileTagCount(tx) if err != nil { return fmt.Errorf("could not retrieve taggings count: %v", err) } var averageTagsPerFile float32 if fileCount > 0 { averageTagsPerFile = float32(fileTagCount) / float32(fileCount) } var averageFilesPerTag float32 if tagCount > 0 { averageFilesPerTag = float32(fileTagCount) / float32(tagCount) } fmt.Println() printInfo("Tags", tagCount, colour) printInfo("Values", valueCount, colour) printInfo("Files", fileCount, colour) printInfo("Taggings", fileTagCount, colour) printInfof("Mean tags per file", "%1.2f", averageTagsPerFile, colour) printInfof("Mean files per tag", "%1.2f", averageFilesPerTag, colour) return nil }