Skip to content

A short gitlas Tutorial

About gitlas :

gitlas is a library aimed at analysts/developers who want to get more out of git logs. Currently these git logs have potential to potray more statistics.
gitlas tries to make more out of the git log data and one of the simple ways is to convert the existing data in JSON objects which can be conviniently stored and utilized for data analysis and visualizations.

Pre steps:

  • get a copy of gitlog data in a text file using the command
git log >gitlog.txt
  • or use clip to copy the contents to cliboard
git log > xclip
  • Install gitlas and other libraries(if not installed or you intend to use)
pip install gitlas

Lets Begin a brief tutorial

1. import the essential libraries (note: gitlas is a standalone library)

In:

from gitlas import Log,JSONExport 
import matplotlib.pyplot as plt
import pandas as pd

2. Create a Log Object with the filename and the file source type to initialize the constructor

In:

data=Log("gitlog.txt","git")

total merge counts can be calculated using Log.mergeCounts() method

In:

data.mergeCounts()
Out:

3

Total Commit counts can be calculated using Log.commitCounts() method

In:

data.commitCounts()
Out:

26

To find the total duration of log use Log.activeDevelopmentDuration() method

In:

data.activeDevelopmentDuration()
Out:

'7 days, 12:30:36'

3. An overview of the statistics in a given year

Generating yearly statistics using Log.yearStats() method

This metric will return a dictionary of the stats

In:

data.yearStats(2020)
Out:

{'Commits': 26,
 'Mergers': 3,
 'ActiveMonths': ['Jun', 'May'],
 'MonthlyCommitReports': {'Jun': 8, 'May': 18},
 'MonthlyMergerReports': {'Jun': 0, 'May': 3}}

4. Viewing day wise statistics and plotting it using Matplotlib

daywise statistics work in a different manner and will can be used to obtain certain stats use Log.specificWeekDayStats()

This kind of statistic can be useful for finding the day with most commits and merges for your project.

In:

data.specificWeekDayStats("Sun") #for a single day
Out:

{'Commits': 0, 'Mergers': 0}

In:

days=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

In:

day_wise_report={}

In:

for i in days:
    day_wise_report[i]=data.specificWeekDayStats(i)

In:

day_wise_report # Report of all days in a week
Out:

{'Mon': {'Commits': 3, 'Mergers': 0},
 'Tue': {'Commits': 4, 'Mergers': 0},
 'Wed': {'Commits': 7, 'Mergers': 0},
 'Thu': {'Commits': 11, 'Mergers': 3},
 'Fri': {'Commits': 0, 'Mergers': 0},
 'Sat': {'Commits': 1, 'Mergers': 0},
 'Sun': {'Commits': 0, 'Mergers': 0}}

In:

dates=day_wise_report.keys()
commitvals=[]
mergevals=[]

In:

for i in days:
    commitvals.append(day_wise_report[i]["Commits"])
    mergevals.append(day_wise_report[i]["Mergers"])

In:

fig,ax = plt.subplots() #Plotting Bar Graphs
ax.bar(dates,commitvals)
ax.bar(dates,mergevals)
Out:

<BarContainer object of 7 artists>

png

5. Lets compare which Author Contributes the most and visualize a pie chart

Author wise data is useful to see the stats of contributions from different contributors/Authors using Log.authorStats()

In:

author_wise_data=data.authorStats()
author_report={}
names=[]
commits=[]
merges=[]
explode=[0,0.25]
for i in author_wise_data.values():
    names.append(i["Name"])
    commits.append(i["Commits"])
    merges.append(i["Mergers"])

In:

fig,bx = plt.subplots()
bx.pie(commits,explode=explode,labels=names,shadow=True, startangle=90)
Out:

([<matplotlib.patches.Wedge at 0x7f25985bafd0>,
  <matplotlib.patches.Wedge at 0x7f25985486d8>],
 [Text(-0.8233618545088074, -0.7294348884854751, 'Abhi-1U'),
  Text(1.0104895487153542, 0.8952155449594471, 'AbhishekUlayil')])

png

6. Lets Look at the activities of May Month in a tabular format using pandas

specific Month reports can be accessed by Log.singleMonthStats()

This method will return few values of the specific month in the year provided

In:

MayData=data.singleMonthStats("May",2020)
MayData
Out:

{'Commits': 18, 'Mergers': 3}

In:

pd.DataFrame(MayData.values(),index=["Commits","Merges"],columns=['May'])
Out:

May
Commits 18
Merges 3

7. Exporting Log files /Meta Data as JSON Format

gitlas.JSONExport() is built for that

In:

JSONExport(data,"GitExport.json")
Out:

Export Of Object Data Successfull!