<commit_before>class AttendancesController < ApplicationController

  skip_before_action :admin_only

  def create
    meeting_id = 0
    @numAttendees = 0
    unless params[:attendance].nil?
      params[:attendance].each do |a|
        words = a.split(',')
        @attendance = Attendance.new(:user_id => words[0].scan(/\d+$/).first,
                                     :meeting_id => words[1][0...-1].scan(/\d+$/).first)
        unless @attendance.save
          flash[:danger] = "Something went wrong."
          redirect_to Meeting.find(meeting_id)
          return
        end
        @numAttendees += 1
        meeting_id = words[1][0...-1].scan(/\d+$/).first
      end
      meeting = Meeting.find(meeting_id)
      @initiative = meeting.initiative
      @totalAttendees = Enrolment.where(:initiative_id => @initiative, :user_id => (User.where(:privilege => 2).ids)).count
      meeting.update_attribute(:attendance, @numAttendees/@totalAttendees.to_f * 100)<commit_msg>Added comments to attendance controller.<commit_after>class AttendancesController < ApplicationController

  skip_before_action :admin_only

  def create
    meeting_id = 0
    @numAttendees = 0
    # If attendance form was completed
    unless params[:attendance].nil?
      params[:attendance].each do |a|
        # Split each entry at the ','
        # Words is a 2 item array with [user_id, meeting_id]
        words = a.split(',')
        # Scan the items to get the target information
        @attendance = Attendance.new(:user_id => words[0].scan(/\d+$/).first,
                                     :meeting_id => words[1][0...-1].scan(/\d+$/).first)
        unless @attendance.save
          flash[:danger] = "Something went wrong."
          redirect_to Meeting.find(meeting_id)
          return
        end
        # Total the number of attendants
        @numAttendees += 1
        # Get the meeting_id, which is always the same
        meeting_id = words[1][0...-1].scan(/\d+$/).first
      end
      meeting = Meeting.find(meeting_id)
      @initiative = meeting.initiative
      # Get the total number of people in the initiative
      @totalAttendees = Enrolment.where(:initiative_id => @initiative, :user_id => (User.where(:privilege => 2).ids)).count
      # Convert totalAttendees to a float to force floating point division
      #   in order to calculate the attendance percentage
      meeting.update_attribute(:attendance, @numAttendees/@totalAttendees.to_f * 100)
{'fraction_non_alphanumeric': 0.11962692619626926, 'fraction_numerical': 0.011759935117599351, 'mean_word_length': 2.5445402298850577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136949', 'n_tokens_mistral': 751, 'n_tokens_neox': 737, 'n_words': 171}