├── .gitignore ├── .prettierrc ├── LICENSE ├── README.org ├── code-compass.el ├── pages ├── age-enclosure-diagram │ ├── script.js │ ├── style.css │ └── zoomable.html ├── edge-bundling │ ├── script.js │ ├── style.css │ └── zoomable.html ├── enclosure-diagram │ ├── script.js │ ├── style.css │ └── zoomable.html └── knowledge-enclosure-diagram │ ├── script.js │ ├── style.css │ └── zoomable.html ├── requirements.txt ├── scripts ├── code_age_csv_as_enclosure_json.py ├── communication_csv_as_edge_bundling.py ├── coupling_csv_as_edge_bundling.py ├── csv-to-pie-graph.py ├── csv_as_enclosure_json.py ├── knowledge_csv_as_enclosure_diagram.py └── refactoring_csv_as_enclosure_diagram.py └── test └── code-compass-test.el /.gitignore: -------------------------------------------------------------------------------- 1 | dependencies/ -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * Code compass 2 | :PROPERTIES: 3 | :ID: 1683c6ef-701e-476c-a104-56db5582c785 4 | :END: 5 | 6 | This package shall guide you in your software development within 7 | Emacs. For example, it will point at the code that requires your 8 | changes the most and it will suggest you who to ask for help when you 9 | are lost. 10 | 11 | I have presented some of the capabilities of *code-compass* in [[https://emacsconf.org/2020/talks/24/][this 12 | talk of EmacsConf2020]]. 13 | 14 | ** Credits 15 | :PROPERTIES: 16 | :ID: 3d3fbd8e-ec09-4dbe-91aa-99713b6fac89 17 | :END: 18 | 19 | A significant part of this project relies on [[https://github.com/adamtornhill/code-maat][code-maat]] and the bright 20 | mind of his author Adam Tornhill. His books are inspiring and a 21 | [[https://pragprog.com/titles/atcrime/your-code-as-a-crime-scene/][suggested]] [[https://pragprog.com/titles/atevol/software-design-x-rays/][read]]. 22 | 23 | ** Features 24 | :PROPERTIES: 25 | :CREATED: [2022-04-30 Sat 21:53] 26 | :ID: 9c50d648-8562-497e-93d4-088db1a326a8 27 | :END: 28 | 29 | Use =code-compass-cheatsheet= to have a quick reference of the available commands and their aim. 30 | Check the =Release Checklist= heading for more information about them. 31 | 32 | ** Installation and Dependencies 33 | :PROPERTIES: 34 | :CREATED: [2020-12-11 Fri 19:10] 35 | :ID: 6d691473-a522-46cf-ae41-09fd5c2c69df 36 | :END: 37 | 38 | *Please run =code-compass-doctor= if you encounter errors in running this tool* 39 | 40 | Note: I label dependencies as *optional* when the commands needing the 41 | dependency warn you they cannot execute because the dependency is 42 | missing. 43 | 44 | This project depends on the following external dependencies: 45 | 46 | - Git 47 | - Python 3 48 | - Java 8 or above 49 | - code-maat 50 | - cloc 51 | - graph-cli (optional - only few commands will not succeed) 52 | - gource (optional) 53 | 54 | And the following Emacs packages: 55 | 56 | - async.el 57 | - dash.el 58 | - s.el 59 | - simple-httpd 60 | 61 | If you are on a Linux system, Docker, the Code Maat image, and cloc can be 62 | installed by running the following script: 63 | 64 | #+begin_src sh :noeval 65 | # Docker is only necessary if you want to use that instead of the (automatically downloaded) JAR file 66 | # see here for how to install in systems different from Linux Debian: https://gist.github.com/rstacruz/297fc799f094f55d062b982f7dac9e41 67 | #sudo apt install docker.io; 68 | #sudo systemctl start docker; 69 | # after you manage to run docker successfully 70 | #git clone https://github.com/adamtornhill/code-maat.git; 71 | #cd code-maat; 72 | #docker build -t code-maat-app . 73 | 74 | sudo apt install cloc; 75 | #+end_src 76 | 77 | Python dependencies are stored in a virtual environment managed by 78 | code-compass. These are installed by the function =code-compass-install=. 79 | 80 | *** Installation from Melpa 81 | 82 | Code-compass can be installed as a package using =use-package=: 83 | 84 | #+begin_src elisp :noeval 85 | (use-package code-compass 86 | :ensure t 87 | :config 88 | (code-compass-install)) 89 | #+end_src 90 | 91 | *** Installation 92 | 93 | Code-compass can be installed from manually with: 94 | 95 | #+begin_src elisp :noeval 96 | (use-package async) 97 | (use-package dash) 98 | (use-package s) 99 | (use-package simple-httpd) 100 | 101 | (use-package code-compass 102 | :load-path "~/.emacs.d/lisp" 103 | :config 104 | (code-compass-install)) 105 | #+end_src 106 | 107 | For trying things out in a clean Emacs: 108 | 109 | #+begin_src elisp :noeval :tangle /tmp/code-compass-minimal-setup.el 110 | (require 'package) 111 | (eval-and-compile 112 | (setq 113 | package-archives 114 | '(("melpa-stable" . "https://stable.melpa.org/packages/") 115 | ("melpa" . "https://melpa.org/packages/") 116 | ("marmalade" . "https://marmalade-repo.org/packages/") 117 | ("org" . "https://orgmode.org/elpa/") 118 | ("gnu" . "https://elpa.gnu.org/packages/")))) 119 | (package-initialize) 120 | 121 | ;;; Bootstrap use-package 122 | ;; Install use-package if it's not already installed. 123 | (unless (package-installed-p 'use-package) 124 | (package-refresh-contents) 125 | (package-install 'use-package)) 126 | (setq use-package-always-ensure 't) 127 | (require 'use-package) 128 | (require 'diminish) 129 | (require 'bind-key) 130 | (use-package async) 131 | (use-package dash) 132 | (use-package s) 133 | (use-package simple-httpd) 134 | #+end_src 135 | 136 | #+begin_src sh :results none 137 | emacs -Q -l /tmp/code-compass-minimal-setup.el -l ./code-compass.el 138 | #+end_src 139 | 140 | ** Limitations 141 | :PROPERTIES: 142 | :CREATED: [2020-12-11 Fri 21:35] 143 | :ID: efdeb29f-083a-487c-93d5-48c93fc5b9c8 144 | :END: 145 | 146 | The limitations I know: 147 | 148 | 1. only Git support for now, but I am open to PRs (should be easy 149 | because code-maat partially support other VCS already) 150 | 151 | 2. Adam said that code-maat may fail for code bases larger than 5 152 | million lines. Please report if you observe that is the case, we 153 | will find a solution. 154 | 155 | 3. most likely others I will eventually discover from the issues ;) 156 | 157 | ** Release Checklist 158 | :PROPERTIES: 159 | :ID: 8450da84-5aa9-46f9-b65c-5055ae907975 160 | :END: 161 | 162 | Releasing this in the wild is exciting, but it will take some time. 163 | Here what you can expect. 164 | 165 | *** DONE install instructions and dependencies 166 | :PROPERTIES: 167 | :ID: 27174a0f-186d-4963-a5b3-4704d680476f 168 | :END: 169 | - https://ag91.github.io/blog/2020/12/11/emacsconf2020-first-steps-towards-emacs-becoming-your-code-compass/ 170 | *** DONE hotspots 171 | :PROPERTIES: 172 | :CREATED: [2020-12-18 Fri 18:01] 173 | :ID: 00f4d809-e7e0-4f29-a2af-30fa07a080e7 174 | :END: 175 | :LOGBOOK: 176 | CLOCK: [2020-12-18 Fri 18:01]--[2020-12-18 Fri 18:01] => 0:00 177 | :END: 178 | - hotspots analysis: https://ag91.github.io/blog/2020/12/18/emacs-as-your-code-compass-finding-code-hotspots/ 179 | - hotspots evolution: https://ag91.github.io/blog/2020/12/24/emacs-as-your-code-compass-looking-at-hotspots-evolution/ 180 | - hotspots analysis for microservices: https://ag91.github.io/blog/2021/04/08/emacs-as-your-code-compass-find-hotspots-in-micro-services/ 181 | *** DONE software complexity 182 | :PROPERTIES: 183 | :ID: 6847956b-75c1-4ad7-b911-1994a21a26ac 184 | :CREATED: [2020-12-27 Sun 14:10] 185 | :END: 186 | - https://ag91.github.io/blog/2020/12/27/emacs-as-your-code-compass-how-complex-is-this-code/ 187 | 188 | *** DONE code churn 189 | :PROPERTIES: 190 | :ID: 04b3a73e-60f7-4a6c-87d7-10ff978e24b4 191 | :CREATED: [2021-01-01 Fri 16:54] 192 | :END: 193 | - https://ag91.github.io/blog/2021/01/01/emacs-as-your-code-compass-how-much-code-we-produced-for-this-repository-lately/ 194 | *** DONE change coupling 195 | :PROPERTIES: 196 | :ID: 59df8e40-e5d3-47dc-b9da-10666301acc8 197 | :END: 198 | - https://ag91.github.io/blog/2021/01/07/emacs-as-your-code-compass-how-related-are-these-modules/ 199 | *** DONE use case of coupling: find coupled files 200 | :PROPERTIES: 201 | :CREATED: [2021-01-12 Tue 22:16] 202 | :ID: 29de5da7-8ba0-46a7-8afa-397b02d4642d 203 | :END: 204 | - https://ag91.github.io/blog/2021/01/12/emacs-as-your-code-compass-let-history-show-you-which-files-to-edit-next/ 205 | *** DONE code communication 206 | :PROPERTIES: 207 | :CREATED: [2021-01-22 Fri 20:32] 208 | :ID: ceb52892-7b08-4171-8887-670254989b4c 209 | :END: 210 | :LOGBOOK: 211 | CLOCK: [2021-01-12 Tue 22:16] 212 | :END: 213 | - [[https://ag91.github.io/blog/2021/01/22/emacs-as-your-code-compass-find-collaborators-you-should-(chit)-chat-with/]] 214 | *** DONE code knowledge 215 | :PROPERTIES: 216 | :CREATED: [2021-01-31 Sun 11:48] 217 | :ID: 04064490-aaa7-44c3-a31c-a8d223db31a0 218 | :END: 219 | :LOGBOOK: 220 | CLOCK: [2021-01-22 Fri 20:32] 221 | :END: 222 | - https://ag91.github.io/blog/2021/01/28/emacs-as-your-code-compass-who-can-i-ask-for-help/ 223 | *** DONE code stability 224 | :PROPERTIES: 225 | :ID: fca4bd0a-8c67-4482-8692-a32f98ea2438 226 | :CREATED: [2021-02-06 Sat 16:42] 227 | :END: 228 | - https://ag91.github.io/blog/2021/02/06/-emacs-as-your-code-compass-how-stable-is-my-code/ 229 | *** DONE fragmentation 230 | :PROPERTIES: 231 | :ID: b72b368e-7436-4311-a0e6-97b71b8f2260 232 | :CREATED: [2021-02-12 Fri 19:19] 233 | :END: 234 | :LOGBOOK: 235 | CLOCK: [2021-02-06 Sat 16:42] 236 | :END: 237 | https://ag91.github.io/blog/2021/02/11/emacs-as-your-code-compass-how-fragmented-is-the-knowledge-of-this-file/ 238 | *** DONE word analysis 239 | :PROPERTIES: 240 | :CREATED: [2021-02-20 Sat 19:14] 241 | :ID: 46dcf690-2294-47fd-bc33-e1699eba845a 242 | :END: 243 | - https://ag91.github.io/blog/2021/02/20/emacs-as-your-code-compass-what-is-this-text-about----without-me-reading-it/ 244 | *** DONE use case of coupling: generate todos for current file 245 | :PROPERTIES: 246 | :CREATED: [2021-03-05 Fri 00:17] 247 | :ID: a5e1f2f8-3836-4092-bbc7-2943aa2ff186 248 | :END: 249 | - https://ag91.github.io/blog/2021/03/04/emacs-as-your-code-compass-what-files-do-i-need-to-change-next/ 250 | *** DONE integrate gource 251 | :PROPERTIES: 252 | :CREATED: [2021-03-04 Thu 10:34] 253 | :ID: 63b080a9-859b-4863-af5f-2d6eed8bd215 254 | :END: 255 | https://ag91.github.io/blog/2021/03/19/emacs-as-your-code-compass-watch-history-with-gource/ 256 | *** DONE file-churn icon 257 | :PROPERTIES: 258 | :CREATED: [2021-02-24 Wed 21:47] 259 | :ID: c4809753-ff55-4726-81d7-e1caa37b60cd 260 | :END: 261 | - https://ag91.github.io/blog/2021/03/26/emacs-as-your-code-compass-a-gentle-trigger-for-maintenance/ 262 | *** DONE main contributors notification 263 | :PROPERTIES: 264 | :ID: da34e784-028f-4d04-81ec-baa267c9c668 265 | :END: 266 | - https://ag91.github.io/blog/2021/04/18/emacs-as-your-code-compass-quietly-show-who-can-help/ 267 | *** DONE code refactoring 268 | :PROPERTIES: 269 | :ID: c0c383ca-c5a1-4c65-be7d-853dce78ac23 270 | :END: 271 | https://ag91.github.io/blog/2022/11/23/emacs-as-your-code-compass-who-is-the-person-who-refactored-most-in-this-project/ 272 | :PROPERTIES: 273 | :CREATED: [2022-11-23 Wed 23:42] 274 | :END: 275 | *** DONE functions complexity 276 | :PROPERTIES: 277 | :CREATED: [2022-11-23 Wed 23:42] 278 | :END: 279 | oh well I needed tree-sitter for this, see here: https://github.com/ag91/moldable-emacs/blob/master/molds/contrib.el#L242 280 | ** License 281 | [[https://www.gnu.org/licenses/gpl-3.0.html][GPLv3]] 282 | 283 | *** Dependencies 284 | [[https://github.com/d3/d3/][d3]]: 285 | 286 | License: [[https://opensource.org/licenses/BSD-3-Clause][BSD-3]] 287 | 288 | Copyright 2010-2020 Mike Bostock 289 | 290 | ** Contributing 291 | :PROPERTIES: 292 | :CREATED: [2020-12-11 Fri 21:40] 293 | :ID: f1b0881f-1c66-49d6-ac46-aecd8dbe9e64 294 | :END: 295 | 296 | If you have ideas or wishes, just open an issue and I will look into 297 | it! Thanks for caring. 298 | 299 | *** Testing 300 | :PROPERTIES: 301 | :CREATED: [2023-03-09 Thu 16:26] 302 | :ID: 7d1a7149-8ef2-41c0-9b6b-36b3000ce561 303 | :END: 304 | 305 | Functions without side effects have tests in their documentation. 306 | 307 | To run those install https://github.com/ag91/doctest (at the time of 308 | writing my fork as enhancements over the original) and run =doctest=. 309 | 310 | ** Alternatives 311 | :PROPERTIES: 312 | :CREATED: [2020-12-18 Fri 16:00] 313 | :ID: 77dac754-8a76-4234-bb1c-0f4e0ea6cb46 314 | :END: 315 | 316 | - [[https://codescene.com/][CodeScene]]: this is the code analysis tool of Adam Tornhill which 317 | organizations can use to manage their software and organizational 318 | complexity. Code-compass learns from CodeScene and adapts to empower 319 | you. 320 | - [[https://github.com/textarcana/code-risk/tree/master/bin][code-risk]]: this is a set of scripts Noah Sussman's uses to find 321 | quality issues in repositories. Code-compass includes these and make 322 | them easily accessible to you. 323 | - [[https://github.com/smontanari/code-forensics][code-forensics]]: this makes available code-maat analyses in a node 324 | application. Code-compass offers a subset of these for now and 325 | focuses more on supporting you while you edit your project. (Thanks 326 | @BlankSpruce to share this repository!) 327 | - [[https://github.com/aspiers/git-deps/][git-deps]]: this shows you dependencies between git commits. Hopefully 328 | code-compass will integrate this project to help you when, for 329 | example, you are struggling to identify the commit that broke your 330 | release. 331 | - ??? 332 | -------------------------------------------------------------------------------- /code-compass.el: -------------------------------------------------------------------------------- 1 | ;;; code-compass.el --- Navigate software aided by metrics and visualization -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2023 Andrea 4 | 5 | ;; Author: Andrea 6 | ;; Version: 0.1.4 7 | ;; Package-Requires: ((emacs "26.1") (s "1.12.0") (dash "2.13") (async "1.9.7") (simple-httpd "1.5.1")) 8 | ;; Keywords: tools, extensions, help 9 | ;; Homepage: https://github.com/ag91/code-compass 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see 23 | 24 | ;;; Commentary: 25 | 26 | ;; Make Emacs your compass in a sea of software complexity. 27 | ;; 28 | ;; This tool puts the power and knowledge of your repository history in your hands. 29 | ;; You can find what analyses are supported with `code-compass-cheatsheet'. 30 | ;; A good way to start is: 31 | ;; - `code-compass-show-hotspots': 32 | ;; show hotspots in code repository as a circle diagram. 33 | ;; Circles are packages or modules. 34 | ;; The redder the circle, the more it has been modified lately. The bigger the more code it contains. 35 | ;; 36 | ;; If you are having trouble with dependencies, try `code-compass-doctor' to get some clarity. 37 | ;; 38 | ;; See documentation at https://github.com/ag91/code-compass 39 | 40 | ;;; Code: 41 | (require 'dash) 42 | (require 's) 43 | (require 'simple-httpd) 44 | (require 'async) 45 | (require 'url) 46 | (require 'vc) 47 | 48 | (defun code-compass--python-script (script) 49 | "Return the command to run a script with code-compass' python. " 50 | (concat code-compass-download-directory "/venv/bin/python3 " script)) 51 | 52 | (defgroup code-compass nil 53 | "Options specific to code-compass." 54 | :tag "code-compass" 55 | :group 'code-compass) 56 | 57 | (defcustom code-compass-default-port 8888 58 | "Default port on which to serve analyses files." 59 | :type 'int 60 | :group 'code-compass) 61 | 62 | (defcustom code-compass-default-periods 63 | '("beginning" "1d" "2d" "3d" "6d" "12d" "18d" "24d" "1m" "2m" "6m") 64 | "Starting date to reduce the Git log for analysis. 65 | 'beginning' is a keyword to say to not reduce. 66 | 'Nd' means to start after N days, where N is a positive number. 67 | 'Nm' means to start after N months, where N is a positive number." 68 | :group 'code-compass 69 | :type 'string) 70 | 71 | (defcustom code-compass-snapshot-periods 72 | '("1d" "3m" "6m" "9m" "12m" "15m") 73 | "A list of snapshots periods to show evolution of analyses over time." 74 | :group 'code-compass 75 | :type 'string) 76 | 77 | (defconst code-compass-path-to-code-compass (file-name-directory (or load-file-name (buffer-file-name))) 78 | "The directory from where code compass was loaded.") 79 | 80 | (defun code-compass--expand-file-name (file-name) 81 | "Expand FILE-NAME with `code-compass-path-to-code-compass'." 82 | (expand-file-name file-name code-compass-path-to-code-compass)) 83 | 84 | (defcustom code-compass-tmp-directory "/tmp" 85 | "Directory to store temporary files generated by code-compass." 86 | :group 'code-compass 87 | :type 'string) 88 | 89 | (defcustom code-compass-docker-data-directory "/data" 90 | "Directory to store temporary docker files generated by code-compass." 91 | :group 'code-compass 92 | :type 'string) 93 | 94 | (defcustom code-compass-download-directory (code-compass--expand-file-name "dependencies") 95 | "Directory to store downloaded dependencies." 96 | :group 'code-compass 97 | :type 'string) 98 | 99 | (defcustom code-compass-code-maat-command 100 | (format "java -jar %s/code-maat-1.0.1-standalone.jar" (code-compass--expand-file-name "dependencies")) 101 | "Command to run Code-maat (https://github.com/adamtornhill/code-maat). 102 | Currently defaults to use docker because easier to setup." 103 | :group 'code-compass 104 | :type 'string 105 | :options `(,(format "java -jar %s/code-maat-1.0.1-standalone.jar" code-compass-download-directory) 106 | ,(format "docker run -v %s/:%s code-maat-app" code-compass-tmp-directory code-compass-docker-data-directory))) 107 | 108 | (defcustom code-compass-preferred-browser 109 | "chromium" 110 | "Browser to use to open graphs served by webserver." 111 | :group 'code-compass 112 | :type 'string) 113 | 114 | (defcustom code-compass-exclude-directories 115 | '("node_modules" "bower_components" "vendor" "tmp") 116 | "A list of directory patterns to exclude from reports. 117 | Contents are passed to the cloc executable via its --exclude-dir argument." 118 | :group 'code-compass 119 | :type 'list) 120 | 121 | (defcustom code-compass-calculate-coupling-project-key-fn 122 | (lambda (repository) 123 | (concat 124 | repository 125 | "-" 126 | (s-trim 127 | (shell-command-to-string 128 | (format "cd %s; git rev-parse --short HEAD" repository))))) 129 | "Function taking a REPOSITORY path and returning a string." 130 | :group 'code-compass 131 | :type 'function) 132 | 133 | (defcustom code-compass-authors-colors (list 134 | "red" 135 | "blue" 136 | "orange" 137 | "gray" 138 | "green" 139 | "violet" 140 | "pink" 141 | "brown" 142 | "aquamarine" 143 | "blueviolet" 144 | "burlywood" 145 | "cadetblue" 146 | "chartreuse" 147 | "chocolate" 148 | "coral" 149 | "cornflowerblue" 150 | "cyan" 151 | "darkblue" 152 | "darkcyan" 153 | "darkgoldenrod" 154 | "darkgray" 155 | "darkgreen" 156 | "darkkhaki" 157 | "darkmagenta" 158 | "darkolivegreen" 159 | "darkorange" 160 | "darkorchid" 161 | "darkred" 162 | "darksalmon" 163 | "darkseagreen" 164 | "darkslateblue" 165 | "darkslategray" 166 | "darkturquoise" 167 | "darkviolet" 168 | "deeppink" 169 | "deepskyblue" 170 | "dimgray" 171 | "dodgerblue" 172 | "firebrick" 173 | "forestgreen" 174 | "fuchsia" 175 | "gold" 176 | "goldenrod" 177 | "greenyellow" 178 | "hotpink" 179 | "indianred" 180 | "indigo" 181 | "lawngreen" 182 | "lightcoral" 183 | "lightgray" 184 | "lightgreen" 185 | "lightpink" 186 | "lightsalmon" 187 | "lightseagreen" 188 | "lightskyblue" 189 | "lightslategray" 190 | "lightsteelblue" 191 | "lime" 192 | "limegreen" 193 | "linen" 194 | "magenta" 195 | "maroon" 196 | "mediumaquamarine" 197 | "mediumblue" 198 | "mediumorchid" 199 | "mediumpurple" 200 | "mediumseagreen" 201 | "mediumslateblue" 202 | "mediumspringgreen" 203 | "mediumturquoise" 204 | "mediumvioletred" 205 | "midnightblue" 206 | "mintcream" 207 | "mistyrose" 208 | "moccasin" 209 | "navajowhite" 210 | "navy" 211 | "oldlace" 212 | "olive" 213 | "olivedrab" 214 | "orangered" 215 | "orchid" 216 | "palegoldenrod" 217 | "palegreen" 218 | "paleturquoise" 219 | "palevioletred" 220 | "papayawhip" 221 | "peachpuff" 222 | "peru" 223 | "plum" 224 | "powderblue" 225 | "purple" 226 | "rosybrown" 227 | "royalblue" 228 | "saddlebrown" 229 | "salmon" 230 | "sandybrown" 231 | "seagreen" 232 | "seashell" 233 | "sienna" 234 | "silver" 235 | "skyblue" 236 | "slateblue" 237 | "slategray" 238 | "snow" 239 | "springgreen" 240 | "steelblue" 241 | "tan" 242 | "teal" 243 | "thistle" 244 | "tomato" 245 | "turquoise" 246 | "wheat" 247 | "whitesmoke" 248 | "yellow" 249 | "yellowgreen") 250 | "Colors to use for authors." 251 | :group 'code-compass 252 | :type 'list) 253 | 254 | (defcustom code-compass-pie-or-bar-chart-command (code-compass--python-script "csv-to-pie-graph.py %s") 255 | "Command to visualize chart." 256 | :group 'code-compass 257 | :type 'string 258 | :options '((code-compass--python-script "csv-to-pie-graph.py %s") "graph %s --bar --width 0.4 --offset='-0.2,0.2'")) 259 | 260 | (defcustom code-compass-gource-command 261 | "gource" 262 | "Command to the gource utility. See https://gource.io/ for more information on how to install." 263 | :group 'code-compass 264 | :type 'string) 265 | 266 | (defcustom code-compass-gource-seconds-per-day 267 | 0.5 268 | "How long each Git history day should take." 269 | :type 'float 270 | :group 'code-compass) 271 | 272 | (defcustom code-compass-display-icon 273 | 't 274 | "Display an icon in modeline showing growth trend of code. 275 | A pointing up icon means the code has been growing, 276 | a pointing down arrow has been decreasing." 277 | :group 'code-compass 278 | :type 'bool) 279 | 280 | (defcustom code-compass-icon-trends 281 | '( 282 | :period "3" 283 | :always-additions (propertize "⬆" 'face `(:background "DarkOrange")) 284 | :always-deletions (propertize "⬇" 'face `(:background "SpringGreen")) 285 | :more-additions (propertize "↗" 'face `(:background "Gold")) 286 | :more-deletions (propertize "↘" 'face `(:background "GreenYellow"))) 287 | "Icon and period of evaluation for trend." 288 | :group 'code-compass 289 | :type 'plist) 290 | 291 | (defcustom code-compass-display-file-contributors 't 292 | "Enable the listing of contributors for a file in the *Messages* buffer." 293 | :group 'code-compass 294 | :type 'bool) 295 | 296 | (defcustom code-compass-cache-file (concat user-emacs-directory ".code-compass/cache") 297 | "Directory to store a cache of coupling files." 298 | :group 'code-compass 299 | :type 'string) 300 | 301 | ;; these definitions are just to satisfy the linting tools 302 | (defvar browse-url-generic-program) 303 | (defvar slack-current-team) 304 | (declare-function slack-team-users "ext:slack.el") 305 | (declare-function slack-create-user-profile-buffer "ext:slack.el") 306 | (declare-function slack-buffer-display-im "ext:slack.el") 307 | 308 | ;;;###autoload 309 | (defun code-compass-install (&optional no-query-p) 310 | (interactive) 311 | (let ((venv-dir (file-name-concat code-compass-download-directory "/venv/"))) 312 | (when (and (not (file-exists-p venv-dir)) (or no-query-p 313 | (y-or-n-p "Need to install code-compass python dependencies, do it now ?"))) 314 | (code-compass--in-directory code-compass-download-directory 315 | (mkdir code-compass-download-directory t) 316 | (let ((compilation-buffer (compilation-start (format "cd %s; python3 -m venv venv && ./venv/bin/pip3 install -r ../requirements.txt" code-compass-download-directory)))) 317 | (if (get-buffer-window compilation-buffer) 318 | (select-window (get-buffer-window compilation-buffer)) 319 | (pop-to-buffer compilation-buffer)) 320 | ))))) 321 | 322 | ;;;###autoload 323 | (defun code-compass-doctor () 324 | "Report if and what dependencies are missing." 325 | (interactive) 326 | (let ((git-p (executable-find "git")) 327 | (python-p (executable-find "python3")) 328 | (python-venv-p (file-exists-p (file-name-concat code-compass-download-directory "/venv/"))) 329 | (java-p (executable-find "java")) 330 | (graph-cli-p (file-exists-p (file-name-concat code-compass-download-directory "/venv/bin/graph"))) 331 | (cloc-p (executable-find "cloc")) 332 | (gource-p (executable-find "gource")) 333 | (docker-p (executable-find "docker")) 334 | (doctor-buffer (get-buffer-create "code-compass dependencies check"))) 335 | (with-current-buffer doctor-buffer 336 | (read-only-mode -1) 337 | (erase-buffer) 338 | (insert "Welcome to Code Compass doctor!\n\n") 339 | (insert "Required dependencies for minimal functionality:\n") 340 | (insert (format "- Git: %s\n" (if git-p "OK" "MISSING"))) 341 | (insert (format "- Python: %s\n" (if python-p "OK" "MISSING"))) 342 | (insert (format "- Python venv: %s\n" (if python-venv-p "OK" "MISSING"))) 343 | (insert (format "- Java: %s\n" (if java-p "OK" "MISSING"))) 344 | (insert (format "- Cloc: %s\n" (if cloc-p "OK" "MISSING"))) 345 | (insert "\n\nOptional dependencies:\n") 346 | (insert (format "- Graph-cli: %s\n" (if graph-cli-p "OK" "MISSING"))) 347 | (insert (format "- Gource: %s\n" (if gource-p "OK" "MISSING"))) 348 | (insert (format "- Docker: %s\n" (if docker-p "OK" "MISSING"))) 349 | (read-only-mode)) 350 | (switch-to-buffer-other-window doctor-buffer))) 351 | (define-obsolete-function-alias 'c/doctor #'code-compass-doctor "0.1.2") 352 | 353 | (defun code-compass--subtract-to-now (n month|day &optional time) 354 | "Subtract N * MONTH|DAY to current time. 355 | Optionally give TIME from which to start." 356 | (time-subtract 357 | (or time (current-time)) 358 | (seconds-to-time (* 60 60 month|day n)))) 359 | 360 | (defun code-compass-request-date (days|months &optional time) 361 | "Request date in days or months by asking how many DAYS|MONTHS ago. 362 | Optionally give TIME from which to start. 363 | 364 | >> (code-compass-request-date \"1d\" '(25610 2072 776840 400000)) 365 | => \"2023-03-08\" 366 | 367 | >> (code-compass-request-date \"1m\" '(25610 2072 776840 400000)) 368 | => \"2023-02-06\"" 369 | (interactive 370 | (list (completing-read "From how long ago? " code-compass-default-periods))) 371 | (when (not (string= days|months "beginning")) 372 | (format-time-string 373 | "%F" 374 | (apply 375 | #'code-compass--subtract-to-now 376 | (-concat 377 | (if (s-contains-p "m" days|months) 378 | (list (string-to-number (s-replace "m" "" days|months)) (* 24 31)) 379 | (list (string-to-number (s-replace "d" "" days|months)) 24)) 380 | (list time)))))) 381 | (define-obsolete-function-alias 'c/request-date #'code-compass-request-date "0.1.2") 382 | 383 | (defun code-compass--first (l) 384 | "Get first element of L." 385 | (car l)) 386 | 387 | (defun code-compass--second (l) 388 | "Get second element of L." 389 | (nth 1 l)) 390 | 391 | (defun code-compass--third (l) 392 | "Get third element of L." 393 | (nth 2 l)) 394 | 395 | (defun code-compass--filename (file) 396 | "Get filename of FILE. 397 | 398 | >> (code-compass--filename \"some/file.txt\") 399 | => \"file.txt\"" 400 | (file-name-nondirectory (directory-file-name file))) 401 | 402 | (defun code-compass--temp-dir (repository) 403 | "Format temporary directory in which store analyses assets for REPOSITORY. 404 | 405 | >> (code-compass--temp-dir \"~/some-repo/\") 406 | => \"/tmp/code-compass-some-repo/\"" 407 | (format "%s/code-compass-%s/" code-compass-tmp-directory (code-compass--filename repository))) 408 | 409 | (defmacro code-compass--in-directory (directory &rest body) 410 | "Execute BODY in DIRECTORY. 411 | Temporarily changes current buffer's default directory to DIRECTORY." 412 | (declare (indent defun)) 413 | `(let ((default-directory ,directory)) 414 | (unwind-protect 415 | ,@body))) 416 | 417 | (defmacro code-compass--in-temp-directory (repository &rest body) 418 | "Execute BODY in temporary directory created for analysed REPOSITORY." 419 | (declare (indent defun)) 420 | `(progn 421 | (mkdir (code-compass--temp-dir ,repository) t) 422 | (code-compass--in-directory 423 | (code-compass--temp-dir ,repository) 424 | ,@body))) 425 | 426 | (defun code-compass--shell-command-error-handler (command buffer-name) 427 | "Run COMMAND with `shell-command' but check if errors are output in BUFFER-NAME." 428 | (ignore-errors (kill-buffer buffer-name)) 429 | (shell-command 430 | command 431 | nil 432 | (get-buffer-create buffer-name)) 433 | (let ((contents 434 | (with-current-buffer buffer-name 435 | (buffer-string)))) 436 | (when (> (length contents) 1) (error (concat buffer-name "\n\n" contents))))) 437 | 438 | (defun code-compass-produce-git-report (repository date &optional before-date authors) 439 | "Create git report for REPOSITORY with a Git log starting at DATE. 440 | Define optionally a BEFORE-DATE. 441 | The knowledge analysis allow to filter by AUTHORS when set." 442 | (interactive 443 | (list (call-interactively #'code-compass-request-date))) 444 | (message "Producing git report...") 445 | (let ((git-command 446 | (s-concat 447 | (format "git -C %s" repository) 448 | " log --all --numstat --date=short --pretty=format:'--%h--%ad--%aN' --no-renames " 449 | (when authors 450 | (format "--perl-regexp --author='%s' " authors)) 451 | (when date 452 | (format "--after=%s " date)) 453 | (when before-date 454 | (format "--before=%s " before-date)) 455 | (when code-compass-exclude-directories 456 | (s-join " " (--map (format "':(exclude)%s'" it) code-compass-exclude-directories))) 457 | " > gitreport.log"))) 458 | (message "Running %s" git-command) 459 | (code-compass--shell-command-error-handler git-command "*code-compass-produce-git-report-errors*")) 460 | repository) 461 | (define-obsolete-function-alias 'c/produce-git-report #'code-compass-produce-git-report "0.1.2") 462 | 463 | (defun code-compass--run-code-maat (command repository) 464 | "Run code-maat's COMMAND on REPOSITORY." 465 | (message "Producing code-maat %s report for %s..." command repository) 466 | (let ((source-file (format "%s/code-maat-1.0.1-standalone.jar" code-compass-download-directory)) 467 | (maat-jar-p (s-contains-p "jar" code-compass-code-maat-command))) 468 | (when (and maat-jar-p (not (file-exists-p (code-compass--expand-file-name source-file)))) 469 | (mkdir code-compass-download-directory t) 470 | (url-copy-file "https://github.com/smontanari/code-forensics/raw/v3.0.0/lib/analysers/code_maat/code-maat-1.0.1-standalone.jar" (code-compass--expand-file-name source-file) t)) 471 | (code-compass--shell-command-error-handler 472 | (format 473 | "%1$s -l %4$s/code-compass-%2$s/gitreport.log -c git2 -a %3$s > %3$s.csv" 474 | code-compass-code-maat-command 475 | (code-compass--filename repository) 476 | command 477 | (if maat-jar-p code-compass-tmp-directory code-compass-docker-data-directory)) 478 | "*code-compass--run-code-maat-errors*"))) 479 | 480 | (defun code-compass--produce-code-maat-revisions-report (repository) 481 | "Create code-maat revisions report for REPOSITORY." 482 | (code-compass--run-code-maat "revisions" repository) 483 | repository) 484 | 485 | (defun code-compass--produce-cloc-report (repository) 486 | "Create cloc report for REPOSITORY. 487 | To filter specific subdirectories out of this report, 488 | edit the variable `code-compass-exclude-directories'." 489 | (let ((cloc-command (format "(cd %s; PERL_BADLANG=0 cloc ./ --timeout 0 --by-file --csv --quiet --exclude-dir=%s) > cloc.csv" repository (string-join code-compass-exclude-directories ",")))) 490 | (message (concat 491 | "Producing cloc report with " 492 | cloc-command 493 | "...")) 494 | (code-compass--shell-command-error-handler 495 | cloc-command 496 | "*code-compass--produce-cloc-report-errors*")) 497 | repository) 498 | 499 | (defun code-compass--copy-file (file-name directory) 500 | "Copy FILE-NAME to DIRECTORY." 501 | (copy-file (code-compass--expand-file-name file-name) directory t) 502 | (set-file-modes (concat directory "/" (file-name-nondirectory file-name)) (file-modes-symbolic-to-number "u=rw,go=r"))) 503 | 504 | (defun code-compass--generate-merger-script (repository) 505 | "Generate a Python script to give weights to the circle diagram of REPOSITORY." 506 | (code-compass--copy-file "./scripts/csv_as_enclosure_json.py" (code-compass--temp-dir repository)) 507 | repository) 508 | 509 | (defun code-compass--generate-d3-v3-lib (repository) 510 | "Make available the D3 library for REPOSITORY. 511 | This is just to not depend on a network connection." 512 | (mkdir "d3" t) 513 | (let ((source-file (format "%s/d3.v3.min.js" code-compass-download-directory))) 514 | (unless (file-exists-p (code-compass--expand-file-name source-file)) 515 | (mkdir code-compass-download-directory t) 516 | (url-copy-file "http://d3js.org/d3.v3.min.js" (code-compass--expand-file-name source-file) t)) 517 | (code-compass--copy-file source-file "d3/")) 518 | repository) 519 | 520 | (defun code-compass--generate-d3-v4-lib (repository) 521 | "Make available the D3 v4 library for REPOSITORY. 522 | This is just to not depend on a network connection." 523 | (mkdir "d3" t) 524 | (let ((source-file (format "%s/d3.v4.min.js" code-compass-download-directory))) 525 | (unless (file-exists-p (code-compass--expand-file-name source-file)) 526 | (mkdir code-compass-download-directory t) 527 | (url-copy-file "http://d3js.org/d3.v4.min.js" (code-compass--expand-file-name source-file) t)) 528 | (code-compass--copy-file source-file "d3/")) 529 | repository) 530 | 531 | (defun code-compass--produce-json (repository) 532 | "Produce json for REPOSITORY." 533 | (message "Produce json...") 534 | (code-compass--shell-command-error-handler 535 | (code-compass--python-script "csv_as_enclosure_json.py --structure cloc.csv --weights revisions.csv > hotspot_proto.json") 536 | "*code-compass--produce-json-errors*") 537 | repository) 538 | 539 | (defun code-compass--generate-host-enclosure-diagram-html (repository) 540 | "Generate host html from REPOSITORY." 541 | (code-compass--copy-file "./pages/enclosure-diagram/style.css" (code-compass--temp-dir repository)) 542 | (code-compass--copy-file "./pages/enclosure-diagram/script.js" (code-compass--temp-dir repository)) 543 | (code-compass--copy-file "./pages/enclosure-diagram/zoomable.html" (code-compass--temp-dir repository)) 544 | repository) 545 | 546 | (defun code-compass--navigate-to-localhost (repository &optional port) 547 | "Navigate to served directory for REPOSITORY, optionally at specified PORT." 548 | (let ((port (or port code-compass-default-port)) 549 | (browse-url-browser-function #'browse-url-generic) 550 | (browse-url-generic-program code-compass-preferred-browser)) 551 | (browse-url (format "http://localhost:%s/zoomable.html" port))) 552 | repository) 553 | 554 | (defun code-compass--run-server (repository &optional port) 555 | "Serve directory for REPOSITORY, optionally at PORT." 556 | (let ((httpd-host 'local) 557 | (httpd-port (or port code-compass-default-port))) 558 | (httpd-stop) 559 | (ignore-errors (httpd-serve-directory (code-compass--temp-dir repository)))) 560 | repository) 561 | 562 | (defun code-compass--run-server-and-navigate (repository &optional port) 563 | "Serve and navigate to REPOSITORY, optionally at PORT." 564 | (when port 565 | (code-compass--run-server repository port) 566 | (code-compass--navigate-to-localhost repository port))) 567 | 568 | (defun code-compass--async-run (command repository date &optional port do-not-serve authors) 569 | "Run asynchronously COMMAND taking a REPOSITORY and a DATE, optionally at PORT. 570 | Optional argument DO-NOT-SERVE skips serving contents on localhost. 571 | Optional argument AUTHORS to filter AUTHORS for knowledge analysis." 572 | (async-start 573 | `(lambda () 574 | (setq load-path ',load-path) 575 | (load-file ,(symbol-file command)) 576 | (setq code-compass-code-maat-command ,code-compass-code-maat-command) 577 | (setq code-compass-pie-or-bar-chart-command ,code-compass-pie-or-bar-chart-command) 578 | (setq code-compass-calculate-coupling-project-key-fn ',code-compass-calculate-coupling-project-key-fn) 579 | (setq code-compass-authors-colors ',code-compass-authors-colors) 580 | (setq code-compass-exclude-directories ',code-compass-exclude-directories) 581 | (setq code-compass-preferred-browser ,code-compass-preferred-browser) 582 | (setq code-compass-snapshot-periods ',code-compass-snapshot-periods) 583 | (setq code-compass-default-periods ',code-compass-default-periods) 584 | (setq code-compass-tmp-directory ',code-compass-tmp-directory) 585 | (setq code-compass-docker-data-directory ',code-compass-docker-data-directory) 586 | (setq code-compass-download-directory ',code-compass-download-directory) 587 | (setq code-compass-default-port ',code-compass-default-port) 588 | (let ((browse-url-browser-function #'browse-url-generic) 589 | (browse-url-generic-program ,code-compass-preferred-browser)) 590 | (condition-case err 591 | (funcall ',command ,repository ,date ',authors) 592 | (error 593 | (funcall ',command ,repository ,date))))) 594 | `(lambda (result) 595 | (when (not ,do-not-serve) (code-compass--run-server-and-navigate ,(expand-file-name repository) (or ,port code-compass-default-port)))))) 596 | 597 | ;;;###autoload 598 | (defun code-compass-show-hotspots-sync (repository date &optional port) 599 | "Show REPOSITORY enclosure diagram for hotspots starting at DATE. 600 | Optionally served at PORT." 601 | (interactive 602 | (list 603 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 604 | (call-interactively #'code-compass-request-date) 605 | code-compass-default-port)) 606 | (code-compass--in-temp-directory 607 | repository 608 | (--> repository 609 | (code-compass-produce-git-report it date) 610 | code-compass--produce-code-maat-revisions-report 611 | code-compass--produce-cloc-report 612 | code-compass--generate-merger-script 613 | code-compass--generate-d3-v3-lib 614 | code-compass--produce-json 615 | code-compass--generate-host-enclosure-diagram-html 616 | (code-compass--run-server-and-navigate it port)))) 617 | (define-obsolete-function-alias 'c/show-hotspots-sync #'code-compass-show-hotspots-sync "0.1.2") 618 | 619 | ;;;###autoload 620 | (defun code-compass-show-hotspots (repository date &optional port) 621 | "Show REPOSITORY enclosure diagram for hotspots. 622 | Starting DATE reduces scope of Git log and 623 | PORT define where the html is served." 624 | (interactive 625 | (list 626 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 627 | (call-interactively #'code-compass-request-date))) 628 | (code-compass--async-run #'code-compass-show-hotspots-sync repository date port)) 629 | (define-obsolete-function-alias 'c/show-hotspots #'code-compass-show-hotspots "0.1.2") 630 | 631 | (defun code-compass-show-hotspot-snapshot-sync (repository) 632 | "Snapshot COMMAND over REPOSITORY over the last year every three months." 633 | (interactive 634 | (list 635 | (read-directory-name "Choose git repository directory:" (vc-root-dir)))) 636 | (--each code-compass-snapshot-periods (code-compass-show-hotspots-sync repository (code-compass-request-date it) code-compass-default-port))) 637 | 638 | (define-obsolete-function-alias 'c/show-hotspot-snapshot-sync #'code-compass-show-hotspot-snapshot-sync "0.1.2") 639 | 640 | ;; BEGIN indentation 641 | 642 | (defun code-compass--split-on-newlines (code) 643 | "Split CODE over newlines." 644 | (s-split "\n" code)) 645 | 646 | (defun code-compass--remove-empty-lines (lines) 647 | "Remove empty LINES. 648 | 649 | >> (code-compass--remove-empty-lines '(\"line\" \" \" \" \" \"\")) 650 | => (\"line\")\"" 651 | (--remove (eq (length (s-trim it)) 0) lines)) 652 | 653 | (defun code-compass--remove-text-after-indentation (lines) 654 | "Remove text in LINES that is not indentation characters.. 655 | 656 | >> (code-compass--remove-text-after-indentation '(\" one indent\")) 657 | => (\" \")" 658 | (--map 659 | (apply #'string (--take-while (or (eq ?\s it) (eq ?\t it)) (string-to-list it))) 660 | lines)) 661 | 662 | (defun code-compass--find-indentation (lines-without-text) 663 | "Infer indentation level in LINES-WITHOUT-TEXT. 664 | If no indentation present in file, defaults to 2. 665 | 666 | >> (code-compass--find-indentation '(\" \" \" \" \" \")) 667 | => 3 668 | 669 | >> (code-compass--find-indentation '(\" \")) 670 | => 1" 671 | (or (--> lines-without-text 672 | (--map (list (s-count-matches "\s" it) (s-count-matches "\t" it)) it) 673 | (let ((spaces-ind (-sort #'< (--remove (eq 0 it) (-map 'code-compass--first it)))) 674 | (tabs-ind (-sort #'< (--remove (eq 0 it) (-map 'code-compass--second it))))) 675 | (if (> (length spaces-ind) (length tabs-ind)) 676 | (code-compass--first spaces-ind) 677 | (code-compass--first tabs-ind)))) 678 | 2)) 679 | 680 | (defun code-compass--convert-tabs-to-spaces (line-without-text n) 681 | "Replace tabs in LINE-WITHOUT-TEXT with N spaces." 682 | (s-replace "\t" (make-string n ?\s) line-without-text)) 683 | 684 | (defun code-compass--calculate-complexity (line-without-text indentation) 685 | "Calculate indentation complexity. 686 | This divides length of LINE-WITHOUT-TEXT by INDENTATION. 687 | 688 | >> (code-compass--calculate-complexity \" \" 2) 689 | => 2.0" 690 | (/ (+ 0.0 (length line-without-text)) indentation)) 691 | 692 | (defun code-compass--as-logical-indents (lines &optional opts) 693 | "Calculate logical indentations of LINES. 694 | Try to infer how many space is an indent unless OPTS provides it." 695 | (let ((indentation (or opts (code-compass--find-indentation lines)))) 696 | (list 697 | (--map 698 | (--> it 699 | (code-compass--convert-tabs-to-spaces it indentation) 700 | (code-compass--calculate-complexity it indentation)) 701 | lines) 702 | indentation))) 703 | 704 | (defun code-compass--stats-from (complexities-indentation) 705 | "Return stats from COMPLEXITIES-INDENTATION." 706 | (let* ((complexities (code-compass--first complexities-indentation)) 707 | (mean (/ (-sum complexities) (length complexities))) 708 | (sd (sqrt (/ (-sum (--map (expt (- it mean) 2) complexities)) (length complexities))))) 709 | `((total . ,(-sum complexities)) 710 | (n-lines . ,(length complexities)) 711 | (max . ,(-max complexities)) 712 | (mean . ,mean) 713 | (standard-deviation . ,sd) 714 | (used-indentation . ,(code-compass--second complexities-indentation))))) 715 | 716 | (defun code-compass-calculate-complexity-stats (code &optional opts) 717 | "Return complexity of CODE based on indentation. 718 | If OPTS is provided, use these settings to define what is the indentation. 719 | Return nil for empty CODE. 720 | 721 | >> (-take 3 (code-compass-calculate-complexity-stats \"1\")) 722 | => ((total . 0.0) (n-lines . 1) (max . 0.0))" 723 | (ignore-errors 724 | (--> code 725 | ;; TODO maybe add line numbers, so that I can also open the most troublesome (max-c) line automatically? 726 | code-compass--split-on-newlines 727 | code-compass--remove-empty-lines 728 | code-compass--remove-text-after-indentation 729 | (code-compass--as-logical-indents it opts) 730 | code-compass--stats-from))) 731 | (define-obsolete-function-alias 'c/calculate-complexity-stats #'code-compass-calculate-complexity-stats "0.1.2") 732 | 733 | ;;;###autoload 734 | (defun code-compass-calculate-complexity-current-buffer (&optional indentation) 735 | "Calculate complexity of the current buffer contents. 736 | Optionally you can provide the INDENTATION level of the file. The 737 | code can infer it automatically." 738 | (interactive) 739 | (code-compass-calculate-complexity-stats 740 | (buffer-substring-no-properties (point-min) (point-max)) indentation)) 741 | 742 | (define-obsolete-function-alias 'c/calculate-complexity-current-buffer #'code-compass-calculate-complexity-current-buffer "0.1.2") 743 | 744 | ;; END indentation 745 | 746 | ;; BEGIN complexity over commits 747 | 748 | (defun code-compass--retrieve-commits-up-to-date-touching-file (file &optional date) 749 | "Retrieve list of commits touching FILE from DATE." 750 | (s-split 751 | "\n" 752 | (shell-command-to-string 753 | (s-concat 754 | "git log --format=format:%H --reverse " 755 | (if date 756 | (s-concat "--after=" date " ") 757 | "") 758 | file)))) 759 | 760 | (defun code-compass--retrieve-file-at-commit-with-git (file commit) 761 | "Retrieve FILE contents at COMMIT." 762 | (let* ((git-dir (with-current-buffer (find-file-noselect file) 763 | (expand-file-name (vc-root-dir)))) 764 | (git-file 765 | (string-remove-prefix 766 | git-dir 767 | (expand-file-name file)))) 768 | (shell-command-to-string (format "git show %s:\"%s\"" commit git-file)))) 769 | 770 | (defun code-compass--git-hash-to-date (commit) 771 | "Return the date of the COMMIT. 772 | Note this is the date of merging in, not of the code change." 773 | (s-replace "\n" "" (shell-command-to-string (s-concat "git show --no-patch --no-notes --pretty='%cd' --date=short " commit)))) 774 | 775 | (defun code-compass--calculate-complexity-over-commits (file &optional opts) 776 | "Calculate complexity of FILE over commits. 777 | Optional argument OPTS defines things like the indentation to use." 778 | (--> (call-interactively #'code-compass-request-date) 779 | (code-compass--retrieve-commits-up-to-date-touching-file file it) 780 | (--map 781 | (--> it 782 | (list it (code-compass--retrieve-file-at-commit-with-git file it)) 783 | (list (code-compass--first it) (code-compass-calculate-complexity-stats (code-compass--second it) opts))) 784 | it))) 785 | (define-obsolete-function-alias 'c/calculate-complexity-over-commits #'code-compass--calculate-complexity-over-commits "0.1.2") 786 | 787 | (defun code-compass--plot-csv-file-with-graph-cli (file) 788 | "Plot CSV FILE with graph-cli." 789 | (async-shell-command 790 | (format "%s/venv/bin/graph --xtick-angle 90 %s" code-compass-download-directory file))) 791 | 792 | (defun code-compass--plot-lines-with-graph-cli (data) 793 | "Plot DATA from lists as a graph." 794 | (let ((tmp-file (format "%s/data-file-graph-cli.csv" code-compass-tmp-directory))) 795 | (with-temp-file tmp-file 796 | (insert "commit-date,total-complexity,loc\n") 797 | (insert (s-join "\n" (--map (s-replace-all '((" " . ",") ("(" . "") (")" . "")) (format "%s" it)) data)))) 798 | (code-compass--plot-csv-file-with-graph-cli tmp-file))) 799 | 800 | ;;;###autoload 801 | (defun code-compass-show-complexity-over-commits (file &optional opts) 802 | "Make a graph plotting complexity out of a FILE. 803 | Optionally give file indentation in OPTS." 804 | (interactive (list (read-file-name "Select file:" nil nil nil (buffer-file-name)))) 805 | (code-compass--plot-lines-with-graph-cli 806 | (--map 807 | (list (code-compass--git-hash-to-date (code-compass--first it)) 808 | (alist-get 'total (code-compass--second it)) 809 | (alist-get 'n-lines (code-compass--second it))) 810 | (code-compass--calculate-complexity-over-commits file opts)))) 811 | (define-obsolete-function-alias 'c/show-complexity-over-commits #'code-compass-show-complexity-over-commits "0.1.2") 812 | 813 | ;; END complexity over commits 814 | 815 | ;; BEGIN code churn 816 | (defun code-compass--produce-code-maat-abs-churn-report (repository) 817 | "Create code-maat abs-churn report for REPOSITORY." 818 | (code-compass--run-code-maat "abs-churn" repository) 819 | repository) 820 | 821 | (defun code-compass-show-code-churn-sync (repository date) 822 | "Show how much code was added and removed from REPOSITORY from a DATE." 823 | (interactive (list 824 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 825 | (call-interactively #'code-compass-request-date))) 826 | (code-compass--in-temp-directory 827 | repository 828 | (progn 829 | (--> repository 830 | (code-compass-produce-git-report it date) 831 | code-compass--produce-code-maat-abs-churn-report) 832 | (code-compass--plot-csv-file-with-graph-cli "abs-churn.csv")))) 833 | (define-obsolete-function-alias 'c/show-code-churn-sync #'code-compass-show-code-churn-sync "0.1.2") 834 | 835 | ;;;###autoload 836 | (defun code-compass-show-code-churn (repository date) 837 | "Show how much code was added and removed from REPOSITORY from a DATE." 838 | (interactive (list 839 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 840 | (call-interactively #'code-compass-request-date))) 841 | (code-compass--async-run #'code-compass-show-code-churn-sync repository date nil 't)) 842 | (define-obsolete-function-alias 'c/show-code-churn #'code-compass-show-code-churn "0.1.2") 843 | ;; END complexity over commits 844 | 845 | ;; BEGIN change coupling 846 | (defun code-compass--produce-code-maat-coupling-report (repository) 847 | "Create code-maat coupling report for REPOSITORY." 848 | (code-compass--run-code-maat "coupling" repository) 849 | repository) 850 | 851 | (defun code-compass--generate-coupling-json-script (repository) 852 | "Generate script to produce a weighted graph for REPOSITORY." 853 | (code-compass--copy-file "./scripts/coupling_csv_as_edge_bundling.py" (code-compass--temp-dir repository)) 854 | repository) 855 | 856 | (defun code-compass--produce-coupling-json (repository) 857 | "Produce coupling json needed by d3 for REPOSITORY." 858 | (message "Produce coupling json...") 859 | (code-compass--shell-command-error-handler 860 | (code-compass--python-script "coupling_csv_as_edge_bundling.py --coupling coupling.csv > edgebundling.json") 861 | "*code-compass--produce-coupling-json-errors*") 862 | repository) 863 | 864 | (defun code-compass--generate-host-edge-bundling-html (repository) 865 | "Generate host html from REPOSITORY." 866 | (code-compass--copy-file "./pages/edge-bundling/script.js" (code-compass--temp-dir repository)) 867 | (code-compass--copy-file "./pages/edge-bundling/style.css" (code-compass--temp-dir repository)) 868 | (code-compass--copy-file "./pages/edge-bundling/zoomable.html" (code-compass--temp-dir repository)) 869 | repository) 870 | 871 | (defun code-compass-show-coupling-graph-sync (repository date &optional port) 872 | "Show REPOSITORY edge bundling synchronously for code coupling up to DATE. 873 | Serve graph on PORT." 874 | (interactive (list 875 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 876 | (call-interactively #'code-compass-request-date) 877 | 8888)) 878 | (code-compass--in-temp-directory 879 | repository 880 | (--> repository 881 | (code-compass-produce-git-report it nil date) 882 | code-compass--produce-code-maat-coupling-report 883 | code-compass--generate-coupling-json-script 884 | code-compass--generate-d3-v4-lib 885 | code-compass--produce-coupling-json 886 | code-compass--generate-host-edge-bundling-html 887 | (code-compass--run-server-and-navigate it port)))) 888 | (define-obsolete-function-alias 'c/show-coupling-graph-sync #'code-compass-show-coupling-graph-sync "0.1.2") 889 | 890 | ;;;###autoload 891 | (defun code-compass-show-coupling-graph (repository date &optional port) 892 | "Show REPOSITORY edge bundling for code coupling up to DATE. Serve graph on PORT." 893 | (interactive (list 894 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 895 | (call-interactively #'code-compass-request-date))) 896 | (code-compass--async-run #'code-compass-show-coupling-graph-sync repository date port)) 897 | (define-obsolete-function-alias 'c/show-coupling-graph #'code-compass-show-coupling-graph "0.1.2") 898 | ;; END change coupling 899 | 900 | ;; BEGIN find coupled files 901 | (defun code-compass--add-filename-to-analysis-columns (repository analysis) 902 | "Add filepath from REPOSITORY to ANALYSIS columns." 903 | (--> analysis 904 | (s-split "\n" it 't) 905 | ;(--remove (s-blank? (s-trim it)) it) 906 | (-concat 907 | (list (car it)) 908 | (--map 909 | (--> (s-split "," it) 910 | (-concat 911 | (list (s-concat repository "/" (code-compass--first it))) 912 | (list 913 | (if (or (null (code-compass--second it)) (not (s-contains-p "/" (code-compass--second it)))) 914 | (code-compass--second it) 915 | (s-concat repository "/" (code-compass--second it)))) 916 | (cdr (cdr it))) 917 | (s-join "," it)) 918 | (cdr it))))) 919 | 920 | (defun code-compass--get-coupling-alist-sync (repository) 921 | "Get list of coupled files in REPOSITORY async." 922 | (code-compass--in-temp-directory 923 | repository 924 | (--> repository 925 | (code-compass-produce-git-report it nil) 926 | code-compass--produce-code-maat-coupling-report) 927 | (--> (code-compass--get-analysis-as-string-from-csv "coupling") 928 | (code-compass--add-filename-to-analysis-columns repository it) 929 | (--map (s-split "," it) (cdr it))))) 930 | 931 | (defun code-compass--get-coupling-alist (repository fun) 932 | "FUN takes a list of coupled files in REPOSITORY." 933 | (async-start 934 | `(lambda () 935 | (setq load-path ',load-path) 936 | (load-file ,(symbol-file 'code-compass--get-coupling-alist)) 937 | (code-compass--get-coupling-alist-sync ,repository)) 938 | fun)) 939 | 940 | (defvar code-compass-coupling-project-map 941 | (make-hash-table :test 'equal) 942 | "Hash table to contain coupling files list.") 943 | 944 | (defun code-compass--get-coupled-files-alist (repository fun) 945 | "Run FUN on the coupled files for REPOSITORY." 946 | (let* ((key (funcall code-compass-calculate-coupling-project-key-fn repository)) 947 | (code-compass-files (gethash key code-compass-coupling-project-map))) 948 | (if code-compass-files 949 | (funcall fun code-compass-files) 950 | (message "Building coupling cache asynchronously...") 951 | (code-compass--get-coupling-alist 952 | repository 953 | `(lambda (result-files) 954 | (message "Coupling Cache Built") 955 | (puthash ,key result-files code-compass-coupling-project-map) 956 | (funcall ,fun result-files) 957 | ;; Save cache to local storage to access it faster next time if nothing has changed 958 | (with-temp-file ,code-compass-cache-file 959 | (prin1 code-compass-coupling-project-map (current-buffer)))))))) 960 | 961 | (defun code-compass-clear-coupling-project-map () 962 | "Clear `code-compass-coupling-project-map' and deletes cache file." 963 | (interactive) 964 | (clrhash code-compass-coupling-project-map) 965 | 966 | (delete-file code-compass-cache-file)) 967 | (define-obsolete-function-alias 'c/clear-coupling-project-map #'code-compass-clear-coupling-project-map "0.1.2") 968 | 969 | (defun code-compass-get-coupled-files-alist-hook-fn () 970 | "Calculate coupled files asynchronously." 971 | (let ((git-root (ignore-errors (vc-root-dir)))) 972 | (when git-root 973 | (code-compass--get-coupled-files-alist 974 | git-root 975 | `(lambda (x) 976 | (message 977 | "Finished to update coupled files for %s and found %s coupled files." 978 | ,git-root 979 | (length x))))))) 980 | (define-obsolete-function-alias 'c/get-coupled-files-alist-hook-fn #'code-compass-get-coupled-files-alist-hook-fn "0.1.2") 981 | 982 | (defun code-compass--coupling-completions (file-name coupled-files root) 983 | "Get a list of files coupled to FILE-NAME. 984 | The coupling information is provided by COUPLED-FILES. 985 | ROOT is the VCS project path. 986 | 987 | >> (code-compass--coupling-completions \"\" nil \"\") 988 | => nil 989 | 990 | >> (code-compass--coupling-completions 991 | (concat code-compass-path-to-code-compass \"code-compass.el\") 992 | (list 993 | (list 994 | (concat code-compass-path-to-code-compass \"/README.org\") 995 | \"code-compass.el\" 996 | 31 997 | 65)) 998 | code-compass-path-to-code-compass) 999 | => (\"README.org\")" 1000 | (let ((default-directory root) 1001 | (root (s-chop-suffixes '("/" "/" "/") root))) 1002 | (--> coupled-files 1003 | (--sort (> (string-to-number (nth 3 it)) (string-to-number (nth 3 other))) it) ;; sort by number of commits 1004 | (--sort (> (string-to-number (nth 2 it)) (string-to-number (nth 2 other))) it) ;; sort then by how often this file has changed 1005 | (-keep 1006 | (lambda (file) 1007 | (let ((src-coupled-file-name (expand-file-name (car file))) 1008 | (target-coupled-file-name-src (expand-file-name (nth 1 file))) 1009 | (file-name (expand-file-name file-name))) 1010 | (when (and 1011 | (file-exists-p src-coupled-file-name) 1012 | (file-exists-p target-coupled-file-name-src) 1013 | (or (string= file-name src-coupled-file-name) 1014 | (string= file-name target-coupled-file-name-src))) 1015 | (s-replace ; this replace is just removing the root prefix, so the completions are human readable 1016 | (concat root "/") 1017 | "" 1018 | (expand-file-name 1019 | (car 1020 | ;; this picks only the coupled files, ignoring the file we are matching against (file-name) 1021 | (--remove 1022 | (string= (expand-file-name file-name) (expand-file-name it)) 1023 | (-take 2 file)))))))) 1024 | it)))) 1025 | 1026 | (defun code-compass--show-coupled-files (files file-name) 1027 | "Gather coupled files to FILE-NAME from all FILES." 1028 | (let* ((root (ignore-errors (car (s-split "//" (caar files))))) 1029 | (completions (ignore-errors 1030 | (-non-nil 1031 | (code-compass--coupling-completions 1032 | file-name 1033 | files 1034 | (expand-file-name root)))))) 1035 | (if completions 1036 | (let ((open-file (completing-read "Find coupled file: " completions nil 't))) 1037 | (find-file (concat root "/" open-file))) 1038 | (error "No coupled file found!")))) 1039 | 1040 | ;;;###autoload 1041 | (defun code-compass-find-coupled-files () 1042 | "Allow user to choose files coupled according to previous modifications." 1043 | (interactive) 1044 | 1045 | (when (file-exists-p code-compass-cache-file) 1046 | (with-temp-buffer 1047 | (insert-file-contents code-compass-cache-file) 1048 | (goto-char (point-min)) 1049 | (set 'code-compass-coupling-project-map (read (current-buffer))))) 1050 | 1051 | (code-compass--get-coupled-files-alist 1052 | (vc-root-dir) 1053 | `(lambda (files) (code-compass--show-coupled-files files ,(buffer-file-name))))) 1054 | 1055 | (define-obsolete-function-alias 'c/find-coupled-files #'code-compass-find-coupled-files "0.1.2") 1056 | ;; END find coupled files 1057 | 1058 | ;; BEGIN code communication 1059 | (defun code-compass--produce-code-maat-communication-report (repository) 1060 | "Create code-maat communication report for REPOSITORY." 1061 | (code-compass--run-code-maat "communication" repository) 1062 | repository) 1063 | 1064 | (defun code-compass--generate-communication-json-script (repository) 1065 | "Generate script to produce a weighted graph for REPOSITORY." 1066 | (code-compass--copy-file "./scripts/communication_csv_as_edge_bundling.py" (code-compass--temp-dir repository)) 1067 | repository) 1068 | 1069 | (defun code-compass--produce-communication-json (repository) 1070 | "Generate REPOSITORY age json." 1071 | (message "Produce age json...") 1072 | (code-compass--shell-command-error-handler 1073 | (code-compass--python-script "communication_csv_as_edge_bundling.py --communication communication.csv > edgebundling.json") 1074 | "*code-compass--produce-communication-json-errors*") 1075 | repository) 1076 | 1077 | (defun code-compass-show-code-communication-sync (repository date &optional port) 1078 | "Show REPOSITORY edge bundling for code communication from DATE. 1079 | Green edges is incoming (dependant) and red outgoing (dependencies). 1080 | Optionally set the PORT on which to serve the graph." 1081 | (interactive 1082 | (list 1083 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1084 | (call-interactively #'code-compass-request-date) 1085 | 8888)) 1086 | (code-compass--in-temp-directory 1087 | repository 1088 | (--> repository 1089 | (code-compass-produce-git-report it date) 1090 | code-compass--produce-code-maat-communication-report 1091 | code-compass--generate-communication-json-script 1092 | code-compass--generate-d3-v4-lib 1093 | code-compass--produce-communication-json 1094 | code-compass--generate-host-edge-bundling-html 1095 | (code-compass--run-server-and-navigate it port)))) 1096 | (define-obsolete-function-alias 'c/show-code-communication-sync #'code-compass-show-code-communication-sync "0.1.2") 1097 | 1098 | ;;;###autoload 1099 | (defun code-compass-show-code-communication (repository date &optional port) 1100 | "Show REPOSITORY edge bundling for code communication from DATE. 1101 | Optionally define PORT on which to serve graph." 1102 | (interactive 1103 | (list 1104 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1105 | (call-interactively #'code-compass-request-date))) 1106 | (code-compass--async-run #'code-compass-show-code-communication-sync repository date port)) 1107 | (define-obsolete-function-alias 'c/show-code-communication #'code-compass-show-code-communication "0.1.2") 1108 | ;; END code communication 1109 | 1110 | ;; BEGIN code knowledge 1111 | (defun code-compass--produce-code-maat-main-dev-report (repository) 1112 | "Create code-maat main-dev report for REPOSITORY." 1113 | (code-compass--run-code-maat "main-dev" repository) 1114 | repository) 1115 | 1116 | (defun code-compass--generate-knowledge-json-script (repository) 1117 | "Generate python script. 1118 | Argument REPOSITORY defines for which repo to run this." 1119 | (code-compass--copy-file "./scripts/knowledge_csv_as_enclosure_diagram.py" (code-compass--temp-dir repository)) 1120 | repository) 1121 | 1122 | (defun code-compass--produce-knowledge-json (repository) 1123 | "Generate REPOSITORY age json." 1124 | (message "Produce knowledge json...") 1125 | (code-compass--shell-command-error-handler 1126 | (code-compass--python-script "knowledge_csv_as_enclosure_diagram.py --structure cloc.csv --owners main-dev.csv --authors authors.csv > knowledge.json") 1127 | "*code-compass--produce-knowledge-json-errors*") 1128 | repository) 1129 | 1130 | (defun code-compass--insert-authors-colors-in-file (authors-colors) 1131 | "Insert a csv of AUTHORS-COLORS in the temporary asset directory for REPOSITORY." 1132 | (with-temp-file "authors.csv" 1133 | (insert "author,color\n") 1134 | (apply #'insert (--map (s-concat (car it) "," (cdr it) "\n") authors-colors)))) 1135 | 1136 | (defun code-compass--get-authors (repository) 1137 | "Retrieve authors in REPOSITORY." 1138 | (--> (s-concat "cd " repository "; git shortlog HEAD -s -n | uniq | cut -f 2") 1139 | shell-command-to-string 1140 | (s-split "\n" it) 1141 | (--remove (s-blank? (s-trim it)) it))) 1142 | 1143 | (defun code-compass--generate-list-authors-colors (repository) 1144 | "Generate list of authors of REPOSITORY." 1145 | (--> (code-compass--get-authors repository) 1146 | (-zip-pair it code-compass-authors-colors) 1147 | (code-compass--insert-authors-colors-in-file it)) 1148 | repository) 1149 | 1150 | (defun code-compass--generate-host-knowledge-enclosure-diagram-html (repository) 1151 | "Generate host html from REPOSITORY." 1152 | (code-compass--copy-file "./pages/knowledge-enclosure-diagram/script.js" (code-compass--temp-dir repository)) 1153 | (code-compass--copy-file "./pages/knowledge-enclosure-diagram/style.css" (code-compass--temp-dir repository)) 1154 | (code-compass--copy-file "./pages/knowledge-enclosure-diagram/zoomable.html" (code-compass--temp-dir repository)) 1155 | repository) 1156 | 1157 | (defun code-compass-show-knowledge-graph-sync (repository date authors &optional port) 1158 | "Show REPOSITORY enclosure diagram for code knowledge. 1159 | Filter by DATE and AUTHORS. 1160 | Optionally define PORT on which to serve graph." 1161 | (interactive (let ((repository (read-directory-name "Choose git repository directory:" (vc-root-dir)))) 1162 | (list 1163 | repository 1164 | (call-interactively #'code-compass-request-date) 1165 | (completing-read-multiple "Filter by authors (TAB-completion) or leave empty for all: " (code-compass--get-authors repository)) 1166 | 8888))) 1167 | (code-compass--in-temp-directory 1168 | repository 1169 | (--> repository 1170 | (code-compass-produce-git-report it date nil (if (> (length authors) 1) 1171 | (s-concat "(" (s-join "|" authors) ")") 1172 | authors)) 1173 | code-compass--produce-code-maat-main-dev-report 1174 | code-compass--produce-cloc-report 1175 | code-compass--generate-knowledge-json-script 1176 | code-compass--generate-d3-v3-lib 1177 | code-compass--generate-list-authors-colors 1178 | code-compass--produce-knowledge-json 1179 | code-compass--generate-host-knowledge-enclosure-diagram-html 1180 | (code-compass--run-server-and-navigate it port)))) 1181 | (define-obsolete-function-alias 'c/show-knowledge-graph-sync #'code-compass-show-knowledge-graph-sync "0.1.2") 1182 | 1183 | ;;;###autoload 1184 | (defun code-compass-show-knowledge-graph (repository date &optional authors port) 1185 | "Show REPOSITORY enclosure diagram for code knowledge. 1186 | Filter by DATE and AUTHORS. 1187 | Optionally define PORT on which to serve graph." 1188 | (interactive (let ((repository (read-directory-name "Choose git repository directory:" (vc-root-dir)))) 1189 | (list 1190 | repository 1191 | (call-interactively #'code-compass-request-date) 1192 | (completing-read-multiple "Filter by authors (TAB-completion) or leave empty for all: " (code-compass--get-authors repository)) 1193 | 8888))) 1194 | (code-compass--async-run #'code-compass-show-knowledge-graph-sync repository date port nil authors)) 1195 | (define-obsolete-function-alias 'c/show-knowledge-graph #'code-compass-show-knowledge-graph "0.1.2") 1196 | ;; END code knowledge 1197 | 1198 | ;; BEGIN code refactoring 1199 | (defun code-compass--produce-code-maat-refactoring-main-dev-report (repository) 1200 | "Create code-maat refactoring-main-dev report for REPOSITORY." 1201 | (code-compass--run-code-maat "refactoring-main-dev" repository) 1202 | repository) 1203 | 1204 | (defun code-compass--generate-refactoring-json-script (repository) 1205 | "Generate python script for REPOSITORY." 1206 | (code-compass--copy-file "./scripts/refactoring_csv_as_enclosure_diagram.py" (code-compass--temp-dir repository)) 1207 | repository) 1208 | 1209 | (defun code-compass--produce-refactoring-json (repository) 1210 | "Generate REPOSITORY age json." 1211 | (message "Produce refactoring json...") 1212 | (code-compass--shell-command-error-handler 1213 | (code-compass--python-script "refactoring_csv_as_enclosure_diagram.py --structure cloc.csv --owners refactoring-main-dev.csv --authors authors.csv > knowledge.json") ; TODO should be refactoring.json, but leaving knowledge.json for code reuse 1214 | "*code-compass--produce-refactoring-json-errors*") 1215 | repository) 1216 | 1217 | (defun code-compass-show-refactoring-graph-sync (repository date &optional port) 1218 | "Show REPOSITORY enclosure diagram for code knowledge up to DATE. 1219 | Optionally define PORT on which to serve graph." 1220 | (interactive 1221 | (list 1222 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1223 | (call-interactively #'code-compass-request-date) 1224 | 8888)) 1225 | (code-compass--in-temp-directory 1226 | repository 1227 | (--> repository 1228 | (code-compass-produce-git-report it date) 1229 | code-compass--produce-code-maat-refactoring-main-dev-report 1230 | code-compass--produce-cloc-report 1231 | code-compass--generate-refactoring-json-script ;; added,total-added, vs removed,total-removed 1232 | code-compass--generate-d3-v3-lib 1233 | code-compass--generate-list-authors-colors 1234 | code-compass--produce-refactoring-json 1235 | code-compass--generate-host-knowledge-enclosure-diagram-html 1236 | (code-compass--run-server-and-navigate it port)))) 1237 | (define-obsolete-function-alias 'c/show-refactoring-graph-sync #'code-compass-show-refactoring-graph-sync "0.1.2") 1238 | 1239 | ;;;###autoload 1240 | (defun code-compass-show-refactoring-graph (repository date &optional port) 1241 | "Show REPOSITORY enclosure diagram for code refactoring. 1242 | Filter by DATE. 1243 | Optionally define PORT on which to serve graph." 1244 | (interactive (list 1245 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1246 | (call-interactively #'code-compass-request-date))) 1247 | (code-compass--async-run #'code-compass-show-refactoring-graph-sync repository date port)) 1248 | (define-obsolete-function-alias 'c/show-refactoring-graph #'code-compass-show-refactoring-graph "0.1.2") 1249 | ;; END code refactoring 1250 | 1251 | ;; BEGIN code stability 1252 | (defun code-compass-produce-code-maat-age-report (repository) 1253 | "Create code-maat age report for REPOSITORY." 1254 | (code-compass--run-code-maat "age" repository) 1255 | repository) 1256 | 1257 | (defun code-compass--generate-age-json-script (repository) 1258 | "Generate python script for REPOSITORY." 1259 | (code-compass--copy-file "./scripts/code_age_csv_as_enclosure_json.py" (code-compass--temp-dir repository)) 1260 | repository) 1261 | 1262 | (defun code-compass--produce-age-json (repository) 1263 | "Generate REPOSITORY age json." 1264 | (message "Produce age json...") 1265 | (code-compass--shell-command-error-handler 1266 | (code-compass--python-script "code_age_csv_as_enclosure_json.py --structure cloc.csv --weights age.csv > age.json") 1267 | "*code-compass--produce-age-json-errors*") 1268 | repository) 1269 | 1270 | (defun code-compass--generate-host-age-enclosure-diagram-html (repository) 1271 | "Generate host html from REPOSITORY." 1272 | (code-compass--copy-file "./pages/age-enclosure-diagram/script.js" (code-compass--temp-dir repository)) 1273 | (code-compass--copy-file "./pages/age-enclosure-diagram/style.css" (code-compass--temp-dir repository)) 1274 | (code-compass--copy-file "./pages/age-enclosure-diagram/zoomable.html" (code-compass--temp-dir repository)) 1275 | repository) 1276 | 1277 | (defun code-compass-show-code-age-sync (repository date &optional port) 1278 | "Show REPOSITORY enclosure diagram for code stability/age. 1279 | Filter by DATE. 1280 | Optionally define PORT on which to serve graph." 1281 | (interactive 1282 | (list 1283 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1284 | (call-interactively #'code-compass-request-date) 1285 | 8888)) 1286 | (code-compass--in-temp-directory 1287 | repository 1288 | (--> repository 1289 | (code-compass-produce-git-report it date) 1290 | code-compass-produce-code-maat-age-report 1291 | code-compass--produce-cloc-report 1292 | code-compass--generate-age-json-script 1293 | code-compass--generate-d3-v3-lib 1294 | code-compass--produce-age-json 1295 | code-compass--generate-host-age-enclosure-diagram-html 1296 | (code-compass--run-server-and-navigate it port)))) 1297 | (define-obsolete-function-alias 'c/show-code-age-sync #'code-compass-show-code-age-sync "0.1.2") 1298 | 1299 | ;;;###autoload 1300 | (defun code-compass-show-stability-graph (repository date &optional port) 1301 | "Show REPOSITORY enclosure diagram for code stability. 1302 | Filter by DATE. 1303 | Optionally define PORT on which to serve graph." 1304 | (interactive (list 1305 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1306 | (call-interactively #'code-compass-request-date))) 1307 | (code-compass--async-run #'code-compass-show-code-age-sync repository date port)) 1308 | (define-obsolete-function-alias 'c/show-stability-graph #'code-compass-show-stability-graph "0.1.2") 1309 | ;; END code stability 1310 | 1311 | ;; BEGIN code fragmentation 1312 | (defun code-compass--produce-code-maat-entity-ownership-report (repository) 1313 | "Create code-maat entity-ownership report for REPOSITORY." 1314 | (code-compass--run-code-maat "entity-ownership" repository) 1315 | repository) 1316 | 1317 | (defun code-compass--slurp (file) 1318 | "Get string from FILE contents." 1319 | (with-temp-buffer 1320 | (insert-file-contents-literally file) 1321 | (buffer-substring-no-properties (point-min) (point-max)))) 1322 | 1323 | (defun code-compass--get-analysis-as-string-from-csv (analysis) 1324 | "Get ANALYSIS in csv as text." 1325 | (code-compass--slurp (s-concat analysis ".csv"))) 1326 | 1327 | (defun code-compass--generate-pie-script (repository) 1328 | "Generate python script for REPOSITORY." 1329 | (code-compass--copy-file "./scripts/csv-to-pie-graph.py" (code-compass--temp-dir repository)) 1330 | repository) 1331 | 1332 | (defun code-compass--show-pie-chart-command (file) 1333 | "Show pie chart of CSV FILE." 1334 | (format code-compass-pie-or-bar-chart-command file)) 1335 | 1336 | (defun code-compass--sum-by-first-column (rows) 1337 | "Utility to sum ROWS by first column. 1338 | 1339 | >> (code-compass--sum-by-first-column '((a . 1) (a . 2))) 1340 | => ((a . 3))" 1341 | (let (result) 1342 | (dolist (row rows) 1343 | (let* ((key (car row)) 1344 | (value (cdr row)) 1345 | (mapping (assoc key result))) 1346 | (if mapping 1347 | (setcdr mapping (+ (cdr mapping) value)) 1348 | (push (cons key value) result)))) 1349 | result)) 1350 | 1351 | (defun code-compass-show-fragmentation-sync (path &optional date) 1352 | "Show knowledge fragmentation for PATH. 1353 | Optional argument DATE to reduce time window." 1354 | (interactive "fShow fragmentation for:") 1355 | (let* ((path (file-truename path)) 1356 | (repository (s-trim (shell-command-to-string (format "cd %s; git rev-parse --show-toplevel" (file-name-directory path)))))) 1357 | (code-compass--in-temp-directory 1358 | repository 1359 | (--> repository 1360 | (code-compass-produce-git-report it date) 1361 | code-compass--produce-code-maat-entity-ownership-report 1362 | code-compass--generate-pie-script) 1363 | (--> (code-compass--get-analysis-as-string-from-csv "entity-ownership") 1364 | (code-compass--add-filename-to-analysis-columns repository it) 1365 | (--filter (s-starts-with-p path it) it) 1366 | (--map 1367 | (--> (s-split "," it) 1368 | (cons (nth 1 it) (+ (string-to-number (nth 2 it)) (string-to-number (nth 3 it))))) 1369 | it) 1370 | (code-compass--sum-by-first-column it) 1371 | (--map 1372 | (--> it (format "%s,%s\n" (car it) (cdr it))) 1373 | it) 1374 | (cons "author,+&-lines\n" it) 1375 | (with-temp-file "fragmentation.csv" 1376 | (apply #'insert it))) 1377 | (code-compass--shell-command-error-handler 1378 | (code-compass--show-pie-chart-command "fragmentation.csv") 1379 | "*code-compass-show-fragmentation-sync-errors*")))) 1380 | (define-obsolete-function-alias 'c/show-fragmentation-sync #'code-compass-show-fragmentation-sync "0.1.2") 1381 | 1382 | ;;;###autoload 1383 | (defun code-compass-show-fragmentation (path) 1384 | "Show knowledge fragmentation for PATH." 1385 | (interactive "fShow fragmentation for:") 1386 | (code-compass--async-run #'code-compass-show-fragmentation-sync path nil nil 't)) 1387 | (define-obsolete-function-alias 'c/show-fragmentation #'code-compass-show-fragmentation "0.1.2") 1388 | ;; END code fragmentation 1389 | 1390 | ;; BEGIN word analysis 1391 | ;; taken from: https://emacs.stackexchange.com/questions/13514/how-to-obtain-the-statistic-of-the-the-frequency-of-words-in-a-buffer 1392 | (defvar code-compass-punctuation-marks '("," 1393 | "." 1394 | "'" 1395 | "&" 1396 | "\"") 1397 | "List of Punctuation Marks that you want to count.") 1398 | 1399 | (defun code-compass--count-raw-word-list (raw-word-list) 1400 | "Produce a dictionary of RAW-WORD-LIST. 1401 | This contains the number of occurrences for each word." 1402 | (--> raw-word-list 1403 | (--reduce-from 1404 | (progn 1405 | (cl-incf (cdr (or (assoc it acc) 1406 | (code-compass--first (push (cons it 0) acc))))) 1407 | acc) 1408 | nil 1409 | it) 1410 | (sort it (lambda (a b) (string< (car a) (car b)))))) 1411 | 1412 | (defun code-compass--word-stats (string) 1413 | "Return word (as a token between spaces) frequency in STRING." 1414 | (let* ((words (split-string 1415 | (downcase string) 1416 | (format "[ %s\f\t\n\r\v]+" 1417 | (mapconcat #'identity code-compass-punctuation-marks "")) 1418 | t)) 1419 | (punctuation-marks (--filter 1420 | (member it code-compass-punctuation-marks) 1421 | (split-string string "" t))) 1422 | (raw-word-list (append punctuation-marks words)) 1423 | (word-list (code-compass--count-raw-word-list raw-word-list))) 1424 | (sort word-list (lambda (a b) (> (cdr a) (cdr b)))))) 1425 | 1426 | (defun code-compass--word-stats-to-csv-string (string &optional order-fn) 1427 | "Produce occurrences csv table for words in STRING. 1428 | Optionally sorting the table according to ORDER-FN." 1429 | (--> string 1430 | code-compass--word-stats 1431 | (--filter (> (length (car it)) 2) it) 1432 | (sort it (or order-fn (lambda (a b) (> (cdr a) (cdr b))))) 1433 | (--map (format "'%s',%d\n" (car it) (cdr it)) it) 1434 | (apply #'s-concat it) 1435 | (s-concat "word,occurences\n\n" it))) 1436 | 1437 | ;;;###autoload 1438 | (defun code-compass-word-statistics (string &optional order-fn) 1439 | "Produce a buffer with word statistics from STRING. 1440 | Optionally define ORDER-FN 1441 | \(for example to see the ones appearing less first\)." 1442 | (interactive 1443 | (list (buffer-substring-no-properties (point-min) (point-max)))) 1444 | (with-current-buffer (get-buffer-create "*word-statistics*") 1445 | (erase-buffer) 1446 | (insert (code-compass--word-stats-to-csv-string string order-fn))) 1447 | (pop-to-buffer "*word-statistics*") 1448 | (goto-char (point-min))) 1449 | (define-obsolete-function-alias 'c/word-statistics #'code-compass-word-statistics "0.1.2") 1450 | 1451 | ;;;###autoload 1452 | (defun code-compass-word-semantics (string) 1453 | "Produce a buffer with the words least used. 1454 | This could contain the most semantically relevant from STRING." 1455 | (interactive 1456 | (list (buffer-substring-no-properties (point-min) (point-max)))) 1457 | (code-compass-word-statistics string (lambda (a b) (< (cdr a) (cdr b))))) 1458 | (define-obsolete-function-alias 'c/word-semantics #'code-compass-word-semantics "0.1.2") 1459 | 1460 | ;;;###autoload 1461 | (defun code-compass-word-analysis-commits (arg) 1462 | "Show the frequency of words used in commits messages. 1463 | When ARG is set show only history for given file." 1464 | (interactive "P") 1465 | (--> (shell-command-to-string (s-concat 1466 | "git log --pretty=format:\"%s\"" 1467 | (when arg (format " %s" (read-file-name "Analyze history of:"))))) 1468 | code-compass-word-statistics)) 1469 | (define-obsolete-function-alias 'c/word-analysis-commits #'code-compass-word-analysis-commits "0.1.2") 1470 | 1471 | ;;;###autoload 1472 | (defun code-compass-word-analysis-region () 1473 | "Show the frequency of words in a region." 1474 | (interactive) 1475 | (when (region-active-p) 1476 | (--> (buffer-substring-no-properties (region-beginning) (region-end)) 1477 | code-compass-word-statistics))) 1478 | (define-obsolete-function-alias 'c/word-analysis-region #'code-compass-word-analysis-region "0.1.2") 1479 | 1480 | ;;;###autoload 1481 | (defun code-compass-word-analysis-region-graph () 1482 | "Show the frequency graph for words in region." 1483 | (interactive) 1484 | (when (region-active-p) 1485 | (--> (buffer-substring-no-properties (region-beginning) (region-end)) 1486 | code-compass--word-stats-to-csv-string 1487 | (with-temp-file (format "%s/word-stats.csv" code-compass-tmp-directory) 1488 | (insert it))) 1489 | (shell-command (format "graph --bar --xtick-angle 90 %s/word-stats.csv" code-compass-tmp-directory)))) 1490 | (define-obsolete-function-alias 'c/word-analysis-region-graph #'code-compass-word-analysis-region-graph "0.1.2") 1491 | 1492 | 1493 | ;; END word analysis 1494 | 1495 | ;; BEGIN churn icon 1496 | 1497 | (defun code-compass--calculate-added-delete-lines (file n-weeks-ago) 1498 | "Calculate added and deleted lines for FILE from N-WEEKS-AGO." 1499 | (--> "git log --since \"%s weeks ago\" --numstat --oneline %s " 1500 | (format it n-weeks-ago file) 1501 | (shell-command-to-string it) 1502 | (s-split "\n" it) 1503 | (--map (s-split "\t" it) it) 1504 | (--filter (> (length it) 2) it) 1505 | (--reduce-from 1506 | (list 1507 | :additions (+ (string-to-number (nth 0 it)) (plist-get acc :additions)) 1508 | :deletions (+ (string-to-number (nth 1 it)) (plist-get acc :deletions))) 1509 | (list :additions 0 :deletions 0) 1510 | it))) 1511 | 1512 | (defun code-compass--async-start (start-func &optional finish-func) 1513 | "Call `async-start' with START-FUNC and FINISH-FUNC." 1514 | (async-start 1515 | `(lambda () 1516 | (setq load-path ',load-path) 1517 | (load-file ,(symbol-file 'code-compass--async-start)) 1518 | (funcall ,start-func)) 1519 | finish-func)) 1520 | 1521 | (defun code-compass--display-icon () 1522 | "Display icon for buffer according to the previous history." 1523 | (when (and code-compass-display-icon (vc-root-dir)) 1524 | (let ((current-buffer (current-buffer)) 1525 | (current-file (buffer-file-name))) 1526 | (code-compass--async-start 1527 | `(lambda () 1528 | (let* ((additions-deletions 1529 | (code-compass--calculate-added-delete-lines ,current-file (plist-get ',code-compass-icon-trends :period))) 1530 | 1531 | (additions (plist-get additions-deletions :additions)) 1532 | (deletions (plist-get additions-deletions :deletions)) 1533 | (icon-key (cond 1534 | ((eq additions 0) :always-deletions) 1535 | ((eq deletions 0) :always-additions) 1536 | ((> additions deletions) :more-additions) 1537 | ('otherwise :more-deletions)))) 1538 | (plist-get ',code-compass-icon-trends icon-key))) 1539 | `(lambda (icon) 1540 | (with-current-buffer ,current-buffer 1541 | (code-compass--remove-icon) 1542 | (setq-local mode-line-format (cons `(:eval ,icon) mode-line-format)))))))) 1543 | 1544 | (defun code-compass--remove-icon () 1545 | "Remove icon." 1546 | (setq-local 1547 | mode-line-format 1548 | (--remove 1549 | (-contains-p 1550 | (--remove (symbolp it) code-compass-icon-trends) 1551 | (plist-get it :eval)) 1552 | mode-line-format))) 1553 | 1554 | (defun code-compass--display-icon-delayed () 1555 | "Display icon function for `prog-mode-hook'." 1556 | (run-with-timer 0.1 nil 'code-compass--display-icon)) 1557 | 1558 | (defun code-compass-toggle-churn-status-icon () 1559 | "Enable churn status icon." 1560 | (interactive) 1561 | (if (-contains-p prog-mode-hook #'code-compass--display-icon-delayed) 1562 | (remove-hook 'prog-mode-hook #'code-compass--display-icon-delayed) 1563 | (add-hook 'prog-mode-hook #'code-compass--display-icon-delayed))) 1564 | ;; END churn icon 1565 | ;; BEGIN wrapper gource 1566 | 1567 | ;;;###autoload 1568 | (defun code-compass-show-gource (repository date) 1569 | "Open gource for REPOSITORY from DATE." 1570 | (interactive 1571 | (list 1572 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1573 | (call-interactively #'code-compass-request-date))) 1574 | (if (executable-find code-compass-gource-command) 1575 | (async-shell-command 1576 | (s-concat 1577 | (format "cd %s; %s -seconds-per-day %s" repository code-compass-gource-command code-compass-gource-seconds-per-day) 1578 | (when date (format " --start-date %s" date)))) 1579 | (message 1580 | "Sorry, cannot find executable (%s). Try change the value of `code-compass-gource-command'" 1581 | code-compass-gource-command))) 1582 | (define-obsolete-function-alias 'c/show-gource #'code-compass-show-gource "0.1.2") 1583 | ;; END wrapper gource 1584 | 1585 | 1586 | ;; BEGIN create todos for a coupled files 1587 | (defun code-compass--get-matching-coupled-files (files &optional file) 1588 | "Get coupled FILES that match FILE or current buffer's file." 1589 | (let ((coupled-file (file-truename (or file (buffer-file-name))))) 1590 | (--> files 1591 | (--sort (> (string-to-number (nth 3 it)) (string-to-number (nth 3 other))) it) ;; sort by number of commits 1592 | (--sort (> (string-to-number (nth 2 it)) (string-to-number (nth 2 other))) it) ;; sort then by how often this file has changed 1593 | (-map (lambda (file) 1594 | (when (or (string= coupled-file (file-truename (car file))) 1595 | (string= coupled-file (file-truename (nth 1 file)))) 1596 | (car 1597 | (--remove (string= (buffer-file-name) it) (-take 2 file))))) 1598 | it) 1599 | (-remove 'null it)))) 1600 | 1601 | (defun code-compass--show-todo-buffer (files file) 1602 | "Show a `org-mode' buffer for FILE with the left FILES to modify." 1603 | (let ((buffer (get-buffer-create (concat (file-name-base file) "-todos")))) 1604 | (switch-to-buffer buffer) 1605 | (erase-buffer) 1606 | (org-mode) 1607 | (insert "* Files you need to modify after " (file-name-base file) ":\n") 1608 | (let* ((modified-files (--filter 1609 | (-contains-p 1610 | (s-split "\n" (shell-command-to-string "git diff --name-only HEAD")) 1611 | (file-name-nondirectory it)) 1612 | files)) 1613 | (files-to-modify (-difference files modified-files))) 1614 | (--each files-to-modify 1615 | (insert (format "** TODO [[%s][%s]]\n" it (file-name-base it)))) 1616 | (--each modified-files 1617 | (insert (format "** DONE [[%s][%s]]\n" it (file-name-base it))))) 1618 | buffer)) 1619 | 1620 | ;;;###autoload 1621 | (defun code-compass-create-todos-from-coupled-files (&optional file) 1622 | "Allow user to choose a coupled file to FILE or the current buffer's file." 1623 | (interactive) 1624 | (let ((create-todos 1625 | (lambda (files file) 1626 | (--> (code-compass--get-matching-coupled-files files file) 1627 | (if (null it) 1628 | (message "Nothing left todo for this file in this commit!") 1629 | (code-compass--show-todo-buffer it file)))))) 1630 | (code-compass--get-coupled-files-alist 1631 | (vc-root-dir) 1632 | `(lambda (files) 1633 | (funcall 1634 | ,create-todos 1635 | files 1636 | ,(or file (file-truename (or file (buffer-file-name))))))))) 1637 | (define-obsolete-function-alias 'c/create-todos-from-coupled-files #'code-compass-create-todos-from-coupled-files "0.1.2") 1638 | ;; END create todos for a coupled files 1639 | 1640 | ;; BEGIN EXPERIMENTAL slack support 1641 | (defun code-compass--get-main-contributor-email (&optional file) 1642 | "Find email of main contributor of buffer, or FILE." 1643 | (--> (or file (buffer-file-name)) 1644 | (file-name-nondirectory it) 1645 | (s-concat "./" it) 1646 | (format "git shortlog HEAD -n -sne -- %s" it) 1647 | (shell-command-to-string it) 1648 | (s-split "\n" it) 1649 | car ;; only the first contributor 1650 | (s-split "<" it) 1651 | (nth 1 it) 1652 | (s-split ">" it) 1653 | (nth 0 it))) 1654 | 1655 | (defun code-compass--open-slack-from-email (email) 1656 | "Open slack chat from EMAIL." 1657 | (when (and (fboundp 'slack) slack-current-team) 1658 | (slack-buffer-display-im 1659 | (slack-create-user-profile-buffer 1660 | slack-current-team 1661 | (plist-get ;; TODO fall back to manual choice if the mail cannot be found? 1662 | (--find 1663 | (string= 1664 | email 1665 | (plist-get (plist-get it :profile) :email)) 1666 | (slack-team-users slack-current-team)) 1667 | :id))))) 1668 | 1669 | ;;;###autoload 1670 | (defun code-compass-slack-main-contributor () 1671 | "Open slack chat with main contributor of file." 1672 | (interactive) 1673 | ;; Allow slack only if user has it installed, and has set a current team 1674 | (if (and (fboundp 'slack) slack-current-team) 1675 | (code-compass--open-slack-from-email (code-compass--get-main-contributor-email)) 1676 | (message "Sorry, setup your emacs-slack to use this function. See https://github.com/yuya373/emacs-slack."))) 1677 | (define-obsolete-function-alias 'c/slack-main-contributor #'code-compass-slack-main-contributor "0.1.2") 1678 | 1679 | ;; END EXPERIMENTAL slack support 1680 | 1681 | ;; BEGIN Hotspots for microservices 1682 | (defun code-compass--get-repositories-from-file (file) 1683 | "Extract the list the cluster list of directories. 1684 | We run `code-compass-show-hotspot-cluster-sync' from FILE." 1685 | (when (file-exists-p file) 1686 | (with-temp-buffer 1687 | (insert-file-contents-literally file) 1688 | (--> (buffer-substring-no-properties (point-min) (point-max)) 1689 | (s-split "\n" it) 1690 | (--map (s-concat (file-name-directory file) "/" it) it) 1691 | (--filter 1692 | (and 1693 | (file-directory-p it) 1694 | (file-directory-p (concat it "/.git"))) 1695 | it))))) 1696 | 1697 | (defun code-compass--directory-git-p (directory) 1698 | "Check if DIRECTORY is a Git repository." 1699 | (and 1700 | (file-directory-p directory) 1701 | (file-directory-p (concat directory "/.git")))) 1702 | 1703 | (defun code-compass--add-prepended-reports (directory) 1704 | "Prepend DIRECTORY to gitreport and revisions." 1705 | (copy-file "gitreport.log" (format "%s-gitreport.log" (code-compass--filename directory)) 't) 1706 | (copy-file "revisions.csv" (format "%s-revisions.csv" (code-compass--filename directory)) 't) 1707 | directory) 1708 | 1709 | (defun code-compass-show-hotspot-cluster-sync (repository date &optional port) 1710 | "Show hotspot analysis for repositories in DIRECTORY. 1711 | Filter by DATE. 1712 | If a file `repos-cluster.txt' exists with a list of repositories 1713 | in the current REPOSITORY, this has priority over DIRECTORY." 1714 | (interactive 1715 | (list 1716 | (read-directory-name "Choose repositories directory:" ".") 1717 | (call-interactively #'code-compass-request-date) 1718 | 8888)) 1719 | (let* ((filepath (s-concat repository "/repos-cluster.txt")) 1720 | (directories 1721 | (or (code-compass--get-repositories-from-file filepath) 1722 | (-filter 1723 | #'code-compass--directory-git-p 1724 | (--remove 1725 | (or (s-ends-with? "/." it) (s-ends-with? "/.." it)) 1726 | (directory-files repository 't))))) 1727 | (no-prefix-revisions-fn 1728 | (lambda (repo) 1729 | (code-compass--produce-code-maat-revisions-report repository) 1730 | repo))) 1731 | (message "Used directories: %s" directories) 1732 | (code-compass--in-temp-directory 1733 | repository 1734 | (code-compass--produce-cloc-report repository) 1735 | (--each directories 1736 | (--> it 1737 | (code-compass-produce-git-report it date) 1738 | (funcall no-prefix-revisions-fn it) 1739 | code-compass--add-prepended-reports 1740 | ;; codemaat: prepend "repo-name/" to all entries apart first and last (empty line) 1741 | (let* ((filename (code-compass--filename it)) 1742 | (rev-file (s-concat filename "-revisions.csv"))) 1743 | (--> rev-file 1744 | (with-temp-buffer 1745 | (insert-file-contents-literally it) 1746 | (buffer-substring-no-properties (point-min) (point-max))) 1747 | (s-split "\n" it 'omit-nulls) 1748 | cdr 1749 | (--map (concat filename "/" it) it) 1750 | (s-join "\n" it) 1751 | (format "%s\n" it) 1752 | (write-region it nil rev-file))))) 1753 | (code-compass--in-temp-directory 1754 | repository 1755 | ;; at this point I need to merge all *-revisions.csv and cloc-*.csv in something like "system" 1756 | (shell-command "cat *-revisions.csv | sed '/^[[:space:]]*$/d' > revisions.csv;") 1757 | (write-region 1758 | (concat 1759 | "entity,n-revs\n" 1760 | (with-temp-buffer 1761 | (insert-file-contents-literally "revisions.csv") 1762 | (buffer-substring-no-properties (point-min) (point-max)))) 1763 | nil 1764 | "revisions.csv") 1765 | (--> repository 1766 | code-compass--generate-merger-script 1767 | code-compass--generate-d3-v3-lib 1768 | code-compass--produce-json 1769 | code-compass--generate-host-enclosure-diagram-html 1770 | (code-compass--run-server-and-navigate it port)))))) 1771 | (define-obsolete-function-alias 'c/show-hotspot-cluster-sync #'code-compass-show-hotspot-cluster-sync "0.1.2") 1772 | 1773 | ;;;###autoload 1774 | (defun code-compass-show-hotspot-cluster (directory date &optional port) 1775 | "Show DIRECTORY enclosure diagram for hotspots. 1776 | Starting DATE reduces scope of Git log. 1777 | PORT defines where the html is served." 1778 | (interactive 1779 | (list 1780 | (read-directory-name "Choose repositories directory:" ".") 1781 | (call-interactively #'code-compass-request-date))) 1782 | (code-compass--async-run #'code-compass-show-hotspot-cluster-sync directory date port)) 1783 | (define-obsolete-function-alias 'c/show-hotspot-cluster #'code-compass-show-hotspot-cluster "0.1.2") 1784 | 1785 | ;; END Hotspots for microservices 1786 | 1787 | ;; BEGIN display contributors 1788 | 1789 | 1790 | (defun code-compass--contributors-list-for-current-buffer () 1791 | "Return contributors of this file if it is in a git repository." 1792 | (if (vc-root-dir) 1793 | (shell-command-to-string 1794 | (concat 1795 | "git shortlog HEAD -n -s -- " 1796 | (buffer-file-name))) 1797 | " No history yet")) 1798 | 1799 | (defun code-compass-file-name-parent-directory (filename) 1800 | "Get parent of FILENAME. This comes in Emacs 29." 1801 | (let* ((expanded-filename (expand-file-name filename)) 1802 | (parent (file-name-directory (directory-file-name expanded-filename)))) 1803 | (cond 1804 | ;; filename is at top-level, therefore no parent 1805 | ((or (null parent) 1806 | ;; `equal' is enough, we don't need to resolve symlinks here 1807 | ;; with `file-equal-p', also for performance 1808 | (equal parent expanded-filename)) 1809 | nil) 1810 | ;; filename is relative, return relative parent 1811 | ((not (file-name-absolute-p filename)) 1812 | (file-relative-name parent)) 1813 | (t 1814 | parent)))) 1815 | 1816 | ;;;###autoload 1817 | (defun code-compass-display-contributors () 1818 | "Show in minibuffer the main contributors of this file." 1819 | (interactive) 1820 | (when (and code-compass-display-file-contributors (buffer-file-name)) 1821 | (let ((file-path buffer-file-name)) 1822 | ;; When we have the ability to infer the project root, we will use that to display the relative file path 1823 | ;; Otherwise, we will display the entire full path. 1824 | ;; We can infer project root when file in question, is in VCS. If its a new file, the function won't 1825 | ;; be able to pick it up, so it will display the full file path. 1826 | (when (vc-root-dir) 1827 | (setq file-path (file-relative-name (buffer-file-name) (code-compass-file-name-parent-directory (vc-root-dir))))) 1828 | (message "Contributors of %s:\n%s" file-path (code-compass--contributors-list-for-current-buffer))))) 1829 | (define-obsolete-function-alias 'c/display-contributors #'code-compass-display-contributors "0.1.2") 1830 | 1831 | (defun code-compass-display-contributors-delayed () 1832 | "Delayed version of `code-compass--display-contributors' for use in hooks. 1833 | For example `prog-mode-hook'." 1834 | (run-with-timer 0.1 nil 'code-compass-display-contributors)) 1835 | (define-obsolete-function-alias 'c/display-contributors-delayed #'code-compass-display-contributors-delayed "0.1.2") 1836 | 1837 | 1838 | (defun code-compass-toggle-display-contributors () 1839 | "Show the contributors when opening files." 1840 | (interactive) 1841 | (if (-contains-p prog-mode-hook #'code-compass-display-contributors-delayed) 1842 | (remove-hook 'prog-mode-hook #'code-compass-display-contributors-delayed) 1843 | (add-hook 'prog-mode-hook #'code-compass-display-contributors-delayed))) 1844 | ;; END display contributors 1845 | 1846 | (defun code-compass-cheatsheet () 1847 | "Show cheatsheet for code compass." 1848 | (interactive) 1849 | (switch-to-buffer (get-buffer-create "*Code Compass Help*")) 1850 | (org-mode) 1851 | (insert " 1852 | | Command | Description | 1853 | |--------------------------------------------------+-----------------------------------------------------------------| 1854 | | code-compass-doctor | Check dependencies are satisfied. | 1855 | |--------------------------------------------------+-----------------------------------------------------------------| 1856 | | Graphs | | 1857 | |--------------------------------------------------+-----------------------------------------------------------------| 1858 | | code-compass-show-hotspots | Show code that changed more frequently in the last period. | 1859 | | code-compass-show-hotspot-snapshot-sync | Show hotspots over many intervals of times. | 1860 | | code-compass-show-hotspot-cluster | Show hotspots graph for a directory containing many projects. | 1861 | | code-compass-show-code-churn | Show code throughput/churn in the last period. | 1862 | | code-compass-show-coupling-graph | Show which file is coupled to which in the last period. | 1863 | | code-compass-show-code-communication | Show which contributors are/should likely chat with each other. | 1864 | | code-compass-show-knowledge-graph | Show who knows most about what code. | 1865 | | code-compass-show-refactoring-graph | Show who refactored most what code. | 1866 | | code-compass-show-stability-graph | Show the code that is most stable in last period. | 1867 | | code-compass-show-fragmentation | Show pie chart with how much people contributed to file. | 1868 | | code-compass-show-gource | Show gource video of repository contributions. | 1869 | |--------------------------------------------------+-----------------------------------------------------------------| 1870 | | Complexity | | 1871 | |--------------------------------------------------+-----------------------------------------------------------------| 1872 | | code-compass-calculate-complexity-current-buffer | Prints complexity stats of current buffer. | 1873 | | code-compass-show-complexity-over-commits | Show line graph of complexity for current file from the start. | 1874 | |--------------------------------------------------+-----------------------------------------------------------------| 1875 | | Word analysis | | 1876 | |--------------------------------------------------+-----------------------------------------------------------------| 1877 | | code-compass-word-statistics | Show stats about words in buffer. | 1878 | | code-compass-word-semantics | Show words least used in buffer. | 1879 | | code-compass-word-analysis-commits | Show frequency of words in commit messages. | 1880 | | code-compass-word-analysis-region | Show frequency of words in region (useful on functions) | 1881 | | code-compass-word-analysis-region-graph | Show graph for words frequency in region. | 1882 | |--------------------------------------------------+-----------------------------------------------------------------| 1883 | | Coupling extras | | 1884 | |--------------------------------------------------+-----------------------------------------------------------------| 1885 | | code-compass-create-todos-from-coupled-files | Make TODO list from coupled files. | 1886 | | code-compass-find-coupled-files | Jump to a file coupled to the current one, if available. | 1887 | |--------------------------------------------------+-----------------------------------------------------------------| 1888 | | Contributors extras | | 1889 | |--------------------------------------------------+-----------------------------------------------------------------| 1890 | | code-compass-slack-main-contributor | Chat with main contributor of file via emacs-slack. | 1891 | | code-compass-display-contributors | Show contributors for current file in minibuffer. | 1892 | | code-compass-show-raw-csv | Show the raw csv file for code-maat analyses. | 1893 | |--------------------------------------------------+-----------------------------------------------------------------| 1894 | 1895 | ")) 1896 | (define-obsolete-function-alias 'c/cheatsheet #'code-compass-cheatsheet "0.1.2") 1897 | 1898 | ;;;###autoload 1899 | (defun code-compass-show-raw-csv (analysis repository date) 1900 | "Show REPOSITORY edge bundling synchronously for code coupling up to DATE. 1901 | Serve graph on PORT. 1902 | Argument ANALYSIS sets the anylysis command to run." 1903 | (interactive (list 1904 | (completing-read "Analysis:" 1905 | '("authors" "revisions" "coupling" "soc" "summary" "identity" "abs-churn" "author-churn" "entity-churn" "entity-ownership" "main-dev" "refactoring-main-dev" "entity-effort" "main-dev-by-revs" "fragmentation" "communication" "messages" "age")) 1906 | (read-directory-name "Choose git repository directory:" (vc-root-dir)) 1907 | (call-interactively #'code-compass-request-date))) 1908 | (code-compass--in-temp-directory 1909 | repository 1910 | (--> repository 1911 | (code-compass-produce-git-report it nil date) 1912 | (code-compass--run-code-maat analysis it)) 1913 | (find-file (concat "./" analysis ".csv")) 1914 | (when (progn (goto-char (point-min)) 1915 | (search-forward "entity," nil t)) 1916 | (while (search-forward-regexp "\\\n." nil t) 1917 | (goto-char (- (point) 1)) 1918 | (insert repository)) 1919 | (goto-char (point-min))))) 1920 | (define-obsolete-function-alias 'c/show-raw-csv #'code-compass-show-raw-csv "0.1.2") 1921 | 1922 | (provide 'code-compass) 1923 | 1924 | ;;; code-compass.el ends here 1925 | -------------------------------------------------------------------------------- /pages/age-enclosure-diagram/script.js: -------------------------------------------------------------------------------- 1 | var margin = 10, 2 | outerDiameter = 960, 3 | innerDiameter = outerDiameter - margin - margin; 4 | 5 | var x = d3.scale.linear() 6 | .range([0, innerDiameter]); 7 | 8 | var y = d3.scale.linear() 9 | .range([0, innerDiameter]); 10 | 11 | var color = d3.scale.linear() 12 | .domain([-1, 5]) 13 | .range(["hsl(185,60%,99%)", "hsl(187,40%,70%)"]) 14 | .interpolate(d3.interpolateHcl); 15 | 16 | var pack = d3.layout.pack() 17 | .padding(2) 18 | .size([innerDiameter, innerDiameter]) 19 | .value(function(d) { return d.size; }) 20 | 21 | var svg = d3.select("body").append("svg") 22 | .attr("width", outerDiameter) 23 | .attr("height", outerDiameter) 24 | .append("g") 25 | .attr("transform", "translate(" + margin + "," + margin + ")"); 26 | 27 | d3.json("age.json", function(error, root) { 28 | var focus = root, 29 | nodes = pack.nodes(root); 30 | 31 | svg.append("g").selectAll("circle") 32 | .data(nodes) 33 | .enter().append("circle") 34 | .attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; }) 35 | .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) 36 | .attr("r", function(d) { return d.r; }) 37 | .style("fill", function(d) { return d.weight > 0.0 ? "whitesmoke" : 38 | d.children ? color(d.depth) : "black"; }) 39 | .style("fill-opacity", function(d) { return !!d.weight ? 1.0 - Math.min(1.0, d.weight) : d.weight;}) 40 | .on("click", function(d) { return zoom(focus == d ? root : d); }); 41 | 42 | 43 | svg.append("g").selectAll("text") 44 | .data(nodes) 45 | .enter().append("text") 46 | .attr("class", "label") 47 | .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) 48 | .style("fill-opacity", function(d) { return d.parent === root ? 1 : 0; }) 49 | .style("display", function(d) { return d.parent === root ? null : "none"; }) 50 | .text(function(d) { return d.name; }); 51 | 52 | d3.select(window) 53 | .on("click", function() { zoom(root); }); 54 | 55 | function zoom(d, i) { 56 | var focus0 = focus; 57 | focus = d; 58 | 59 | var k = innerDiameter / d.r / 2; 60 | x.domain([d.x - d.r, d.x + d.r]); 61 | y.domain([d.y - d.r, d.y + d.r]); 62 | d3.event.stopPropagation(); 63 | 64 | var transition = d3.selectAll("text,circle").transition() 65 | .duration(d3.event.altKey ? 7500 : 750) 66 | .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; }); 67 | 68 | transition.filter("circle") 69 | .attr("r", function(d) { return k * d.r; }); 70 | 71 | transition.filter("text") 72 | .filter(function(d) { return d.parent === focus || d.parent === focus0; }) 73 | .style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; }) 74 | .each("start", function(d) { if (d.parent === focus) this.style.display = "inline"; }) 75 | .each("end", function(d) { if (d.parent !== focus) this.style.display = "none"; }); 76 | }} 77 | ); 78 | 79 | d3.select(self.frameElement).style("height", outerDiameter + "px"); 80 | -------------------------------------------------------------------------------- /pages/age-enclosure-diagram/style.css: -------------------------------------------------------------------------------- 1 | .node { 2 | cursor: pointer; 3 | } 4 | 5 | .node:hover { 6 | stroke: #000; 7 | stroke-width: 1.5px; 8 | } 9 | 10 | .node--root { 11 | stroke: #777; 12 | stroke-width: 2px; 13 | } 14 | 15 | .node--leaf { 16 | fill: white; 17 | stroke: #777; 18 | stroke-width: 1px; 19 | } 20 | 21 | .label { 22 | font: 14px "Helvetica Neue", Helvetica, Arial, sans-serif; 23 | text-anchor: middle; 24 | fill: black; 25 | //text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff; 26 | } 27 | 28 | .label, 29 | .node--root, 30 | .node--leaf { 31 | pointer-events: none; 32 | } 33 | -------------------------------------------------------------------------------- /pages/age-enclosure-diagram/zoomable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pages/edge-bundling/script.js: -------------------------------------------------------------------------------- 1 | var diameter = 960, 2 | radius = diameter / 2, 3 | innerRadius = radius - 120; 4 | 5 | var cluster = d3.cluster().size([360, innerRadius]); 6 | 7 | var line = d3 8 | .radialLine() 9 | .curve(d3.curveBundle.beta(0.85)) 10 | .radius(function (d) { 11 | return d.y; 12 | }) 13 | .angle(function (d) { 14 | return (d.x / 180) * Math.PI; 15 | }); 16 | 17 | var svg = d3 18 | .select("body") 19 | .append("svg") 20 | .attr("width", diameter) 21 | .attr("height", diameter) 22 | .append("g") 23 | .attr("transform", "translate(" + radius + "," + radius + ")"); 24 | 25 | var link = svg.append("g").selectAll(".link"), 26 | node = svg.append("g").selectAll(".node"); 27 | 28 | d3.json("edgebundling.json", function (error, classes) { 29 | if (error) throw error; 30 | 31 | var root = packageHierarchy(classes).sum(function (d) { 32 | return d.size; 33 | }); 34 | 35 | cluster(root); 36 | 37 | link = link 38 | .data(packageImports(root.leaves())) 39 | .enter() 40 | .append("path") 41 | .each(function (d) { 42 | (d.source = d[0]), (d.target = d[d.length - 1]); 43 | }) 44 | .attr("class", "link") 45 | .attr("d", line); 46 | 47 | node = node 48 | .data(root.leaves()) 49 | .enter() 50 | .append("text") 51 | .attr("class", "node") 52 | .attr("dy", "0.31em") 53 | .attr("transform", function (d) { 54 | return ( 55 | "rotate(" + 56 | (d.x - 90) + 57 | ")translate(" + 58 | (d.y + 8) + 59 | ",0)" + 60 | (d.x < 180 ? "" : "rotate(180)") 61 | ); 62 | }) 63 | .attr("text-anchor", function (d) { 64 | return d.x < 180 ? "start" : "end"; 65 | }) 66 | .text(function (d) { 67 | return d.data.key; 68 | }) 69 | .on("mouseover", mouseovered) 70 | .on("mouseout", mouseouted); 71 | }); 72 | 73 | function mouseovered(d) { 74 | node.each(function (n) { 75 | n.target = n.source = false; 76 | }); 77 | 78 | link.classed("link--target", function (l) { 79 | if (l.target === d) return (l.source.source = true); 80 | }) 81 | .classed("link--source", function (l) { 82 | if (l.source === d) return (l.target.target = true); 83 | }) 84 | .filter(function (l) { 85 | return l.target === d || l.source === d; 86 | }) 87 | .raise(); 88 | 89 | node.classed("node--target", function (n) { 90 | return n.target; 91 | }).classed("node--source", function (n) { 92 | return n.source; 93 | }); 94 | } 95 | 96 | function mouseouted(d) { 97 | link.classed("link--target", false).classed("link--source", false); 98 | 99 | node.classed("node--target", false).classed("node--source", false); 100 | } 101 | 102 | // Lazily construct the package hierarchy from class names. 103 | function packageHierarchy(classes) { 104 | var map = {}; 105 | 106 | function find(name, data) { 107 | var node = map[name], 108 | i; 109 | if (!node) { 110 | node = map[name] = data || { name: name, children: [] }; 111 | if (name.length) { 112 | node.parent = find( 113 | name.substring(0, (i = name.lastIndexOf("/"))) 114 | ); 115 | node.parent.children.push(node); 116 | node.key = name.substring(i + 1); 117 | } 118 | } 119 | return node; 120 | } 121 | 122 | classes.forEach(function (d) { 123 | find(d.name, d); 124 | }); 125 | 126 | return d3.hierarchy(map[""]); 127 | } 128 | 129 | // Return a list of imports for the given array of nodes. 130 | function packageImports(nodes) { 131 | var map = {}, 132 | imports = []; 133 | 134 | // Compute a map from name to node. 135 | nodes.forEach(function (d) { 136 | map[d.data.name] = d; 137 | }); 138 | 139 | // For each import, construct a link from the source to target node. 140 | nodes.forEach(function (d) { 141 | if (d.data.imports) 142 | d.data.imports.forEach(function (i) { 143 | if (map[i]) { 144 | // skip nodes that do not have a pair 145 | imports.push(map[d.data.name].path(map[i])); 146 | } 147 | }); 148 | }); 149 | 150 | return imports; 151 | } 152 | -------------------------------------------------------------------------------- /pages/edge-bundling/style.css: -------------------------------------------------------------------------------- 1 | .node { 2 | font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif; 3 | fill: #bbb; 4 | } 5 | 6 | .node:hover { 7 | fill: #000; 8 | } 9 | 10 | .link { 11 | stroke: steelblue; 12 | stroke-opacity: 0.4; 13 | fill: none; 14 | pointer-events: none; 15 | } 16 | 17 | .node:hover, 18 | .node--source, 19 | .node--target { 20 | font-weight: 700; 21 | } 22 | 23 | .node--source { 24 | fill: #2ca02c; 25 | } 26 | 27 | .node--target { 28 | fill: #d62728; 29 | } 30 | 31 | .link--source, 32 | .link--target { 33 | stroke-opacity: 1; 34 | stroke-width: 2px; 35 | } 36 | 37 | .link--source { 38 | stroke: #d62728; 39 | } 40 | 41 | .link--target { 42 | stroke: #2ca02c; 43 | } 44 | -------------------------------------------------------------------------------- /pages/edge-bundling/zoomable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pages/enclosure-diagram/script.js: -------------------------------------------------------------------------------- 1 | var margin = 10, 2 | outerDiameter = 960, 3 | innerDiameter = outerDiameter - margin - margin; 4 | 5 | var x = d3.scale.linear().range([0, innerDiameter]); 6 | 7 | var y = d3.scale.linear().range([0, innerDiameter]); 8 | 9 | var color = d3.scale 10 | .linear() 11 | .domain([-1, 5]) 12 | .range(["hsl(185,60%,99%)", "hsl(187,40%,70%)"]) 13 | .interpolate(d3.interpolateHcl); 14 | 15 | var pack = d3.layout 16 | .pack() 17 | .padding(2) 18 | .size([innerDiameter, innerDiameter]) 19 | .value(function (d) { 20 | return d.size; 21 | }); 22 | 23 | var svg = d3 24 | .select("body") 25 | .append("svg") 26 | .attr("width", outerDiameter) 27 | .attr("height", outerDiameter) 28 | .append("g") 29 | .attr("transform", "translate(" + margin + "," + margin + ")"); 30 | 31 | d3.json("hotspot_proto.json", function (error, root) { 32 | var focus = root, 33 | nodes = pack.nodes(root); 34 | 35 | svg.append("g") 36 | .selectAll("circle") 37 | .data(nodes) 38 | .enter() 39 | .append("circle") 40 | .attr("class", function (d) { 41 | return d.parent 42 | ? d.children 43 | ? "node" 44 | : "node node--leaf" 45 | : "node node--root"; 46 | }) 47 | .attr("transform", function (d) { 48 | return "translate(" + d.x + "," + d.y + ")"; 49 | }) 50 | .attr("r", function (d) { 51 | return d.r; 52 | }) 53 | .style("fill", function (d) { 54 | return d.weight > 0.0 55 | ? "darkred" 56 | : d.children 57 | ? color(d.depth) 58 | : "black"; 59 | }) 60 | .style("fill-opacity", function (d) { 61 | return d.weight; 62 | }) 63 | .on("click", function (d) { 64 | return zoom(focus == d ? root : d); 65 | }); 66 | 67 | svg.append("g") 68 | .selectAll("text") 69 | .data(nodes) 70 | .enter() 71 | .append("text") 72 | .attr("class", "label") 73 | .attr("transform", function (d) { 74 | return "translate(" + d.x + "," + d.y + ")"; 75 | }) 76 | .style("fill-opacity", function (d) { 77 | return d.parent === root ? 1 : 0; 78 | }) 79 | .style("display", function (d) { 80 | return d.parent === root ? null : "none"; 81 | }) 82 | .text(function (d) { 83 | return d.name; 84 | }); 85 | 86 | d3.select(window).on("click", function () { 87 | zoom(root); 88 | }); 89 | 90 | function zoom(d, i) { 91 | var focus0 = focus; 92 | focus = d; 93 | 94 | var k = innerDiameter / d.r / 2; 95 | x.domain([d.x - d.r, d.x + d.r]); 96 | y.domain([d.y - d.r, d.y + d.r]); 97 | d3.event.stopPropagation(); 98 | 99 | var transition = d3 100 | .selectAll("text,circle") 101 | .transition() 102 | .duration(d3.event.altKey ? 7500 : 750) 103 | .attr("transform", function (d) { 104 | return "translate(" + x(d.x) + "," + y(d.y) + ")"; 105 | }); 106 | 107 | transition.filter("circle").attr("r", function (d) { 108 | return k * d.r; 109 | }); 110 | 111 | transition 112 | .filter("text") 113 | .filter(function (d) { 114 | return d.parent === focus || d.parent === focus0; 115 | }) 116 | .style("fill-opacity", function (d) { 117 | return d.parent === focus ? 1 : 0; 118 | }) 119 | .each("start", function (d) { 120 | if (d.parent === focus) this.style.display = "inline"; 121 | }) 122 | .each("end", function (d) { 123 | if (d.parent !== focus) this.style.display = "none"; 124 | }); 125 | } 126 | }); 127 | 128 | d3.select(self.frameElement).style("height", outerDiameter + "px"); 129 | -------------------------------------------------------------------------------- /pages/enclosure-diagram/style.css: -------------------------------------------------------------------------------- 1 | .node { 2 | cursor: pointer; 3 | } 4 | 5 | .node:hover { 6 | stroke: #000; 7 | stroke-width: 1.5px; 8 | } 9 | 10 | .node--root { 11 | stroke: #777; 12 | stroke-width: 2px; 13 | } 14 | 15 | .node--leaf { 16 | fill: white; 17 | stroke: #777; 18 | stroke-width: 1px; 19 | } 20 | 21 | .label { 22 | font: 14px "Helvetica Neue", Helvetica, Arial, sans-serif; 23 | text-anchor: middle; 24 | fill: white; 25 | //text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff; 26 | } 27 | 28 | .label, 29 | .node--root, 30 | .node--leaf { 31 | pointer-events: none; 32 | } 33 | -------------------------------------------------------------------------------- /pages/enclosure-diagram/zoomable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /pages/knowledge-enclosure-diagram/script.js: -------------------------------------------------------------------------------- 1 | var margin = 10, 2 | outerDiameter = 960, 3 | innerDiameter = outerDiameter - margin - margin; 4 | 5 | var x = d3.scale.linear() 6 | .range([0, innerDiameter]); 7 | 8 | var y = d3.scale.linear() 9 | .range([0, innerDiameter]); 10 | 11 | var color = d3.scale.linear() 12 | .domain([-1, 5]) 13 | .range(["hsl(185,60%,99%)", "hsl(187,40%,70%)"]) 14 | .interpolate(d3.interpolateHcl); 15 | 16 | var pack = d3.layout.pack() 17 | .padding(2) 18 | .size([innerDiameter, innerDiameter]) 19 | .value(function(d) { return d.size; }) 20 | 21 | var mainDiv = d3 22 | .select("body") 23 | .append("div") 24 | .attr("id", "maindiv") 25 | .style("width", "100%") 26 | .style("float", "left") 27 | 28 | var graphDiv = d3 29 | .select("#maindiv") 30 | .append("div") 31 | .attr("id", "graphdiv") 32 | .style("width", "600px") 33 | .style("float", "left") 34 | 35 | var svg = d3 36 | .select("#graphdiv") 37 | .append("svg") 38 | .attr("width", outerDiameter) 39 | .attr("height", outerDiameter) 40 | .append("g") 41 | .attr("transform", "translate(" + margin + "," + margin + ")"); 42 | 43 | d3.json("knowledge.json", function(error, root) { 44 | var focus = root, 45 | nodes = pack.nodes(root); 46 | 47 | svg.append("g").selectAll("circle") 48 | .data(nodes) 49 | .enter().append("circle") 50 | .attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; }) 51 | .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) 52 | .attr("r", function(d) { return d.r; }) 53 | .style("fill", function(d) { return d.weight > 0.0 ? d.author_color : 54 | d.children ? color(d.depth) : "black"; }) 55 | .style("fill-opacity", function(d) { return d.effort; }) 56 | .on("click", function(d) { return d.children ? zoom(focus == d ? root : d) : undefined; }); 57 | 58 | svg.append("g").selectAll("text") 59 | .data(nodes) 60 | .enter().append("text") 61 | .attr("class", "label") 62 | .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) 63 | .style("fill-opacity", function(d) { return d.parent === root ? 1 : 0; }) 64 | .style("display", function(d) { return d.parent === root ? null : "none"; }) 65 | .text(function(d) { return d.name; }) 66 | .on("mouseover", function(d){this.innerHTML = d.author || d.name;}) 67 | .on("mouseout", function(d){this.innerHTML = d.name;}); 68 | 69 | d3.select(window) 70 | .on("click", function() { zoom(root); }); 71 | 72 | function zoom(d, i) { 73 | var focus0 = focus; 74 | focus = d; 75 | 76 | var k = innerDiameter / d.r / 2; 77 | x.domain([d.x - d.r, d.x + d.r]); 78 | y.domain([d.y - d.r, d.y + d.r]); 79 | d3.event.stopPropagation(); 80 | 81 | var transition = d3.selectAll("text,circle").transition() 82 | .duration(d3.event.altKey ? 7500 : 750) 83 | .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; }); 84 | 85 | transition.filter("circle") 86 | .attr("r", function(d) { return k * d.r; }); 87 | 88 | transition.filter("text") 89 | .filter(function(d) { return d.parent === focus || d.parent === focus0; }) 90 | .style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; }) 91 | .each("start", function(d) { if (d.parent === focus) this.style.display = "inline"; }) 92 | .each("end", function(d) { if (d.parent !== focus) this.style.display = "none"; }); 93 | }} 94 | ); 95 | 96 | d3.select(self.frameElement).style("height", outerDiameter + "px"); 97 | 98 | 99 | var div = d3 100 | .select("#maindiv") 101 | .append("div") 102 | .attr("id", "legendiv") 103 | .attr("width", outerDiameter) 104 | .attr("height", outerDiameter) 105 | .style("margin-left", "1020px") 106 | .style("height", "800px") 107 | .style("overflow-y", "scroll"); 108 | 109 | var legendSVG = d3 110 | .select("#legendiv") 111 | .append("svg") 112 | .style("height", "3000") 113 | .style("width", "450"); 114 | 115 | var size = 20 116 | d3.csv("authors.csv", function(authorsColors){ 117 | // Add dots 118 | legendSVG.selectAll("mydots") 119 | .data(authorsColors) 120 | .enter() 121 | .append("rect") 122 | .attr("x", 100) 123 | .attr("y", function(d,i){ return 100 + i*(size+5)}) // 100 is where the first dot appears. 25 is the distance between dots 124 | .attr("width", size) 125 | .attr("height", size) 126 | .style("fill", function(d){ return d.color}) 127 | 128 | // Add names. 129 | legendSVG.selectAll("mylabels") 130 | .data(authorsColors) 131 | .enter() 132 | .append("text") 133 | .attr("x", 100 + size*1.2) 134 | .attr("y", function(d,i){ return 100 + i*(size+5) + (size/2)}) 135 | .style("fill", function(d){ return d.color}) 136 | .text(function(d){ return d.author}) 137 | .attr("text-anchor", "left") 138 | .style("alignment-baseline", "middle") 139 | }) 140 | -------------------------------------------------------------------------------- /pages/knowledge-enclosure-diagram/style.css: -------------------------------------------------------------------------------- 1 | 2 | .node { 3 | cursor: pointer; 4 | } 5 | 6 | .node:hover { 7 | stroke: #000; 8 | stroke-width: 1.5px; 9 | } 10 | 11 | .node--root { 12 | stroke: #777; 13 | stroke-width: 2px; 14 | } 15 | 16 | .node--leaf { 17 | fill: white; 18 | stroke: #777; 19 | stroke-width: 1px; 20 | } 21 | 22 | .label { 23 | font: 14px "Helvetica Neue", Helvetica, Arial, sans-serif; 24 | text-anchor: middle; 25 | fill: white; 26 | //text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff; 27 | } 28 | 29 | .label, 30 | .node--root, 31 | .node--leaf { 32 | } 33 | -------------------------------------------------------------------------------- /pages/knowledge-enclosure-diagram/zoomable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | graph-cli 2 | PyQT5 3 | -------------------------------------------------------------------------------- /scripts/code_age_csv_as_enclosure_json.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | ####################################################################### 4 | ## This program generates a JSON document suitable for a D3.js 5 | ## enclosure diagram visualization. This script is used together with 6 | ## a Code Maat age analysis in order to calculate the exponential 7 | ## decay and stabilization of code. 8 | ## 9 | ## The input data is read from two CSV files: 10 | ## 1) The complete system structure, including size metrics. 11 | ## 2) A code age analysis result used to assign weights to the modules. 12 | ####################################################################### 13 | 14 | import argparse 15 | import csv 16 | import json 17 | import sys 18 | 19 | class MergeError(Exception): 20 | def __init__(self, message): 21 | Exception.__init__(self, message) 22 | 23 | class Merged(object): 24 | def __init__(self): 25 | self._all_modules_with_complexity = {} 26 | self._merged = {} 27 | 28 | def sorted_result(self): 29 | # Sort on descending order: 30 | ordered = sorted(list(self._merged.items()), key=lambda item: item[1][0], reverse=True) 31 | return ordered 32 | 33 | def extend_with(self, name, freqs): 34 | if name in self._all_modules_with_complexity: 35 | complexity = self._all_modules_with_complexity[name] 36 | self._merged[name] = freqs, complexity 37 | 38 | def record_detected(self, name, complexity): 39 | self._all_modules_with_complexity[name] = complexity 40 | 41 | def write_csv(stats): 42 | print('module,revisions,code') 43 | for s in stats: 44 | name, (f,c) = s 45 | print(name + ',' + f + ',' + c) 46 | 47 | def parse_complexity(merged, row): 48 | name = row[1][2:] 49 | complexity = row[4] 50 | merged.record_detected(name, complexity) 51 | 52 | def parse_freqs(merged, row): 53 | name = row[0] 54 | freqs = row[1] 55 | merged.extend_with(name, freqs) 56 | 57 | def merge(revs_file, comp_file): 58 | merged = Merged() 59 | parse_csv(merged, comp_file, parse_complexity, expected_format='language,filename,blank,comment,code') 60 | parse_csv(merged, revs_file, parse_freqs, expected_format='entity,n-revs') 61 | write_csv(merged.sorted_result()) 62 | 63 | ###################################################################### 64 | ## Parse input 65 | ###################################################################### 66 | 67 | def validate_content_by(heading, expected): 68 | if not expected: 69 | return # no validation 70 | comparison = expected.split(',') 71 | stripped = heading[0:len(comparison)] # allow extra fields 72 | if stripped != comparison: 73 | raise MergeError('Erroneous content. Expected = ' + expected + ', got = ' + ','.join(heading)) 74 | 75 | def parse_csv(filename, parse_action, expected_format=None): 76 | def read_heading_from(r): 77 | p = next(r) 78 | while p == []: 79 | p = next(r) 80 | return p 81 | with open(filename, 'r', encoding="utf8") as csvfile: 82 | r = csv.reader(csvfile, delimiter=',') 83 | heading = read_heading_from(r) 84 | validate_content_by(heading, expected_format) 85 | return [parse_action(row) for row in r] 86 | 87 | class StructuralElement(object): 88 | def __init__(self, name, complexity): 89 | self.name = name 90 | self.complexity = complexity 91 | def parts(self): 92 | return self.name.split('/') 93 | 94 | def parse_structural_element(csv_row): 95 | name = csv_row[1][2:] 96 | complexity = csv_row[4] 97 | return StructuralElement(name, complexity) 98 | 99 | def make_element_weight_parser(weight_column): 100 | """ Parameterize with the column - this allows us 101 | to generate data from different analysis result types. 102 | """ 103 | def parse_element_weight(csv_row): 104 | name = csv_row[0] 105 | weight = float(csv_row[weight_column]) # Assert not zero? 106 | return name, weight 107 | return parse_element_weight 108 | 109 | ###################################################################### 110 | ## Calculating weights from the given CSV analysis file 111 | ###################################################################### 112 | 113 | class WeightCalculator(object): 114 | """ 115 | Calculates code age using exponential decay. 116 | """ 117 | def __init__(self, half_life, analysis_results): 118 | self._half_life_months = float(half_life) 119 | def as_half_life(age): 120 | return 1 / 2**(float(age)/self._half_life_months) 121 | def as_color(age): 122 | if age < self._half_life_months: 123 | return "darkred" 124 | return "DodgerBlue" 125 | def as_colored_weight(age): 126 | return as_half_life(age), as_color(age) 127 | self._colored_weights = dict([(name, as_colored_weight(n)) for name,n in analysis_results]) 128 | 129 | def weight_for(self, module_name): 130 | if module_name in self._colored_weights: 131 | weight, _ = self._colored_weights[module_name] 132 | return weight 133 | return 0.0 134 | 135 | def color_of(self, module_name): 136 | if module_name in self._colored_weights: 137 | _, color = self._colored_weights[module_name] 138 | return color 139 | return "gray" 140 | 141 | ###################################################################### 142 | ## Building the structure of the system 143 | ###################################################################### 144 | 145 | def _matching_part_in(hierarchy, part): 146 | return next((x for x in hierarchy if x['name']==part), None) 147 | 148 | def _ensure_branch_exists(hierarchy, branch): 149 | existing = _matching_part_in(hierarchy, branch) 150 | if not existing: 151 | new_branch = {'name':branch, 'children':[]} 152 | hierarchy.append(new_branch) 153 | existing = new_branch 154 | return existing 155 | 156 | def _add_leaf(hierarchy, module, weight_calculator, name): 157 | new_leaf = {'name':name, 'children':[], 158 | 'size':module.complexity, 159 | 'weight':weight_calculator.weight_for(module.name), 160 | 'color':weight_calculator.color_of(module.name)} 161 | hierarchy.append(new_leaf) 162 | return hierarchy 163 | 164 | def _insert_parts_into(hierarchy, module, weight_calculator, parts): 165 | """ Recursively traverse the hierarchy and insert the individual parts 166 | of the module, one by one. 167 | The parts specify branches. If any branch is missing, it's 168 | created during the traversal. 169 | The final part specifies a module name (sans its path, of course). 170 | This is where we add size and weight to the leaf. 171 | """ 172 | if len(parts) == 1: 173 | return _add_leaf(hierarchy, module, weight_calculator, name=parts[0]) 174 | next_branch = parts[0] 175 | existing_branch = _ensure_branch_exists(hierarchy, next_branch) 176 | return _insert_parts_into(existing_branch['children'], 177 | module, 178 | weight_calculator, 179 | parts=parts[1:]) 180 | 181 | def generate_structure_from(modules, weight_calculator): 182 | hierarchy = [] 183 | for module in modules: 184 | parts = module.parts() 185 | _insert_parts_into(hierarchy, module, weight_calculator, parts) 186 | 187 | structure = {'name':'root', 'children':hierarchy} 188 | return structure 189 | 190 | ###################################################################### 191 | ## Output 192 | ###################################################################### 193 | 194 | def write_json(result): 195 | print(json.dumps(result)) 196 | 197 | ###################################################################### 198 | ## Main 199 | ###################################################################### 200 | 201 | def run(args): 202 | raw_weights = parse_csv(args.weights, parse_action=make_element_weight_parser(args.weightcolumn)) 203 | weight_calculator = WeightCalculator(args.halflife, raw_weights) 204 | 205 | structure_input = parse_csv(args.structure, 206 | expected_format='language,filename,blank,comment,code', 207 | parse_action=parse_structural_element) 208 | weighted_system_structure = generate_structure_from(structure_input, weight_calculator) 209 | write_json(weighted_system_structure) 210 | 211 | if __name__ == "__main__": 212 | parser = argparse.ArgumentParser(description='Generates a JSON document suitable for enclosure diagrams.') 213 | parser.add_argument('--structure', required=True, help='A CSV file generated by cloc') 214 | parser.add_argument('--weights', required=True, help='A CSV file with code age results from Code Maat') 215 | parser.add_argument('--weightcolumn', type=int, default=1, help="The index specifying the column to use in the weight table") 216 | parser.add_argument('--halflife', type=int, default=1, help="Specifies the half life for a module in months") 217 | 218 | args = parser.parse_args() 219 | run(args) 220 | 221 | -------------------------------------------------------------------------------- /scripts/communication_csv_as_edge_bundling.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | ####################################################################### 4 | ## This program generates a JSON document suitable for a D3.js 5 | ## Hierarchical Edge Bundling visualization (see https://gist.github.com/mbostock/7607999) 6 | ## 7 | ## The input data is read from a Code Maat CSV file containing the result 8 | ## of a analysis. 9 | ####################################################################### 10 | 11 | import argparse 12 | import csv 13 | import json 14 | import sys 15 | 16 | ###################################################################### 17 | ## Parse input 18 | ###################################################################### 19 | 20 | def validate_content_by(heading, expected): 21 | if not expected: 22 | return # no validation 23 | comparison = expected.split(',') 24 | stripped = heading[0:len(comparison)] # allow extra fields 25 | if stripped != comparison: 26 | raise MergeError('Erroneous content. Expected = ' + expected + ', got = ' + ','.join(heading)) 27 | 28 | def parse_csv(filename, parse_action, expected_format=None): 29 | def read_heading_from(r): 30 | p = next(r) 31 | while p == []: 32 | p = next(r) 33 | return p 34 | with open(filename, 'rt', encoding="utf8") as csvfile: 35 | r = csv.reader(csvfile, delimiter=',') 36 | heading = read_heading_from(r) 37 | validate_content_by(heading, expected_format) 38 | return [parse_action(row) for row in r] 39 | 40 | class LinkBetweenPeer(object): 41 | def __init__(self, author, peer, strength): 42 | self.author = author 43 | self.peer = peer 44 | self.strength = int(strength) 45 | 46 | def parse_peers(csv_row): 47 | return LinkBetweenPeer(csv_row[0], csv_row[1], csv_row[4]) 48 | 49 | ###################################################################### 50 | ## Assemble the individual entries into an aggregated structure 51 | ###################################################################### 52 | 53 | def link_to(existing_authors, new_link): 54 | if not new_link.author in existing_authors: 55 | return {'name':new_link.author, 'size':new_link.strength, 'imports':[new_link.peer]} 56 | existing_author = existing_authors[new_link.author] 57 | existing_author['imports'].append(new_link.peer) 58 | existing_author['size'] = existing_author['size'] + new_link.strength 59 | return existing_author 60 | 61 | def aggregate_links_per_author_in(peer_links): 62 | links_per_author = {} 63 | for peer in peer_links: 64 | links_per_author[peer.author] = link_to(links_per_author, peer) 65 | return links_per_author 66 | 67 | ###################################################################### 68 | ## Output 69 | ###################################################################### 70 | 71 | def write_json(result): 72 | print(json.dumps(result)) 73 | 74 | ###################################################################### 75 | ## Main 76 | ###################################################################### 77 | 78 | def run(args): 79 | peer_links = parse_csv(args.communication, 80 | expected_format='author,peer,shared,average,strength', 81 | parse_action=parse_peers) 82 | links_by_author = aggregate_links_per_author_in(peer_links) 83 | write_json(list(links_by_author.values())) 84 | 85 | if __name__ == "__main__": 86 | parser = argparse.ArgumentParser(description='Generates a JSON document suitable for communication diagrams.') 87 | parser.add_argument('--communication', required=True, help='A CSV file containing the result of a communication analysis') 88 | 89 | args = parser.parse_args() 90 | run(args) 91 | -------------------------------------------------------------------------------- /scripts/coupling_csv_as_edge_bundling.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | """ 4 | The input data is read from a Code Maat CSV file containing the result 5 | of a analysis. 6 | """ 7 | 8 | import argparse 9 | import csv 10 | import json 11 | import sys 12 | 13 | 14 | def validate_content_by(heading, expected): 15 | if not expected: 16 | return # no validation 17 | comparison = expected.split(",") 18 | stripped = heading[0 : len(comparison)] # allow extra fields 19 | if stripped != comparison: 20 | raise MergeError( 21 | "Erroneous content. Expected = " + expected + ", got = " + ",".join(heading) 22 | ) 23 | 24 | 25 | def parse_csv(filename, parse_action, expected_format=None): 26 | def read_heading_from(r): 27 | p = next(r) 28 | while p == []: 29 | p = next(r) 30 | return p 31 | 32 | with open(filename, "rt", encoding="utf8") as csvfile: 33 | r = csv.reader(csvfile, delimiter=",") 34 | heading = read_heading_from(r) 35 | validate_content_by(heading, expected_format) 36 | return [parse_action(row) for row in r] 37 | 38 | 39 | class LinkBetweenCoupled(object): 40 | def __init__(self, entity, coupled, degree): 41 | self.entity = entity 42 | self.coupled = coupled 43 | self.degree = int(degree) 44 | 45 | 46 | def parse_coupleds(csv_row): 47 | return LinkBetweenCoupled( 48 | csv_row[0], csv_row[1], csv_row[2] 49 | ) # 2020-07-05 AG: editing this to make it work with software dependencies, TODO rename all entity based naming to coupled stuff 50 | 51 | 52 | def link_to(existing_entitys, new_link): 53 | if not new_link.entity in existing_entitys: 54 | return { 55 | "name": new_link.entity, 56 | "size": new_link.degree, 57 | "imports": [new_link.coupled], 58 | } 59 | existing_entity = existing_entitys[new_link.entity] 60 | existing_entity["imports"].append(new_link.coupled) 61 | existing_entity["size"] = existing_entity["size"] + new_link.degree 62 | return existing_entity 63 | 64 | 65 | def aggregate_links_per_entity_in(coupled_links): 66 | links_per_entity = {} 67 | for coupled in coupled_links: 68 | links_per_entity[coupled.entity] = link_to(links_per_entity, coupled) 69 | return links_per_entity 70 | 71 | 72 | def write_json(result): 73 | print(json.dumps(result)) 74 | 75 | 76 | def run(args): 77 | coupled_links = parse_csv( 78 | args.coupling, 79 | expected_format="entity,coupled,degree,average-revs", 80 | parse_action=parse_coupleds, 81 | ) 82 | links_by_entity = aggregate_links_per_entity_in(coupled_links) 83 | write_json(list(links_by_entity.values())) 84 | 85 | 86 | if __name__ == "__main__": 87 | parser = argparse.ArgumentParser( 88 | description="Generates a JSON document suitable for coupling diagrams." 89 | ) 90 | parser.add_argument( 91 | "--coupling", 92 | required=True, 93 | help="A CSV file containing the result of a coupling analysis", 94 | ) 95 | 96 | args = parser.parse_args() 97 | run(args) 98 | -------------------------------------------------------------------------------- /scripts/csv-to-pie-graph.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import pandas as pd 4 | import matplotlib.pyplot as plt 5 | import argparse 6 | 7 | parser = argparse.ArgumentParser("simple_example") 8 | parser.add_argument("csv", help="The csv file containing 2 columns.") 9 | args = parser.parse_args() 10 | csv_file=args.csv 11 | data = pd.read_csv(csv_file) 12 | Authors = data["author"] 13 | Lines = data["+&-lines"] 14 | x=[] 15 | y=[] 16 | x=list(Lines) 17 | y=list(Authors) 18 | plt.title('Ownership Fragmentation') 19 | plt.pie(x,labels=y,autopct='%.2f%%') 20 | plt.show() 21 | -------------------------------------------------------------------------------- /scripts/csv_as_enclosure_json.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | """ 4 | This program generates a JSON document suitable for a D3.js 5 | enclosure diagram visualization. 6 | The input data is read from two CSV files: 7 | 1) The complete system structure, including size metrics. 8 | 2) A hotspot analysis result used to assign weights to the modules. 9 | """ 10 | 11 | import argparse 12 | import csv 13 | import json 14 | 15 | 16 | class MergeError(Exception): 17 | pass 18 | 19 | 20 | class Merged(object): 21 | def __init__(self): 22 | self._all_modules_with_complexity = {} 23 | self._merged = {} 24 | 25 | def sorted_result(self): 26 | # Sort on descending order: 27 | return sorted( 28 | list(self._merged.items()), key=lambda item: item[1][0], reverse=True 29 | ) 30 | 31 | def extend_with(self, name, freqs): 32 | if name in self._all_modules_with_complexity: 33 | complexity = self._all_modules_with_complexity[name] 34 | self._merged[name] = freqs, complexity 35 | 36 | def record_detected(self, name, complexity): 37 | self._all_modules_with_complexity[name] = complexity 38 | 39 | 40 | def write_csv(stats): 41 | print("module,revisions,code") 42 | for name, (f, c) in stats: 43 | print(f"{name},{f},{c}") 44 | 45 | 46 | def parse_complexity(merged, row): 47 | _, name, _, _, complexity, *_ = row 48 | merged.record_detected(name[2:], complexity) 49 | 50 | 51 | def parse_freqs(merged, row): 52 | name, freqs, *_ = row 53 | merged.extend_with(name, freqs) 54 | 55 | 56 | def merge(revs_file, comp_file): 57 | merged = Merged() 58 | parse_csv( 59 | merged, 60 | comp_file, 61 | parse_complexity, 62 | expected_format="language,filename,blank,comment,code", 63 | ) 64 | parse_csv(merged, revs_file, parse_freqs, expected_format="entity,n-revs") 65 | write_csv(merged.sorted_result()) 66 | 67 | 68 | def validate_content_by(heading, expected): 69 | if not expected: 70 | return # no validation 71 | comparison = expected.split(",") 72 | stripped = heading[0 : len(comparison)] # allow extra fields 73 | if stripped != comparison: 74 | raise MergeError( 75 | f"Erroneous content. Expected = {expected}, got = {','.join(heading)}" 76 | ) 77 | 78 | 79 | def parse_csv(filename, parse_action, expected_format=None): 80 | def read_heading_from(r): 81 | p = next(r) 82 | while p == []: 83 | p = next(r) 84 | return p 85 | 86 | with open(filename, "r") as csvfile: 87 | r = csv.reader(csvfile, delimiter=",") 88 | heading = read_heading_from(r) 89 | validate_content_by(heading, expected_format) 90 | return [parse_action(row) for row in r] 91 | 92 | 93 | class StructuralElement(object): 94 | def __init__(self, name, complexity): 95 | self.name = name 96 | self.complexity = complexity 97 | 98 | def parts(self): 99 | return self.name.split("/") 100 | 101 | 102 | def parse_structural_element(csv_row): 103 | _, name, _, _, complexity, *_ = csv_row 104 | return StructuralElement(name[2:], complexity) 105 | 106 | 107 | def make_element_weight_parser(weight_column): 108 | """Parameterize with the column - this allows us 109 | to generate data from different analysis result types. 110 | """ 111 | 112 | def parse_element_weight(csv_row): 113 | name = csv_row[0] 114 | weight = float(csv_row[weight_column]) # Assert not zero? 115 | return name, weight 116 | 117 | return parse_element_weight 118 | 119 | 120 | def module_weight_calculator_from(analysis_results): 121 | max_raw_weight = max(analysis_results, key=lambda e: e[1]) 122 | max_value = max_raw_weight[1] 123 | normalized_weights = dict( 124 | [(name, (1.0 / max_value) * n) for name, n in analysis_results] 125 | ) 126 | 127 | def normalized_weight_for(module_name): 128 | if module_name in normalized_weights: 129 | return normalized_weights[module_name] 130 | return 0.0 131 | 132 | return normalized_weight_for 133 | 134 | 135 | def _matching_part_in(hierarchy, part): 136 | return next((x for x in hierarchy if x["name"] == part), None) 137 | 138 | 139 | def _ensure_branch_exists(hierarchy, branch): 140 | existing = _matching_part_in(hierarchy, branch) 141 | if not existing: 142 | new_branch = {"name": branch, "children": []} 143 | hierarchy.append(new_branch) 144 | existing = new_branch 145 | return existing 146 | 147 | 148 | def _add_leaf(hierarchy, module, weight_calculator, name): 149 | # TODO: augment with weight here! 150 | new_leaf = { 151 | "name": name, 152 | "children": [], 153 | "size": module.complexity, 154 | "weight": weight_calculator(module.name), 155 | } 156 | hierarchy.append(new_leaf) 157 | return hierarchy 158 | 159 | 160 | def _insert_parts_into(hierarchy, module, weight_calculator, parts): 161 | """Recursively traverse the hierarchy and insert the individual parts 162 | of the module, one by one. 163 | The parts specify branches. If any branch is missing, it's 164 | created during the traversal. 165 | The final part specifies a module name (sans its path, of course). 166 | This is where we add size and weight to the leaf. 167 | """ 168 | if len(parts) == 1: 169 | return _add_leaf(hierarchy, module, weight_calculator, name=parts[0]) 170 | next_branch, *rest = parts 171 | existing_branch = _ensure_branch_exists(hierarchy, next_branch) 172 | return _insert_parts_into( 173 | existing_branch["children"], module, weight_calculator, parts=rest 174 | ) 175 | 176 | 177 | def generate_structure_from(modules, weight_calculator): 178 | hierarchy = [] 179 | for module in modules: 180 | parts = module.parts() 181 | _insert_parts_into(hierarchy, module, weight_calculator, parts) 182 | 183 | return {"name": "root", "children": hierarchy} 184 | 185 | 186 | def write_json(result): 187 | print(json.dumps(result)) 188 | 189 | 190 | # TODO: turn it around: parse the weights first and add them to individual elements 191 | # as the raw structure list is built! 192 | 193 | 194 | def run(args): 195 | raw_weights = parse_csv( 196 | args.weights, parse_action=make_element_weight_parser(args.weightcolumn) 197 | ) 198 | weight_calculator = module_weight_calculator_from(raw_weights) 199 | 200 | structure_input = parse_csv( 201 | args.structure, 202 | expected_format="language,filename,blank,comment,code", 203 | parse_action=parse_structural_element, 204 | ) 205 | weighted_system_structure = generate_structure_from( 206 | structure_input, weight_calculator 207 | ) 208 | write_json(weighted_system_structure) 209 | 210 | 211 | if __name__ == "__main__": 212 | parser = argparse.ArgumentParser( 213 | description="Generates a JSON document suitable for enclosure diagrams." 214 | ) 215 | parser.add_argument( 216 | "--structure", required=True, help="A CSV file generated by cloc" 217 | ) 218 | parser.add_argument( 219 | "--weights", 220 | required=True, 221 | help="A CSV file with hotspot results from Code Maat", 222 | ) 223 | parser.add_argument( 224 | "--weightcolumn", 225 | type=int, 226 | default=1, 227 | help="The index specifying the columnt to use in the weight table", 228 | ) 229 | # TODO: add arguments to specify which CSV columns to use! 230 | 231 | args = parser.parse_args() 232 | run(args) 233 | -------------------------------------------------------------------------------- /scripts/knowledge_csv_as_enclosure_diagram.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | ####################################################################### 4 | ## This program generates a JSON document suitable for a D3.js 5 | ## enclosure diagram visualization. 6 | ## The input data is read from three CSV files: 7 | ## 1) A cloc output file specifying the static structure of the system. 8 | ## 2) A file containing Code Maat main developer results. 9 | ## 3) A file specifying the color to use for a certain author. If that 10 | ## information is absent, this script will treat that code as a 11 | ## dead spot. 12 | ## This CSV file must have two columns: author, color 13 | ####################################################################### 14 | 15 | import argparse 16 | import csv 17 | import json 18 | import sys 19 | 20 | ###################################################################### 21 | ## Parse input 22 | ###################################################################### 23 | 24 | def validate_content_by(heading, expected): 25 | if not expected: 26 | return # no validation 27 | comparison = expected.split(',') 28 | stripped = heading[0:len(comparison)] # allow extra fields 29 | if stripped != comparison: 30 | raise MergeError('Erroneous content. Expected = ' + expected + ', got = ' + ','.join(heading)) 31 | 32 | def parse_csv(filename, parse_action, expected_format=None): 33 | def read_heading_from(r): 34 | p = next(r) 35 | while p == []: 36 | p = next(r) 37 | return p 38 | with open(filename, 'r') as csvfile: 39 | r = csv.reader(csvfile, delimiter=',') 40 | heading = read_heading_from(r) 41 | validate_content_by(heading, expected_format) 42 | return [parse_action(row) for row in r] 43 | 44 | class StructuralElement(object): 45 | def __init__(self, name, complexity): 46 | self.name = name 47 | self.complexity = complexity 48 | def parts(self): 49 | return self.name.split('/') 50 | 51 | def parse_structural_element(csv_row): 52 | name = csv_row[1][2:] 53 | complexity = csv_row[4] 54 | return StructuralElement(name, complexity) 55 | 56 | def parse_author_color(csv_row): 57 | author = csv_row[0] 58 | color = csv_row[1] 59 | return author,color 60 | 61 | class Ownership(object): 62 | def __init__(self, module, main_author, ownership): 63 | self.module = module 64 | self.main_author = main_author 65 | self.ownership = ownership 66 | 67 | def parse_ownership(csv_row): 68 | module = csv_row[0] 69 | main_author = csv_row[1] 70 | ownership = csv_row[4] 71 | return Ownership(module, main_author,ownership) 72 | 73 | ###################################################################### 74 | ## Organizational information to augment the structure 75 | ###################################################################### 76 | 77 | class Knowledge(object): 78 | DEFAULT_COLOR = "black" 79 | def __init__(self, authors_colors, ownerships): 80 | self._authors_colors = authors_colors 81 | self._ownership = dict([(o.module, o) for o in ownerships]) 82 | 83 | def color_of(self, author): 84 | if author in self._authors_colors: 85 | return self._authors_colors[author] 86 | return self.DEFAULT_COLOR 87 | 88 | def owner_of(self, module_name): 89 | if module_name in self._ownership: 90 | o = self._ownership[module_name] 91 | return o.main_author 92 | return None 93 | 94 | def degree_of_ownership_for(self, module_name): 95 | if module_name in self._ownership: 96 | o = self._ownership[module_name] 97 | return o.ownership 98 | return 0.0 99 | 100 | ###################################################################### 101 | ## Building the structure of the system 102 | ###################################################################### 103 | 104 | def _matching_part_in(hierarchy, part): 105 | return next((x for x in hierarchy if x['name']==part), None) 106 | 107 | def _ensure_branch_exists(hierarchy, branch): 108 | existing = _matching_part_in(hierarchy, branch) 109 | if not existing: 110 | new_branch = {'name':branch, 'children':[]} 111 | hierarchy.append(new_branch) 112 | existing = new_branch 113 | return existing 114 | 115 | def _add_leaf(hierarchy, module, knowledge, name): 116 | owner = knowledge.owner_of(module.name) 117 | new_leaf = {'name':name, 'children':[], 118 | 'size':module.complexity, 119 | 'weight':knowledge.degree_of_ownership_for(module.name), 120 | 'author': owner, 121 | 'author_color':knowledge.color_of(owner)} 122 | hierarchy.append(new_leaf) 123 | return hierarchy 124 | 125 | def _insert_parts_into(hierarchy, module, knowledge, parts): 126 | """ Recursively traverse the hierarchy and insert the individual parts 127 | of the module, one by one. 128 | The parts specify branches. If any branch is missing, it's 129 | created during the traversal. 130 | The final part specifies a module name (sans its path, of course). 131 | This is where we add size and weight to the leaf. 132 | """ 133 | if len(parts) == 1: 134 | return _add_leaf(hierarchy, module, knowledge, name=parts[0]) 135 | next_branch = parts[0] 136 | existing_branch = _ensure_branch_exists(hierarchy, next_branch) 137 | return _insert_parts_into(existing_branch['children'], 138 | module, 139 | knowledge, 140 | parts=parts[1:]) 141 | 142 | def generate_structure_from(modules, knowledge): 143 | hierarchy = [] 144 | for module in modules: 145 | parts = module.parts() 146 | _insert_parts_into(hierarchy, module, knowledge, parts) 147 | 148 | structure = {'name':'root', 'children':hierarchy} 149 | return structure 150 | 151 | ###################################################################### 152 | ## Output 153 | ###################################################################### 154 | 155 | def write_json(result): 156 | print(json.dumps(result)) 157 | 158 | ###################################################################### 159 | ## Main 160 | ###################################################################### 161 | 162 | def run(args): 163 | authors_colors = dict(parse_csv(args.authors, 164 | expected_format='author,color', 165 | parse_action=parse_author_color)) 166 | module_ownership = parse_csv(args.owners, 167 | expected_format='entity,main-dev,added,total-added,ownership', 168 | parse_action=parse_ownership) 169 | structure_input = parse_csv(args.structure, 170 | expected_format='language,filename,blank,comment,code', 171 | parse_action=parse_structural_element) 172 | knowledge = Knowledge(authors_colors, module_ownership) 173 | knowledge_structure = generate_structure_from(structure_input, knowledge) 174 | write_json(knowledge_structure) 175 | 176 | if __name__ == "__main__": 177 | parser = argparse.ArgumentParser(description='Generates a JSON document suitable for knowledge diagrams.') 178 | parser.add_argument('--structure', required=True, help='A CSV file generated by cloc') 179 | parser.add_argument('--owners', required=True, help='A CSV file generated by a Code Maat main-dev analysis') 180 | parser.add_argument('--authors', required=True, help='A CSV file specifying the color to use for each author') 181 | 182 | args = parser.parse_args() 183 | run(args) 184 | -------------------------------------------------------------------------------- /scripts/refactoring_csv_as_enclosure_diagram.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | ####################################################################### 4 | ## This program generates a JSON document suitable for a D3.js 5 | ## enclosure diagram visualization. 6 | ## The input data is read from three CSV files: 7 | ## 1) A cloc output file specifying the static structure of the system. 8 | ## 2) A file containing Code Maat main developer results. 9 | ## 3) A file specifying the color to use for a certain author. If that 10 | ## information is absent, this script will treat that code as a 11 | ## dead spot. 12 | ## This CSV file must have two columns: author, color 13 | ####################################################################### 14 | 15 | import argparse 16 | import csv 17 | import json 18 | import sys 19 | 20 | ###################################################################### 21 | ## Parse input 22 | ###################################################################### 23 | 24 | def validate_content_by(heading, expected): 25 | if not expected: 26 | return # no validation 27 | comparison = expected.split(',') 28 | stripped = heading[0:len(comparison)] # allow extra fields 29 | if stripped != comparison: 30 | raise MergeError('Erroneous content. Expected = ' + expected + ', got = ' + ','.join(heading)) 31 | 32 | def parse_csv(filename, parse_action, expected_format=None): 33 | def read_heading_from(r): 34 | p = next(r) 35 | while p == []: 36 | p = next(r) 37 | return p 38 | with open(filename, 'r') as csvfile: 39 | r = csv.reader(csvfile, delimiter=',') 40 | heading = read_heading_from(r) 41 | validate_content_by(heading, expected_format) 42 | return [parse_action(row) for row in r] 43 | 44 | class StructuralElement(object): 45 | def __init__(self, name, complexity): 46 | self.name = name 47 | self.complexity = complexity 48 | def parts(self): 49 | return self.name.split('/') 50 | 51 | def parse_structural_element(csv_row): 52 | name = csv_row[1][2:] 53 | complexity = csv_row[4] 54 | return StructuralElement(name, complexity) 55 | 56 | def parse_author_color(csv_row): 57 | author = csv_row[0] 58 | color = csv_row[1] 59 | return author,color 60 | 61 | class Ownership(object): 62 | def __init__(self, module, main_author, ownership): 63 | self.module = module 64 | self.main_author = main_author 65 | self.ownership = ownership 66 | 67 | def parse_ownership(csv_row): 68 | module = csv_row[0] 69 | main_author = csv_row[1] 70 | ownership = csv_row[4] 71 | return Ownership(module, main_author,ownership) 72 | 73 | ###################################################################### 74 | ## Organizational information to augment the structure 75 | ###################################################################### 76 | 77 | class Knowledge(object): 78 | DEFAULT_COLOR = "black" 79 | def __init__(self, authors_colors, ownerships): 80 | self._authors_colors = authors_colors 81 | self._ownership = dict([(o.module, o) for o in ownerships]) 82 | 83 | def color_of(self, author): 84 | if author in self._authors_colors: 85 | return self._authors_colors[author] 86 | return self.DEFAULT_COLOR 87 | 88 | def owner_of(self, module_name): 89 | if module_name in self._ownership: 90 | o = self._ownership[module_name] 91 | return o.main_author 92 | return None 93 | 94 | def degree_of_ownership_for(self, module_name): 95 | if module_name in self._ownership: 96 | o = self._ownership[module_name] 97 | return o.ownership 98 | return 0.0 99 | 100 | ###################################################################### 101 | ## Building the structure of the system 102 | ###################################################################### 103 | 104 | def _matching_part_in(hierarchy, part): 105 | return next((x for x in hierarchy if x['name']==part), None) 106 | 107 | def _ensure_branch_exists(hierarchy, branch): 108 | existing = _matching_part_in(hierarchy, branch) 109 | if not existing: 110 | new_branch = {'name':branch, 'children':[]} 111 | hierarchy.append(new_branch) 112 | existing = new_branch 113 | return existing 114 | 115 | def _add_leaf(hierarchy, module, knowledge, name): 116 | owner = knowledge.owner_of(module.name) 117 | new_leaf = {'name':name, 'children':[], 118 | 'size':module.complexity, 119 | 'weight':knowledge.degree_of_ownership_for(module.name), 120 | 'author': owner, 121 | 'author_color':knowledge.color_of(owner)} 122 | hierarchy.append(new_leaf) 123 | return hierarchy 124 | 125 | def _insert_parts_into(hierarchy, module, knowledge, parts): 126 | """ Recursively traverse the hierarchy and insert the individual parts 127 | of the module, one by one. 128 | The parts specify branches. If any branch is missing, it's 129 | created during the traversal. 130 | The final part specifies a module name (sans its path, of course). 131 | This is where we add size and weight to the leaf. 132 | """ 133 | if len(parts) == 1: 134 | return _add_leaf(hierarchy, module, knowledge, name=parts[0]) 135 | next_branch = parts[0] 136 | existing_branch = _ensure_branch_exists(hierarchy, next_branch) 137 | return _insert_parts_into(existing_branch['children'], 138 | module, 139 | knowledge, 140 | parts=parts[1:]) 141 | 142 | def generate_structure_from(modules, knowledge): 143 | hierarchy = [] 144 | for module in modules: 145 | parts = module.parts() 146 | _insert_parts_into(hierarchy, module, knowledge, parts) 147 | 148 | structure = {'name':'root', 'children':hierarchy} 149 | return structure 150 | 151 | ###################################################################### 152 | ## Output 153 | ###################################################################### 154 | 155 | def write_json(result): 156 | print(json.dumps(result)) 157 | 158 | ###################################################################### 159 | ## Main 160 | ###################################################################### 161 | 162 | def run(args): 163 | authors_colors = dict(parse_csv(args.authors, 164 | expected_format='author,color', 165 | parse_action=parse_author_color)) 166 | module_ownership = parse_csv(args.owners, 167 | expected_format='entity,main-dev,removed,total-removed,ownership', 168 | parse_action=parse_ownership) 169 | structure_input = parse_csv(args.structure, 170 | expected_format='language,filename,blank,comment,code', 171 | parse_action=parse_structural_element) 172 | knowledge = Knowledge(authors_colors, module_ownership) 173 | knowledge_structure = generate_structure_from(structure_input, knowledge) 174 | write_json(knowledge_structure) 175 | 176 | if __name__ == "__main__": 177 | parser = argparse.ArgumentParser(description='Generates a JSON document suitable for knowledge diagrams.') 178 | parser.add_argument('--structure', required=True, help='A CSV file generated by cloc') 179 | parser.add_argument('--owners', required=True, help='A CSV file generated by a Code Maat main-dev analysis') 180 | parser.add_argument('--authors', required=True, help='A CSV file specifying the color to use for each author') 181 | 182 | args = parser.parse_args() 183 | run(args) 184 | -------------------------------------------------------------------------------- /test/code-compass-test.el: -------------------------------------------------------------------------------- 1 | ;;; code-compass.el --- Tests for code-compass. 2 | 3 | ;; Copyright (C) 2020 Andrea Giugliano 4 | 5 | ;; Author: Andrea Giugliano 6 | 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation, either version 3 of the License, or 10 | ;; (at your option) any later version. 11 | 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | 17 | ;; You should have received a copy of the GNU General Public License 18 | ;; along with this program. If not, see . 19 | 20 | ;;; Commentary: 21 | 22 | ;; Tests for code-compass 23 | ;; 24 | 25 | ;;; Code: 26 | 27 | 28 | (ert-deftest c/expand-file-name_expanded-file-name () 29 | (let ((default-directory "/tmp") 30 | (code-compass-path-to-code-compass "somePath")) 31 | (should 32 | (string= (code-compass--expand-file-name "someFile") "/tmp/somePath/someFile")))) 33 | 34 | (defun utils/parse-string-as-time (date-string) 35 | "Parse DATE-STRING as time." 36 | (let ((l (parse-time-string date-string))) 37 | (encode-time 0 0 0 (nth 3 l) (nth 4 l) (nth 5 l))) 38 | ) 39 | 40 | (ert-deftest c/subtract-to-now_return-the-day-before () 41 | (should 42 | (string= 43 | (format-time-string 44 | "%Y-%m-%d" 45 | (code-compass--subtract-to-now 46 | 1 47 | 24 48 | (utils/parse-string-as-time "2021-01-02"))) 49 | "2021-01-01"))) 50 | 51 | (ert-deftest c/request-date_git-date () 52 | (should 53 | (string= 54 | (code-compass-request-date "1d" (utils/parse-string-as-time "2021-01-02")) 55 | "2021-01-01"))) 56 | 57 | (ert-deftest c/temp-dir_give-temp-dir-for-analyses () 58 | (should 59 | (string= (code-compass--temp-dir "someRepo") "/tmp/code-compass-someRepo/"))) 60 | 61 | (ert-deftest c/in-temp-directory_run-in-directory () 62 | (should 63 | (string= (code-compass--in-temp-directory "someDir" default-directory) "/tmp/code-compass-someDir/"))) 64 | 65 | (ert-deftest c/calculate-complexity-stats_empty-stats () 66 | (should 67 | (string= (code-compass--calculate-complexity-stats "") nil))) 68 | 69 | (ert-deftest c/calculate-complexity-stats_return-stats () 70 | (should 71 | (equal 72 | (code-compass--calculate-complexity-stats 73 | " 74 | (let ((x 1)) 75 | (let ((y 2)) 76 | (let ((z 3))) 77 | (+ x y z)))") 78 | '((total . 6.0) 79 | (n-lines . 4) 80 | (max . 3.0) 81 | (mean . 1.5) 82 | (standard-deviation . 1.118033988749895) 83 | (used-indentation . 2))))) 84 | 85 | (ert-deftest c/add-filename-to-analysis-columns_prefix-lines () 86 | (should 87 | (equal 88 | (code-compass--add-filename-to-analysis-columns 89 | "someRepo" 90 | "some,analysis\nsomeEntry,someData\n\n") 91 | '("some,analysis" "someRepo/someEntry,someData")))) 92 | 93 | (ert-deftest c/sum-by-first-column_sums-rows-first-column () 94 | (should 95 | (equal (code-compass--sum-by-first-column 96 | '(("a" . 1) 97 | ("b" . 1) 98 | ("a" . 1) 99 | ("c" . 1) 100 | ("c" . 1) 101 | ("c" . 1))) 102 | '(("c" . 3) ("b" . 1) ("a" . 2))))) 103 | 104 | (ert-deftest c/word-stats_distribution-of-words () 105 | (should 106 | (equal 107 | (code-compass--word-stats "hi, hi, hi, hello, hello\nbla") 108 | '(("," . 4) ("hi" . 3) ("hello" . 2) ("bla" . 1))))) 109 | 110 | ;; Just evaluate buffer to run tests. 111 | (ert--stats-passed-expected (ert-run-tests 't (lambda (&rest args)))) 112 | 113 | ;;; code-compass ends here 114 | --------------------------------------------------------------------------------