This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd76db3
commit ed4af48
Showing
17 changed files
with
510 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
defmodule BranchEngine do | ||
|
||
def analize_branch(repo_dir) do | ||
commits = get_commits_in_branch(repo_dir) | ||
authors = get_authors_in_branch(commits) | ||
frequency = FrequencyEngine.get_frequency(commits) | ||
def analize_branch(repo_dir) do | ||
commits = get_commits_in_branch(repo_dir) | ||
authors = get_authors_in_branch(commits) | ||
frequency = FrequencyEngine.get_frequency(commits) | ||
words = get_words_by_commits(commits) | ||
%Branch{ | ||
commits: commits, | ||
authors: authors, | ||
words: words, | ||
frequency: frequency | ||
} | ||
end | ||
|
||
%Branch{ | ||
commits: commits, | ||
authors: authors, | ||
words: words, | ||
frequency: frequency | ||
} | ||
end | ||
|
||
def get_commits_in_branch(repo_dir) do | ||
repo_dir | ||
|> get_commit_history_string() | ||
|> Utils.get_commits() | ||
|> get_commit_history_string() | ||
|> Utils.get_commits() | ||
end | ||
|
||
def get_commit_history_string(repo_dir) do | ||
{body, 0} = | ||
System.cmd( | ||
"git", | ||
["log", "--all", "--pretty=format:'%h<->%cn<->%ad<->%s%Creset'"], | ||
cd: repo_dir) | ||
System.cmd( | ||
"git", | ||
["log", "--all", "--pretty=format:'%h<->%cn<->%ad<->%s%Creset'"], | ||
cd: repo_dir | ||
) | ||
|
||
body | ||
end | ||
|
||
def get_words_by_commits(commits) do | ||
commits | ||
|> Utils.get_list_of_words_in_commits() | ||
|> Utils.get_words_counters() | ||
|> Utils.get_list_of_words_in_commits() | ||
|> Utils.get_words_counters() | ||
end | ||
|
||
def get_authors_in_branch(commits), do: Utils.get_authors(commits) | ||
def get_authors_in_branch(commits), do: Utils.get_authors(commits) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
defmodule FrequencyEngine do | ||
|
||
def get_frequency(commits) do | ||
frequency_counters = %Frequency{} | ||
update_frequency_counters(commits, frequency_counters) | ||
frequency_counters = %Frequency{} | ||
update_frequency_counters(commits, frequency_counters) | ||
end | ||
|
||
def update_frequency_counters([], frequency_counters), do: frequency_counters | ||
def update_frequency_counters([commit|commits], frequency_counters) do | ||
{day, date_created} = commit.date_created | ||
day_key = get_day_key(day) | ||
current_day = Map.get(frequency_counters, day_key) | ||
hour_key = String.to_atom("hour_#{date_created.hour}") | ||
hour_counter = Map.get(current_day, hour_key) | ||
current_day_updated = Map.put(current_day, hour_key, hour_counter+1) | ||
frequency_counters_updated = Map.put(frequency_counters, day_key, current_day_updated) | ||
update_frequency_counters(commits, frequency_counters_updated) | ||
end | ||
def update_frequency_counters([], frequency_counters), do: frequency_counters | ||
|
||
def update_frequency_counters([commit | commits], frequency_counters) do | ||
{day, date_created} = commit.date_created | ||
day_key = get_day_key(day) | ||
current_day = Map.get(frequency_counters, day_key) | ||
hour_key = String.to_atom("hour_#{date_created.hour}") | ||
hour_counter = Map.get(current_day, hour_key) | ||
current_day_updated = Map.put(current_day, hour_key, hour_counter + 1) | ||
frequency_counters_updated = Map.put(frequency_counters, day_key, current_day_updated) | ||
update_frequency_counters(commits, frequency_counters_updated) | ||
end | ||
|
||
defp get_day_key(day) do | ||
days = | ||
%{"Mon" => :monday, "Tue" => :tuesday, "Wed" => :wednesday, | ||
"Thu" => :thursday, "Fri" => :friday, "Sat" => :saturday, "Sun" => :sunday} | ||
days[day] | ||
end | ||
defp get_day_key(day) do | ||
days = %{ | ||
"Mon" => :monday, | ||
"Tue" => :tuesday, | ||
"Wed" => :wednesday, | ||
"Thu" => :thursday, | ||
"Fri" => :friday, | ||
"Sat" => :saturday, | ||
"Sun" => :sunday | ||
} | ||
|
||
days[day] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
defmodule GitEngine do | ||
|
||
def clone_repo(repo) do | ||
date = :os.system_time(:millisecond) | ||
tmp_dir = "#{System.tmp_dir()}repo-#{date}" | ||
{"", 0} = System.cmd("git", ["clone", repo, tmp_dir]) | ||
tmp_dir | ||
end | ||
|
||
def get_all_branches(repo_dir) do | ||
def get_all_branches(repo_dir) do | ||
{body, 0} = System.cmd("git", ["branch", "--all"], cd: repo_dir) | ||
Utils.get_branches_names(body) | ||
end | ||
Utils.get_branches_names(body) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
defmodule NetworkConsumer do | ||
|
||
@options [recv_timeout: 5000] | ||
|
||
def get(url) do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.