From 5cd138451f18775c2a42223f70c3154a35a24b0a Mon Sep 17 00:00:00 2001 From: mkp Date: Tue, 15 Oct 2024 16:39:15 +0200 Subject: [PATCH] Get usage count for other dependencies as well Also refreeze FrozenTest to match the updated Test.amxd Note: not all objects that have external dependencies may be covered yet --- maxdiff/frozen_device_printer.py | 15 ++---- maxdiff/get_frozen_stats.py | 48 ++++++++++++++---- .../tests/test_baselines/FrozenTest.amxd.txt | 14 ++--- .../tests/test_baselines/StatsTest.amxd.txt | 2 +- maxdiff/tests/test_baselines/Test.amxd.txt | 3 +- maxdiff/tests/test_files/FrozenTest.amxd | Bin 38139 -> 38751 bytes maxdiff/tests/test_files/Test.amxd | Bin 23990 -> 24459 bytes 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/maxdiff/frozen_device_printer.py b/maxdiff/frozen_device_printer.py index 08eba01..9e6ce3b 100644 --- a/maxdiff/frozen_device_printer.py +++ b/maxdiff/frozen_device_printer.py @@ -1,5 +1,5 @@ from freezing_utils import * -from get_frozen_stats import get_stats, get_used_abstractions +from get_frozen_stats import get_stats, get_used_files def print_frozen_device(data: bytes) -> str: @@ -19,7 +19,7 @@ def print_frozen_device(data: bytes) -> str: footer_entries = parse_footer(footer_data[8:]) device_entries = get_device_entries(data, footer_entries) - used_abstractions = get_used_abstractions(device_entries) + used_files = get_used_files(device_entries) i = 0 for entry in device_entries: @@ -29,15 +29,10 @@ def print_frozen_device(data: bytes) -> str: if i == 0: frozen_string += f"{description} <= Device \n" else: - if file_name.endswith(".maxpat"): - if file_name in used_abstractions: - frozen_string += ( - f"{description}, {used_abstractions[file_name]} instances\n" - ) - else: - frozen_string += f"{description}, UNUSED\n" + if file_name in used_files: + frozen_string += f"{description}, {used_files[file_name]} instances\n" else: - frozen_string += f"{description}\n" + frozen_string += f"{description}, NOT FOUND IN PATCH\n" i += 1 frozen_string += get_stats(device_entries) return frozen_string diff --git a/maxdiff/get_frozen_stats.py b/maxdiff/get_frozen_stats.py index 6e4a18e..11c8354 100644 --- a/maxdiff/get_frozen_stats.py +++ b/maxdiff/get_frozen_stats.py @@ -57,7 +57,7 @@ def get_stats(entries: list[device_entry_with_data]): return summary -def get_used_abstractions(entries: list[device_entry_with_data]) -> dict[str, int]: +def get_used_files(entries: list[device_entry_with_data]) -> dict[str, int]: device = entries[0] # the first entry is always the device file abstraction_entries = [ @@ -65,7 +65,7 @@ def get_used_abstractions(entries: list[device_entry_with_data]) -> dict[str, in ] device_patch = get_patcher_dict(device) - abstractions_processor = AbstractionFileNamesProcessor() + abstractions_processor = FileNamesProcessor() process_patch_recursive(device_patch, abstraction_entries, abstractions_processor) return abstractions_processor.get_results() @@ -221,19 +221,49 @@ def get_results(self): return self.object_count, self.line_count -# TODO: expend with dependencies that might be included in the frozen device, like pictures -class AbstractionFileNamesProcessor(Processor): +# TODO: extend with dependencies that might be included in the frozen device, like pictures +class FileNamesProcessor(Processor): def __init__(self): - self.found_abstractions = {} + self.found_filenames = {} def process_elements(self, patcher, voice_count: int, abstraction_name=""): """If this patcher is an abstraction, i.e. when an abstraction_name is passed in, increment the entry in the dict""" + + filenames = get_filenames(patcher) if abstraction_name != "": - if abstraction_name in self.found_abstractions: - self.found_abstractions[abstraction_name] += voice_count + filenames.append(abstraction_name) + + for filename in filenames: + if filename in self.found_filenames: + self.found_filenames[filename] += voice_count else: - self.found_abstractions[abstraction_name] = voice_count + self.found_filenames[filename] = voice_count def get_results(self): """Returns a dict of used abstractions mapped to how oftern they are used.""" - return self.found_abstractions + return self.found_filenames + + +def get_filenames(patcher): + filenames = [] + for box_entry in patcher["boxes"]: + box = box_entry["box"] + + if box.get("pic"): + filenames.append(box.get("pic")) + + if box.get("pictures"): + for name in box.get("pictures"): + filenames.append(name) + + if box["maxclass"] == "pictctrl": + if box.get("name"): + filenames.append(box.get("name")) + + if box.get("bkgndpict"): + filenames.append(box.get("bkgndpict")) + + if box.get("knobpict"): + filenames.append(box.get("knobpict")) + + return filenames diff --git a/maxdiff/tests/test_baselines/FrozenTest.amxd.txt b/maxdiff/tests/test_baselines/FrozenTest.amxd.txt index 25a2398..d603761 100644 --- a/maxdiff/tests/test_baselines/FrozenTest.amxd.txt +++ b/maxdiff/tests/test_baselines/FrozenTest.amxd.txt @@ -2,18 +2,18 @@ MIDI Effect Device ------------------- Device is frozen ----- Contents ----- -Test.amxd: 23958 bytes, modified at 2024/10/15 14:31:39 UTC <= Device +Test.amxd: 24570 bytes, modified at 2024/10/15 14:34:06 UTC <= Device ParamAbstraction.maxpat: 1570 bytes, modified at 2024/05/24 13:59:36 UTC, 2 instances MyAbstraction.maxpat: 2015 bytes, modified at 2024/10/15 14:31:31 UTC, 2 instances AbstractionWithParameter.maxpat: 1569 bytes, modified at 2024/05/24 13:59:36 UTC, 2 instances -hz-icon.svg: 484 bytes, modified at 2024/05/24 13:59:36 UTC -beat-icon.svg: 533 bytes, modified at 2024/05/24 13:59:36 UTC -fpic.png: 7094 bytes, modified at 2024/05/24 13:59:36 UTC -collContent.txt: 8 bytes, modified at 2024/05/24 13:59:36 UTC +hz-icon.svg: 484 bytes, modified at 2024/05/24 13:59:36 UTC, 1 instances +beat-icon.svg: 533 bytes, modified at 2024/05/24 13:59:36 UTC, 1 instances +fpic.png: 7094 bytes, modified at 2024/05/24 13:59:36 UTC, 4 instances +collContent.txt: 8 bytes, modified at 2024/05/24 13:59:36 UTC, NOT FOUND IN PATCH Total - Counting every abstraction instance - Indicates loading time - Object instances: 49 + Object instances: 51 Connections: 16 Unique - Counting abstractions once - Indicates maintainability - Object instances: 44 + Object instances: 46 Connections: 14 diff --git a/maxdiff/tests/test_baselines/StatsTest.amxd.txt b/maxdiff/tests/test_baselines/StatsTest.amxd.txt index ea52654..14acecb 100644 --- a/maxdiff/tests/test_baselines/StatsTest.amxd.txt +++ b/maxdiff/tests/test_baselines/StatsTest.amxd.txt @@ -4,7 +4,7 @@ Device is frozen ----- Contents ----- StatsTest.amxd: 9344 bytes, modified at 2024/10/15 13:55:42 UTC <= Device MyAbstraction.maxpat: 2015 bytes, modified at 2024/10/15 13:54:08 UTC, 7 instances -UnusedAbstraction.maxpat: 2015 bytes, modified at 2024/10/15 13:54:59 UTC, UNUSED +UnusedAbstraction.maxpat: 2015 bytes, modified at 2024/10/15 13:54:59 UTC, NOT FOUND IN PATCH Total - Counting every abstraction instance - Indicates loading time Object instances: 33 diff --git a/maxdiff/tests/test_baselines/Test.amxd.txt b/maxdiff/tests/test_baselines/Test.amxd.txt index 4fa0d95..aeacacb 100644 --- a/maxdiff/tests/test_baselines/Test.amxd.txt +++ b/maxdiff/tests/test_baselines/Test.amxd.txt @@ -18,7 +18,6 @@ dependency_cache: {'name': 'MyAbstraction.maxpat', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1} {'name': 'ParamAbstraction.maxpat', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1} {'name': 'beat-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1} - {'name': 'collContent.txt', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1} {'name': 'fpic.png', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'PNG', 'implicit': 1} {'name': 'hz-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1} @@ -31,6 +30,8 @@ project: ----------- patcher ----------- appversion: 8.6.2-x64-1 | rect: [65, 399, 927, 289] | openrect: [0, 0, 0, 169] | default_fontsize: 10.0 | default_fontname: Arial Bold | gridsize: [8, 8] | boxanimatetime: 500 | latency: 0 | is_mpe: 0 | platform_compatibility: 0 | autosave: 0 ----------- objects ----------- +[pictslider] bkgndpict: fpic.png | clickedimage: 0 | knobpict: fpic.png +[pictctrl] name: fpic.png [bpatcher ThisWasAnAbstractionBeforeEmbeddingIt.maxpat] embed: 1 ----------- patcher ----------- appversion: 8.6.2-x64-1 | rect: [927, 431, 640, 480] diff --git a/maxdiff/tests/test_files/FrozenTest.amxd b/maxdiff/tests/test_files/FrozenTest.amxd index e72138fd71f6ed71388b488029540db55305cfbb..aeaf82298aa693f0cf42156eb01a3caf16cad3da 100644 GIT binary patch delta 585 zcmZXPO>5LZ7{`;@g55;g?Y0df6^3Yq){rKXOp+~IwxQt5UR)1)lfGnM2)mosx=1fx z#7i%AyHCNJcQ1m@7bvJ7KokTkTcM?T=qK<6oQbp`9T@)4^PhQs|CwJe(f%vcofs=U zm!$T_d?ZOyj&Hu;;I(y>nQk_c>RKFibUcgoIY`p`s1LOn5OHCmr3udYr(W5X08OghqT~ zS_ZalSBRT7E`cz%pfYk^b_7uu#Hh30It@>j+qM6m%#&`wvwRK~!@S^*6E_9=)T9O` zwty2m#p2>TyF2hPi-^ajhtA0=Eu=57eA9yB@LNO+Am_dbIpE@Z@P6c2$cxb__?q8E zj>F3z8EOfgf;VIRLElRQDD0Pu?9;e5gn|M)zWjy5ofPf_ro}!?GF1uEG%)~M_M!T( zwbSs&Xnz=dvDX4gwMk?^|V ztqNNF347Z!av#)Q87(PLf@|=kw}9#fFEM=Y-9w4W%N5iyV0FiZ&p^W*)DT385nKu6JTfL zHa68W&`~fnFw--gyg=|U2ZV2GJlR*cX!2d53?^gK$?n1rm`sf(Yl^%9QE$aGCp(B9 zU^1`-GquI`Gn<%OZhkAq&d6bE1TxLYbh5vn&1MS;F+L_U)6D^Dw-^PDEW!2|o9mhC zD3}8|li!&-ZLZbG=H@d4JHgx(Bm=aVPfU8Upvh5gh%m%u4^95S_#hKDzc4jp<}wCb zW^SNouvx?MFAI~I;pDgWv6J`N)Jkqr z#ZH@SKSiI>dvg91FQ(XKlk=x(PkuJVnJM`Mkf|`)dukX{_HrQ8Wb*Z?dQ62NQSHh9 drg2WTo@T^UyavckVk$id6}4uXSPo>W005hLd!qmV diff --git a/maxdiff/tests/test_files/Test.amxd b/maxdiff/tests/test_files/Test.amxd index cf5f281e1212c3789d1b8eef5e0f70d3055ad745..d3d406b90588cff5eb9e4dd795dadc3d1c760be0 100644 GIT binary patch delta 488 zcmdnCo3VR8;{+L|?D&mxFPOEm)ALdaGLuV`6s#1K(ts?zg1mGk9WG7~P)g3pOwLYC z$;?emPo2EMN=vm)PWUvK*5g#P}!6J4$h8 z=9MVvC@5v-O?Grtm|W*9BW7f7q-UU`U}$IpqD;UX6QfBk29q5Gc^HjB1}cFJOfD(P zf!m#zn45~?VxUFtlk0^9Ci^=Ifs7S3G69=sZmMUhqhMqRGTX>-l1ss6SC-41Oh#s# zrTEwxxlJv>b{m-M8BEsUKg?umIr$_10}ypt-~p4l+2pN)Z$MO^u;%15LI;?Pje*P; z%%%n)T66Luk$W8GW?-{TC!hDS*?dG)jE~8}a`PSKTR_8&!G;@K=oxH2sJfY(%K~g0 zNWWX7(OTAh8BVXR*ye5h<(yuT_i_ delta 311 zcmeC)&$w+j;{+L|X|WsSUNBEyZ)3lCCEI0ACIh3*bpq^++{UJQ2099c24;GulP3rs z=78``jVId*7fn7Zl)+?dI@w(K0h6iGWJ!@XAnLA|=41oW155^%V5YR#er6MM%guMi z*cmxYjXmYEyq8ElrY{L8{*W;pq- zeeC3QHg%If*}Vk$@UDF!Ba@lI<^ab@OhEqR07tLQdM-aj`I7TcMm^hzow WzYq6i32}`Gnd}f@uvtASg%tn_gkDSl