Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

2358-2 #266

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

2358-2 #266

wants to merge 2 commits into from

Conversation

bigbrother13
Copy link
Contributor

@bigbrother13 bigbrother13 commented Jul 21, 2018

Номер

2358

Номер задания

2

Ссылка на видео с демо

https://youtu.be/U3CgabuJJoE

Комментарии

  1. Третий уровень в прогрессе

Copy link
Collaborator

@HolyWalley HolyWalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it's ok

2358/2/index.rb Outdated
require 'russian_obscenity'
require 'terminal-table'

TEXTS_PATH = '/home/dshop/Vova/word/texts'.freeze
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a bad idea. use Dir.pwd

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a VERY bad idea.

2358/2/index.rb Outdated

Dir.new(TEXTS_PATH).each do |file|
next if file =~ /^\./
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.split.join(' ') ??

2358/2/index.rb Outdated
next if file =~ /^\./
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ')

name_from_hash = RAPPER_NAMES.find { |_, v| rapper_name =~ v }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'v' is a bad name. how about 'pattern'?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the code below for 'v' and 'k'

2358/2/index.rb Outdated
bad_words_counter = {}
words_per_battle_counter = {}
words_per_round_counter = {}
average_words_per_round_conter = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean counter?

2358/2/index.rb Outdated

RAPPER_NAMES.each do |k, _|
words_per_battle_counter[k] = (bad_words_counter[k].to_f / battles_count[k]).round(2)
average_words_per_round_conter[k] = words_per_round_counter[k] / (battles_count[k] * 3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 3?

@allomov
Copy link
Collaborator

allomov commented Jul 23, 2018

сразу нет из-за названия

@allomov
Copy link
Collaborator

allomov commented Jul 23, 2018

нужно больше больше ООП

2358/2/index.rb Outdated
end
end

def show_table

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/MethodLength: Method has too many lines. [15/10]

2358/2/index.rb Outdated

private

def calculation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for calculation is too high. [40.94/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for calculation is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [31/10]
Metrics/PerceivedComplexity: Perceived complexity for calculation is too high. [10/7]

2358/2/index.rb Outdated

words_from_text = lines.join.tr("\n", ' ').delete('.,;').split

bad_words_count = words_from_text.select do |x|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UncommunicativeVariableName: TextHandler#calculation has the variable name 'x'. More info.

2358/2/index.rb Outdated
end
end

def show_table

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TooManyStatements: TextHandler#show_table has approx 6 statements. More info.

2358/2/index.rb Outdated

private

def calculation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TooManyStatements: TextHandler#calculation has approx 20 statements. More info.

2358/2/index.rb Outdated
require 'terminal-table'
require_relative 'constants'

class TextHandler

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TooManyInstanceVariables: TextHandler has at least 6 instance variables. More info.


name_from_hash = RAPPER_NAMES.find { |_, reg| rapper_name =~ reg }

next if name_from_hash.nil?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NilCheck: TextHandler#calculation performs a nil-check. More info.

next if file =~ /^\./
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ')

name_from_hash = RAPPER_NAMES.find { |_, reg| rapper_name =~ reg }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NestedIterators: TextHandler#calculation contains iterators nested 2 deep. More info.

@bigbrother13 bigbrother13 changed the title VERSUS parser battle texts handler (level 1) Jul 24, 2018
@bigbrother13 bigbrother13 changed the title battle texts handler (level 1) 2358-2 Jul 24, 2018
2358/2/index.rb Outdated
end



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLines: Extra blank line detected.

2358/2/index.rb Outdated
end
end


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLines: Extra blank line detected.

2358/2/index.rb Outdated
end
else
puts "Рэпер #{@name} не известен мне. Зато мне известны:"
RAPPER_NAMES.keys.shuffle.first(5).each { |name| puts "#{name}\n" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance/Sample: Use sample(5) instead of shuffle.first(5).

2358/2/index.rb Outdated
def show_favorite_word
if RAPPER_NAMES[@name]
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] }
list_of_words = Hash[counter_array].sort_by {|_, counter| counter }.reverse

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceInsideBlockBraces: Space between { and | missing.

2358/2/index.rb Outdated

def show_favorite_word
if RAPPER_NAMES[@name]
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [130/120]

2358/2/index.rb Outdated
end
# rubocop:enable Metrics/MethodLength

def show_favorite_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [20.12/15]

# :reek:NilCheck
# :reek:NestedIterators
def calculation
Dir.new(TEXTS_PATH).each do |file|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [30/25]

2358/2/index.rb Outdated
end
# rubocop:enable Metrics/MethodLength

def show_favorite_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TooManyStatements: TextHandler#show_favorite_word has approx 10 statements. More info.

2358/2/index.rb Outdated

def show_result
calculation
if @name.nil?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NilCheck: TextHandler#show_result performs a nil-check. More info.

@@ -0,0 +1,111 @@
TEXTS_PATH = "#{Dir.pwd}/texts".freeze
SHORT_WORDS = %w[в на и я с не ни по под от у ты что Я И ТЫ как это Но - тебя но меня он А мне за все бы был кто так же его то Это тебе Ты а про вы мой Он тут Что из есть у здесь нет Как к Если Не там даже Вы для Ты ф про вы мой Он тут Что из у Как к Не там Вы где для В до всё мы или – У То *** раз Вот Мы еще со их Ну о без].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [335/120]
Layout/SpaceInsideArrayPercentLiteral: Use only a single space inside array percent literal.

2358/2/index.rb Outdated
)
puts table
end
# rubocop:disable Metrics/LineLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/LineLength.

2358/2/index.rb Outdated
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/PerceivedComplexity.

2358/2/index.rb Outdated

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/CyclomaticComplexity.

2358/2/index.rb Outdated
private

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/AbcSize.

2358/2/index.rb Outdated

private

# rubocop:disable Metrics/MethodLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.

# :reek:NilCheck
TEXTS_PATH = "#{Dir.pwd}/texts".freeze

SHORT_WORDS = %w[в на и я с не ни по под от у ты что Я И ТЫ как это Но - тебя но меня он А мне за все бы был кто так же его то Это тебе Ты а про вы мой Он тут Что из есть у здесь нет Как к Если Не там даже Вы для Ты ф про вы мой Он тут Что из у Как к Не там Вы где для В до всё мы или – У То *** раз Вот Мы еще со их Ну о без].freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [335/120]
Layout/SpaceInsideArrayPercentLiteral: Use only a single space inside array percent literal.

2358/2/index.rb Outdated
end
else
puts "Рэпер #{@name} не известен мне. Зато мне известны:"
RAPPER_NAMES.keys.shuffle.first(5).each do |name|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance/Sample: Use sample(5) instead of shuffle.first(5).

2358/2/index.rb Outdated
# :reek:TooManyStatements
def show_favorite_word
if RAPPER_NAMES[@name]
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [130/120]

2358/2/index.rb Outdated
end

# :reek:TooManyStatements
def show_favorite_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [20.12/15]
Metrics/MethodLength: Method has too many lines. [12/10]

2358/2/index.rb Outdated
puts table
end

# :reek:TooManyStatements

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CommentIndentation: Incorrect indentation detected (column 1 instead of 2).

2358/2/index.rb Outdated
end

# :reek:TooManyStatements
def show_table

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/MethodLength: Method has too many lines. [15/10]

# :reek:TooManyStatements
# :reek:NilCheck
# :reek:NestedIterators
def calculation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for calculation is too high. [43.65/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for calculation is too high. [8/6]
Metrics/MethodLength: Method has too many lines. [36/10]
Metrics/PerceivedComplexity: Perceived complexity for calculation is too high. [12/7]

2358/2/index.rb Outdated
@name = name
end
# :reek:NilCheck
def show_result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLineBetweenDefs: Use empty lines between method definitions.

2358/2/index.rb Outdated
@top = top
@name = name
end
# :reek:NilCheck

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CommentIndentation: Incorrect indentation detected (column 0 instead of 2).

2358/2/index.rb Outdated
end

# :reek:TooManyStatements
def show_favorite_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [19.13/15]
Metrics/MethodLength: Method has too many lines. [12/10]

2358/2/index.rb Outdated
# rubocop:disable Metrics/AbcSize
# rubocop:disable Layout/CommentIndentation
# :reek:TooManyStatements
def show_favorite_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLineBetweenDefs: Use empty lines between method definitions.

2358/2/index.rb Outdated
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/LineLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Layout/CommentIndentation.

2358/2/index.rb Outdated
)
puts table
end
# rubocop:disable Metrics/MethodLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.

2358/2/index.rb Outdated
end
# rubocop:enable Layout/EmptyLineBetweenDefs
# rubocop:enable Layout/CommentIndentation
private

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLinesAroundAccessModifier: Keep a blank line before and after private.

2358/2/index.rb Outdated
@top = top
@name = name
end
# rubocop:disable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopDisableDirective: Unnecessary disabling of Layout/CommentIndentation.

2358/2/index.rb Outdated
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/LineLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.

2358/2/index.rb Outdated
end
end
# rubocop:enable Layout/EmptyLineBetweenDefs
# rubocop:enable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.

2358/2/index.rb Outdated
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/LineLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.

2358/2/index.rb Outdated
end
end
# rubocop:enable Layout/EmptyLineBetweenDefs
# rubocop:enable Layout/CommentIndentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants