Compare commits
No commits in common. "main" and "master" have entirely different histories.
162
.gitignore
vendored
162
.gitignore
vendored
@ -1,162 +0,0 @@
|
|||||||
# ---> Python
|
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
share/python-wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# PyInstaller
|
|
||||||
# Usually these files are written by a python script from a template
|
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
||||||
*.manifest
|
|
||||||
*.spec
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.nox/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
*.py,cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
cover/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
db.sqlite3
|
|
||||||
db.sqlite3-journal
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
.pybuilder/
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# IPython
|
|
||||||
profile_default/
|
|
||||||
ipython_config.py
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
# For a library or package, you might want to ignore these files since the code is
|
|
||||||
# intended to run in multiple environments; otherwise, check them in:
|
|
||||||
# .python-version
|
|
||||||
|
|
||||||
# pipenv
|
|
||||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
||||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
||||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
||||||
# install all needed dependencies.
|
|
||||||
#Pipfile.lock
|
|
||||||
|
|
||||||
# poetry
|
|
||||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
||||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
||||||
# commonly ignored for libraries.
|
|
||||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
||||||
#poetry.lock
|
|
||||||
|
|
||||||
# pdm
|
|
||||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
||||||
#pdm.lock
|
|
||||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
||||||
# in version control.
|
|
||||||
# https://pdm.fming.dev/#use-with-ide
|
|
||||||
.pdm.toml
|
|
||||||
|
|
||||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
||||||
__pypackages__/
|
|
||||||
|
|
||||||
# Celery stuff
|
|
||||||
celerybeat-schedule
|
|
||||||
celerybeat.pid
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Environments
|
|
||||||
.env
|
|
||||||
.venv
|
|
||||||
env/
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
env.bak/
|
|
||||||
venv.bak/
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
.dmypy.json
|
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
||||||
|
|
||||||
# pytype static type analyzer
|
|
||||||
.pytype/
|
|
||||||
|
|
||||||
# Cython debug symbols
|
|
||||||
cython_debug/
|
|
||||||
|
|
||||||
# PyCharm
|
|
||||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
||||||
#.idea/
|
|
||||||
|
|
||||||
140
nime1.py
Normal file
140
nime1.py
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
# Превращаем "иванов ПЕТР" в "Иванов П. П."
|
||||||
|
def format_customer_name(full_name):
|
||||||
|
fio = full_name.split()
|
||||||
|
if not fio: return ""
|
||||||
|
surname = fio[0].capitalize()
|
||||||
|
# Собираем инициалы через цикл
|
||||||
|
initials = ""
|
||||||
|
for name in fio[1:]:
|
||||||
|
initials += f" {name[0].upper()}."
|
||||||
|
return f"{surname}{initials}"
|
||||||
|
|
||||||
|
|
||||||
|
# Считаем скидочку: электроника - 10%, остальное - 5%
|
||||||
|
def calculate_discount(total_sum, category):
|
||||||
|
if category.lower() == "electronics":
|
||||||
|
rate = 0.10
|
||||||
|
else:
|
||||||
|
rate = 0.05
|
||||||
|
return round(total_sum * rate, 2)
|
||||||
|
|
||||||
|
|
||||||
|
# Проверяем, не пустой ли склад
|
||||||
|
def validate_stock(product_id, quantity, warehouse_db):
|
||||||
|
v_nalichii = warehouse_db.get(product_id, 0)
|
||||||
|
return v_nalichii >= quantity
|
||||||
|
|
||||||
|
|
||||||
|
# Добавляем налог региона
|
||||||
|
def apply_tax(price, region_code):
|
||||||
|
taxes = {"77": 1.20, "78": 1.15} # Москва и Питер
|
||||||
|
tax_rate = taxes.get(region_code, 1.10) # Остальные - 10%
|
||||||
|
return round(price * tax_rate, 2)
|
||||||
|
|
||||||
|
|
||||||
|
# Бьем строку из файла на части
|
||||||
|
def parse_raw_order(csv_line):
|
||||||
|
d = csv_line.strip().split(';')
|
||||||
|
return {
|
||||||
|
"id": d[0], "product": d[1], "price": float(d[2]),
|
||||||
|
"qty": int(d[3]), "user_id": d[4], "customer_name": d[5],
|
||||||
|
"category": d[6], "region": d[7]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Просто фильтр по цене
|
||||||
|
def filter_by_price(orders_list, min_price):
|
||||||
|
res = []
|
||||||
|
for o in orders_list:
|
||||||
|
if o['price'] >= min_price:
|
||||||
|
res.append(o)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
# Собираем все уникальные категории в кучу
|
||||||
|
def get_unique_categories(products_list):
|
||||||
|
cats = []
|
||||||
|
for p in products_list:
|
||||||
|
cats.append(p['category'])
|
||||||
|
return set(cats)
|
||||||
|
|
||||||
|
|
||||||
|
# Считаем сколько юзер накупил за все время
|
||||||
|
def summarize_user_activity(user_id, all_orders):
|
||||||
|
u_orders = [o for o in all_orders if o['user_id'] == user_id]
|
||||||
|
total = sum(o['total_spent'] for o in u_orders)
|
||||||
|
return {"total_orders": len(u_orders), "total_spent": round(total, 2)}
|
||||||
|
|
||||||
|
|
||||||
|
# Генерим красивый номер дока
|
||||||
|
def generate_invoice_id(index, region):
|
||||||
|
return f"2024-{region}-{index:04d}"
|
||||||
|
|
||||||
|
|
||||||
|
# Просто вывод лога с временем
|
||||||
|
def log_transaction(status, message):
|
||||||
|
t = datetime.datetime.now().strftime("%H:%M:%S")
|
||||||
|
return f"[{t}] {status.upper()}: {message}"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Типа наша база данных
|
||||||
|
sklad = {"101": 50, "102": 2, "103": 100, "104": 15}
|
||||||
|
|
||||||
|
orders_list = []
|
||||||
|
|
||||||
|
# Читаем данные из файла
|
||||||
|
try:
|
||||||
|
with open('data.txt', 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Ошибка: Файл data.txt не найден!")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(log_transaction("info", "Начинаем обработку..."))
|
||||||
|
|
||||||
|
for i, line in enumerate(lines, 1):
|
||||||
|
if not line.strip(): continue # Пропуск пустых строк
|
||||||
|
|
||||||
|
# Парсим строку в словарь
|
||||||
|
order = parse_raw_order(line)
|
||||||
|
|
||||||
|
# Проверяем склад
|
||||||
|
if validate_stock(order['id'], order['qty'], sklad):
|
||||||
|
# Считаем деньги
|
||||||
|
raw_sum = order['price'] * order['qty']
|
||||||
|
discount = calculate_discount(raw_sum, order['category'])
|
||||||
|
final_sum = apply_tax(raw_sum - discount, order['region'])
|
||||||
|
|
||||||
|
# Дописываем новые данные в словарь
|
||||||
|
order['invoice'] = generate_invoice_id(i, order['region'])
|
||||||
|
order['clean_name'] = format_customer_name(order['customer_name'])
|
||||||
|
order['total_spent'] = final_sum
|
||||||
|
|
||||||
|
orders_list.append(order)
|
||||||
|
print(log_transaction("ok", f"Заказ {order['invoice']} для {order['clean_name']} готов"))
|
||||||
|
else:
|
||||||
|
print(log_transaction("error", f"Товара {order['id']} маловато на складе"))
|
||||||
|
|
||||||
|
# Выводим финальную стату
|
||||||
|
print("\n" + "=" * 30)
|
||||||
|
print("ИТОГОВЫЙ ОТЧЕТ ПО ЮЗЕРАМ:")
|
||||||
|
print("=" * 30)
|
||||||
|
|
||||||
|
unique_users = set(o['user_id'] for o in orders_list)
|
||||||
|
for u in unique_users:
|
||||||
|
stats = summarize_user_activity(u, orders_list)
|
||||||
|
# Находим имя юзера для красоты
|
||||||
|
name = next(o['clean_name'] for o in orders_list if o['user_id'] == u)
|
||||||
|
print(f"Клиент: {name:20} | Заказов: {stats['total_orders']} | Итого: {stats['total_spent']} руб.")
|
||||||
|
|
||||||
|
# Список всех категорий
|
||||||
|
all_cats = get_unique_categories(orders_list)
|
||||||
|
print("\nРаботали с категориями:", ", ".join(all_cats))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user