thundergolfer/mAIcroft

View on GitHub
maicroft/activity_metrics_proc.py

Summary

Maintainability
F
1 wk
Test Coverage

Function process_submission_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def process_submission_metrics(user, submission):
    """
    Process the part of a submission that relates to metrics
    """
    submission_timestamp = datetime.datetime.fromtimestamp(
Severity: Minor
Found in maicroft/activity_metrics_proc.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 process_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def process_metrics(user, comment):
    """
    Process the part of a comment that relates to metrics.
    """

Severity: Minor
Found in maicroft/activity_metrics_proc.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

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

    if (submission_timestamp.date() - days_ago_60).days > 0:
        user.metrics["heatmap"][
            ((submission_timestamp.date() - days_ago_60).days-1) * 24 + submission_timestamp.hour
        ] += 1
        user.metrics["recent_karma"][
Severity: Major
Found in maicroft/activity_metrics_proc.py and 1 other location - About 1 day to fix
maicroft/users/reddit_user.py on lines 594..603

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

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 (comment_timestamp.date() - days_ago_60).days > 0:
        user.metrics["heatmap"][
            (comment_timestamp.date() - days_ago_60).days*24 +
            comment_timestamp.hour
        ] += 1
Severity: Major
Found in maicroft/activity_metrics_proc.py and 1 other location - About 1 day to fix
maicroft/users/reddit_user.py on lines 512..521

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

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

    for i, d in enumerate(user.metrics["date"]):
        if d["date"] == (
            submission_timestamp.date().year,
            submission_timestamp.date().month
        ):
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 6 hrs to fix
maicroft/activity_metrics_proc.py on lines 45..53
maicroft/users/reddit_user.py on lines 525..533
maicroft/users/reddit_user.py on lines 606..614

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

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

    for i, d in enumerate(user.metrics["date"]):
        if d["date"] == (
            comment_timestamp.date().year,
            comment_timestamp.date().month
        ):
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 6 hrs to fix
maicroft/activity_metrics_proc.py on lines 102..110
maicroft/users/reddit_user.py on lines 525..533
maicroft/users/reddit_user.py on lines 606..614

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

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

    for i, w in enumerate(user.metrics["weekday"]):
        if w["weekday"] == submission_timestamp.date().weekday():
            w["submissions"] += 1
            w["submission_karma"] += submission.score
            user.metrics["weekday"][i] = w
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 5 hrs to fix
maicroft/activity_metrics_proc.py on lines 62..67
maicroft/users/reddit_user.py on lines 542..547
maicroft/users/reddit_user.py on lines 623..628

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

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

    for i, w in enumerate(user.metrics["weekday"]):
        if w["weekday"] == comment_timestamp.date().weekday():
            w["comments"] += 1
            w["comment_karma"] += comment.score
            user.metrics["weekday"][i] = w
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 5 hrs to fix
maicroft/activity_metrics_proc.py on lines 119..124
maicroft/users/reddit_user.py on lines 542..547
maicroft/users/reddit_user.py on lines 623..628

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

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

    for i, h in enumerate(user.metrics["hour"]):
        if h["hour"] == submission_timestamp.hour:
            h["submissions"] += 1
            h["submission_karma"] += submission.score
            user.metrics["hour"][i] = h
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 5 hrs to fix
maicroft/activity_metrics_proc.py on lines 55..60
maicroft/users/reddit_user.py on lines 535..540
maicroft/users/reddit_user.py on lines 616..621

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

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

    for i, h in enumerate(user.metrics["hour"]):
        if h["hour"] == comment_timestamp.hour:
            h["comments"] += 1
            h["comment_karma"] += comment.score
            user.metrics["hour"][i] = h
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 5 hrs to fix
maicroft/activity_metrics_proc.py on lines 112..117
maicroft/users/reddit_user.py on lines 535..540
maicroft/users/reddit_user.py on lines 616..621

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

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

    if submission.score > user.best_submission.score:
        user.best_submission = submission
    elif submission.score < user.worst_submission.score:
        user.worst_submission = submission
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 1 hr to fix
maicroft/activity_metrics_proc.py on lines 69..72
maicroft/users/reddit_user.py on lines 549..552
maicroft/users/reddit_user.py on lines 665..668

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

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

    if comment.score > user.best_comment.score:
        user.best_comment = comment
    elif comment.score < user.worst_comment.score:
        user.worst_comment = comment
Severity: Major
Found in maicroft/activity_metrics_proc.py and 3 other locations - About 1 hr to fix
maicroft/activity_metrics_proc.py on lines 85..88
maicroft/users/reddit_user.py on lines 549..552
maicroft/users/reddit_user.py on lines 665..668

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

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

There are no issues that match your filters.

Category
Status