Class: HomeWorkChecker::ArchiveResult::PythonCodeQuality
- Inherits:
-
Object
- Object
- HomeWorkChecker::ArchiveResult::PythonCodeQuality
- Defined in:
- lib/hw_checker/python_code_quality.rb
Instance Method Summary collapse
- #calc_percent_quality(filename) ⇒ Object
-
#initialize(tmp_path, dirname) ⇒ PythonCodeQuality
constructor
A new instance of PythonCodeQuality.
- #perform ⇒ Object
Constructor Details
#initialize(tmp_path, dirname) ⇒ PythonCodeQuality
Returns a new instance of PythonCodeQuality.
4 5 6 7 8 |
# File 'lib/hw_checker/python_code_quality.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 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hw_checker/python_code_quality.rb', line 20 def calc_percent_quality(filename) =begin rake = ((`tail -n 75 #{filename}`).scan(/\d{1,2}\.\d{1,2}\\/).shift.to_f) if rake > 10 (rake / 10).round(2) else (rake * 10).round(2) end =end File.open(filename).each_line do |line| next unless line.match(/^Your\scode\shas\sbeen\srated\sat/) return ( line.scan(/[\d\.]+/).shift.to_f * 10 ) end end |
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/hw_checker/python_code_quality.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 |