Calculate code metrics in various languages
Project description
NOTE: This is an edited version of multimetric, that allows you use this module in a programmatically way, it's not intended to replace the original CLI module, and I won't update more this package. For more info, see the original package
Usage
from multimetricprog import calculator
calculator.calculate('''
print("your python code")
''')
returns
{
"files": {
"fp.py": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"lang": [
"Python"
],
"loc": 1,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2
}
},
"overall": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"loc": 1,
"maintainability_index": 100,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2,
"pylint": 100.0,
"tiobe": 99.32835820895522,
"tiobe_compiler": 100.0,
"tiobe_complexity": 95.5223880597015,
"tiobe_coverage": 100.0,
"tiobe_duplication": 100.0,
"tiobe_fanout": 100.0,
"tiobe_functional": 100.0,
"tiobe_security": 100.0,
"tiobe_standard": 100.0
},
"stats": {
"max": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"loc": 1,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2
},
"mean": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"loc": 1,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2
},
"median": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"loc": 1,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2
},
"min": {
"comment_ratio": 0.0,
"cyclomatic_complexity": 2,
"fanout_external": 0,
"fanout_internal": 0,
"halstead_bugprop": 0.004643856189774725,
"halstead_difficulty": 1.3333333333333333,
"halstead_effort": 18.575424759098897,
"halstead_timerequired": 1.0319680421721609,
"halstead_volume": 13.931568569324174,
"loc": 1,
"operands_sum": 4,
"operands_uniq": 3,
"operators_sum": 2,
"operators_uniq": 2
}
}
}
Notes
By default, the filename "fp.py" is hardcoded in order to make the module work, if you're interested, you can fork this and make a better version for this module (also, a better README.md).
Item structure
item | description | range | recommendation |
---|---|---|---|
comment_ratio | Comment to Code percentage | 0..100 | > 30.0 |
cyclomatic_complexity | Cyclomatic complexity according to McCabe | 0..(inf) | < 10 |
fanout_external | Number imports from out of tree modules | 0..(inf) | |
fanout_internal | Number imports from same source tree modules | 0..(inf) | |
halstead_bugprop | Number of delivered bugs according to Halstead | 0..(inf) | < 0.05 |
halstead_difficulty | Difficulty according to Halstead | 0..(inf) | |
halstead_effort | Effort according to Halstead | 0..(inf) | |
halstead_timerequired | Time required to program according to Halstead | 0..(inf) | |
halstead_volume | Volume according to Halstead | 0..(inf) | |
lang | list of identified programming languages | list | |
loc | Lines of code | 1..(inf) | |
maintainability_index | Maintainability index | 0..100 | > 80.0 |
operands_sum | Number of used operands | 1..(inf) | |
operands_uniq | Number of unique used operands | 1..(inf) | |
operators_sum | Number of used operators | 1..(inf) | |
operators_uniq | Number of unique used operators | 1..(inf) | |
pylint | General quality score according to pylint | 0..100 | > 80.0 |
tiobe_compiler | Compiler warnings score according to TIOBE | 0..100 | > 90.0 |
tiobe_complexity | Complexity according to TIOBE | 0..100 | > 80.0 |
tiobe_coverage | Coverage according to TIOBE | 0..100 | > 80.0 |
tiobe_duplication | Code duplications score according to TIOBE | 0..100 | > 80.0 |
tiobe_fanout | Fan-Out score according to TIOBE | 0..100 | > 80.0 |
tiobe_functional | Functional defect score according to TIOBE | 0..100 | > 90.0 |
tiobe_security | Security score according to TIOBE | 0..100 | > 90.0 |
tiobe_standard | Language standard score according to TIOBE | 0..100 | > 80.0 |
tiobe | General quality score according to TIOBE | 0..100 | > 80.0 |
Statistics
The item stats
contains in addition to the above mentioned the following items, which by themselves contain all the items mentioned at Item structure
max
= the maximum value of all items of the metricmean
= statistical mean over all items of the metricmedian
= statistical median over all items of the metricmin
= the minimum value of all items of the metricsd
= standard deviation over all items of the metric
Further reading
Bugs & Contribution
Feel free to create issues or pull requests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multimetricprog.tar.gz
(16.3 kB
view details)
Built Distribution
multimetricprog-py3-none-any.whl
(22.4 kB
view details)
File details
Details for the file multimetricprog.tar.gz
.
File metadata
- Download URL: multimetricprog.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7eb74463399af7fe5c4856a6cc81bc9b031411ec5bf40595f82e0d4bc409c85 |
|
MD5 | 9b3279c3beeaa6fab8adb5ff12805b0d |
|
BLAKE2b-256 | 301967e089a7af0b7cd2fac7419382d907999d1dfd48a7cf5cbaed9bf45ef63c |
File details
Details for the file multimetricprog-py3-none-any.whl
.
File metadata
- Download URL: multimetricprog-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags:
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f2b05f60457cc98b69658e6977dd372af936f42f5a057d1011dc07155b53e8f |
|
MD5 | 5fb7c04e55a3169509ad9499c42a95b1 |
|
BLAKE2b-256 | f4cb84c6d72e5ee1e773d6ad5e34f6fd3d68a27fba11c1a272474e214d067cd9 |