class SexReport {
private array $persons;
public function __construct(array $persons) {
$this->persons = $persons;
}
public function getPersons(): array {
return $this->persons;
}
public function getPersonsBySex(Sex $sex): array {
return filterPersonsBySex($this->persons, $sex);
}
public function getSexStats(): array {
return getSexStats($this->persons);
}
public function createDetailedReport(): string {
$report = "=== ОТЧЕТ ПО ПОЛУ ===\n\n";
$stats = $this->getSexStats();
// Общая статистика
$report .= "📊 ОБЩАЯ СТАТИСТИКА:\n";
$report .= "Всего персон: {$stats['total']}\n";
$report .= "Мужчин: {$stats['male']}\n";
$report .= "Женщин: {$stats['female']}\n";
$report .= "Неизвестно: {$stats['unknown']}\n\n";
// Процентное распределение
if ($stats['total'] > 0) {
$malePercent = round(($stats['male'] / $stats['total']) * 100, 1);
$femalePercent = round(($stats['female'] / $stats['total']) * 100, 1);
$unknownPercent = round(($stats['unknown'] / $stats['total']) * 100, 1);
$report .= "📈 ПРОЦЕНТНОЕ РАСПРЕДЕЛЕНИЕ:\n";
$report .= "• Мужчины: {$malePercent}%\n";
$report .= "• Женщины: {$femalePercent}%\n";
$report .= "• Неизвестно: {$unknownPercent}%\n\n";
}
// Детали по каждому полу
$malePersons = $this->getPersonsBySex(Sex::MALE);
$femalePersons = $this->getPersonsBySex(Sex::FEMALE);
$unknownPersons = $this->getPersonsBySex(Sex::UNKNOWN);
if (!empty($malePersons)) {
$report .= "👨 МУЖЧИНЫ (" . count($malePersons) . " персон):\n";
foreach (array_slice($malePersons, 0, 10) as $person) {
$report .= "• {$person->getDisplayName()}\n";
}
if (count($malePersons) > 10) {
$report .= "... и еще " . (count($malePersons) - 10) . " человек\n";
}
$report .= "\n";
}
if (!empty($femalePersons)) {
$report .= "👩 ЖЕНЩИНЫ (" . count($femalePersons) . " персон):\n";
foreach (array_slice($femalePersons, 0, 10) as $person) {
$report .= "• {$person->getDisplayName()}\n";
}
if (count($femalePersons) > 10) {
$report .= "... и еще " . (count($femalePersons) - 10) . " человек\n";
}
$report .= "\n";
}
if (!empty($unknownPersons)) {
$report .= "❓ НЕИЗВЕСТНЫЙ ПОЛ (" . count($unknownPersons) . " персон):\n";
foreach (array_slice($unknownPersons, 0, 10) as $person) {
$report .= "• {$person->getDisplayName()}\n";
}
if (count($unknownPersons) > 10) {
$report .= "... и еще " . (count($unknownPersons) - 10) . " человек\n";
}
$report .= "\n";
}
return $report;
}
public function createHtmlReport(string $title): string {
$html = "<!DOCTYPE html>\n<html>\n<head>\n";
$html .= "<title>{$title}</title>\n";
$html .= "<style>\n";
$html .= ".report { max-width: 1200px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; }\n";
$html .= ".section { margin-bottom: 30px; }\n";
$html .= ".section-title { font-size: 20px; font-weight: bold; margin-bottom: 15px; padding: 10px; background-color: #f8f9fa; border-radius: 5px; }\n";
$html .= ".person-item { margin-bottom: 10px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }\n";
$html .= ".person-name { font-weight: bold; font-size: 16px; margin-bottom: 5px; }\n";
$html .= ".person-meta { font-size: 14px; color: #666; margin-bottom: 5px; }\n";
$html .= ".stats { background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-bottom: 20px; }\n";
$html .= ".person-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }\n";
$html .= ".male { border-left: 5px solid #007bff; }\n";
$html .= ".female { border-left: 5px solid #e83e8c; }\n";
$html .= ".unknown { border-left: 5px solid #6c757d; }\n";
$html .= ".progress-bar { width: 100%; background-color: #e9ecef; border-radius: 5px; overflow: hidden; margin: 5px 0; }\n";
$html .= ".progress-fill { height: 20px; transition: width 0.3s ease; }\n";
$html .= ".male-fill { background-color: #007bff; }\n";
$html .= ".female-fill { background-color: #e83e8c; }\n";
$html .= ".unknown-fill { background-color: #6c757d; }\n";
$html .= "</style>\n</head>\n<body>\n";
$html .= "<div class='report'>\n";
$html .= "<h1>{$title}</h1>\n";
$stats = $this->getSexStats();
$malePersons = $this->getPersonsBySex(Sex::MALE);
$femalePersons = $this->getPersonsBySex(Sex::FEMALE);
$unknownPersons = $this->getPersonsBySex(Sex::UNKNOWN);
// Статистика
$html .= "<div class='stats'>\n";
$html .= "<h2>Общая статистика</h2>\n";
$html .= "<p><strong>Всего персон:</strong> {$stats['total']}</p>\n";
$html .= "<p><strong>Мужчин:</strong> {$stats['male']}</p>\n";
$html .= "<p><strong>Женщин:</strong> {$stats['female']}</p>\n";
$html .= "<p><strong>Неизвестно:</strong> {$stats['unknown']}</p>\n";
// Прогресс-бары
if ($stats['total'] > 0) {
$malePercent = round(($stats['male'] / $stats['total']) * 100, 1);
$femalePercent = round(($stats['female'] / $stats['total']) * 100, 1);
$unknownPercent = round(($stats['unknown'] / $stats['total']) * 100, 1);
$html .= "<h3>Распределение по полу</h3>\n";
$html .= "<div class='progress-bar'>\n";
$html .= "<div class='progress-fill male-fill' style='width: {$malePercent}%'></div>\n";
$html .= "</div>\n";
$html .= "<p>Мужчины: {$malePercent}%</p>\n";
$html .= "<div class='progress-bar'>\n";
$html .= "<div class='progress-fill female-fill' style='width: {$femalePercent}%'></div>\n";
$html .= "</div>\n";
$html .= "<p>Женщины: {$femalePercent}%</p>\n";
$html .= "<div class='progress-bar'>\n";
$html .= "<div class='progress-fill unknown-fill' style='width: {$unknownPercent}%'></div>\n";
$html .= "</div>\n";
$html .= "<p>Неизвестно: {$unknownPercent}%</p>\n";
}
$html .= "</div>\n";
// Мужчины
if (!empty($malePersons)) {
$html .= "<div class='section'>\n";
$html .= "<div class='section-title'>👨 Мужчины (" . count($malePersons) . " персон)</div>\n";
$html .= "<div class='person-grid'>\n";
foreach (array_slice($malePersons, 0, 12) as $person) {
$html .= "<div class='person-item male'>\n";
$html .= "<div class='person-name'>{$person->getDisplayName()}</div>\n";
if ($person->profession) {
$html .= "<div class='person-meta'>Профессия: {$person->profession}</div>\n";
}
$html .= "</div>\n";
}
$html .= "</div>\n</div>\n";
}
// Женщины
if (!empty($femalePersons)) {
$html .= "<div class='section'>\n";
$html .= "<div class='section-title'>👩 Женщины (" . count($femalePersons) . " персон)</div>\n";
$html .= "<div class='person-grid'>\n";
foreach (array_slice($femalePersons, 0, 12) as $person) {
$html .= "<div class='person-item female'>\n";
$html .= "<div class='person-name'>{$person->getDisplayName()}</div>\n";
if ($person->profession) {
$html .= "<div class='person-meta'>Профессия: {$person->profession}</div>\n";
}
$html .= "</div>\n";
}
$html .= "</div>\n</div>\n";
}
// Неизвестный пол
if (!empty($unknownPersons)) {
$html .= "<div class='section'>\n";
$html .= "<div class='section-title'>❓ Неизвестный пол (" . count($unknownPersons) . " персон)</div>\n";
$html .= "<div class='person-grid'>\n";
foreach (array_slice($unknownPersons, 0, 12) as $person) {
$html .= "<div class='person-item unknown'>\n";
$html .= "<div class='person-name'>{$person->getDisplayName()}</div>\n";
if ($person->profession) {
$html .= "<div class='person-meta'>Профессия: {$person->profession}</div>\n";
}
$html .= "</div>\n";
}
$html .= "</div>\n</div>\n";
}
$html .= "</div>\n</body>\n</html>";
return $html;
}
}
// Использование
$persons = $personService->getPersonsByFilm(301); // ID фильма
$report = new SexReport($persons);
// Создание текстового отчета
$textReport = $report->createDetailedReport();
echo $textReport;
// Создание HTML отчета
$htmlReport = $report->createHtmlReport('Отчет по полу');
file_put_contents('sex_report.html', $htmlReport);
echo "\n✅ HTML отчет сохранен в sex_report.html\n";