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 @@ + + + + + + + + +

Projects Statistics

+
19133210805349209510473651849814311492245032845201881415225878238111182817315107819591861567477116318240935128824132487104041320697414709090212192037912505115821649728415372076204068033290169611310309175566388053784135544351053114921548206532018813773133731222910179100319244751565756067378731822397399SpecsSourcescorekituserssaascommon_interfaceruby_extfilesthemesvfsmy_clustersearchmongoid_miscmiconvosclass_loaderbagfaceassetsstorecluster_management4ire.netfake_gemjs0k25k50k75k100k125k150k175k200k225kCharacters Count Highcharts.com
+

Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCharsBy LangIgnoredSpec CharsSpec by LangSpec IgnoredUnknown
core103 091Ruby: 91 977
Yaml: 10 899
Erb: 215
88 241Ruby: 85 998
Erb: 1 963
Haml: 280
md
kit75 566Ruby: 56 665
Haml: 10 718
Yaml: 7 657
Erb: 526
JavaScript: 032 487Ruby: 32 238
Yaml: 249
css, less, md, txt
users38 805Ruby: 25 014
Yaml: 8 634
Haml: 5 157
JavaScript: 64 56210 404Ruby: 10 404css, gif, html, ico, less, md, ru
saas37 841Ruby: 25 507
Yaml: 6 268
Haml: 6 066
13 206Ruby: 13 206md, ru
common_interface35 544Haml: 20 328
Ruby: 9 309
Erb: 5 841
Yaml: 66
JavaScript: 106 947974Ruby: 974css, html, jpg, less, md, png, ru
ruby_ext35 105Ruby: 35 10514 709Ruby: 14 709md
files31 149Ruby: 22 007
Haml: 5 181
Yaml: 2 898
Erb: 1 063
0jpg, md, pdf, png, txt
themes21 548Haml: 10 738
Ruby: 5 968
Erb: 4 441
Yaml: 401
902Ruby: 902css, gif, jpg, md, zip
vfs20 653Ruby: 20 65312 192Ruby: 12 192md
my_cluster20 188Ruby: 19 205
Yaml: 983
0conf, md, original, pub, sh
search13 773Ruby: 12 504
Haml: 1 269
379Ruby: 379md
mongoid_misc13 373Ruby: 11 993
Yaml: 1 380
12 505Ruby: 12 505jpg, md, txt
micon12 229Ruby: 12 22911 582Ruby: 11 377
Yaml: 205
md
vos10 179Ruby: 10 1791 649Ruby: 1 507
Yaml: 142
md
class_loader10 031Ruby: 10 0317 284Ruby: 7 284md, zip
bag9 244Yaml: 3 552
Ruby: 2 967
Haml: 2 725
1 537Ruby: 1 537css, iconp, jpg, less, md, pdf, ru, thumbp
face7 515Ruby: 7 475
Yaml: 40
2 076Ruby: 2 014
Erb: 62
md
assets6 575Ruby: 6 547
Yaml: 28
2 040Ruby: 2 040JavaScript: 28md
store6 067Ruby: 2 252
Haml: 2 061
Yaml: 1 754
680Ruby: 680css, less, md
cluster_management3 787Ruby: 3 7873 329Ruby: 3 226
Yaml: 103
ai, md, png, svg
4ire.net3 182Ruby: 2 539
Yaml: 643
0ico, md, ru
fake_gem2 397Ruby: 2 3971 696Ruby: 1 696md
js399Ruby: 399JavaScript: 204 760113Ruby: 113css, 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 @@ + + + + + + + + +

Projects Statistics

+
2045936169718277897738634623397619133216700673567132793610922134307462136491238908824197365399277180006049693482311726971100861030916964133640SpecsSourcesactionpackactiverecordactivesupportrailtiesactivemodelcoreactiveresourceactionmailer0k250k500k750k1000k1250k1500k1750k2000k2250kCharacters Count Highcharts.com
+

Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCharsBy LangIgnoredSpec CharsSpec by LangSpec IgnoredUnknown
actionpack718 000Ruby: 711 021
Erb: 3 871
Yaml: 3 108
1 327 936Ruby: 1 320 139
Erb: 6 474
Yaml: 1 323
JavaScript: 106builder, css, erb~, gemspec, html, javascript, jpg, mab, png, rake, rdoc, sql, styles, txt
activerecord604 969Ruby: 604 024
Yaml: 945
1 092 213Ruby: 1 069 307
Yaml: 22 906
csv, gemspec, jpg, log, rake, rdoc
activesupport348 231Ruby: 347 475
Yaml: 756
430 746Ruby: 430 746dat, gemspec, rdoc
railties172 697Ruby: 166 093
Yaml: 4 701
Erb: 1 903
JavaScript: 0213 649Ruby: 213 591
Yaml: 58
css, gemspec, html, ico, png, rake, rdoc, ru, tt, txt
activemodel110 086Ruby: 109 206
Yaml: 880
123 890Ruby: 123 890gemspec, rdoc
core103 091Ruby: 91 977
Yaml: 10 899
Erb: 215
88 241Ruby: 85 998
Erb: 1 963
Haml: 280
md
activeresource69 641Ruby: 69 64197 365Ruby: 97 365gemspec, rdoc
actionmailer33 640Ruby: 33 64039 927Ruby: 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