diff --git a/docs/.DS_Store b/.DS_Store similarity index 91% rename from docs/.DS_Store rename to .DS_Store index 0a77de6..b66b063 100644 Binary files a/docs/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index ccf9fdd..eed02a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *~ -.DS_Store +**/.DS_Store .require_paths Thumbs.db projects_statistics.html \ No newline at end of file diff --git a/docs/power-law.png b/docs/power-law.png new file mode 100644 index 0000000..438943a Binary files /dev/null and b/docs/power-law.png differ diff --git a/docs/power-law.svg b/docs/power-law.svg new file mode 100644 index 0000000..438943a Binary files /dev/null and b/docs/power-law.svg differ diff --git a/docs/rad-sbs-pareto.png b/docs/rad-sbs-pareto.png new file mode 100644 index 0000000..e66b284 Binary files /dev/null and b/docs/rad-sbs-pareto.png differ diff --git a/docs/rad-sbs-pareto.thumb.png b/docs/rad-sbs-pareto.thumb.png new file mode 100644 index 0000000..3bff2d3 Binary files /dev/null and b/docs/rad-sbs-pareto.thumb.png differ diff --git a/docs/rad-sbs.html b/docs/rad-sbs.html new file mode 100644 index 0000000..e039d98 --- /dev/null +++ b/docs/rad-sbs.html @@ -0,0 +1,20421 @@ + + +
+ + + + + +Name | +Chars | +By Lang | +Ignored | +Spec Chars | +Spec by Lang | +Spec Ignored | +Unknown | +
---|---|---|---|---|---|---|---|
core | +103 091 | +Ruby: 91 977 Yaml: 10 899 Erb: 215 |
+ + | 88 241 | +Ruby: 85 998 Erb: 1 963 Haml: 280 |
+ + | md | +
kit | +75 566 | +Ruby: 56 665 Haml: 10 718 Yaml: 7 657 Erb: 526 |
+ JavaScript: 0 | +32 487 | +Ruby: 32 238 Yaml: 249 |
+ + | css, less, md, txt | +
users | +38 805 | +Ruby: 25 014 Yaml: 8 634 Haml: 5 157 |
+ JavaScript: 64 562 | +10 404 | +Ruby: 10 404 | ++ | css, gif, html, ico, less, md, ru | +
saas | +37 841 | +Ruby: 25 507 Yaml: 6 268 Haml: 6 066 |
+ + | 13 206 | +Ruby: 13 206 | ++ | md, ru | +
common_interface | +35 544 | +Haml: 20 328 Ruby: 9 309 Erb: 5 841 Yaml: 66 |
+ JavaScript: 106 947 | +974 | +Ruby: 974 | ++ | css, html, jpg, less, md, png, ru | +
ruby_ext | +35 105 | +Ruby: 35 105 | ++ | 14 709 | +Ruby: 14 709 | ++ | md | +
files | +31 149 | +Ruby: 22 007 Haml: 5 181 Yaml: 2 898 Erb: 1 063 |
+ + | 0 | ++ | + | jpg, md, pdf, png, txt | +
themes | +21 548 | +Haml: 10 738 Ruby: 5 968 Erb: 4 441 Yaml: 401 |
+ + | 902 | +Ruby: 902 | ++ | css, gif, jpg, md, zip | +
vfs | +20 653 | +Ruby: 20 653 | ++ | 12 192 | +Ruby: 12 192 | ++ | md | +
my_cluster | +20 188 | +Ruby: 19 205 Yaml: 983 |
+ + | 0 | ++ | + | conf, md, original, pub, sh | +
search | +13 773 | +Ruby: 12 504 Haml: 1 269 |
+ + | 379 | +Ruby: 379 | ++ | md | +
mongoid_misc | +13 373 | +Ruby: 11 993 Yaml: 1 380 |
+ + | 12 505 | +Ruby: 12 505 | ++ | jpg, md, txt | +
micon | +12 229 | +Ruby: 12 229 | ++ | 11 582 | +Ruby: 11 377 Yaml: 205 |
+ + | md | +
vos | +10 179 | +Ruby: 10 179 | ++ | 1 649 | +Ruby: 1 507 Yaml: 142 |
+ + | md | +
class_loader | +10 031 | +Ruby: 10 031 | ++ | 7 284 | +Ruby: 7 284 | ++ | md, zip | +
bag | +9 244 | +Yaml: 3 552 Ruby: 2 967 Haml: 2 725 |
+ + | 1 537 | +Ruby: 1 537 | ++ | css, iconp, jpg, less, md, pdf, ru, thumbp | +
face | +7 515 | +Ruby: 7 475 Yaml: 40 |
+ + | 2 076 | +Ruby: 2 014 Erb: 62 |
+ + | md | +
assets | +6 575 | +Ruby: 6 547 Yaml: 28 |
+ + | 2 040 | +Ruby: 2 040 | +JavaScript: 28 | +md | +
store | +6 067 | +Ruby: 2 252 Haml: 2 061 Yaml: 1 754 |
+ + | 680 | +Ruby: 680 | ++ | css, less, md | +
cluster_management | +3 787 | +Ruby: 3 787 | ++ | 3 329 | +Ruby: 3 226 Yaml: 103 |
+ + | ai, md, png, svg | +
4ire.net | +3 182 | +Ruby: 2 539 Yaml: 643 |
+ + | 0 | ++ | + | ico, md, ru | +
fake_gem | +2 397 | +Ruby: 2 397 | ++ | 1 696 | +Ruby: 1 696 | ++ | md | +
js | +399 | +Ruby: 399 | +JavaScript: 204 760 | +113 | +Ruby: 113 | ++ | css, md | +
+ Powered by code_stats +
+ + + \ No newline at end of file diff --git a/docs/rad-sbs.png b/docs/rad-sbs.png new file mode 100644 index 0000000..b3df35a Binary files /dev/null and b/docs/rad-sbs.png differ diff --git a/docs/rad-sbs.thumb.png b/docs/rad-sbs.thumb.png new file mode 100644 index 0000000..71ec4ca Binary files /dev/null and b/docs/rad-sbs.thumb.png differ diff --git a/docs/rad-vs-rails.html b/docs/rad-vs-rails.html new file mode 100644 index 0000000..701abfa --- /dev/null +++ b/docs/rad-vs-rails.html @@ -0,0 +1,20256 @@ + + + + + + + + +Name | +Chars | +By Lang | +Ignored | +Spec Chars | +Spec by Lang | +Spec Ignored | +Unknown | +
---|---|---|---|---|---|---|---|
actionpack | +718 000 | +Ruby: 711 021 Erb: 3 871 Yaml: 3 108 |
+ + | 1 327 936 | +Ruby: 1 320 139 Erb: 6 474 Yaml: 1 323 |
+ JavaScript: 106 | +builder, css, erb~, gemspec, html, javascript, jpg, mab, png, rake, rdoc, sql, styles, txt | +
activerecord | +604 969 | +Ruby: 604 024 Yaml: 945 |
+ + | 1 092 213 | +Ruby: 1 069 307 Yaml: 22 906 |
+ + | csv, gemspec, jpg, log, rake, rdoc | +
activesupport | +348 231 | +Ruby: 347 475 Yaml: 756 |
+ + | 430 746 | +Ruby: 430 746 | ++ | dat, gemspec, rdoc | +
railties | +172 697 | +Ruby: 166 093 Yaml: 4 701 Erb: 1 903 |
+ JavaScript: 0 | +213 649 | +Ruby: 213 591 Yaml: 58 |
+ + | css, gemspec, html, ico, png, rake, rdoc, ru, tt, txt | +
activemodel | +110 086 | +Ruby: 109 206 Yaml: 880 |
+ + | 123 890 | +Ruby: 123 890 | ++ | gemspec, rdoc | +
core | +103 091 | +Ruby: 91 977 Yaml: 10 899 Erb: 215 |
+ + | 88 241 | +Ruby: 85 998 Erb: 1 963 Haml: 280 |
+ + | md | +
activeresource | +69 641 | +Ruby: 69 641 | ++ | 97 365 | +Ruby: 97 365 | ++ | gemspec, rdoc | +
actionmailer | +33 640 | +Ruby: 33 640 | ++ | 39 927 | +Ruby: 38 518 Erb: 1 335 Haml: 74 |
+ + | bak, erb~, gemspec, jpg, rdoc, rxml | +
+ Powered by code_stats +
+ + + \ No newline at end of file diff --git a/docs/rad-vs-rails.png b/docs/rad-vs-rails.png new file mode 100644 index 0000000..2961bab Binary files /dev/null and b/docs/rad-vs-rails.png differ diff --git a/docs/rad-vs-rails.thumb.png b/docs/rad-vs-rails.thumb.png new file mode 100644 index 0000000..8e021fb Binary files /dev/null and b/docs/rad-vs-rails.thumb.png differ diff --git a/my/analyze.rb b/my/analyze.rb index 0fad1f9..c2f88f9 100644 --- a/my/analyze.rb +++ b/my/analyze.rb @@ -20,7 +20,7 @@ # Rails paths = "/Users/alex/other_projects/z-libs/rails".to_dir.dirs.collect{|dir| dir.path}.select{|dir| dir =~ /\/acti|\/railti/} -# paths << "/Users/alex/projects/core" +paths << "/Users/alex/projects/core" CodeStats.analyze_and_report(*(paths << {except: :JavaScript})) diff --git a/readme.md b/readme.md index e7a3fd6..383582c 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,14 @@ -# Code Stats +# CodeStats + +Source code statistics and metrics. [![rails-thumb]][rails-img] [![some-os-projects-thumb]][some-os-projects-img] [![mongoid-vs-mongomapper-thumb]][mongoid-vs-mongomapper-img] -Screenshots are showing us: Complexity of [Rails libraries][rails-img], comparison of [some Open Source projects][some-os-projects-img] and [MongoMapper vs Mongoid][mongoid-vs-mongomapper-img] (You can see actual .html report files in [docs][docs]). +Screenshots showing us: Complexity of [Rails libraries][rails-img], comparison of [some Open Source projects][some-os-projects-img] and [MongoMapper vs Mongoid][mongoid-vs-mongomapper-img] (You can see actual .html report files in [docs][docs]). # Installation & Usage -This tool is language-agnostic, but it itself is made with Ruby, so You need Ruby installed to use it. Next, just install it as a gem: +This tool is language-agnostic, but it itself is made with Ruby, so You need Ruby installed to use it, to install it type: ``` bash gem install code_stats2 @@ -19,9 +21,7 @@ code_stats /projects/wordpress code_stats /projects/* except: JavaScript ``` -Also You can easily customize it, sources of Code Stats is small and simple as an egg. - - +Also You can easily customize it, sources are small and simple as an egg. Copyright (c) Alexey Petrushin http://petrush.in, released under the MIT license. diff --git a/todo.md b/todo.md index 957fa2b..9b2eb67 100644 --- a/todo.md +++ b/todo.md @@ -1,16 +1,71 @@ - Add html, json, jade +# Article stub: -# Docs +# Why may You need such numbers and graphs? -Power law, efficiency and decision making +I developed this tool and made it language agnostic because: -[TODO about the [Power law][power_law] (also known as the Pareto principle and the 80-20 rule) and it's fundamental nature] +- I wanted to find simple open source game project to examine and play with. There are lots of such projects and because I have very little free time I need a way to measure how big and complex they are and select a simple one. So this tool can be useful to roughly **estimate tons of unknown projects** in different languages. +You can also **estimate how healthy they are** by looking at the code / specs ratio. -[TODO about my causes to write such strange tool: why it's so simple and why language-agnostic is important: find simple game project, compare my own projects with other, find big places in my sources, see spec/code ratio to evaluate helth of project] +- I also was curious how my own projects are compared to other well know projects. How big the source code are, how well is it covered with specs. -[TODO about decition makin: right now there's tons and tons and tons of tools, projects and all stuff, it's hard to navigate, examine and score them] +- I wanted a way to find most heavy and most useful parts of code in my projects, in order to try to eliminate the first and pay more attention to the second (see next section). -[TODO efficiency: what code parts is most important] +# Power law, efficiency and decision making -[TODO I deliberately choose the Red color for the sources (and the Blue for specs / tests) because the less code - the better (in general, with other things been equal).] \ No newline at end of file +You probably noticed that if You compare multiple projects the graph almost always looks like this ![power-law-img]. The code distribution is uneven, this distribution is known as the [Power law][power-law] (it also known as the Pareto principle and the 80-20 rule). + +Why is this interesting and important? Because it affects Your efficiency - the source code of Your projects fall under the [Power law][power-law], with the following consequence: **20% of code responsible for 80% of app value**, other 80% of code are responsible only for 20% of value. + +How can we use this? I would like to use a detached sample to better illustrate this - sales also fall under this law - 80% of income are come from 20% of clients. And one of the salesperson's rule of effectiveness: + +1. analyze sales and find those 20% of clients +2. pay more attention to them and less to other 80% + +The same are valid for the code, and You can use this tool to analyze it find those important 20% of code and pay more attention to it and less to the other. + +There's also the second consequence: **80% of code are produced by 20% of application's modules**. Note: these 20% - it's the different code, not the same as the "important 20% part". + +Also would like to illustrate this with sales example - there are 20% of clients that causes 80% of troubles, and if You want to be efficient - You need to pay attention to the quality of the client base and sometimes drop those clients that produce more troubles than the money. +Back to code - **try to cut fat parts**, this tool help You to find it. + +And, the last consequence, a philosophical one - no matter what You do the project's code always will comply to Power law, and there always will be 20/80 ratio :). + +# Sample analysis of rad_sbs + +Here's sample analysis of my project [rad_sbs][rad_sbs], it's a very simple solution for small businesses (site, forum, e-commerce, organizer). It builded as a lots of cooperated modules, let's look at it's code statistics (see first image): + +``` bash +code_stats ~/projects/* except: JavaScript +``` + +[![rad-sbs-thumb]][rad-sbs-img] [![rad-sbs-pareto-thumb]][rad-sbs-pareto-img] + +How to find those important 20%? I don't know, but I belive that in general application code is more important than code of support libraries. Let's divide app and support libraries (see second image): green tick - actual app logic, red cross - framework libraries, strikethrough - some other libraries, ignored. Totals: libs: 283 000 vs app: 114 000. + +What to do next? Also don't know, but believe it would be good to do following: + +- for the app: try to even more distill app logic and move code to support libraries +- for libraries: try to replace our own custom libraries with public libraries supported by other developers + +# Sample analysis Rad vs Rails + +I created the [Rad][rad] framework and was curious - how it's sources are compared to Rails? + +[![rad-vs-rails-thumb]][rad-vs-rails] + +See? It's small! Taken into account that it has about 90% of Rails features - not bad huh? + +[rad]: https://github.com/alexeypetrushin/rad_core + +[power-law]: http://en.wikipedia.org/wiki/Power_law + +[power-law-img]: https://github.com/alexeypetrushin/code_stats/raw/master/docs/power-law.png +[rad_sbs]: https://github.com/alexeypetrushin/rad_sbs +[rad-sbs-pareto-img]: https://github.com/alexeypetrushin/code_stats/raw/master/docs/rad-sbs-pareto.png + +[rad]: https://github.com/alexeypetrushin/rad_core +[rad-vs-rails]: https://github.com/alexeypetrushin/code_stats/raw/master/docs/rad-sbs-pareto.png +[rad-vs-rails-thumb]: https://github.com/alexeypetrushin/code_stats/raw/master/docs/rad-sbs-pareto.png \ No newline at end of file