Class: HomeWorkChecker::TestRunStat::PythonStat
- Inherits:
-
Object
- Object
- HomeWorkChecker::TestRunStat::PythonStat
- Defined in:
- lib/hw_checker/python_stat.rb
Instance Method Summary collapse
- #calc_percent_quality(filename) ⇒ Object
-
#initialize(tmp_path, dirname) ⇒ PythonStat
constructor
A new instance of PythonStat.
- #perform ⇒ Object
Constructor Details
#initialize(tmp_path, dirname) ⇒ PythonStat
Returns a new instance of PythonStat.
4 5 6 7 8 |
# File 'lib/hw_checker/python_stat.rb', line 4 def initialize(tmp_path, dirname) @work_path = "#{tmp_path}/#{dirname}/tests/statistic" raise DirectoryExistError, "Archive '#{dirname}' is invalid" unless Dir::exist?(@work_path) @lines_all = @lines_failed = 0 end |
Instance Method Details
#calc_percent_quality(filename) ⇒ Object
20 21 22 |
# File 'lib/hw_checker/python_stat.rb', line 20 def calc_percent_quality(filename) ( (`tail -n 2 #{filename}`).scan(/\d{1,2}/).shift.to_f / 10 * 100).round(2) end |
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/hw_checker/python_stat.rb', line 10 def perform result = 0 Dir.foreach(@work_path) do |p| next unless File.file?("#{@work_path}/#{p}") && File.extname(p) == '.py' && p != '__init__.py' `pylint #{@work_path}/#{p} > #{@work_path}/#{p}.tmp 2>&1` result = calc_percent_quality("#{@work_path}/#{p}.tmp") end result end |