prefeiturasp/SME-PratoAberto-Edu

View on GitHub

Showing 17 of 17 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        for meal in meals:
            menu_with_meal = ''
            menu_str += '{}:\n'.format(meal)
            menu_with_meal += '{}:\n'.format(meal)
            for food in meals[meal]:
Severity: Major
Found in subscriptions.py and 1 other location - About 4 hrs to fix
chatbots/edubot.py on lines 206..213

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 79.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            if meal in school_meals:
                menu_with_meal = ''
                menu_str += '{}:\n'.format(meal)
                menu_with_meal += '{}:\n'.format(meal)
                for food in meals[meal]:
Severity: Major
Found in chatbots/edubot.py and 1 other location - About 4 hrs to fix
subscriptions.py on lines 46..53

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 79.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function update_flow_control has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def update_flow_control(self, **kwargs):
        fields = ['flow_name', 'flow_step', 'school', 'age', 'comment',
                  'menu_date', 'satisfied', 'evaluation', 'meal']
        user = self._get_user()
        # TODO refatorar isso.
Severity: Minor
Found in chatbots/model/bot_model.py - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        elif step == self.STEP_EVALUATION:
            # TODO: validador de opções
            self.bot.update_flow_data(evaluation=self.bot.text)
            self.bot.send_message('Gostaria de deixar alguma opnião?', keyboard_opts=self.yesno_opts)
            self.bot.set_flow(current_flow, self.STEP_HAS_OPINION)
Severity: Major
Found in chatbots/edubot.py and 1 other location - About 1 hr to fix
chatbots/edubot.py on lines 118..121

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 49.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        elif step == self.STEP_MENU_SHOWN2:
            self.bot.update_flow_data(meal=self.bot.text)
            self.bot.send_message('Satisfeito com as refeições?', keyboard_opts=self.yesno_opts)
            self.bot.set_flow(current_flow, self.STEP_SATISFIED)
Severity: Major
Found in chatbots/edubot.py and 1 other location - About 1 hr to fix
chatbots/edubot.py on lines 127..131

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 49.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if self._is_age_option(self.bot.text):
                self.bot.update_flow_data(age=self.bot.text)
                self.bot.save_notification()
                self.bot.send_message('Sua notificação foi salva!')
                self._main_menu()
Severity: Major
Found in chatbots/edubot.py and 1 other location - About 1 hr to fix
chatbots/edubot.py on lines 140..144

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        elif step == self.STEP_OPINION:
            self.bot.update_flow_data(comment=self.bot.text)
            self.bot.concat_evaluation()
            self.bot.send_message('Obrigado!')
            self._main_menu()
Severity: Major
Found in chatbots/edubot.py and 1 other location - About 1 hr to fix
chatbots/edubot.py on lines 155..159

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function _flow_evaluate_meal has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def _flow_evaluate_meal(self, step):
        current_flow = BotFlowEnum.AVALIAR_REFEICAO.value
        if step == self.STEP_MENU_SHOWN:
            self._show_menu(has_buttons=True)
            self.bot.set_flow(current_flow, self.STEP_MENU_SHOWN2)
Severity: Minor
Found in chatbots/edubot.py - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function validate_payload has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def validate_payload(payload, platform):
    # TODO: improve this validator
    if platform == 'facebook':
        messaging = payload['entry'][0]['messaging'][0]
        if messaging.get('message'):
Severity: Minor
Found in chatbots/utils.py - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def cancel_notification(self):
        user = self._get_user()
        if user:
            user.notification = None
            user.save()
Severity: Minor
Found in chatbots/model/bot_model.py and 1 other location - About 50 mins to fix
chatbots/model/bot_model.py on lines 79..84

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 36.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def clean_flow_control_data(self):
        user = self._get_user()
        if user:
            user.flow_control = None
            user.save()
Severity: Minor
Found in chatbots/model/bot_model.py and 1 other location - About 50 mins to fix
chatbots/model/bot_model.py on lines 94..99

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 36.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function _show_menu has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def _show_menu(self, has_buttons=False):
        user_data = self.bot.get_user_data()
        flow_control = user_data['flow_control']
        timestamp = str(flow_control['menu_date']['$date'])[:10]
        menu_date = datetime.datetime.utcfromtimestamp(int(timestamp)).strftime('%Y%m%d')
Severity: Minor
Found in chatbots/edubot.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _print_menu has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def _print_menu(self, menu, has_buttons=False, school_meals=[]):
        # XXX: because of poor REST API
        menu_str = ''
        buttons = []
        meals = menu[0]['cardapio']
Severity: Minor
Found in chatbots/edubot.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _base_menu_flow has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def _base_menu_flow(self, current_flow, step):
        """Search for school and returns menu"""
        if step == self.STEP_SEARCH_SCHOOL:
            self.bot.send_message('Digite o nome da escola')
            self.bot.set_flow(current_flow, self.STEP_SEARCH_SCHOOL2)
Severity: Minor
Found in chatbots/edubot.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid too many return statements within this function.
Open

    return False
Severity: Major
Found in chatbots/utils.py - About 30 mins to fix

    Function _flow_meal_alert has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _flow_meal_alert(self, step):
            current_flow = BotFlowEnum.RECEBER_NOTIFICACAO.value
            if step == self.STEP_SEARCH_SCHOOL:
                self.bot.send_message('Digite o nome da escola')
                self.bot.set_flow(current_flow, self.STEP_SEARCH_SCHOOL2)
    Severity: Minor
    Found in chatbots/edubot.py - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function send_notifications has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def send_notifications(self):
            for user_data in self.users_with_notification:
                if self._validate_user_notification(user_data):
                    notification = user_data.notification
                    today_api_format = datetime.datetime.today().strftime('%Y%m%d')
    Severity: Minor
    Found in subscriptions.py - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Severity
    Category
    Status
    Source
    Language