Skip to content

ronek22/ZJP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Zaawansowane Języki Programowania

Python

Narzędzie

Opis

pylint

looks for programming errors, helps enforcing a coding standard and sniffs for some code smells. It additionally includes pyreverse (an UML diagram generator) and symilar (a similarities checker).

radon

tool that computes various metrics from the source code like McCabe’s complexity, raw metrics (SLOC, blank lines etc.), halstead metrics, maintainability index

vulture

finds unused code in Python programs. This is useful for cleaning up and finding errors in large code bases.

1. Discovering a pain in the code

def compareTimMin(time, timeList, distance): 31 =
    test = len(time.split(':'))
    flattened = [ n for row in matrix for n in row ] # 2 +
    doubled = [ n * 2 for n in numbers if n % 2 == 1 ] # 2 +
    time_in_sec_from_min = [ x*60 for x in time ] # 1 +
    fahrenheit = [ ((float(9)/5)* x + 32) for x in Celsius  if x > 0 ] # + 1 + 1 +
    coloured_things = [ (x,y) for x in colours for y in things ] # 2 +

    if (test == 2 or test == 6) and (distance <= 7 and distance > 1): # 1 + 3 +
        list2 = [ float('.'.join(i.split(':'))) for i in timeList ] # 1 +
        out = ':'.join(list2.split('.'))
        if (len(out) > 0 and len(out) <= 4) or len == -2: # 1 + 2 +
            out += '0'
        ind = vdot.iloc[:, distance - 1][vdot.iloc[:,distance - 1] == out].index.tolist()[0]
        return out, ind
    elif (test == 2 or test == 4) and (distance > 7 and distance <= 42) : # 1 + 3 +
        print("Error: time must be in format(hh:mm:ss)")
        return "", ""
    elif (test == 3 or test == 1) and (distance > 7 and distance <= 42): # 1 + 3 +
        list2 = [ int(''.join(i.split(':'))) for i in timeList ] # 1 +
        out = out[:1] + ':' + out[1:3] + ':' + out[3:]
        ind = vdot.iloc[:, distance - 1][vdot.iloc[:,distance - 1] == out].index.tolist()[0]
        return out, ind
    elif (test == 3 or test == 4) and (distance <= 7 and distance > 1): # 1 + 3 +
        print("Error: time must be in format(mm:ss)")
        return "", ""
radon cc time.py -s
time.py
    F 1:0 compareTimMin - E (31)

Wynik liczony jest od 1, dlatego uzyskaliśmy 12 punktów mimo, że suma daje 11

Construct

Effect on CC

Reasoning

if

+ 1

An if statement is a single decision.

elif

+ 1

The elif statement adds another decision.

else

+ 0

The else statement does not cause a new decision. The decision is at the if.

for

+ 1

There is a decision at the start of the loop.

while

+ 1

There is a decision at the while statement.

except

+ 1

Each except branch adds a new conditional path of execution.

finally

+ 0

The finally block is unconditionally executed.

with

+ 1

The with statement roughly corresponds to a try/except block (see PEP 343 for details).

assert

+ 1

The assert statement internally roughly equals a conditional statement.

Comprehension

+ 1

A list/set/dict comprehension of generator expression is equivalent to a for loop.

boolean

+ 1

Every boolean operator (and, or) adds a decision point.

CC score

Rank

Risk

1 - 5

A

low - simple block

6 - 10

B

low - well structured and stable block

11 - 20

C

moderate - slighltly complex block

21 - 30

D

more than moderate - more complex block

31 - 40

E

high - complex block, alarming

41+

F

very high - error-prone, unstable block

Spowiedź

Table 1. Wyniki refaktoryzacji
Metrics Before refactorization After refactorization

Cyclomatic Complexity [lower is better]

calc.py
    F 40:0 menu - B (9)
vdot.py
    F 7:0 compareTimMin - C (12)
9 blocks (classes, functions, methods) analyzed.

Average complexity: A (3.33)

24 blocks (classes, functions, methods) analyzed.

Average complexity: A (1.25)

Maintainability Index [higher is better]

calc.py - A (47.36)
vdot.py - A (51.01)

Average maintainability: 49.19

runningCalculator.py - A (84.58)
calculator.py - A (57.13)
constants.py - A (79.88)
control.py - A (64.79)
runningIndex.py - A (78.45)
utils.py - A (51.99)

Average maintainability: 69.47

Unused, dead code by Vulture

vdot.py:65: unused variable 'timeTab' (60% confidence)
No errors

Pylint [higher is better, can be negative]

Your code has been rated at -1.58/10
Your code has been rated at 9.17/10

About

Laboratoria: Zaawansowane języki programowania

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages