<commit_before>require "json"

module FReCon
	class TeamsController
		def self.create(request, params)
			# Rewind the request body (an IO object)
			# in case someone else has already played
			# through it.
			request.body.rewind

			begin
				# Parse the POST data as a JSON hash
				# (because that's what it is)
				post_data = JSON.parse(request.body.read)
			rescue JSON::ParserError => e
				# If we have malformed JSON (JSON::ParserError is raised),
				# escape out of the function
				return JSON.generate({ status: 422, errors: [ e.message ] })
			end

			@team = FReCon::Team.new
			@team.number = post_data["number"]
			@team.location = post_data["location"]
			@team.name = post_data["name"]

			if @team.save
				@team.to_json
			else
				JSON.generate({ status: 422, errors: @team.errors.full_messages })
			end
		end

		def self.update(request, params)
			raise IncorrectParamError, "Must supply a team number!" unless params[:number]

			# Rewind the request body (an IO object)
			# in case someone else has already played
			# through it.
			request.body.rewind

			begin
				# Parse the POST data as a JSON hash
				# (because that's what it is)
				post_data = JSON.parse(request.body.read)<commit_msg>Add some comments<commit_after>require "json"

module FReCon
	class TeamsController
		def self.create(request, params)
			# Rewind the request body (an IO object)
			# in case someone else has already played
			# through it.
			request.body.rewind

			begin
				# Parse the POST data as a JSON hash
				# (because that's what it is)
				post_data = JSON.parse(request.body.read)
			rescue JSON::ParserError => e
				# If we have malformed JSON (JSON::ParserError is raised),
				# escape out of the function
				return JSON.generate({ status: 422, errors: [ e.message ] })
			end

			# Even though "location" and "name" are optional,
			# still set them.  If they are nil, @team.location
			# and @team.name will be set to nil.
			@team = FReCon::Team.new
			@team.number = post_data["number"]
			@team.location = post_data["location"]
			@team.name = post_data["name"]

			if @team.save
				# Use to_json for now; we can filter it later.
				@team.to_json
			else
				JSON.generate({ status: 422, errors: @team.errors.full_messages })
			end
		end

		def self.update(request, params)
			raise IncorrectParamError, "Must supply a team number!" unless params[:number]

			# Rewind the request body (an IO object)
			# in case someone else has already played
			# through it.
			request.body.rewind

			begin
				# Parse the POST data as a JSON hash
				# (because that's what it is)
				post_data = JSON.parse(request.body.read)
{'fraction_non_alphanumeric': 0.09803921568627451, 'fraction_numerical': 0.004524886877828055, 'mean_word_length': 3.1131782945736433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '401453', 'n_tokens_mistral': 1012, 'n_tokens_neox': 813, 'n_words': 290}