Fehlerberechnung mehrerer Def in Python Dash PlotlyPython

Python-Programme
Anonymous
 Fehlerberechnung mehrerer Def in Python Dash Plotly

Post by Anonymous »

Ich habe Probleme, das korrekte Ergebnis aus der DEF „Calculed_Value_M1“ zu erhalten, die die obigen DEFs aufruft. Wie kann ich es lösen? < /p>

Code: Select all

def calc_objetivo_c(row):
temp_prod = row.get("Temp Prod", 0)
qtd = row.get("qtdPares", 0)
data = row.get("data1", None)
if pd.isna(data) or temp_prod == 0:
logging.warning(f"Missing data or Temp Prod is zero: {row}")
return 0

python_weekday = data.weekday()
dax_weekday = ((python_weekday + 1) % 7) + 1
if dax_weekday in [2, 3, 4, 5, 6]:
result = qtd / (1 - (7.5 - temp_prod) / 7.5)
elif dax_weekday == 7 and qtd != 0:
result = qtd / (1 - (5.75 - temp_prod) / 5.75)
return result
< /code>
Rufen Sie ein Def auf, um das manuelle Ziel in Excel zu lesen: < /p>
def objetivo_manual(excel_path):
try:
df_obj = pd.read_excel(excel_path, sheet_name="Objetivos")
return df_obj
except Exception as e:
logging.error(f"Failed to load Excel file: {e}")
return pd.DataFrame()

def objetivo(row, calc_objetivo_c, objetivo_manual):
obj_manual = objetivo_manual(excel_path)
if obj_manual.empty:
return calc_objetivo_c(row)
else:
logging.info(f"Using manual objetivo: {obj_manual}")
return obj_manual.iloc[0, 0]
< /code>
In diesem Teil möchte ich, wenn ich keine Daten (int) in Excel anzeigen kanndef valor_calculado_m1(row, df_ntrab, objetivo):
data_prod = row.get("data1", None)
if pd.isna(data_prod):
return 0
data_date = data_prod.date()
linha = row.get("Linha", "")
dff = df_ntrab[
(df_ntrab["Linha"] == linha) &
(df_ntrab["Data"] == data_date)
]
if dff.empty:
return 0

soma = 0
for _, trab in dff.iterrows():
n = trab["NTrab"]
if n >= 15:
soma += objetivo * n / 15
else:
soma += objetivo * n / 12
return soma
< /code>
Ein weiteres auf Seite: m1.py < /p>
    dff["valor_objetivo"] = dff.apply(
lambda row: objetivo(row, calc_objetivo_c, objetivo_manual),
axis=1
)

dff["objetivo-c"] = dff.apply(
lambda row: valor_calculado_m1(row, df_ntrab, row["valor_objetivo"]),
axis=1
)
valor_calc_m1_total = dff["objetivo-c"].sum()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post