This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lots of code changes for the cseducation week questions. NO DELTAS. D…
…O NOT USE
- Loading branch information
Showing
16 changed files
with
190 additions
and
8 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
@import "variables"; | ||
|
||
.cse-banner { | ||
height: 210px; | ||
width: 700px; | ||
margin: 0px auto; | ||
display: block; | ||
} | ||
|
||
h3.heading { | ||
margin-top: 20px; | ||
} | ||
|
||
.link-section { | ||
margin: 20px 0px 100px 0px; | ||
|
||
h2 { | ||
font-size: 20px; | ||
} | ||
|
||
a:visited { | ||
color: #000000; | ||
} | ||
|
||
a:hover { | ||
color: $hackers-orange; | ||
} | ||
|
||
} | ||
|
||
.question-id, .question-text { | ||
margin-bottom: 15px; | ||
} | ||
|
||
.leaderboard { | ||
margin-bottom: 100px; | ||
|
||
h3 { | ||
margin-bottom: 15px; | ||
} | ||
|
||
p { | ||
margin-bottom: 5px; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class CseducationAnswer < ActiveRecord::Base | ||
|
||
# The number of trivia questions | ||
NUM_QUESTIONS = 4 | ||
|
||
attr_accessible :uniqname, :value, :qid | ||
|
||
def self.persist_answer(cand, ques) | ||
# If the user has already answered, do not double count | ||
return unless CseducationAnswer.find_by_uniqname_and_qid(cand[:uniqname], cand[:qid]).nil? | ||
CseducationAnswer.new({uniqname: cand[:uniqname], value: ques["val"], qid: cand[:qid]}).save | ||
end | ||
|
||
def self.get_leaderboard() | ||
|
||
# Build the ordered results array | ||
results = CseducationAnswer.sum(:value, group: :uniqname).to_a.sort do |e1, e2| | ||
# Check if the sums are equal | ||
if e1[1] == e2[1] | ||
# Use the string ordering | ||
e2[0] <=> e1[0] | ||
else | ||
# Use the number of ones to sort | ||
e1_count = e1[1].to_s.split("").count(1) | ||
e2_count = e2[1].to_s.split("").count(1) | ||
# Use the one with the most ones, else the one with the higher value | ||
e1_count == e2_count ? e2[1] <=> e1[1] : e2_count <=> e1_count | ||
end | ||
end | ||
|
||
# Map the question numbers into question answered - unanswered values | ||
results.map do |e| | ||
# Split the number into a char array | ||
e_new = e[1].to_s.split("").reverse | ||
e_new.concat(Array.new(NUM_QUESTIONS - e_new.count, 0)) if e_new.count < NUM_QUESTIONS | ||
e[1] = e_new.map {|e| e == "1" } | ||
e | ||
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
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,15 @@ | ||
- css_for_head "cseducation" | ||
|
||
%img.cse-banner{src: "/assets/images/cseducation_banner.jpg"} | ||
|
||
%h3.heading.center= "This year's CSEducation Week Puzzles are sponsored by Michigan Hackers!" | ||
%p.center= "To compete, find the 4 puzzles, submit your answers, and score points, all before December 7th." | ||
|
||
.link-section | ||
.col1.spacer | ||
%h2 | ||
%a.col3{href: "/cseducation/question1"}= "Question One" | ||
%h2 | ||
%a.col3{href: "/cseducation/submit"}= "Submit Answers" | ||
%h2 | ||
%a.col3{href: "/cseducation/leaderboard"}= "Leaderboard" |
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,12 @@ | ||
- css_for_head "cseducation" | ||
|
||
.leaderboard | ||
%h3.col2= "Uniqname" | ||
%h3.col2= "Question 1" | ||
%h3.col2= "Question 2" | ||
%h3.col2= "Question 3" | ||
%h3.col2= "Question 4" | ||
- @leaderboard.each do |elem| | ||
%p.col2= elem[0] | ||
- elem[1].each do |is_solved| | ||
%p.col2= is_solved ? "Solved" : "----------" |
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,7 @@ | ||
- css_for_head "cseducation" | ||
|
||
.col10.question-id | ||
%strong= "Question ID" | ||
= "#{@question["qid"]}" | ||
.col10.question-text | ||
%p= @question["txt"] |
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,15 @@ | ||
= form_tag cs_edu_process_path, method: :post do | ||
.row | ||
.col4 | ||
%fieldset | ||
= label :question, :uniqname, class: "line-break" | ||
= text_field :question, :uniqname | ||
%fieldset | ||
= label :question, :qid, "Question ID", class: "line-break" | ||
= text_field :question, :qid | ||
%fieldset | ||
= label :question, :answer, class: "line-break" | ||
= password_field :question, :answer | ||
%fieldset | ||
%input{type: :submit, value: "Submit Your Answer"} | ||
.col6 |
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