stats

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutOfRange           = 99999
	DaysInLastSixMonths  = 183
	WeeksInLastSixMonths = 26
	HoursInDay           = 24
	DaysInWeek           = 7
)

Constants for time calculations and display

Variables

This section is empty.

Functions

func BuildCols

func BuildCols(keys []int, commits map[int]int) map[int]Column

BuildCols organizes commit data into columns for display in the contribution graph. Each column represents a week, and each cell in the column represents a day.

Parameters:

  • keys: A sorted slice of day indices
  • commits: A map of days to commit counts

Returns:

  • map[int]Column: A map of week numbers to columns of commit counts

func CalculateWeekdayOffset

func CalculateWeekdayOffset() int

CalculateWeekdayOffset calculates an offset value based on the current day of the week. This is used for positioning in the contribution graph.

Returns:

  • int: A value from 0 to 6 representing the day of the week (0=Sunday, 1=Monday, etc.)

func CountDaysSinceDate

func CountDaysSinceDate(date time.Time) int

CountDaysSinceDate calculates the number of days between the given date and today. If the difference is greater than DaysInLastSixMonths, it returns OutOfRange.

Parameters:

  • date: The starting date to count from

Returns:

  • int: The number of days since the given date, or OutOfRange if more than DaysInLastSixMonths

func GetBeginningOfDay

func GetBeginningOfDay(t time.Time) time.Time

GetBeginningOfDay returns a new time.Time with the same date as the input time but with the time set to 00:00:00.

Parameters:

  • t: The time to get the beginning of the day for

Returns:

  • time.Time: A new time.Time representing the beginning of the day

func GetCommitsFromRepo

func GetCommitsFromRepo(email string, path string, commits map[int]int) (map[int]int, error)

GetCommitsFromRepo retrieves commit information from a Git repository. If an email is provided, it filters commits by that email address. If no email is provided, it includes commits from all users. It updates the provided commits map with the count of commits per day.

Parameters:

  • email: The email address to filter commits by (if empty, includes all commits)
  • path: The path to the Git repository
  • commits: A map of days to commit counts to update

Returns:

  • map[int]int: The updated commits map
  • error: An error if any occurred during repository processing

func PrintCell

func PrintCell(val int, today bool, date time.Time, showCommitCount bool, showDaysOfMonth bool)

PrintCell prints a single cell in the contribution graph with the appropriate coloring based on the number of commits and whether it represents today.

Parameters:

  • val: The number of commits for this cell
  • today: Whether this cell represents today
  • date: The date for this cell
  • showCommitCount: Whether to display the number of commits on each cell
  • showDaysOfMonth: Whether to display the days of the month on the graph calendar

func PrintCells

func PrintCells(cols map[int]Column, showCommitCount bool, showDaysOfMonth bool)

PrintCells renders the contribution graph by printing all cells in a grid format. It first prints the month labels, then iterates through each day of the week and each week, printing the appropriate cell for each position.

Parameters:

  • cols: A map of week numbers to columns of commit counts
  • showCommitCount: Whether to display the number of commits on each cell
  • showDaysOfMonth: Whether to display the days of the month on the graph calendar

func PrintCommitsStats

func PrintCommitsStats(commits map[int]int, showCommitCount bool, showDaysOfMonth bool)

PrintCommitsStats displays a visual representation of commit statistics in a calendar-like grid. It processes the commits' map, builds the columns, and prints the cells.

Parameters:

  • commits: A map of days to commit counts
  • showCommitCount: Whether to display the number of commits on each cell
  • showDaysOfMonth: Whether to display the days of the month on the graph calendar

func PrintDayCol

func PrintDayCol(day int)

PrintDayCol prints the day labels on the left side of the contribution graph. It displays the first letter of each day of the week.

Parameters:

  • day: The day index (0-6) to print a label for

func PrintMonths

func PrintMonths()

PrintMonths prints the month labels at the top of the contribution graph. It places month names on columns with the first day of that month.

func ProcessRepositories

func ProcessRepositories(email string, directory string) (map[int]int, error)

ProcessRepositories processes a Git repository and collects commit statistics. If an email is provided, it filters commits by that email address. If no email is provided, it includes commits from all users.

Parameters:

  • email: The email address to filter commits by (if empty, includes all commits)
  • directory: The directory to analyze (should be a Git repository)

Returns:

  • map[int]int: A map of days to commit counts
  • error: An error if any occurred during processing

func SortMapIntoSlice

func SortMapIntoSlice(m map[int]int) []int

SortMapIntoSlice extracts the keys from a map and returns them as a sorted slice.

Parameters:

  • m: The map to extract keys from

Returns:

  • []int: A sorted slice of the map's keys

Types

type Column

type Column []int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL