コード例 #1
0
ファイル: tags.go プロジェクト: logtcn/TMSU
func listAllTags(store *storage.Storage, tx *storage.Tx, showCount, onePerLine bool) error {
	log.Info(2, "retrieving all tags.")

	if showCount {
		count, err := store.TagCount(tx)
		if err != nil {
			return fmt.Errorf("could not retrieve tag count: %v", err)
		}

		fmt.Println(count)
	} else {
		tags, err := store.Tags(tx)
		if err != nil {
			return fmt.Errorf("could not retrieve tags: %v", err)
		}

		if onePerLine {
			for _, tag := range tags {
				fmt.Println(escape(tag.Name, '=', ' '))
			}
		} else {
			tagNames := make([]string, len(tags))
			for index, tag := range tags {
				tagNames[index] = escape(tag.Name, '=', ' ')
			}

			terminal.PrintColumns(tagNames)
		}
	}

	return nil
}
コード例 #2
0
ファイル: info.go プロジェクト: 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
}