Lambda-School-Labs/pt-synaps-ds

View on GitHub

Showing 24 of 24 total issues

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

def weekly_per_min_comparison(df):
    """Function to compare this week's avg cards per minute to last week's. Returns a dictionary of weekly cards per
    minute, percentage difference, unicode for the up/down/equal sign, and a color code """
    df = convert_to_datetime(df)
    today = datetime.date.today()
Severity: Major
Found in comparative_metrics.py and 1 other location - About 4 days to fix
comparative_metrics.py on lines 137..183

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 444.

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 monthly_per_min_comparison(df):
    """Function to compare today's stats to yesterday's. Returns a dictionary of monthly cards per minute,
    percentage difference, unicode for the up/down/equal sign, and a color code"""
    df = convert_to_datetime(df)
    today = datetime.date.today()
Severity: Major
Found in comparative_metrics.py and 1 other location - About 4 days to fix
comparative_metrics.py on lines 88..134

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 444.

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 best_session_weekly(df):
    """Function to determine the best session length in minutes for this week and last week. Takes in a
    user session dataframe and returns a dictionary of weekly best session,
    percentage difference, unicode for the up/down/equal sign, and a color code"""
    df = convert_to_datetime(df)
Severity: Major
Found in comparative_metrics.py and 1 other location - About 3 days to fix
comparative_metrics.py on lines 295..337

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 387.

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 best_session_monthly(df):
    """Function to determine the best session length in minutes for this month and last month. Takes in a
    user session dataframe and returns a dictionary of monthly best session,
    percentage difference, unicode for the up/down/equal sign, and a color code"""
    df = convert_to_datetime(df)
Severity: Major
Found in comparative_metrics.py and 1 other location - About 3 days to fix
comparative_metrics.py on lines 250..292

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 387.

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 monthly_viewed(df):
    """Function to compare today's stats to yesterday's. Returns a dictionary of monthly cards per minute,
    percentage difference, unicode for the up/down/equal sign, and a color code"""
    df = convert_to_datetime(df)
    today = datetime.date.today()
Severity: Major
Found in comparative_metrics.py and 1 other location - About 2 days to fix
comparative_metrics.py on lines 365..388

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 234.

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 weekly_viewed(df):
    """Function to compare this week's avg cards per minute to last week's. Returns a dictionary of weekly cards per
    minute, percentage difference, unicode for the up/down/equal sign, and a color code """
    df = convert_to_datetime(df)
    today = datetime.date.today()
Severity: Major
Found in comparative_metrics.py and 1 other location - About 2 days to fix
comparative_metrics.py on lines 391..413

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 234.

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

    for index, row in df.iterrows():
        if row['session_start'].date() == today:
            per_min = get_cards_per_min(row)
            todays_per_min.append(per_min)
            today_viewed.append(row['total_looked_at'])
Severity: Major
Found in comparative_metrics.py and 1 other location - About 7 hrs to fix
comparative_metrics.py on lines 42..50

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 119.

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

    for index, row in df.iterrows():
        if row['session_start'].date() == today:
            per_min = get_cards_per_min(row)
            todays_per_min.append(per_min)
            today_viewed.append(row['total_looked_at'])
Severity: Major
Found in comparative_metrics.py and 1 other location - About 7 hrs to fix
comparative_metrics.py on lines 351..359

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 119.

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 6 locations. Consider refactoring.
Open

    def test_monthly_per_min_comparison(self):
        self.assertEqual(len(monthly_per_min_comparison(self.test_df_2)), 4)
        self.assertEqual(monthly_per_min_comparison(self.test_df_2)['monthly_cards_min'], 0)
        self.assertEqual(monthly_per_min_comparison(self.test_df_2)['difference'], 100)
        self.assertEqual(monthly_per_min_comparison(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 35..40
test_suite.py on lines 42..47
test_suite.py on lines 56..61
test_suite.py on lines 63..68
test_suite.py on lines 70..75

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 114.

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 6 locations. Consider refactoring.
Open

    def test_best_session_monthly(self):
        self.assertEqual(len(best_session_monthly(self.test_df_2)), 4)
        self.assertEqual(best_session_monthly(self.test_df_2)['best_session_monthly'], 0)
        self.assertEqual(best_session_monthly(self.test_df_2)['difference'], 100)
        self.assertEqual(best_session_monthly(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 35..40
test_suite.py on lines 42..47
test_suite.py on lines 49..54
test_suite.py on lines 56..61
test_suite.py on lines 63..68

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 114.

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 6 locations. Consider refactoring.
Open

    def test_daily_cards_min_comparison(self):
        self.assertEqual(len(daily_cards_min_comparison(self.test_df_2)), 4)
        self.assertEqual(daily_cards_min_comparison(self.test_df_2)['daily_cards_min'], 0)
        self.assertEqual(daily_cards_min_comparison(self.test_df_2)['difference'], 100)
        self.assertEqual(daily_cards_min_comparison(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 42..47
test_suite.py on lines 49..54
test_suite.py on lines 56..61
test_suite.py on lines 63..68
test_suite.py on lines 70..75

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 114.

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 6 locations. Consider refactoring.
Open

    def test_weekly_per_min_comparison(self):
        self.assertEqual(len(weekly_per_min_comparison(self.test_df_2)), 4)
        self.assertEqual(weekly_per_min_comparison(self.test_df_2)['weekly_cards_min'], 0)
        self.assertEqual(weekly_per_min_comparison(self.test_df_2)['difference'], 100)
        self.assertEqual(weekly_per_min_comparison(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 35..40
test_suite.py on lines 49..54
test_suite.py on lines 56..61
test_suite.py on lines 63..68
test_suite.py on lines 70..75

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 114.

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 6 locations. Consider refactoring.
Open

    def test_best_session_daily(self):
        self.assertEqual(len(best_session_daily(self.test_df_2)), 4)
        self.assertEqual(best_session_daily(self.test_df_2)['best_session_daily'], 0)
        self.assertEqual(best_session_daily(self.test_df_2)['difference'], 100)
        self.assertEqual(best_session_daily(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 35..40
test_suite.py on lines 42..47
test_suite.py on lines 49..54
test_suite.py on lines 63..68
test_suite.py on lines 70..75

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 114.

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 6 locations. Consider refactoring.
Open

    def test_best_session_weekly(self):
        self.assertEqual(len(best_session_daily(self.test_df_2)), 4)
        self.assertEqual(best_session_weekly(self.test_df_2)['best_session_weekly'], 0)
        self.assertEqual(best_session_weekly(self.test_df_2)['difference'], 100)
        self.assertEqual(best_session_weekly(self.test_df_2)['color_code'], '000000')
Severity: Major
Found in test_suite.py and 5 other locations - About 7 hrs to fix
test_suite.py on lines 35..40
test_suite.py on lines 42..47
test_suite.py on lines 49..54
test_suite.py on lines 56..61
test_suite.py on lines 70..75

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 114.

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

File comparative_metrics.py has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import pandas as pd
import datetime
from datetime import timedelta

pd.set_option('mode.chained_assignment', None)
Severity: Minor
Found in comparative_metrics.py - About 4 hrs to fix

    Function daily_cards_min_comparison has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def daily_cards_min_comparison(df):
        """Function to compare today's avg cards per minute to yesterday's. Returns a dictionary of daily cards per minute,
        percentage difference, unicode for the up/down/equal sign, and a color code"""
        df = convert_to_datetime(df)
        today = datetime.date.today()
    Severity: Minor
    Found in comparative_metrics.py - About 1 hr 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 weekly_per_min_comparison has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def weekly_per_min_comparison(df):
        """Function to compare this week's avg cards per minute to last week's. Returns a dictionary of weekly cards per
        minute, percentage difference, unicode for the up/down/equal sign, and a color code """
        df = convert_to_datetime(df)
        today = datetime.date.today()
    Severity: Minor
    Found in comparative_metrics.py - About 1 hr 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 monthly_per_min_comparison has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def monthly_per_min_comparison(df):
        """Function to compare today's stats to yesterday's. Returns a dictionary of monthly cards per minute,
        percentage difference, unicode for the up/down/equal sign, and a color code"""
        df = convert_to_datetime(df)
        today = datetime.date.today()
    Severity: Minor
    Found in comparative_metrics.py - About 1 hr 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 best_session_monthly has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def best_session_monthly(df):
        """Function to determine the best session length in minutes for this month and last month. Takes in a
        user session dataframe and returns a dictionary of monthly best session,
        percentage difference, unicode for the up/down/equal sign, and a color code"""
        df = convert_to_datetime(df)
    Severity: Minor
    Found in comparative_metrics.py - About 1 hr 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 best_session_daily has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def best_session_daily(df):
        """Function to determine the best session length in minutes for today and yesterday. Takes in a
        user session dataframe and returns a dictionary of daily best session,
        percentage difference, unicode for the up/down/equal sign, and a color code"""
        df = convert_to_datetime(df)
    Severity: Minor
    Found in comparative_metrics.py - About 1 hr 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