Ejemplo n.º 1
0
Archivo: info.go Proyecto: logtcn/TMSU
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
}