Spaces:
Running
Running
Guilherme Silberfarb Costa commited on
Commit ·
b6d4e48
1
Parent(s): 9a6f968
correcao de equacoes para excel
Browse files
backend/app/services/equacao_service.py
CHANGED
|
@@ -247,24 +247,31 @@ def _build_formula_excel_sab(
|
|
| 247 |
transf_y = _normalize_transform(transformacao_y)
|
| 248 |
# Forma direta sem EXP/LN quando y esta em log.
|
| 249 |
if transf_y == "ln(x)":
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
var_resolver=var_resolver,
|
| 255 |
-
mode=_MODE_EXCEL_SAB,
|
| 256 |
-
include_ln_terms=False,
|
| 257 |
-
)
|
| 258 |
-
expr = f"({_E_CONST_BR}^({base_linear}))"
|
| 259 |
for coluna in colunas_x:
|
|
|
|
|
|
|
|
|
|
| 260 |
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 261 |
if transf != "ln(x)":
|
| 262 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
coef = _resolve_coef(params, coluna)
|
| 264 |
if abs(coef) < 1e-15:
|
| 265 |
continue
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
linear = _compose_linear_expression(
|
| 270 |
params=params,
|
|
@@ -304,24 +311,29 @@ def _build_formula_calc_excel_sab(
|
|
| 304 |
) -> str:
|
| 305 |
transf_y = _normalize_transform(transformacao_y)
|
| 306 |
if transf_y == "ln(x)":
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
transformacoes_x=transformacoes_x,
|
| 311 |
-
var_resolver=var_resolver,
|
| 312 |
-
mode=_MODE_EXCEL_SAB,
|
| 313 |
-
include_ln_terms=False,
|
| 314 |
-
)
|
| 315 |
-
expr = f"({_E_CONST_DOT}^({base_linear}))"
|
| 316 |
for coluna in colunas_x:
|
|
|
|
|
|
|
|
|
|
| 317 |
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 318 |
if transf != "ln(x)":
|
| 319 |
continue
|
|
|
|
|
|
|
|
|
|
| 320 |
coef = _resolve_coef(params, coluna)
|
| 321 |
if abs(coef) < 1e-15:
|
| 322 |
continue
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
linear = _compose_linear_expression_calc(
|
| 327 |
params=params,
|
|
|
|
| 247 |
transf_y = _normalize_transform(transformacao_y)
|
| 248 |
# Forma direta sem EXP/LN quando y esta em log.
|
| 249 |
if transf_y == "ln(x)":
|
| 250 |
+
partes: list[str] = []
|
| 251 |
+
partes.append(_format_number_br(math.exp(_resolve_const(params))))
|
| 252 |
+
|
| 253 |
+
# Primeiro os termos ln(x), que viram x^coef (mais legivel no estilo SAB).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
for coluna in colunas_x:
|
| 255 |
+
coef = _resolve_coef(params, coluna)
|
| 256 |
+
if abs(coef) < 1e-15:
|
| 257 |
+
continue
|
| 258 |
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 259 |
if transf != "ln(x)":
|
| 260 |
continue
|
| 261 |
+
partes.append(f"{var_resolver(coluna)}^{_format_number_br(coef)}")
|
| 262 |
+
|
| 263 |
+
# Depois os demais termos, na forma exp(coef)^termo.
|
| 264 |
+
for coluna in colunas_x:
|
| 265 |
coef = _resolve_coef(params, coluna)
|
| 266 |
if abs(coef) < 1e-15:
|
| 267 |
continue
|
| 268 |
+
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 269 |
+
if transf == "ln(x)":
|
| 270 |
+
continue
|
| 271 |
+
termo = _term_expr_excel(transf, var_resolver(coluna), _MODE_EXCEL_SAB)
|
| 272 |
+
partes.append(f"{_format_number_br(math.exp(coef))}^{termo}")
|
| 273 |
+
|
| 274 |
+
return "= " + " * ".join(partes)
|
| 275 |
|
| 276 |
linear = _compose_linear_expression(
|
| 277 |
params=params,
|
|
|
|
| 311 |
) -> str:
|
| 312 |
transf_y = _normalize_transform(transformacao_y)
|
| 313 |
if transf_y == "ln(x)":
|
| 314 |
+
partes: list[str] = []
|
| 315 |
+
partes.append(_format_number_calc(math.exp(_resolve_const(params))))
|
| 316 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
for coluna in colunas_x:
|
| 318 |
+
coef = _resolve_coef(params, coluna)
|
| 319 |
+
if abs(coef) < 1e-15:
|
| 320 |
+
continue
|
| 321 |
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 322 |
if transf != "ln(x)":
|
| 323 |
continue
|
| 324 |
+
partes.append(f"{var_resolver(coluna)}^{_format_number_calc(coef)}")
|
| 325 |
+
|
| 326 |
+
for coluna in colunas_x:
|
| 327 |
coef = _resolve_coef(params, coluna)
|
| 328 |
if abs(coef) < 1e-15:
|
| 329 |
continue
|
| 330 |
+
transf = _normalize_transform(transformacoes_x.get(coluna, "(x)"))
|
| 331 |
+
if transf == "ln(x)":
|
| 332 |
+
continue
|
| 333 |
+
termo = _term_expr_calc(transf, var_resolver(coluna), _MODE_EXCEL_SAB)
|
| 334 |
+
partes.append(f"{_format_number_calc(math.exp(coef))}^{termo}")
|
| 335 |
+
|
| 336 |
+
return "=" + "*".join(partes)
|
| 337 |
|
| 338 |
linear = _compose_linear_expression_calc(
|
| 339 |
params=params,
|