class StudentProgress::CLI

Public Instance Methods

add_students_to_cohort_view() click to toggle source
# File lib/student_progress/cli.rb, line 108
def add_students_to_cohort_view
  puts "Enter the github usernames of the students you'd like to add as a comma separated list"
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  usernames = @input.chomp.split(',').map(&:strip)
  @selected_cohort.add_students(usernames)
  puts "Just added #{usernames.count} students to your cohort"
  puts "#{@selected_cohort.name} now has #{@selected_cohort.students.count} students"
  show_options_for_cohort
end
call() click to toggle source
# File lib/student_progress/cli.rb, line 2
def call
  puts "Hello from CLI"
  prompt_for_login 
  StudentProgress::Scraper.scrape_lessons
  main_menu
  goodbye
end
delete_this_cohort_view() click to toggle source
# File lib/student_progress/cli.rb, line 140
def delete_this_cohort_view 
  puts "Are you sure you want to delete the #{@selected_cohort.name} cohort?"
  puts "type 'yes' to confirm or 'no' to go back to the cohort menu"
  puts "You can also type 'back' to return to the main menu, or 'exit' to exit the CLI"
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  case @input.downcase 
  when 'yes'
    @selected_cohort.delete_and_unassign_students
    @selected_cohort = nil
    puts "cohort successfully deleted"
    list_choices
  when 'no'
    show_options_for_cohort
  else
    puts "Whoops! Didn't understand that."
    delete_this_cohort_view
  end
end
display_students() click to toggle source
# File lib/student_progress/cli.rb, line 209
def display_students
  output = []
  now = DateTime.now
  output << now.strftime('%b %e, %Y %l:%M %p')
  @selected_cohort ||= StudentProgress::Student.all
  @selected_cohort.run_progress_report
  if @goal
    output << "\n"
    output << "Students should #{@goal[:goal]} by the end of the week"
    output << "To do that, they'll have completed #{@goal[:lessons]} lessons and #{@goal[:labs]} labs"
  end
  headers = ['Student Name', 'Current Lab', 'Current Topic', 'Lessons', 'Labs']
  report = @selected_cohort.progress_reports.last
  rows = report.student_reports.collect.with_index(1) do |student_report|
    student_report.generate_current_topic_status
    [student_report.student_name, student_report.current_lab, student_report.current_topic_status, student_report.lessons_complete, student_report.labs_complete]
  end
  table = Terminal::Table.new headings: headers, rows: rows
  output << table

  if @goal
    split_by_progress = report.on_track(@goal, @selected_cohort)
    on_track = split_by_progress[:on_track].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    behind = split_by_progress[:behind].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    ahead = split_by_progress[:ahead].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    behind_table = Terminal::Table.new headings: headers, rows: behind
    on_track_table = Terminal::Table.new headings: headers, rows: on_track
    ahead_table = Terminal::Table.new headings: headers, rows: ahead
    output << "BEHIND"
    output << behind_table
    output << "ON TRACK"
    output << on_track_table
    output << "Ahead"
    output << ahead_table
  end
  report.content = output.join("\n")
  report.save
  puts output
end
goodbye() click to toggle source
# File lib/student_progress/cli.rb, line 281
def goodbye
  puts "\n"
  puts "Thanks for using the Student Tracker CLI! See you next time!!!"
end
list_choices() click to toggle source
# File lib/student_progress/cli.rb, line 52
def list_choices
  puts "Choose an option below by number"
  puts "1. Manage Cohorts"
  puts "2. Add Cohort"
  puts "3. Set goal for the week"
  puts "4. To view a list of past reports"
  puts "'exit' to leave the program"
  puts "type 'menu' at any point if you'd like to see these options again"
end
list_cohorts() click to toggle source
# File lib/student_progress/cli.rb, line 62
def list_cohorts
  @selected_cohort = nil
  until @selected_cohort || @input == "exit"
    puts "Please select the cohort you'd like to view details for"
    StudentProgress::Cohort.all.each.with_index(1) do |cohort, index|
      puts "#{index}. #{cohort.name}"
    end
    @input = gets.strip
    if @input.to_i > 0 && @input.to_i <= StudentProgress::Cohort.count 
      @selected_cohort = StudentProgress::Cohort.all[@input.to_i - 1]
    elsif @input == "exit" || @input == "back"
      return
    else
      puts "Whoops! Didn't understand that input"
    end
  end
  show_options_for_cohort
end
list_previous_reports() click to toggle source
# File lib/student_progress/cli.rb, line 275
def list_previous_reports
  DB[:progress_reports].each do |p|
    puts "#{p[:id]}. #{p[:created_at].strftime('%b %e, %Y %l:%M %p')}" if p[:created_at]
  end
end
main_menu() click to toggle source
prompt_for_cohort_name() click to toggle source
# File lib/student_progress/cli.rb, line 160
def prompt_for_cohort_name
  puts "Please enter the name of the cohort you'd like to create"
  name = gets.chomp
  @new_cohort = StudentProgress::Cohort.find_or_create(name: name)
  prompt_for_usernames
end
prompt_for_goal() click to toggle source
# File lib/student_progress/cli.rb, line 175
def prompt_for_goal 
  @goal = nil
  puts "Which topic should students be working in at the end of the week?"
  StudentProgress::Topic.all.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
  @input = gets.strip
  if @input == "exit" 
    return
  elsif @input.to_i <= 0 
    puts "Make sure you enter a number in range"
    prompt_for_goal
  elsif topic = StudentProgress::Topic.all[@input.to_i-1]
    puts "Great! We'll be looking within #{topic.title}"
  else
    puts "Whoops! Don't have that option"
    prompt_for_goal
  end
  while @input != "exit" && @goal.nil?
    puts "Which unit should students finish by the end of the week?"
    topic.units.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
    @input = gets.strip
    if @input == "exit" 
      return
    elsif @input.to_i <= 0 
      puts "Make sure you enter a number in range"
      prompt_for_goal
    elsif unit = topic.units[@input.to_i-1]
      puts "Great! We'll set the goal for the week"
      @goal = StudentProgress::Lesson.progress_when_unit_complete(unit.title)
    else
      puts "Whoops! Don't have that option"
    end
  end
end
prompt_for_login() click to toggle source
# File lib/student_progress/cli.rb, line 10
def prompt_for_login
  puts "Log in to your learn.co account:"
  print "Email: "
  email = gets.strip
  puts "\n"
  print "Password: "
  password = STDIN.noecho(&:gets).chomp
  unless StudentProgress::Scraper.login_user(email, password)
    prompt_for_login
  end
  true
end
prompt_for_reports() click to toggle source
# File lib/student_progress/cli.rb, line 255
def prompt_for_reports 
  list_previous_reports
  
  @input = nil 
  until @input == "exit" || @input == "back"
    puts "Enter the number of the report you'd like to view (type 'back' to return to main menu)"
    puts "You can also type 'list' to see the list of reports again"
    @input = gets.strip
    if DB[:progress_reports].first(id: @input.to_i)
      puts DB[:progress_reports].first(id: @input.to_i)[:content]
    elsif @input == "list"
      list_previous_reports
    elsif @input == "exit" || @input == "back"
      break
    else
      put "Whoops! I didn't understand that."
    end
  end
end
prompt_for_usernames() click to toggle source
# File lib/student_progress/cli.rb, line 167
def prompt_for_usernames
  puts "Please enter the GitHub usernames for the students you'd like info about (separated by commas)"
  usernames = gets.chomp.split(',').map(&:strip).map(&:downcase)
  puts "Hang on a sec, adding #{usernames.count} students"
  @new_cohort.add_students(usernames)
  puts "All done!"
end
remove_students_from_cohort_view() click to toggle source
# File lib/student_progress/cli.rb, line 119
def remove_students_from_cohort_view 
  puts "Enter the github usernames of the students you'd like to remove as a comma separated list"
  puts "Current usernames:"
  puts @selected_cohort.students.collect{|s| s.github_username}.join(', ')
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  usernames = @input.chomp.split(',').map(&:strip)
  removed = @selected_cohort.remove_students(usernames)
  puts "Just removed #{removed} students from the cohort"
  puts "#{@selected_cohort.name} now has #{@selected_cohort.students.count} students"
  show_options_for_cohort
end
show_options_for_cohort() click to toggle source
# File lib/student_progress/cli.rb, line 81
def show_options_for_cohort
  puts "What would you like to do with the cohort?"
  puts "1. Create Progress Report"
  puts "2. Add a member(s) to the cohort"
  puts "3. Remove a member from the cohort"
  puts "4. Add a periscope URL to scrape progress from"
  puts "5. Delete this cohort"
  puts "type 'back' to return to the main menu or 'exit' to exit the CLI"
  @input = gets.strip.downcase
  return if ["back", "exit"].include?(@input)
  case @input.to_i 
  when 1
    display_students
  when 2 
    add_students_to_cohort_view
  when 3
    remove_students_from_cohort_view
  when 4
    add_periscope_link_for_cohort_data
  when 5
    delete_this_cohort_view
  else
    puts "Whoops! didn't understand that input"
    show_options_for_cohort
  end
end