digitalization
This commit is contained in:
31
server/backend/api/excel_prices.py
Normal file
31
server/backend/api/excel_prices.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import math
|
||||
import server.backend.services.excel as excel
|
||||
from server.backend.schemas.pydantic import settings
|
||||
from functools import lru_cache
|
||||
@lru_cache(maxsize=1)
|
||||
def fetch_nomenclature(arti:int,price:int):
|
||||
xls = excel.BaseHandler(settings.PRICES_DIR)
|
||||
struct = xls.struct()
|
||||
if "ЦЕНЫ" in struct.sheet_names:
|
||||
df = xls.read(sheet_name="ЦЕНЫ").iloc[:,[arti,price]].copy()
|
||||
else:
|
||||
raise Exception(f"В файле {settings.PRICES_DIR} отсутствуют необходимые листы")
|
||||
df.dropna(inplace=True)
|
||||
df.columns = ['description', 'price']
|
||||
#df["price"] = (df["price"]+ df["price"]*0.1).apply(math.ceil)
|
||||
df['description'] = df['description'].astype(str).str.upper().str.extract(f'({settings.PATTERN})')
|
||||
df = df.drop_duplicates(subset='description')
|
||||
return df
|
||||
def processing(df):
|
||||
df2 = fetch_nomenclature(1,6)
|
||||
result = df.merge(
|
||||
df2[['description', 'price']], #берутся столбцы из df2
|
||||
left_on='arti', #столбец для сравнения в df
|
||||
right_on='description', #столбец для сравнения в df2
|
||||
how='left' #left join для df
|
||||
).drop(columns='description') #удаление временного стобца
|
||||
print(result)
|
||||
not_matched = result.loc[result['price'].isna(), 'arti'].unique()
|
||||
if len(not_matched) > 0:
|
||||
raise ValueError(f'Не найдены значения: {not_matched}')
|
||||
return result
|
||||
Reference in New Issue
Block a user