-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontributor_monthly.py
executable file
·56 lines (44 loc) · 1.74 KB
/
contributor_monthly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import datetime as datetime
import os
def organize_monthly(path):
committer_per_month_path = path + 'committer-per-month/'
if not os.path.exists(committer_per_month_path):
os.makedirs(committer_per_month_path)
for file in os.listdir(path):
if file.endswith('.txt'):
this_file = open(os.path.join(path,file))
this_data = this_file.readlines()
committers = collect_contributors(this_data)
organize_and_write_file(committers,committer_per_month_path,str(file))
def collect_contributors(data):
contributors = []
for line in data:
this = line.split('-')
if (len(this) > 1):
date = datetime_it(this[0],this[1],this[2])
contributors.append(date)
return contributors
def datetime_it(day,month,year):
date = datetime.datetime(int(day),int(month),int(year))
return date
def organize_and_write_file(data,folder_path,file_name):
this_file = open(os.path.join(folder_path + file_name),'w')
years = []
for date in data:
if date.year not in years:
years.append(date.year)
months = [[list() for month in range(12)] for year in range(len(years))]
for current_year,current_month_list in zip(years,months):
for current_month_number,month in zip(range(1,13),current_month_list):
for date in data:
if date.year == current_year:
if date.month == current_month_number:
month.append(date.day)
for year,month in zip(years,months):
this_file.write(str(year))
this_file.write('\n')
for month_number, month_data in zip(range(1,13), month):
this_file.write(str(month_number) + '->' + str(len(month_data)))
this_file.write('\n')
contributor_folder_path = raw_input('Please specify the folder where are the data generated by [Committers|Newcomers].sh:')
organize_monthly(contributor_folder_path)