← กลับผลงานทั้งหมด
📊

Revenue Dashboard

DEV

วิเคราะห์รายได้วิลล่า 200+ หลังจากข้อมูลปฏิทินจอง

PythonPlaywrightFlaskDockerHTML/JS Dashboard

// ความตั้งใจ
อยากรู้ว่าวิลล่าแต่ละหลังสร้างรายได้เท่าไหร่ต่อปี แต่ข้อมูลนี้ไม่มีใน API ไหน — อยู่ใน "ปฏิทินการจอง" ของแต่ละหลังบนเว็บ pattayapartypoolvilla.com เลยสร้าง pipeline อัตโนมัติที่เข้าไป scrape ปฏิทินทีละหลัง คำนวณรายได้จากช่วงวันที่จอง และแสดงผลใน dashboard พร้อมจัดอันดับ agent ที่ทำยอดได้ดีที่สุด
// ปัญหาที่แก้

ไม่มีทางรู้ occupancy rate และรายได้จริงของแต่ละ villa โดยไม่เข้าไปดูทีละหน้า — ข้อมูลซ่อนอยู่ใน DOM

// Architecture
architecture
pattayapartypoolvilla.com
         │  (Playwright scrape calendar DOM)
         ▼
  scrape_calendar.py
         │  calendar_data.json
         ▼
  aggregate_revenue.py
         │  revenue_summary.json
         ▼
  dashboard/ (HTML + Chart.js)
    ├── index.html          ← รายได้รวม / กราฟรายปี
    ├── agent-ranking.html  ← จัดอันดับ agent
    └── commission-estimate.html

// ฟีเจอร์หลัก
01

Calendar Scraper

ใช้ Playwright เปิดหน้า villa แต่ละหลัง ดึง booked dates จาก calendar DOM โดยอัตโนมัติ รองรับ pagination และ lazy loading

02

Revenue Aggregation

คำนวณรายได้จากจำนวนคืนที่จอง × อัตราเฉลี่ยต่อคืน แยกตามปี/เดือน/หลัง

03

Agent Ranking Dashboard

จัดอันดับ agent ตามยอดจอง — ระบุว่า agent ไหน productive ที่สุดในพอร์ต

04

Commission Estimator

ประมาณการค่าคอมมิชชั่นรวมของแต่ละ agent จากข้อมูลจอง

05

Docker Deployment

รันทั้งระบบใน Docker container เดียว — scraper + dashboard serve บน port 8000

06

Demo Mode

รัน --demo flag เพื่อใช้ข้อมูลสุ่มแทนการ scrape จริง สำหรับทดสอบ dashboard


// Code
scrape_calendar.py — ดึง booked dates จาก DOMpython
async def scrape_villa_calendar(page, villa_url):
    await page.goto(villa_url, wait_until="domcontentloaded")
    await page.wait_for_selector(".calendar-month", timeout=10000)

    booked_dates = []
    months = await page.query_selector_all(".calendar-month")
    for month in months:
        days = await month.query_selector_all(".day.booked")
        for day in days:
            date_str = await day.get_attribute("data-date")
            booked_dates.append(date_str)

    return booked_dates

// Commands
demo$python3 scrape_calendar.py --demo --limit 50
scrape$python3 scrape_calendar.py --limit 200
dashboard$python3 -m http.server 8000 --directory dashboard
docker$docker compose up -d

// ผลลัพธ์

วิเคราะห์รายได้ portfolio 200+ หลังได้ภายในไม่กี่นาที — ข้อมูลที่ต้องนั่งเปิดดูทีละหน้าหลายชั่วโมง


← ผลงานทั้งหมด