devops/script/dynamicLv.py
2025-01-15 11:49:26 +08:00

133 lines
4.0 KiB
Python

import pandas as pd
import math
subEmitColor = ["Wood", "Clothes storage bag"]
file_path = './script/MergeData.xlsx'
df = pd.read_excel(file_path, engine='openpyxl')
df = df.drop(index=0)
df_emitter = df[(df['Type'] == 'Emitter') & (df['Emit_Product'].notnull())]
df_emitter = df_emitter.assign(Dynamic=df_emitter['Emit_Product'])
# for index, row in df_emitter.iterrows():
# print(f"Index: {index}")
# print(row['Emit_List'])
# a1 = row['Emit_List'].split(',')
# Product = row['Emit_Product'].split(',')
# main = row['Emit_Product'].split(',')[0]
# if len(a1) == 1:
# a2 = a1[0].split('=')
# color_values = df[df["Id"] == int(a2[0])]["Color"].values[0]
# if color_values in subEmitColor:
# print(f"Main: {main} - Sub: {color_values}")
# else:
# df_emitter.loc[index, 'Dynamic'] = f"{color_values}=0"
# continue
# d = {}
# for i in Product:
# d[i] = 0.0
# for i in a1 :
# a2 = i.split('=')
# color = df[df["Id"] == int(a2[0])]["Color"].values[0]
# d[color] += float(a2[1])*(int(a2[0])%10)
# c = {}
# mainNum = d[main]
# for k, i in d.items():
# if k == main:
# c[k] = 0
# else:
# x = round(mainNum/i)
# c[k] = round(math.log(x, 2))
# print(df_emitter.head())
def getDynamicValue1(df, index):
row = df.loc[index]
d = {}
Emit_List = row['Emit_List'].split(',')
Product = row['Emit_Product'].split(',')
main = row['Emit_Product'].split(',')[0]
if len(Emit_List) == 1:
a2 = Emit_List[0].split('=')
color_values = df[df["Id"] == int(a2[0])]["Color"].values[0]
d[color_values] = 0
return d
else:
for i in Product:
d[i] = 0.0
for i in Emit_List :
a2 = i.split('=')
color = df[df["Id"] == int(a2[0])]["Color"].values[0]
d[color] += float(a2[1])*(int(a2[0])%10)
c = {}
mainNum = d[main]
for k, i in d.items():
if k == main:
c[k] = 0
else:
x = mainNum/i
c[k] = math.floor(math.log(x, 2))
return c
def getDynamicValueG(df, index):
row = df.loc[index]
d = {}
Emit_List = row['Emit_List'].split(',')
Product = row['Emit_Product'].split(',')
main = row['Emit_Product'].split(',')[0]
if len(Emit_List) == 1:
a2 = Emit_List[0].split('=')
color_values = df[df["Id"] == int(a2[0])]["Color"].values[0]
d[color_values] = 0
return d
else:
for i in Product:
d[i] = 0.0
for i in Emit_List :
a2 = i.split('=')
color = df[df["Id"] == int(a2[0])]["Color"].values[0]
if color == "Clothes storage bag":
d["Dress"] += float(a2[1])*(int(a2[0])%10)
else:
d[color] += float(a2[1])*(int(a2[0])%10)
c = {}
mainNum = d[main]
for k, i in d.items():
if k == main:
c[k] = 0
else:
x = mainNum/i
c[k] = math.floor(math.log(x, 2))
return c
def getDynamicValue3(df, id):
return df[df['Id'] == id]['Dynamic'].values[0]
for index, row in df_emitter.iterrows():
if row['Emit_ID'] == 'I':
d = getDynamicValueG(df, index)
else:
continue
# if row['Emit_ID'] == 'B':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'C':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'D':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'E':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'F':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'G':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'H':
# d = getDynamicValue1(df, index)
# if row['Emit_ID'] == 'I':
# d = getDynamicValue1(df, index)
str = ""
for i,j in d.items():
str += f"{i}={j},"
str = str[:-1]
print(str)