<commit_before>require "gnuplot"
require "statsample"
require "cli-console"

class MainCalculations
	private
	extend CLI::Task

	public

	attr_accessor :file_name, :all_times

	def initialize(file_name, json=false, session="")
		@file_name = file_name
		@all_times = Array.new
		@json_file = json
		@session = session
		read_from_file
	end

	usage 'Say Hello to the user'
	desc 'Imitating human warmth in a computer program!'
	def hello(params)
		puts "Hello, what's up?"
		puts "You gave me #{params.inspect} as parameters"
	end

	def read_from_file
		if @json_file
			start_reading = false
			require 'json'
			file_obj = JSON.parse(File.read(@file_name))

			# check if given session is in the file
			if not file_obj.keys.include?(@session)
				p "Provided session (#{@session})was not there in the file"
				p 'Session names are generally session2, session3, etc'
				exit 1
			end

			# session is in the file

			session_obj = JSON.parse(file_obj[@session])
			#p session_obj.length

			# now check each object and push the float
			# value of the solvetime into the main object
			# TODO

		else
			start_reading = false
			# read the input file
			File.open(@file_name, "r") do |filin|
				while(line = filin.gets)
					if not start_reading and /Time\sList/.match(line)
						start_reading = true
					end

					if start_reading
						matches = line.scan(/\d{2}.\d{2}/)
						matches.each do |match|
							@all_times.push(match.to_f)
						end
					end
				end
			end
			@main_vector = @all_times.to_vector(:scale)
		end
	end

	usage 'Output the number of solves that were provided by the user'
	desc 'This is a quick check to ensure that the file provided by the user was imported'
	def number_of_points(params)
		p "#{@all_times.count} solves were in the input file"
	end

	usage 'Show some basic statistics about the solvetimes'
	desc 'Statistics include average, standard deviation, best and worst times'
	def basic_stats(params)
		p '----------------------------'
		p '----------------------------'
		p '-------- STATISTICS --------'
		p 'Mean of the solvetimes   : %0.2f' % @main_vector.mean
		p 'Median of the solvetimes : %0.2f' % @main_vector.median
		p 'Best solvetime           : %0.2f' % @main_vector.min
		p 'Worst solvetime          : %0.2f' % @main_vector.max<commit_msg>Complete the import of JSON files<commit_after>require "gnuplot"
require "statsample"
require "cli-console"

class MainCalculations
	private
	extend CLI::Task

	public

	attr_accessor :file_name, :all_times

	def initialize(file_name, json=false, session="")
		@file_name = file_name
		@all_times = Array.new
		@json_file = json
		@session = session
		read_from_file
	end

	usage 'Say Hello to the user'
	desc 'Imitating human warmth in a computer program!'
	def hello(params)
		puts "Hello, what's up?"
		puts "You gave me #{params.inspect} as parameters"
	end

	def read_from_file
		if @json_file
			start_reading = false
			require 'json'
			file_obj = JSON.parse(File.read(@file_name))

			# check if given session is in the file
			if not file_obj.keys.include?(@session)
				p "Provided session (#{@session})was not there in the file"
				p 'Session names are generally session2, session3, etc'
				exit 1
			end

			# session is in the file

			session_obj = JSON.parse(file_obj[@session])
			#p session_obj.length

			# now check each object and push the float
			# value of the solvetime into the main object
			# TODO
			session_obj.each{|time_obj| @all_times.push((time_obj[0][-1] / 1000.0).to_f)}

		else
			start_reading = false
			# read the input file
			File.open(@file_name, "r") do |filin|
				while(line = filin.gets)
					if not start_reading and /Time\sList/.match(line)
						start_reading = true
					end

					if start_reading
						matches = line.scan(/\d{2}.\d{2}/)
						matches.each do |match|
							@all_times.push(match.to_f)
						end
					end
				end
			end
		end
		@main_vector = @all_times.to_vector(:scale)
	end

	usage 'Output the number of solves that were provided by the user'
	desc 'This is a quick check to ensure that the file provided by the user was imported'
	def number_of_points(params)
		p "#{@all_times.count} solves were in the input file"
	end

	usage 'Show some basic statistics about the solvetimes'
	desc 'Statistics include average, standard deviation, best and worst times'
	def basic_stats(params)
		p '----------------------------'
		p '----------------------------'
		p '-------- STATISTICS --------'
		p 'Mean of the solvetimes   : %0.2f' % @main_vector.mean
		p 'Median of the solvetimes : %0.2f' % @main_vector.median
		p 'Best solvetime           : %0.2f' % @main_vector.min
		p 'Worst solvetime          : %0.2f' % @main_vector.max
{'fraction_non_alphanumeric': 0.12127024722932651, 'fraction_numerical': 0.007033248081841432, 'mean_word_length': 2.878512396694215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6851674', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1526, 'n_words': 505}