release: Mantoz — population-scale evaluation with simulated personas
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
FROM mcr.microsoft.com/playwright/python:v1.49.1-noble
|
||||
# Образ на Ubuntu - bash уже есть (Harbor оборачивает команды в bash).
|
||||
# В образе браузеры (/ms-playwright), но нет pip-пакета - ставим ровно ту
|
||||
# версию, под которую собраны браузеры образа.
|
||||
RUN pip install --no-cache-dir playwright==1.49.1
|
||||
WORKDIR /app
|
||||
COPY stand.html run_scenario.py /app/
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Проходит сценарий выбора тарифа в настоящем браузере (Playwright/Chromium).
|
||||
|
||||
Читает план из /app/plan.json (запечён хостом из признаков персоны), исполняет
|
||||
его кликами по странице-стенду и пишет /app/result.json: след действий и
|
||||
итоговое решение, ПРОЧИТАННОЕ ИЗ DOM страницы, а не из плана.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
OPTIONS = ("base", "standart", "premium")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
plan = json.loads(Path("/app/plan.json").read_text("utf-8"))
|
||||
inspect = plan.get("inspect") or []
|
||||
choose = plan.get("choose")
|
||||
unknown = [o for o in [*inspect, choose] if o is not None and o not in OPTIONS]
|
||||
if unknown:
|
||||
print(f"неизвестные тарифы в плане: {unknown}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
actions = []
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch()
|
||||
try:
|
||||
page = browser.new_page()
|
||||
page.goto("file:///app/stand.html")
|
||||
page.wait_for_selector("h1")
|
||||
actions.append({"type": "open", "target": "stand"})
|
||||
for option_id in inspect:
|
||||
page.click(f"[data-details='{option_id}']")
|
||||
page.wait_for_selector(f"[data-panel='{option_id}'].open")
|
||||
actions.append({"type": "inspect", "target": option_id})
|
||||
decision = None
|
||||
if choose is not None:
|
||||
page.click(f"[data-choose='{choose}']")
|
||||
page.wait_for_selector("#confirmation[data-decision]")
|
||||
# Решение - из DOM страницы, не из плана: это итог браузерного
|
||||
# прогона, а не пересказ входных данных.
|
||||
decision = page.get_attribute("#confirmation", "data-decision")
|
||||
actions.append({"type": "choose", "target": decision})
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
Path("/app/result.json").write_text(
|
||||
json.dumps({"actions": actions, "decision": decision}, ensure_ascii=False)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Выбор тарифа</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; max-width: 720px; margin: 2rem auto; }
|
||||
.card { border: 1px solid #999; border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
|
||||
.panel { display: none; margin: 0.5rem 0; color: #333; }
|
||||
.panel.open { display: block; }
|
||||
#confirmation { display: none; margin-top: 1rem; font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Выберите тариф сервиса</h1>
|
||||
|
||||
<section class="card" data-card="base">
|
||||
<h2>Базовый</h2>
|
||||
<p>0 ₽ в месяц</p>
|
||||
<button type="button" data-details="base">Подробнее</button>
|
||||
<div class="panel" data-panel="base">Один проект, без поддержки, данные только на устройстве.</div>
|
||||
<button type="button" data-choose="base">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<section class="card" data-card="standart">
|
||||
<h2>Стандарт</h2>
|
||||
<p>490 ₽ в месяц</p>
|
||||
<button type="button" data-details="standart">Подробнее</button>
|
||||
<div class="panel" data-panel="standart">Десять проектов, поддержка по почте, резервные копии.</div>
|
||||
<button type="button" data-choose="standart">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<section class="card" data-card="premium">
|
||||
<h2>Премиум</h2>
|
||||
<p>1490 ₽ в месяц</p>
|
||||
<button type="button" data-details="premium">Подробнее</button>
|
||||
<div class="panel" data-panel="premium">Без ограничений, личный менеджер, приоритетная поддержка.</div>
|
||||
<button type="button" data-choose="premium">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<div id="confirmation" role="status"></div>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll("[data-details]").forEach(function (button) {
|
||||
button.addEventListener("click", function () {
|
||||
var id = button.getAttribute("data-details");
|
||||
document.querySelector('[data-panel="' + id + '"]').classList.toggle("open");
|
||||
});
|
||||
});
|
||||
document.querySelectorAll("[data-choose]").forEach(function (button) {
|
||||
button.addEventListener("click", function () {
|
||||
var id = button.getAttribute("data-choose");
|
||||
var confirmation = document.getElementById("confirmation");
|
||||
confirmation.setAttribute("data-decision", id);
|
||||
confirmation.textContent = "Выбран тариф: " + id;
|
||||
confirmation.style.display = "block";
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user