From c4a1a452d344de0ee45e2fb2c8284c636eb05818 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 15 Aug 2019 13:30:19 +0200 Subject: digikey-search-parts: Adding summary in download report. --- src/ee/digikey/search_parts.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index c0da731..703e65f 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -80,7 +80,7 @@ class QueryEngine(object): def pn_spn_search(self, pn, is_spn): s = "Searching for '{}'".format(pn) print(s, file=self.log) - print("=" * len(s) + "\n", file=self.log) + print("-" * len(s) + "\n", file=self.log) out_part = None result = None @@ -220,24 +220,52 @@ def run_search_parts(in_path: Path, out_path: Path, log, cache_dir: Path, store_ pn_queries = list(sorted(pn_qs)) spn_queries = list(sorted(spn_qs)) - print("Executing {} manufacturer product number searches\n\n".format(len(pn_queries)), file=log) + s = "Manufacturer product number searches" + print("{}\n{}\n".format(s, "=" * len(s)), file=log) + print("Executing {} manufacturer product number searches:\n\n".format(len(pn_queries)), file=log) exception = False + mpn_results = {} for q in pn_queries: res = engine.pn_search(q.pn) + + if res in mpn_results: + mpn_results[res] = mpn_results[res] + 1 + else: + mpn_results[res] = 1 + if res == SearchResponseTypes.EXCEPTION: exception = True break + spn_results = {} if not exception: - print("Executing {} supplier product number searches\n\n".format(len(spn_queries)), file=log) + if len(spn_queries) == 0: + print("Executing no supplier product number searches.\n\n".format(len(spn_queries)), file=log) + else: + print("Executing {} supplier product number searches:\n\n".format(len(spn_queries)), file=log) for q in spn_queries: res = engine.spn_search(q.spn) + + if res in spn_results: + spn_results[res] = spn_results[res] + 1 + else: + spn_results[res] = 1 + if res == SearchResponseTypes.EXCEPTION: exception = True break + header = "Statistics" + print("{}\n{}\n".format(header, "=" * len(header)), file=log) + + for name, results in [("MPN", mpn_results), ("SPN", spn_results)]: + print("{} Searches:\n".format(name), file=log) + for res, count in results.items(): + print("* {}: {}".format(res.name, count), file=log) + print("", file=log) + part_db = PartDb() for part in engine.out_parts: part_db.add_entry(part, True) -- cgit v1.2.3