Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cs 2657 Feed our Prediction API #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APP_NAME="Challege Prediction"
GOOGLE_CLIENT_EMAIL=
GOOGLE_KEYFILE=
GOOGLE_PASSPHRASE=
GOOGLE_STORAGE_BUCKET_NAME="cs_prediction"
PREDICTION_DATA_OBJECT="prediction_data.csv"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
/tmp
#/config/*.p12
.DS_Store
.elasticbeanstalk/
.elasticbeanstalk/

.env
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
Expand Down Expand Up @@ -40,6 +38,10 @@ gem 'rvm-capistrano'
# To use debugger
# gem 'debugger'

gem 'foreman'
gem 'unicorn'
gem 'httparty'

gem 'sequel'
gem 'sextant'
gem 'simple_form'
Expand Down
148 changes: 78 additions & 70 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ GEM
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
addressable (2.3.5)
arel (3.0.2)
autoparse (0.3.2)
autoparse (0.3.3)
addressable (>= 2.3.1)
extlib (>= 0.9.15)
multi_json (>= 1.0.0)
bootstrap-sass (2.2.1.0)
bootstrap-sass (2.3.2.1)
sass (~> 3.2)
builder (3.0.4)
capistrano (2.13.5)
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
Expand All @@ -51,66 +51,74 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.4.0)
coffee-script-source (1.6.3)
dotenv (0.8.0)
erubis (2.7.0)
eventmachine (1.0.0)
eventmachine (1.0.3)
execjs (1.4.0)
multi_json (~> 1.0)
extlib (0.9.16)
faraday (0.8.4)
multipart-post (~> 1.1)
google-api-client (0.6.0)
faraday (0.8.8)
multipart-post (~> 1.2.0)
foreman (0.63.0)
dotenv (>= 0.7)
thor (>= 0.13.6)
google-api-client (0.6.4)
addressable (>= 2.3.2)
autoparse (>= 0.3.2)
autoparse (>= 0.3.3)
extlib (>= 0.9.15)
faraday (~> 0.8.4)
jwt (>= 0.1.5)
launchy (>= 2.1.1)
multi_json (>= 1.0.0)
signet (>= 0.4.4)
signet (~> 0.4.5)
uuidtools (>= 2.1.0)
highline (1.6.15)
hike (1.2.1)
i18n (0.6.1)
highline (1.6.19)
hike (1.2.3)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
i18n (0.6.5)
journey (1.0.4)
jquery-rails (2.1.4)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.6)
jwt (0.1.5)
multi_json (>= 1.0)
kgio (2.7.4)
launchy (2.1.2)
json (1.8.0)
jwt (0.1.8)
multi_json (>= 1.5)
kgio (2.8.0)
launchy (2.3.0)
addressable (~> 2.3)
libv8 (3.3.10.4)
libv8 (3.11.8.17)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
mongoid (3.0.17)
activemodel (~> 3.1)
moped (~> 1.2)
mime-types (1.24)
mongoid (3.1.4)
activemodel (~> 3.2)
moped (~> 1.4)
origin (~> 1.0)
tzinfo (~> 0.3.22)
moped (1.3.2)
multi_json (1.5.0)
multipart-post (1.1.5)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.6.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
origin (1.0.11)
moped (1.5.1)
multi_json (1.7.9)
multi_xml (0.5.5)
multipart-post (1.2.0)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.6.8)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
origin (1.1.0)
polyglot (0.3.3)
rack (1.4.4)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.3.2)
rack-protection (1.5.0)
rack
rack-ssl (1.3.2)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
Expand All @@ -129,61 +137,59 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rainbows (4.4.1)
rainbows (4.5.0)
kgio (~> 2.5)
rack (~> 1.1)
unicorn (~> 4.1)
raindrops (0.10.0)
rake (10.0.3)
rdoc (3.12)
unicorn (~> 4.6, >= 4.6.2)
raindrops (0.11.0)
rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
rvm-capistrano (1.2.7)
capistrano (>= 2.0.0)
sass (3.2.5)
sass-rails (3.2.5)
ref (1.0.5)
rvm-capistrano (1.4.4)
capistrano (>= 2.15.4)
sass (3.2.10)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sequel (3.43.0)
sextant (0.1.3)
activesupport (>= 3.2)
sequel (4.1.1)
sextant (0.2.4)
rails (>= 3.2)
signet (0.4.4)
signet (0.4.5)
addressable (>= 2.2.3)
faraday (~> 0.8.1)
jwt (>= 0.1.5)
multi_json (>= 1.0.0)
simple_form (2.0.4)
simple_form (2.1.0)
actionpack (~> 3.0)
activemodel (~> 3.0)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra (1.4.3)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
therubyracer (0.11.4)
libv8 (~> 3.11.8.12)
ref
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.35)
uglifier (1.3.0)
tzinfo (0.3.37)
uglifier (2.1.2)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unicorn (4.4.0)
unicorn (4.6.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
uuidtools (2.1.3)
uuidtools (2.1.4)

PLATFORMS
ruby
Expand All @@ -194,7 +200,9 @@ DEPENDENCIES
capistrano-ext
coffee-rails (~> 3.2.1)
eventmachine
foreman
google-api-client
httparty
jquery-rails
mongoid
rails (= 3.2.9)
Expand All @@ -205,6 +213,6 @@ DEPENDENCIES
sextant
simple_form
sinatra
sqlite3-ruby
therubyracer
uglifier (>= 1.0.3)
unicorn
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT
43 changes: 26 additions & 17 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
require 'csv'
class UploadsController < ApplicationController
def index
@upload = Upload.new
@challenge_participants = (DB[:challenge_participants] if DB.table_exists?(:challenge_participants)) || []
@challenges = (DB[:challenges] if DB.table_exists?(:challenges)) || []
@challenge_categories = (DB[:challenge_categories] if DB.table_exists?(:challenge_categories)) || []
@challenge_participants = PredictionData.session[:challenge_participants].find
@challenges = PredictionData.session[:challenges].find
@challenge_platforms = PredictionData.session[:challenge_platforms].find
@challenge_technologies = PredictionData.session[:challenge_technologies].find
end

def challenge_categories
data = CSV.new params[:upload][:data].tempfile
PredictionData.import_challenge_categories(data.to_hash)
def challenge_platforms
data = HashableCSV.new params[:upload][:data].tempfile
PredictionData.import_challenge_platforms(data.to_hash)
redirect_to uploads_path
end

def challenge_technologies
data = HashableCSV.new params[:upload][:data].tempfile
PredictionData.import_challenge_technologies(data.to_hash)
redirect_to uploads_path
end

def challlenges
data = CSV.new params[:upload][:data].tempfile
data = HashableCSV.new params[:upload][:data].tempfile
PredictionData.import_challenges(data.to_hash)
redirect_to uploads_path
end

def challenge_participants
data = CSV.new params[:upload][:data].tempfile
data = HashableCSV.new params[:upload][:data].tempfile
PredictionData.import_challenge_participants(data.to_hash)
redirect_to uploads_path, notice: 'Upload completed'
end
Expand All @@ -31,12 +37,15 @@ def generate_prediction_data
PredictionData.generate
send_data PredictionData.to_csv, filename: 'prediction_data.csv'
end
end

class CSV
def to_hash
headers = self.shift.map {|i| i.to_s }
string_data = self.map {|row| row.map {|cell| cell.to_s } }
array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] }
end
end
def upload_prediction_data
PredictionData.delete_all
PredictionData.generate

gs = GoogleStorage.new
gs.upload_prediction_data(PredictionData.to_csv)

redirect_to root_path, notice: 'Successfully uploaded Prediction Data'
end

end
Loading