-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: results.txt
- Loading branch information
Showing
25 changed files
with
9,158 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
cache/ | ||
test/cache/ |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the app.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << '.' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'memcache' | ||
|
||
class Cache | ||
|
||
def self.cache_dir | ||
@@cache_dir ||= 'cache' | ||
end | ||
|
||
def self.fetch(key, &block) | ||
@@cache ||= {} | ||
|
||
# Return the cached value if already in memory. | ||
return @@cache[key] unless @@cache[key].nil? | ||
|
||
# Try to load from file. | ||
@@cache[key] = File.open(File.join(cache_dir, key), 'rb'){ |io| Marshal.load(io) } rescue nil | ||
return @@cache[key] unless @@cache[key].nil? | ||
|
||
# Barring all else, perform the operation to obtain value to cache. | ||
@@cache[key] = block.call | ||
File.open(File.join(cache_dir, key), 'wb'){ |f| Marshal.dump(@@cache[key], f) } | ||
|
||
@@cache[key] | ||
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,65 +1,78 @@ | ||
require 'rubygems' | ||
require 'ai4r' | ||
require 'memoize' | ||
|
||
require 'repository' | ||
require 'watcher' | ||
require 'cache' | ||
|
||
class DataLoader | ||
|
||
def self.load_watchings(data_dir='data') | ||
data_labels = ['user_id', 'repo_id'] | ||
data_items = [] | ||
def self.load_watchings | ||
Cache.fetch('watchings') do | ||
data_labels = ['user_id', 'repo_id'] | ||
data_items = [] | ||
|
||
IO.foreach(File.join(data_dir, 'data.txt')) do |line| | ||
data_items << line.strip.split(':') | ||
end | ||
IO.foreach(File.join(data_dir, 'data.txt')) do |line| | ||
data_items << line.strip.split(':') | ||
end | ||
|
||
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items) | ||
data_set | ||
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items) | ||
data_set | ||
end | ||
end | ||
|
||
def self.load_repositories(data_dir='data') | ||
repositories = {} | ||
|
||
relationships = {} | ||
def self.load_repositories | ||
Cache.fetch('repositories') do | ||
@@repositories ||= {} | ||
return @@repositories unless @@repositories.empty? | ||
|
||
IO.foreach(File.join(data_dir, 'repos.txt')) do |line| | ||
repo_id, repo_data = line.strip.split(':') | ||
name, created_at, parent_id = repo_data.split(',') | ||
relationships = {} | ||
|
||
# Add the repository to the result hash. | ||
repositories[repo_id] = Repository.new(repo_id, name, created_at) | ||
IO.foreach(File.join(data_dir, 'repos.txt')) do |line| | ||
repo_id, repo_data = line.strip.split(':') | ||
name, created_at, parent_id = repo_data.split(',') | ||
|
||
# Keep track of parent-child relationships. | ||
relationships[repo_id] = parent_id unless parent_id.nil? | ||
end | ||
# Add the repository to the result hash. | ||
@@repositories[repo_id] = Repository.new(repo_id, name, created_at) | ||
|
||
# Now that all the repositories have been loaded, establish any parent-child relationships. | ||
relationships.each do |child_id, parent_id| | ||
repositories[child_id].parent = repositories[parent_id] | ||
end | ||
# Keep track of parent-child relationships. | ||
relationships[repo_id] = parent_id unless parent_id.nil? | ||
end | ||
|
||
# Load in the watchers. | ||
watchers = {} | ||
IO.foreach(File.join(data_dir, 'data.txt')) do |line| | ||
user_id, repo_id = line.strip.split(':') | ||
watcher = watchers[user_id] || Watcher.new(user_id) | ||
watchers[user_id] = watcher | ||
repositories[repo_id].watchers << watcher | ||
end | ||
# Now that all the repositories have been loaded, establish any parent-child relationships. | ||
relationships.each do |child_id, parent_id| | ||
@@repositories[child_id].parent = @@repositories[parent_id] | ||
end | ||
|
||
repositories | ||
# Load in the watchers. | ||
watchers = {} | ||
IO.foreach(File.join(data_dir, 'data.txt')) do |line| | ||
user_id, repo_id = line.strip.split(':') | ||
watcher = watchers[user_id] || Watcher.new(user_id) | ||
watchers[user_id] = watcher | ||
@@repositories[repo_id].watchers << watcher | ||
end | ||
|
||
@@repositories | ||
end | ||
end | ||
|
||
def self.load_predictings(data_file='data/test.txt') | ||
data_labels = ['user_id'] | ||
data_items = [] | ||
def self.load_predictings | ||
Cache.fetch('predictings') do | ||
data_labels = ['user_id'] | ||
data_items = [] | ||
|
||
IO.foreach(data_file) do |line| | ||
data_items << [line.strip] | ||
IO.foreach(File.join(data_dir, 'test.txt')) do |line| | ||
data_items << [line.strip] | ||
end | ||
|
||
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items) | ||
data_set | ||
end | ||
end | ||
|
||
data_set = Ai4r::Data::DataSet.new(:data_labels => data_labels, :data_items => data_items) | ||
data_set | ||
def self.data_dir | ||
@@data_dir ||= 'data' | ||
end | ||
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
Oops, something went wrong.