From 1204356f8f8f29ea9d295e4550dec8afdc39cacd Mon Sep 17 00:00:00 2001 From: bouni Date: Thu, 4 Jul 2024 17:14:27 +0200 Subject: [PATCH 1/6] Show the price for the number of selected parts --- partselector.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/partselector.py b/partselector.py index 6ae3cfb2..2c538e8b 100644 --- a/partselector.py +++ b/partselector.py @@ -642,6 +642,24 @@ def update_subcategories(self, *_): # search now that categories might have changed self.search(None) + def get_price(self, quantity, prices): + """Find the prce for the number of selected parts accordning to the price ranges.""" + price_ranges = prices.split(",") + min_quantity = int(price_ranges[0].split("-")[0]) + if quantity <= min_quantity: + range, price = price_ranges[0].split(":") + return price + for p in price_ranges: + range, price = p.split(":") + lower,upper = range.split("-") + if not upper: # upper bound of price ranges + return price + lower = int(lower) + upper = int(upper) + self.logger.debug(upper) + if lower <= quantity < upper: + return price + def populate_part_list(self, parts, search_duration): """Populate the list with the result of the search.""" search_duration_text = ( @@ -662,19 +680,19 @@ def populate_part_list(self, parts, search_duration): for p in parts: item = [str(c) for c in p] # Munge price to be more readable - pricecol = 8 # Must match order in library.py search function - price = [] - try: - for t in item[pricecol].split(","): - qty, p = t.split(":") - p = float(p) - if p < 1.0: - price.append(f"{qty}: {p * 100:.2f}c") - else: - price.append(f"{qty}: ${p:.2f}") - item[pricecol] = ", ".join(price) - except ValueError: - self.logger.warning("unable to parse price %s", item[pricecol]) + pricecol = 8 # Must match order in library.py search function + item[pricecol] = f"{len(self.parts)} parts: {self.get_price(len(self.parts), item[pricecol])} each" + # try: + # for t in item[pricecol].split(","): + # qty, p = t.split(":") + # p = float(p) + # if p < 1.0: + # price.append(f"{qty}: {p * 100:.2f}c") + # else: + # price.append(f"{qty}: ${p:.2f}") + # item[pricecol] = ", ".join(price) + # except ValueError: + # self.logger.warning("unable to parse price %s", item[pricecol]) self.part_list.AppendItem(item) def select_part(self, *_): From c0231df4958574bb5e18230486b703ab64af4f8f Mon Sep 17 00:00:00 2001 From: bouni Date: Wed, 31 Jul 2024 15:11:48 +0200 Subject: [PATCH 2/6] fix typo --- partselector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partselector.py b/partselector.py index 2c538e8b..284a65a4 100644 --- a/partselector.py +++ b/partselector.py @@ -643,7 +643,7 @@ def update_subcategories(self, *_): self.search(None) def get_price(self, quantity, prices): - """Find the prce for the number of selected parts accordning to the price ranges.""" + """Find the price for the number of selected parts accordning to the price ranges.""" price_ranges = prices.split(",") min_quantity = int(price_ranges[0].split("-")[0]) if quantity <= min_quantity: From 5bd4d5b1a1f7c1d787b53d032178887a1a35598a Mon Sep 17 00:00:00 2001 From: bouni Date: Wed, 31 Jul 2024 15:12:13 +0200 Subject: [PATCH 3/6] Remove commented code --- partselector.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/partselector.py b/partselector.py index 284a65a4..32fdef39 100644 --- a/partselector.py +++ b/partselector.py @@ -679,20 +679,8 @@ def populate_part_list(self, parts, search_duration): self.result_count.SetLabel(f"{count} Results in {search_duration_text}") for p in parts: item = [str(c) for c in p] - # Munge price to be more readable pricecol = 8 # Must match order in library.py search function item[pricecol] = f"{len(self.parts)} parts: {self.get_price(len(self.parts), item[pricecol])} each" - # try: - # for t in item[pricecol].split(","): - # qty, p = t.split(":") - # p = float(p) - # if p < 1.0: - # price.append(f"{qty}: {p * 100:.2f}c") - # else: - # price.append(f"{qty}: ${p:.2f}") - # item[pricecol] = ", ".join(price) - # except ValueError: - # self.logger.warning("unable to parse price %s", item[pricecol]) self.part_list.AppendItem(item) def select_part(self, *_): From d3c153894b4728c053f7cf170fa7cf4a559e8c71 Mon Sep 17 00:00:00 2001 From: bouni Date: Wed, 31 Jul 2024 15:44:22 +0200 Subject: [PATCH 4/6] Round prices --- partselector.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/partselector.py b/partselector.py index 32fdef39..260389e1 100644 --- a/partselector.py +++ b/partselector.py @@ -642,23 +642,23 @@ def update_subcategories(self, *_): # search now that categories might have changed self.search(None) - def get_price(self, quantity, prices): + def get_price(self, quantity, prices) -> float: """Find the price for the number of selected parts accordning to the price ranges.""" price_ranges = prices.split(",") min_quantity = int(price_ranges[0].split("-")[0]) if quantity <= min_quantity: range, price = price_ranges[0].split(":") - return price + return float(price) for p in price_ranges: range, price = p.split(":") lower,upper = range.split("-") if not upper: # upper bound of price ranges - return price + return float(price) lower = int(lower) upper = int(upper) self.logger.debug(upper) if lower <= quantity < upper: - return price + return float(price) def populate_part_list(self, parts, search_duration): """Populate the list with the result of the search.""" @@ -680,7 +680,8 @@ def populate_part_list(self, parts, search_duration): for p in parts: item = [str(c) for c in p] pricecol = 8 # Must match order in library.py search function - item[pricecol] = f"{len(self.parts)} parts: {self.get_price(len(self.parts), item[pricecol])} each" + price = round(self.get_price(len(self.parts), item[pricecol]) , 3) + item[pricecol] = f"{len(self.parts)} parts: ${price} each" self.part_list.AppendItem(item) def select_part(self, *_): From e4ef2a016f199a8e6935abfa2a6d1fa2f3d1de6c Mon Sep 17 00:00:00 2001 From: bouni Date: Mon, 5 Aug 2024 14:09:20 +0200 Subject: [PATCH 5/6] remove debug message --- partselector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/partselector.py b/partselector.py index 260389e1..52a6009a 100644 --- a/partselector.py +++ b/partselector.py @@ -656,7 +656,6 @@ def get_price(self, quantity, prices) -> float: return float(price) lower = int(lower) upper = int(upper) - self.logger.debug(upper) if lower <= quantity < upper: return float(price) From 611546e162ee320fed1bac038bb2b920bfc0245e Mon Sep 17 00:00:00 2001 From: bouni Date: Mon, 5 Aug 2024 14:13:45 +0200 Subject: [PATCH 6/6] Add sum --- partselector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/partselector.py b/partselector.py index 52a6009a..1ea714a4 100644 --- a/partselector.py +++ b/partselector.py @@ -680,7 +680,8 @@ def populate_part_list(self, parts, search_duration): item = [str(c) for c in p] pricecol = 8 # Must match order in library.py search function price = round(self.get_price(len(self.parts), item[pricecol]) , 3) - item[pricecol] = f"{len(self.parts)} parts: ${price} each" + sum = round(price * len(self.parts), 3) + item[pricecol] = f"{len(self.parts)} parts: ${price} each / ${sum} total" self.part_list.AppendItem(item) def select_part(self, *_):