<commit_before>require 'cdo/regexp'
require 'cdo/geocoder'
require 'cdo/web_purify'

class ActivitiesController < ApplicationController
  include LevelsHelper

  # TODO: milestone is the only action so the below lines essentially do nothing. commenting out bc
  # the TODO is to figure out why (forgery protection is useful -- why can't we use it? blockly?)
#  protect_from_forgery except: :milestone
#  check_authorization except: [:milestone]
#  load_and_authorize_resource except: [:milestone]
  before_filter :nonminimal, only: :milestone

  MAX_INT_MILESTONE = 2147483647
  USER_ENTERED_TEXT_TITLE_NAMES = %w(TITLE TEXT)

  def milestone
    # TODO: do we use the :result and :testResult params for the same thing?
    solved = ('true' == params[:result])
    if params[:script_level_id]
      @script_level = ScriptLevel.cache_find(params[:script_level_id].to_i)
      @level = @script_level.level
    elsif params[:level_id]
      # TODO: do we need a cache_find for Level like we have for ScriptLevel?
      @level = Level.find(params[:level_id].to_i)
    end

    if params[:program]
      begin
        share_failure = find_share_failure(params[:program])
      rescue OpenURI::HTTPError => e
        share_checking_error = e
      end

      unless share_failure
        @level_source = LevelSource.find_identical_or_create(@level, params[:program])
        slog(tag: 'share_checking_error', error: "#{e}", level_source_id: @level_source.id) if share_checking_error
      end
    end

    log_milestone(@level_source, params)

    # Store the image only if the image is set, and the image has not been saved
    if params[:image] && @level_source
      @level_source_image = LevelSourceImage.find_or_create_by(:level_source_id => @level_source.id)
      @level_source_image.replace_image_if_better Base64.decode64(params[:image])
    end

    @new_level_completed = false
    if current_user
      track_progress_for_user
    else
      track_progress_in_session
    end

    total_lines = if current_user && current_user.total_lines
                    current_user.total_lines
                  elsif session[:lines]
                    session[:lines]
                  else
                    0
                  end

    render json: milestone_response(script_level: @script_level,
                                    total_lines: total_lines,<commit_msg>Skip intermediate variable for share checking error<commit_after>require 'cdo/regexp'
require 'cdo/geocoder'
require 'cdo/web_purify'

class ActivitiesController < ApplicationController
  include LevelsHelper

  # TODO: milestone is the only action so the below lines essentially do nothing. commenting out bc
  # the TODO is to figure out why (forgery protection is useful -- why can't we use it? blockly?)
#  protect_from_forgery except: :milestone
#  check_authorization except: [:milestone]
#  load_and_authorize_resource except: [:milestone]
  before_filter :nonminimal, only: :milestone

  MAX_INT_MILESTONE = 2147483647
  USER_ENTERED_TEXT_TITLE_NAMES = %w(TITLE TEXT)

  def milestone
    # TODO: do we use the :result and :testResult params for the same thing?
    solved = ('true' == params[:result])
    if params[:script_level_id]
      @script_level = ScriptLevel.cache_find(params[:script_level_id].to_i)
      @level = @script_level.level
    elsif params[:level_id]
      # TODO: do we need a cache_find for Level like we have for ScriptLevel?
      @level = Level.find(params[:level_id].to_i)
    end

    if params[:program]
      begin
        share_failure = find_share_failure(params[:program])
      rescue OpenURI::HTTPError => share_checking_error
      end

      unless share_failure
        @level_source = LevelSource.find_identical_or_create(@level, params[:program])
        slog(tag: 'share_checking_error', error: "#{share_checking_error}", level_source_id: @level_source.id) if share_checking_error
      end
    end

    log_milestone(@level_source, params)

    # Store the image only if the image is set, and the image has not been saved
    if params[:image] && @level_source
      @level_source_image = LevelSourceImage.find_or_create_by(:level_source_id => @level_source.id)
      @level_source_image.replace_image_if_better Base64.decode64(params[:image])
    end

    @new_level_completed = false
    if current_user
      track_progress_for_user
    else
      track_progress_in_session
    end

    total_lines = if current_user && current_user.total_lines
                    current_user.total_lines
                  elsif session[:lines]
                    session[:lines]
                  else
                    0
                  end

    render json: milestone_response(script_level: @script_level,
                                    total_lines: total_lines,
{'fraction_non_alphanumeric': 0.0758303739293921, 'fraction_numerical': 0.006266973052015876, 'mean_word_length': 3.1204819277108435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6196169', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1383, 'n_words': 367}