Spaces:
Sleeping
Sleeping
Update pdf_generator.py
Browse files- pdf_generator.py +26 -23
pdf_generator.py
CHANGED
@@ -27,7 +27,7 @@ class SliderFlowable(Flowable):
|
|
27 |
|
28 |
# Draw slider value
|
29 |
if self.max_val == self.min_val:
|
30 |
-
value_width = 50 #
|
31 |
else:
|
32 |
value_width = 50 + ((self.value - self.min_val) / (self.max_val - self.min_val) * 300)
|
33 |
value_bar = Rect(50, 30, value_width - 50, 20, fillColor=colors.HexColor("#9999ff"), strokeColor=None)
|
@@ -51,13 +51,13 @@ class SliderFlowable(Flowable):
|
|
51 |
|
52 |
drawing.drawOn(self.canv, 0, 0)
|
53 |
|
54 |
-
def format_value(self,
|
55 |
if self.is_percentage:
|
56 |
-
return f"{
|
57 |
-
elif isinstance(
|
58 |
-
return f"{
|
59 |
else:
|
60 |
-
return f"{
|
61 |
|
62 |
def create_styles():
|
63 |
styles = getSampleStyleSheet()
|
@@ -159,27 +159,30 @@ def process_quantitative_criteria(answer, styles):
|
|
159 |
return story
|
160 |
|
161 |
def parse_quantitative_criteria(input_string):
|
162 |
-
# Match
|
163 |
-
match = re.match(r'(.+?)
|
|
|
164 |
if match:
|
165 |
-
name, min_val, max_val = match.groups()
|
166 |
name = name.strip()
|
167 |
|
168 |
-
|
169 |
-
if '%' in val:
|
170 |
-
return float(val.rstrip('%')), True
|
171 |
-
elif '.' in val:
|
172 |
-
return float(val), False
|
173 |
-
else:
|
174 |
-
return int(val), False
|
175 |
-
|
176 |
-
min_val, is_min_percent = parse_value(min_val)
|
177 |
-
max_val, is_max_percent = parse_value(max_val)
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
return name, value, min_val, max_val, is_percentage
|
185 |
return None
|
|
|
27 |
|
28 |
# Draw slider value
|
29 |
if self.max_val == self.min_val:
|
30 |
+
value_width = 50 # Default width when min and max are the same
|
31 |
else:
|
32 |
value_width = 50 + ((self.value - self.min_val) / (self.max_val - self.min_val) * 300)
|
33 |
value_bar = Rect(50, 30, value_width - 50, 20, fillColor=colors.HexColor("#9999ff"), strokeColor=None)
|
|
|
51 |
|
52 |
drawing.drawOn(self.canv, 0, 0)
|
53 |
|
54 |
+
def format_value(self, value):
|
55 |
if self.is_percentage:
|
56 |
+
return f"{value:.1f}%"
|
57 |
+
elif isinstance(value, int):
|
58 |
+
return f"{value}"
|
59 |
else:
|
60 |
+
return f"{value:.2f}"
|
61 |
|
62 |
def create_styles():
|
63 |
styles = getSampleStyleSheet()
|
|
|
159 |
return story
|
160 |
|
161 |
def parse_quantitative_criteria(input_string):
|
162 |
+
# Match the entire string, with an optional value before the range
|
163 |
+
match = re.match(r'(.+?)(?:\s*:\s*([-+]?(?:\d*\.*\d+)(?:%)?))?\s*\[([-+]?(?:\d*\.*\d+)(?:%)?)\s*-\s*([-+]?(?:\d*\.*\d+)(?:%)?)?\]', input_string)
|
164 |
+
|
165 |
if match:
|
166 |
+
name, value, min_val, max_val = match.groups()
|
167 |
name = name.strip()
|
168 |
|
169 |
+
is_percentage = '%' in min_val or '%' in max_val
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
+
def parse_value(val):
|
172 |
+
if val is None:
|
173 |
+
return None
|
174 |
+
val = val.rstrip('%')
|
175 |
+
if '.' in val:
|
176 |
+
return float(val)
|
177 |
+
return int(val)
|
178 |
+
|
179 |
+
value = parse_value(value)
|
180 |
+
min_val = parse_value(min_val)
|
181 |
+
max_val = parse_value(max_val)
|
182 |
+
|
183 |
+
# If no value is provided, use the minimum value as default
|
184 |
+
if value is None:
|
185 |
+
value = min_val
|
186 |
|
187 |
return name, value, min_val, max_val, is_percentage
|
188 |
return None
|