student_progress 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 364b785b9683aa474e8dfdfdd8b5016877042155b61dbb9a2ea1d2bc11c5c7c4
4
+ data.tar.gz: 958a8434d01d1e491b03af4d21175237e3753f36a7deda63836accc01bbaf2b9
5
+ SHA512:
6
+ metadata.gz: 6e05b7180e76f426cecbf2978efe99a0d0921391031a8a21de6399157ae4cae61b69b9f8b0593f3ec988098f4e4fa613a7d77da412c74efa1f75ca94cb24ffef
7
+ data.tar.gz: 446aa1937aac0ed6ac2f11fe2e571d7506265b4389c25f666a49f77c04d725208ef2964d144ef8f434f7f864133fa057d2336f63039ec9c698e25659c1fe2747
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ usernames
10
+ student_progress.db
11
+ results.data
12
+ test.data
13
+ ignore/*
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dakotaleemusic@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in student_progress.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ student_progress (0.1.0)
5
+ json
6
+ nokogiri
7
+ poltergeist
8
+ sequel
9
+ sqlite3
10
+ terminal-table
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ addressable (2.5.2)
16
+ public_suffix (>= 2.0.2, < 4.0)
17
+ capybara (3.3.1)
18
+ addressable
19
+ mini_mime (>= 0.1.3)
20
+ nokogiri (~> 1.8)
21
+ rack (>= 1.6.0)
22
+ rack-test (>= 0.6.3)
23
+ xpath (~> 3.1)
24
+ cliver (0.3.2)
25
+ coderay (1.1.2)
26
+ diff-lcs (1.3)
27
+ gem-release (2.0.1)
28
+ json (2.1.0)
29
+ method_source (0.9.0)
30
+ mini_mime (1.0.0)
31
+ mini_portile2 (2.3.0)
32
+ nokogiri (1.8.4)
33
+ mini_portile2 (~> 2.3.0)
34
+ poltergeist (1.18.1)
35
+ capybara (>= 2.1, < 4)
36
+ cliver (~> 0.3.1)
37
+ websocket-driver (>= 0.2.0)
38
+ pry (0.11.3)
39
+ coderay (~> 1.1.0)
40
+ method_source (~> 0.9.0)
41
+ public_suffix (3.0.2)
42
+ rack (2.0.5)
43
+ rack-test (1.0.0)
44
+ rack (>= 1.0, < 3)
45
+ rake (10.5.0)
46
+ rspec (3.7.0)
47
+ rspec-core (~> 3.7.0)
48
+ rspec-expectations (~> 3.7.0)
49
+ rspec-mocks (~> 3.7.0)
50
+ rspec-core (3.7.1)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-expectations (3.7.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-mocks (3.7.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.7.0)
58
+ rspec-support (3.7.1)
59
+ sequel (5.10.0)
60
+ sqlite3 (1.3.13)
61
+ terminal-table (1.8.0)
62
+ unicode-display_width (~> 1.1, >= 1.1.1)
63
+ unicode-display_width (1.4.0)
64
+ websocket-driver (0.7.0)
65
+ websocket-extensions (>= 0.1.0)
66
+ websocket-extensions (0.1.3)
67
+ xpath (3.1.0)
68
+ nokogiri (~> 1.8)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler (~> 1.16)
75
+ gem-release
76
+ pry
77
+ rake (~> 10.0)
78
+ rspec (~> 3.0)
79
+ student_progress!
80
+
81
+ BUNDLED WITH
82
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dakota Martinez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # StudentProgress
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/student_progress`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'student_progress'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install student_progress
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DakotaLMartinez/student_progress. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the StudentProgress project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DakotaLMartinez/student_progress/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative "../lib/student_progress"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/student_progress"
4
+
5
+ StudentProgress::CLI.new.call
@@ -0,0 +1,206 @@
1
+ class StudentProgress::CLI
2
+ def call
3
+ puts "Hello from CLI"
4
+ prompt_for_login
5
+ StudentProgress::Scraper.scrape_lessons
6
+ main_menu
7
+ goodbye
8
+ end
9
+
10
+ def prompt_for_login
11
+ puts "Log in to your learn.co account:"
12
+ print "Email: "
13
+ email = gets.strip
14
+ puts "\n"
15
+ print "Password: "
16
+ password = STDIN.noecho(&:gets).chomp
17
+ StudentProgress::Scraper.login_user(email, password)
18
+ end
19
+
20
+ def main_menu
21
+ @input = nil
22
+ @goal = nil
23
+ @selected_cohort = nil
24
+ list_choices
25
+ while @input != "exit"
26
+ puts "type 'exit' at any point to quit or 'menu' to see your options"
27
+ @input = gets.strip
28
+ if @input == 'menu'
29
+ list_choices
30
+ elsif @input == '1'
31
+ list_cohorts
32
+ elsif @input == '2'
33
+ prompt_for_cohort_name
34
+ elsif @input == '3'
35
+ prompt_for_goal
36
+ elsif @input == '4'
37
+ prompt_for_reports
38
+ elsif @input == 'exit'
39
+ break
40
+ elsif @input == 'debug'
41
+ binding.pry
42
+ else
43
+ puts "Whoops! I didn't understand that"
44
+ list_choices
45
+ end
46
+ end
47
+ end
48
+
49
+ def list_choices
50
+ puts "Choose an option below by number"
51
+ puts "1. Select Cohort"
52
+ puts "2. Add Cohort"
53
+ puts "3. Set goal for the week"
54
+ puts "4. To view a list of past reports"
55
+ puts "'exit' to leave the program"
56
+ puts "type 'menu' at any point if you'd like to see these options again"
57
+ end
58
+
59
+ def list_cohorts
60
+ @selected_cohort = nil
61
+ until @selected_cohort || @input == "exit"
62
+ puts "Please select the cohort you'd like to view details for"
63
+ StudentProgress::Cohort.all.each.with_index(1) do |cohort, index|
64
+ puts "#{index}. #{cohort.name}"
65
+ end
66
+ @input = gets.strip
67
+ if @input.to_i > 0 && @input.to_i <= StudentProgress::Cohort.count
68
+ @selected_cohort = StudentProgress::Cohort.all[@input.to_i - 1]
69
+ elsif @input == "exit" || @input == "back"
70
+ return
71
+ else
72
+ puts "Whoops! Didn't understand that input"
73
+ end
74
+ end
75
+ display_students
76
+ end
77
+
78
+ def prompt_for_cohort_by_number
79
+
80
+ end
81
+
82
+ def prompt_for_cohort_name
83
+ puts "Please enter the name of the cohort you'd like to create"
84
+ name = gets.chomp
85
+ @new_cohort = StudentProgress::Cohort.find_or_create(name: name)
86
+ prompt_for_usernames
87
+ end
88
+
89
+ def prompt_for_usernames
90
+ puts "Please enter the GitHub usernames for the students you'd like info about (separated by commas)"
91
+ usernames = gets.chomp.split(',').map(&:strip)
92
+ puts "Hang on a sec, adding #{usernames.count} students"
93
+ @new_cohort.add_students(usernames)
94
+ puts "All done!"
95
+ end
96
+
97
+ def prompt_for_goal
98
+ @goal = nil
99
+ puts "Which topic should students be working in at the end of the week?"
100
+ StudentProgress::Topic.all.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
101
+ @input = gets.strip
102
+ if @input == "exit"
103
+ return
104
+ elsif @input.to_i <= 0
105
+ puts "Make sure you enter a number in range"
106
+ prompt_for_goal
107
+ elsif topic = StudentProgress::Topic.all[@input.to_i-1]
108
+ puts "Great! We'll be looking within #{topic.title}"
109
+ else
110
+ puts "Whoops! Don't have that option"
111
+ prompt_for_goal
112
+ end
113
+ while @input != "exit" && @goal.nil?
114
+ puts "Which unit should students finish by the end of the week?"
115
+ topic.units.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
116
+ @input = gets.strip
117
+ if @input == "exit"
118
+ return
119
+ elsif @input.to_i <= 0
120
+ puts "Make sure you enter a number in range"
121
+ prompt_for_goal
122
+ elsif unit = topic.units[@input.to_i-1]
123
+ puts "Great! We'll set the goal for the week"
124
+ @goal = StudentProgress::Lesson.progress_when_unit_complete(unit.title)
125
+ else
126
+ puts "Whoops! Don't have that option"
127
+ end
128
+ end
129
+ end
130
+
131
+ def display_students
132
+ output = []
133
+ now = DateTime.now
134
+ output << now.strftime('%b %e, %Y %l:%M %p')
135
+ @selected_cohort ||= StudentProgress::Student.all
136
+ @selected_cohort.run_progress_report
137
+ if @goal
138
+ output << "\n"
139
+ output << "Students should #{@goal[:goal]} by the end of the week"
140
+ output << "To do that, they'll have completed #{@goal[:lessons]} lessons and #{@goal[:labs]} labs"
141
+ end
142
+ headers = ['Student Name', 'Current Lab', 'Lessons', 'Labs']
143
+ report = @selected_cohort.progress_reports.last
144
+ rows = report.student_reports.collect.with_index(1) do |student_report|
145
+ [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
146
+ end
147
+ table = Terminal::Table.new headings: headers, rows: rows
148
+ output << table
149
+
150
+ if @goal
151
+ split_by_progress = report.on_track(@goal, @selected_cohort)
152
+ on_track = split_by_progress[:on_track].collect.with_index(1) do |student_report|
153
+ [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
154
+ end
155
+ behind = split_by_progress[:behind].collect.with_index(1) do |student_report|
156
+ [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
157
+ end
158
+ ahead = split_by_progress[:ahead].collect.with_index(1) do |student_report|
159
+ [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
160
+ end
161
+ behind_table = Terminal::Table.new headings: headers, rows: behind
162
+ on_track_table = Terminal::Table.new headings: headers, rows: on_track
163
+ ahead_table = Terminal::Table.new headings: headers, rows: ahead
164
+ output << "BEHIND"
165
+ output << behind_table
166
+ output << "ON TRACK"
167
+ output << on_track_table
168
+ output << "Ahead"
169
+ output << ahead_table
170
+ end
171
+ report.content = output.join("\n")
172
+ report.save
173
+ puts output
174
+ end
175
+
176
+ def prompt_for_reports
177
+ list_previous_reports
178
+
179
+ @input = nil
180
+ until @input == "exit" || @input == "back"
181
+ puts "Enter the number of the report you'd like to view (type 'back' to return to main menu)"
182
+ puts "You can also type 'list' to see the list of reports again"
183
+ @input = gets.strip
184
+ if DB[:progress_reports].first(id: @input.to_i)
185
+ puts DB[:progress_reports].first(id: @input.to_i)[:content]
186
+ elsif @input == "list"
187
+ list_previous_reports
188
+ elsif @input == "exit" || @input == "back"
189
+ break
190
+ else
191
+ put "Whoops! I didn't understand that."
192
+ end
193
+ end
194
+ end
195
+
196
+ def list_previous_reports
197
+ DB[:progress_reports].each do |p|
198
+ puts "#{p[:id]}. #{p[:created_at].strftime('%b %e, %Y %l:%M %p')}" if p[:created_at]
199
+ end
200
+ end
201
+
202
+ def goodbye
203
+ puts "\n"
204
+ puts "Thanks for using the Student Tracker CLI! See you next time!!!"
205
+ end
206
+ end
@@ -0,0 +1,15 @@
1
+ class StudentProgress::Cohort < Sequel::Model
2
+ one_to_many :students
3
+ one_to_many :progress_reports
4
+ def add_students(usernames)
5
+ usernames.each do |username|
6
+ student = StudentProgress::Student.find_or_create(github_username: username)
7
+ student.cohort_id = self.id
8
+ student.save
9
+ end
10
+ end
11
+
12
+ def run_progress_report
13
+ StudentProgress::Scraper.scrape_progress(self)
14
+ end
15
+ end
@@ -0,0 +1,99 @@
1
+ class StudentProgress::Lesson
2
+ attr_accessor :title, :content_type, :repo, :id
3
+ attr_reader :unit
4
+
5
+ SECTIONS = {}
6
+
7
+ @@all = []
8
+
9
+ def self.all
10
+ @@all
11
+ end
12
+
13
+ def self.create_from_hash(hash)
14
+ new(hash).save
15
+ end
16
+
17
+ def self.find_by_id(id)
18
+ all.find {|l| l.id == id}
19
+ end
20
+
21
+ def self.pre_cli
22
+ pre_cli_end = nil
23
+ StudentProgress::Lesson.all.each_with_index do |lesson, index|
24
+ if lesson.id == 32164
25
+ pre_cli_end = index
26
+ end
27
+ end
28
+ result = StudentProgress::Lesson.all[0..pre_cli_end]
29
+ end
30
+
31
+ def self.build_section_hash
32
+ ordinal = 0
33
+ self.all.each do |lesson|
34
+ if !SECTIONS[lesson.unit.topic.title]
35
+ SECTIONS[lesson.unit.topic.title] = {}
36
+ end
37
+ if !SECTIONS[lesson.unit.topic.title][lesson.unit.title]
38
+ SECTIONS[lesson.unit.topic.title][lesson.unit.title] = {
39
+ "Readme" => lesson.content_type == "Readme" ? 1 : 0,
40
+ "Lab" => lesson.content_type == "Lab" ? 1 : 0,
41
+ "Project" => lesson.content_type == "Project" ? 1 : 0,
42
+ "ordinal" => ordinal
43
+ }
44
+ ordinal += 1
45
+ else
46
+ SECTIONS[lesson.unit.topic.title][lesson.unit.title][lesson.content_type] += 1
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.unit_from_lesson_title(lesson_title)
52
+ lesson = @@all.find{ |l| l.title == lesson_title}
53
+ lesson ? lesson.unit.title : "couldn't find that lesson"
54
+ end
55
+
56
+ def self.progress_when_unit_complete(unit_title)
57
+ lessons = 0
58
+ labs = 0
59
+ all.find do |lesson|
60
+ lessons += 1
61
+ if lesson.content_type == "Lab"
62
+ labs += 1
63
+ end
64
+ # when the next lesson is on a different unit we're at the end
65
+ lesson.unit.title == unit_title && all[lessons] && all[lessons].unit.title != unit_title
66
+ end
67
+ {
68
+ goal: "Complete #{unit_title}",
69
+ lessons: lessons,
70
+ labs: labs
71
+ }
72
+ end
73
+
74
+ def self.progress_when_topic_complete(topic_title)
75
+ topic = StudentProgress::Topic.find_by_title(topic_title)
76
+ progress_when_unit_complete(topic.units.last.title)
77
+ end
78
+
79
+ def initialize(attrs = {})
80
+ attrs.each do |attr, value|
81
+ self.send("#{attr}=", value)
82
+ end
83
+ end
84
+
85
+ def save
86
+ @@all << self
87
+ self
88
+ end
89
+
90
+ def topic
91
+ @unit && @unit.topic
92
+ end
93
+
94
+ def unit=(unit)
95
+ @unit = unit
96
+ unit.add_lesson(self)
97
+ @unit
98
+ end
99
+ end
@@ -0,0 +1,17 @@
1
+ class StudentProgress::ProgressReport < Sequel::Model
2
+ one_to_many :student_reports
3
+
4
+ def on_track(labs_goal, cohort=nil)
5
+ result = {}
6
+ result[:on_track] = student_reports.select do |report|
7
+ labs_goal[:labs] - report.labs_complete <= 5 && (cohort.nil? || report.student.cohort == cohort)
8
+ end
9
+ result[:behind] = student_reports.select do |report|
10
+ labs_goal[:labs] - report.labs_complete > 5 && (cohort.nil? || report.student.cohort == cohort)
11
+ end
12
+ result[:ahead] = student_reports.select do |report|
13
+ labs_goal[:labs] - report.labs_complete <= -5 && (cohort.nil? || report.student.cohort == cohort)
14
+ end
15
+ result
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ class StudentProgress::Scraper
2
+ attr_accessor :first_name, :last_name, :profile_url, :current_lab,
3
+ :total_labs_complete, :total_lessons_complete
4
+ def self.scrape_progress(cohort)
5
+ print "#students loaded: "
6
+ report = StudentProgress::ProgressReport.create(created_at: DateTime.now, cohort_id: cohort.id)
7
+ cohort.students.collect do |s|
8
+ s.github_username
9
+ end.each.with_index(1) do |username, index|
10
+ @@session.visit("https://learn.co/#{username}")
11
+ student = StudentProgress::Student.find_or_create(
12
+ github_username: username
13
+ )
14
+ student.first_name = @@session.first('.media-block__content--fill').text.split("\n").first.split(' ').first
15
+ student.last_name = @@session.first('.media-block__content--fill').text.split("\n").first.split(' ').slice(1)
16
+ student.save
17
+ StudentProgress::StudentReport.create(
18
+ current_lab: @@session.find('h4 a').text,
19
+ lessons_complete: @@session.all('.flex-grid__item__stretcher h3.heading').map{|n| n.text}[1].split(' / ').first.to_i,
20
+ created_at: DateTime.now,
21
+ labs_complete: @@session.all('.flex-grid__item__stretcher h3.heading').map{|n| n.text}[3].split(' / ').first.to_i,
22
+ student_id: student.id,
23
+ progress_report_id: report.id
24
+ )
25
+
26
+ print "#{index}.."
27
+ end
28
+ puts "Done!"
29
+ end
30
+
31
+ def self.login_user(email, password)
32
+ @@session = Capybara::Session.new(:poltergeist)
33
+
34
+ @@session.visit('https://learn.co')
35
+ @@session.fill_in "user-email", with: email
36
+ @@session.fill_in "user-password", with: password
37
+ puts "Signing in now..."
38
+ sleep 0.5
39
+ @@session.click_button "Sign in"
40
+ end
41
+
42
+ def self.scrape_lessons
43
+ doc = Nokogiri::HTML(@@session.body)
44
+ script = doc.css('script')[8].text
45
+ data = script.gsub("\n//<![CDATA[",'').gsub("//]]>",'')
46
+ match_data = /track_nav_data=(.+);/.match(data)
47
+ string = match_data.captures.first.split(';').first
48
+ hash = JSON.parse(string)
49
+ hash['topics'].each.with_index(1) do |topic_hash, index|
50
+
51
+ topic = StudentProgress::Topic.create_from_hash({
52
+ title: topic_hash['title'],
53
+ id: topic_hash['id']
54
+ })
55
+ topic_hash['units'].each do |unit_hash|
56
+ unit = StudentProgress::Unit.create_from_hash({
57
+ title: unit_hash['title'],
58
+ id: unit_hash['id'],
59
+ topic: topic
60
+ })
61
+ unit_hash['lessons'].each do |lesson_hash|
62
+ lesson = StudentProgress::Lesson.create_from_hash({
63
+ id: lesson_hash['id'],
64
+ title: lesson_hash['title'],
65
+ content_type: lesson_hash['content_type'],
66
+ repo: "https://github.com/#{lesson_hash['github_repo_name']}",
67
+ unit: unit
68
+ })
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,26 @@
1
+ class StudentProgress::Student < Sequel::Model
2
+ many_to_one :cohort
3
+ one_to_many :student_reports
4
+
5
+ def current_lab
6
+ student_reports.last.current_lab
7
+ end
8
+
9
+ def full_name
10
+ "#{first_name} #{last_name}"
11
+ end
12
+
13
+ def distance_to_goal(goal)
14
+ current_index = StudentProgress::Lesson.all.index { |l| l.title == current_lab }
15
+ goal_index = StudentProgress::Lesson.all.index { |l| l.title == goal }
16
+ distance = {
17
+ "Readme" => 0,
18
+ "Lab" => 0,
19
+ "Project" => 0
20
+ }
21
+ StudentProgress::Lesson.all[current_index..goal_index].each do |l|
22
+ distance[l.content_type] += 1
23
+ end
24
+ distance
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ class StudentProgress::StudentReport < Sequel::Model
2
+ many_to_one :progress_report
3
+ many_to_one :student
4
+
5
+ def student_name
6
+ self.student && self.student.full_name
7
+ end
8
+ end
@@ -0,0 +1,59 @@
1
+ class StudentProgress::Topic
2
+ attr_accessor :title, :id
3
+ attr_reader :units
4
+
5
+ @@all = []
6
+
7
+ def self.all
8
+ @@all
9
+ end
10
+
11
+ def self.create_from_hash(hash)
12
+ new(hash).save
13
+ end
14
+
15
+ def self.find_by_title(title)
16
+ all.find{|t| t.title == title}
17
+ end
18
+
19
+ def initialize(attrs = {})
20
+ attrs.each do |attr, value|
21
+ self.send("#{attr}=", value)
22
+ end
23
+ @units = []
24
+ end
25
+
26
+ def save
27
+ @@all << self
28
+ self
29
+ end
30
+
31
+ def add_unit(unit)
32
+ @units << unit unless @units.include?(unit)
33
+ unit.topic = self unless unit.topic == self
34
+ unit
35
+ end
36
+
37
+ def lessons
38
+ @units.map{|u| u.lessons}.flatten
39
+ end
40
+
41
+ def lessons_by_unit
42
+ result = {}
43
+ @units.each do |unit|
44
+ result[unit.title] = unit.lessons.map{|l| "#{l.title} - #{l.content_type} (#{l.id})"}
45
+ end
46
+ result
47
+ end
48
+
49
+ def summary
50
+ {
51
+ topic: title,
52
+ units: @units.map{|u| u.title},
53
+ lessons: lessons_by_unit,
54
+ readmes: lessons.count{|l| l.content_type == "Readme"},
55
+ labs: lessons.count{|l| l.content_type == "Lab"},
56
+ projects: lessons.count{|l| l.content_type == "Project"}
57
+ }
58
+ end
59
+ end
@@ -0,0 +1,52 @@
1
+ class StudentProgress::Unit
2
+ attr_accessor :title, :id, :topic
3
+ attr_reader :lessons
4
+
5
+ @@all = []
6
+
7
+ def self.all
8
+ @@all
9
+ end
10
+
11
+ def self.create_from_hash(hash)
12
+ new(hash).save
13
+ end
14
+
15
+ def initialize(attrs = {})
16
+ attrs.each do |attr, value|
17
+ self.send("#{attr}=", value)
18
+ end
19
+ @lessons = []
20
+ end
21
+
22
+ def save
23
+ @@all << self
24
+ self
25
+ end
26
+
27
+ def add_lesson(lesson)
28
+ @lessons << lesson unless @lessons.include?(lesson)
29
+ lesson.unit = self unless lesson.unit == self
30
+ lesson
31
+ end
32
+
33
+ def topic=(topic)
34
+ @topic = topic
35
+ topic.add_unit(self)
36
+ end
37
+
38
+ def lessons_by_type
39
+ @lessons.map{|l| "#{l.title} - #{l.content_type} (#{l.id})"}
40
+ end
41
+
42
+ def summary
43
+ {
44
+ topic: topic,
45
+ unit: title,
46
+ lessons: lessons_by_type,
47
+ readmes: @lessons.count{|l| l.content_type == "Readme"},
48
+ labs: @lessons.count{|l| l.content_type == "Lab"},
49
+ projects: @lessons.count{|l| l.content_type == "Project"}
50
+ }
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module StudentProgress
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,81 @@
1
+ require 'pry'
2
+ require 'capybara/poltergeist'
3
+ require 'nokogiri'
4
+ require 'json'
5
+ require 'io/console'
6
+ require 'terminal-table'
7
+ require 'sqlite3'
8
+ require 'sequel'
9
+
10
+ Capybara.register_driver :poltergeist do |app|
11
+ Capybara::Poltergeist::Driver.new(app, {js_errors: false})
12
+ end
13
+
14
+ DB = Sequel.sqlite('./student_progress.db') # memory database, requires sqlite3
15
+
16
+ unless DB.table_exists? :lessons
17
+ DB.create_table :lessons do
18
+ primary_key :id
19
+ String :title
20
+ String :content_type
21
+ String :repo
22
+ String :unit
23
+ String :track_version
24
+ end
25
+ end
26
+
27
+ unless DB.table_exists? :progress_reports
28
+ DB.create_table :progress_reports do
29
+ primary_key :id
30
+ DateTime :created_at
31
+ String :content
32
+ Integer :cohort_id
33
+ end
34
+ end
35
+
36
+
37
+ unless DB.table_exists? :student_reports
38
+ DB.create_table :student_reports do
39
+ primary_key :id
40
+ DateTime :created_at
41
+ String :current_lab
42
+ Integer :lessons_complete
43
+ Integer :labs_complete
44
+ Integer :progress_report_id
45
+ Integer :student_id
46
+ end
47
+ end
48
+
49
+ unless DB.table_exists? :cohorts
50
+ DB.create_table :cohorts do
51
+ primary_key :id
52
+ String :name
53
+ end
54
+ end
55
+
56
+ unless DB.table_exists? :students
57
+ DB.create_table :students do
58
+ primary_key :id
59
+ String :first_name
60
+ String :last_name
61
+ String :github_username
62
+ String :timezone
63
+ Integer :cohort_id
64
+ end
65
+ end
66
+
67
+ require_relative "./student_progress/version"
68
+ require_relative "./student_progress/cli"
69
+ require_relative "./student_progress/student"
70
+ require_relative "./student_progress/cohort"
71
+ require_relative "./student_progress/scraper"
72
+ require_relative "./student_progress/lesson"
73
+ require_relative "./student_progress/topic"
74
+ require_relative "./student_progress/unit"
75
+ require_relative "./student_progress/student_report"
76
+ require_relative "./student_progress/progress_report"
77
+
78
+
79
+ # module StudentProgress
80
+ # # Your code goes here...
81
+ # end
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "student_progress/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "student_progress"
8
+ spec.version = StudentProgress::VERSION
9
+ spec.authors = ["Dakota Martinez"]
10
+ spec.email = ["dakotaleemusic@gmail.com"]
11
+
12
+ spec.summary = %q{Scrapes Learn.co site to measure student progress}
13
+ spec.description = %q{Collects data about student progress}
14
+ spec.homepage = "https://github.com/DakotaLMartinez"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ # spec.bindir = "exe"
32
+ spec.executables = "student_progress"
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "pry"
39
+ spec.add_development_dependency "gem-release"
40
+ spec.add_dependency "poltergeist"
41
+ spec.add_dependency "nokogiri"
42
+ spec.add_dependency "sqlite3"
43
+ spec.add_dependency "sequel"
44
+ spec.add_dependency "json"
45
+ spec.add_dependency "terminal-table"
46
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: student_progress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dakota Martinez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gem-release
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: poltergeist
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sequel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: terminal-table
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Collects data about student progress
168
+ email:
169
+ - dakotaleemusic@gmail.com
170
+ executables:
171
+ - student_progress
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".travis.yml"
178
+ - CODE_OF_CONDUCT.md
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - bin/console
185
+ - bin/setup
186
+ - bin/student_progress
187
+ - lib/student_progress.rb
188
+ - lib/student_progress/cli.rb
189
+ - lib/student_progress/cohort.rb
190
+ - lib/student_progress/lesson.rb
191
+ - lib/student_progress/progress_report.rb
192
+ - lib/student_progress/scraper.rb
193
+ - lib/student_progress/student.rb
194
+ - lib/student_progress/student_report.rb
195
+ - lib/student_progress/topic.rb
196
+ - lib/student_progress/unit.rb
197
+ - lib/student_progress/version.rb
198
+ - student_progress.gemspec
199
+ homepage: https://github.com/DakotaLMartinez
200
+ licenses:
201
+ - MIT
202
+ metadata: {}
203
+ post_install_message:
204
+ rdoc_options: []
205
+ require_paths:
206
+ - lib
207
+ required_ruby_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 2.7.6
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: Scrapes Learn.co site to measure student progress
223
+ test_files: []