Spaces:
Runtime error
Runtime error
Update pdf_generator.py
Browse files- pdf_generator.py +16 -17
pdf_generator.py
CHANGED
|
@@ -159,28 +159,27 @@ 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,
|
| 166 |
name = name.strip()
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
max_val = float(max_val.rstrip('%'))
|
| 176 |
-
else:
|
| 177 |
-
value = float(value)
|
| 178 |
-
min_val = float(min_val)
|
| 179 |
-
max_val = float(max_val)
|
| 180 |
|
| 181 |
-
#
|
| 182 |
-
|
| 183 |
-
value, min_val, max_val = int(value), int(min_val), int(max_val)
|
| 184 |
|
| 185 |
return name, value, min_val, max_val, is_percentage
|
| 186 |
return None
|
|
|
|
| 159 |
return story
|
| 160 |
|
| 161 |
def parse_quantitative_criteria(input_string):
|
| 162 |
+
# Match "Text [min-max]" format, where min and max can be int, float, or percentage
|
| 163 |
+
match = re.match(r'(.+?)\s*\[([-+]?(?:\d*\.*\d+)(?:%)?)\s*-\s*([-+]?(?:\d*\.*\d+)(?:%)?)\]', input_string)
|
| 164 |
if match:
|
| 165 |
+
name, min_val, max_val = match.groups()
|
| 166 |
name = name.strip()
|
| 167 |
|
| 168 |
+
def parse_value(val):
|
| 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 |
+
is_percentage = is_min_percent or is_max_percent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
+
# If no value is provided, use the minimum value as the default
|
| 182 |
+
value = min_val
|
|
|
|
| 183 |
|
| 184 |
return name, value, min_val, max_val, is_percentage
|
| 185 |
return None
|