Spaces:
Runtime error
Runtime error
Added a couple of convenience methods to the classes to get the representations I needed, but put that in the classes
Browse files- src/datatypes.py +12 -5
src/datatypes.py
CHANGED
@@ -103,6 +103,12 @@ class Category:
|
|
103 |
def product_count(self):
|
104 |
return len(self.products)
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
class Feature:
|
108 |
all = {}
|
@@ -120,6 +126,7 @@ class Feature:
|
|
120 |
def __repr__(self):
|
121 |
return self.name
|
122 |
|
|
|
123 |
class Product:
|
124 |
all = {}
|
125 |
|
@@ -150,6 +157,11 @@ class Product:
|
|
150 |
def for_ids(ids: List[str]):
|
151 |
return[Product.all[i] for i in ids]
|
152 |
|
|
|
|
|
|
|
|
|
|
|
153 |
class Review:
|
154 |
all = {}
|
155 |
|
@@ -158,8 +170,3 @@ class Review:
|
|
158 |
self.rating = rating
|
159 |
self.review_text = review_text
|
160 |
self.product = product
|
161 |
-
|
162 |
-
|
163 |
-
if __name__ == "__main__":
|
164 |
-
DataLoader.load_data()
|
165 |
-
print('test')
|
|
|
103 |
def product_count(self):
|
104 |
return len(self.products)
|
105 |
|
106 |
+
@property
|
107 |
+
def singular_name(self):
|
108 |
+
if self.name[-1] == "s":
|
109 |
+
return self.name[:-1] # Clip the s
|
110 |
+
return self.name
|
111 |
+
|
112 |
|
113 |
class Feature:
|
114 |
all = {}
|
|
|
126 |
def __repr__(self):
|
127 |
return self.name
|
128 |
|
129 |
+
|
130 |
class Product:
|
131 |
all = {}
|
132 |
|
|
|
157 |
def for_ids(ids: List[str]):
|
158 |
return[Product.all[i] for i in ids]
|
159 |
|
160 |
+
@staticmethod
|
161 |
+
def all_as_list():
|
162 |
+
return list(Product.all.values())
|
163 |
+
|
164 |
+
|
165 |
class Review:
|
166 |
all = {}
|
167 |
|
|
|
170 |
self.rating = rating
|
171 |
self.review_text = review_text
|
172 |
self.product = product
|
|
|
|
|
|
|
|
|
|