Class: HomeWorkChecker::TestRunStat::PythonStat

Inherits:
Object
  • Object
show all
Defined in:
lib/hw_checker/python_stat.rb

Instance Method Summary collapse

Constructor Details

#initialize(tmp_path, dirname) ⇒ PythonStat

Returns a new instance of PythonStat.



4
5
6
7
# File 'lib/hw_checker/python_stat.rb', line 4

def initialize(tmp_path, dirname)
  @tmp_path, @dirname= tmp_path, dirname
  @lines_all = @lines_failed = 0
end

Instance Method Details

#calc_percent_quality(filename) ⇒ Object



19
20
21
# File 'lib/hw_checker/python_stat.rb', line 19

def calc_percent_quality(filename)
  ( (`tail -n 2 #{filename}`).scan(/\d{1,2}/).shift.to_f / 10 * 100).round(2)
end

#performObject



9
10
11
12
13
14
15
16
17
# File 'lib/hw_checker/python_stat.rb', line 9

def perform
  result = 0
  Dir.foreach("#{@tmp_path}/#{@dirname}/tests/statistic") do |p|
    next unless File.file?("#{@tmp_path}/#{@dirname}/tests/statistic/#{p}") && File.extname(p) == '.py' && p != '__init__.py'
    `pylint #{@tmp_path}/#{@dirname}/tests/statistic/#{p} > #{@tmp_path}/#{@dirname}/tests/statistic/#{p}.tmp 2>&1`
    result = calc_percent_quality("#{@tmp_path}/#{@dirname}/tests/statistic/#{p}.tmp")
  end
  result
end