OTA PortalHarth Living

Lớp dữ liệu HIỆU SUẤT theo thời gian — schema + luật ghiPERFORMANCE data layer over time — schema + write rules

Some parts of this document are not translated yet — they are shown in Vietnamese.

Lớp này khác data/ ở chỗ cơ bản nhất: hình dạng dữ liệu.

This layer differs from data/ in the most basic way: the shape of the data.

data/<slug>/<kênh>.json metrics/
Trả lời câu hỏi căn này ĐANG khai gì căn này BÁN ĐƯỢC bao nhiêu, qua từng mốc
Hình dạng tài liệu trạng thái bảng sự kiện dạng dài
Khi đọc lại ghi đè chỉ thêm, không bao giờ sửa dòng cũ
Mất lịch sử? có, và không sao không bao giờ — mất lịch sử là mất luôn khả năng phân tích
data/<slug>/<channel>.json metrics/
Answers the question what this property IS declaring right now how much this property SOLD, period by period
Shape a state document a long-form event table
When re-read overwritten append only — never edit an old row
Is history lost? yes, and that is fine never — losing history means losing the ability to analyse

🔴 Luật số một: KHÔNG sửa và KHÔNG xoá dòng đã có trong fact_metrics.csv. Một phép đo sai vẫn là sự thật về điều extranet trả về hôm đó. Muốn sửa thì thêm mốc mới, hoặc thêm cột đánh dấu — đừng viết lại lịch sử.

🔴 Rule number one: do NOT edit and do NOT delete rows already in fact_metrics.csv. A wrong measurement is still the truth about what the extranet returned that day. To correct it, add a new snapshot or add a marker column — do not rewrite history.

Sáu thành phầnSix components

metrics/
├── dim_property.csv           CHIỀU  — 1 dòng mỗi (căn × kênh). Thay đổi chậm.   7 dòng
├── fact_metrics.csv           SỰ KIỆN dạng DÀI — 1 dòng = 1 phép đo.            935 dòng
├── fact_reservations.csv      SỰ KIỆN — 1 dòng = 1 ĐƠN đặt phòng.               164 dòng
├── fact_funnel.csv            SỰ KIỆN dạng RỘNG — 1 dòng = mốc × căn × KỲ.       35 dòng
├── fact_reviews.csv           SỰ KIỆN — 1 dòng = 1 REVIEW.                       14 dòng
├── fact_funnel_monthly.csv    SỰ KIỆN — phễu theo THÁNG × căn × mốc (365 ngày; tháng đang chạy month_to_date=1)  (12/10/2026)
├── fact_search_availability.csv SỰ KIỆN — availability for search theo NGÀY × căn × mốc                  (12/10/2026)
├── fact_booker_insights.csv   SỰ KIỆN — Booker insights 365 ngày theo mục đích + _total, own/peer        (12/10/2026)
├── fact_booking_advice.csv    SỰ KIỆN — gợi ý của Booking trên Ranking dashboard                         (12/10/2026)
├── booking_ranking.csv        SỰ KIỆN — 1 dòng = 1 căn × 1 lượt tìm kiếm CÔNG KHAI (thêm 26/09/2026)
├── crawl_log.csv              NHẬT KÝ — 1 dòng mỗi lần cào.                       4 dòng
└── _raw/…/                    payload gốc nén gzip + _manifest.json

Bảng nào do lượt cào nào lấp — và kiểm đủ bằng gìWhich pull fills which table — and what checks completeness

Bảng Lượt cào Kiểm đã đủ chưa
dim_property viết tay khi thêm/bớt listing số căn khớp mục A của listings.md
fact_metrics ota-metrics-crawl.py + --history ota-metrics.py check 4/4 sạch · không căn nào trống cả một nhóm
fact_reservations ota-read-booking-reservations.mjs → ota-reservations-extract.py mọi cửa sổ ✅ khớp tổng API, không còn dòng 🔴
fact_funnel ota-read-booking-funnel.mjs → ota-funnel-extract.py mỗi căn đủ 4 kỳ (30·60·90·365) = 28 dòng/mốc
fact_reviews payload của lượt ① → ota-reviews-extract.py số dòng khớp review_count trong fact_metrics; lệch thì căn đó >10 review, phải chạy ota-read-booking-reviews.mjs
booking_ranking node scripts/ota-booking-search-rank.mjs … --save (site khách, không qua extranet) mỗi lượt đủ 7 dòng; unique_ids ≈ 900–1.000 (trần Booking)
fact_funnel (từ 12/10) · fact_funnel_monthly · fact_search_availability · fact_booker_insights · fact_booking_advice vault/19-Harthliving-OTA/scripts/read-booking-analytics.mjs (chỉ bấm, qua daemon) → booking-analytics-extract.py 7/7 căn; chạy lại bộ trích +0 dòng
crawl_log script tự ghi có đúng một dòng cho mỗi lượt, kể cả lượt hỏng

🔴 Cào "xong" mà một trong sáu ô kiểm trên chưa đạt thì chưa xong. Chỗ hay hụt nhất là fact_reservations: cửa sổ hỏng thường là cửa sổ đông đơn nhất, bỏ qua là mất cả chục đơn mà không bảng nào báo.

🔴 A pull that is "finished" but where one of the six checks above has not passed is NOT finished. The most common shortfall is fact_reservations: a failed window is usually the busiest one, and skipping it loses a dozen reservations without any table reporting it.

_raw/ là bảo hiểm: bộ trích có bug thì dựng lại số từ payload gốc, không phải đi cào lại (và không cào lại được — extranet không cho xem số của quá khứ).

_raw/ is insurance: if the extractor has a bug, the numbers can be rebuilt from the original payload, without going back to scrape (and scraping again is not possible — the extranet does not show past figures).

Tên file trong _raw/ và cách soát độ phủFile names in _raw/ and how to check coverage

<slug>__<trang>__<file mạng>.gz, <trang> là một trong reviews · sales · showrank. Nhìn tên là biết payload của căn nào, trang nào — không phải giải nén ra mới biết.

<slug>__<trang>__<network file>.gz, where <trang> is one of reviews · sales · showrank. The name tells you which property and which page the payload belongs to — you do not have to decompress it to know.

⚠️ File tên dạng NN-admin.booking.com_hotel_hoteladmin_extranet__… là của lược đồ cũ (trước 23/09/2026). Lược đồ đó cắt tên thư mục ở 46 ký tự nên mất cả hotel_id lẫn tên trang, và chạy bù trong cùng ngày thì ghi đè lên nhau. Đừng dùng lại.

⚠️ Files named NN-admin.booking.com_hotel_hoteladmin_extranet__… belong to the old schema (before 23/09/2026). That schema cut folder names at 46 characters, so it lost both hotel_id and the page name, and running a catch-up on the same day overwrote the files. Do not reuse it.

_manifest.json có ba khối đọc được ngay, không cần mở file .gz nào:

_manifest.json has three blocks that can be read straight away, without opening any .gz file:

Khoá Nghĩa
coverage mỗi slug đã có payload của những nhóm nào (sales · rank · reviews)
missing nhóm nào còn thiếu — đây là chỗ đọc để biết lần cào có hụt hay không
files[].alias payload trùng byte chỉ ghi một lần; các chỗ dùng lại nằm ở đây, nên coverage vẫn đúng
Key Meaning
coverage which groups each slug has payloads for (sales · rank · reviews)
missing which groups are still missing — read this to find out whether a pull fell short
files[].alias byte-identical payloads are written only once; the places that reuse them are recorded here, so coverage stays correct

Cào bù trong cùng ngày thì manifest được gộp, không ghi đè — mất mục lục là mất luôn khả năng biết payload nào đã có.

When a catch-up pull is made on the same day, the manifest is merged, not overwritten — losing the index means losing the ability to know which payloads already exist.

🔴 Payload trả về rỗng vẫn phải giữ. salesInsightsTotal với data: [], hoặc với propertyValue: -1, là bằng chứng đã hỏi và extranet trả về không có gì — đó là thứ duy nhất phân biệt 0 thật với cào hụt.

🔴 Empty payloads must still be kept. salesInsightsTotal with data: [], or with propertyValue: -1, is evidence that the question was asked and the extranet returned nothing — that is the only thing that distinguishes a true 0 from a failed scrape.

-1 của Booking nghĩa là "không có dữ liệu", không phải "bằng 0"Booking's -1 means "no data", not "equal to 0"

salesInsightsTotal trả roomNights · totalTransactionValue · averageDailyRate cùng bằng -1 (kể cả benchmarkValue) khi căn không có đêm ở nào trong cửa sổ 12 tháng; kèm theo salesInsightsBreakdown.rooms: []. Bộ trích bỏ qua giá trị âm — ghi -1 vào bảng là bịa số, mà ghi 0 cũng là bịa vì extranet không nói thế.

salesInsightsTotal returns roomNights · totalTransactionValue · averageDailyRate all as -1 (including benchmarkValue) when the property has no room nights in the 12-month window, together with salesInsightsBreakdown.rooms: []. The extractor skips negative values — writing -1 into the table would be making up numbers, and writing 0 would also be making up numbers, because the extranet does not say that.

⇒ Căn trống cả khối 12m không mặc nhiên là cào hụt. Mở _raw/<slug>__sales__*.gz: thấy -1 hoặc data: [] là đã hỏi rồi; không có file mới là chưa hỏi được. Đã xác minh trên alacarte404, 23/09/2026 (đối chứng alacarte305: 174 đêm / 336.132.266 ₫).

⇒ A property with an empty 12m block is not automatically a failed scrape. Open _raw/<slug>__sales__*.gz: if you see -1 or data: [], the question was asked; if there is no new file, the question could not be asked. Verified on alacarte404, 23/09/2026 (control alacarte305: 174 nights / 336,132,266 ₫).

Lược đồ fact_metrics.csvfact_metrics.csv schema

Cột Nghĩa
snapshot_date ngày cào, không phải ngày của số liệu
channel · slug · external_id khoá nối sang dim_property.csv
metric tên chỉ số, snake_case
value · unit giá trị + đơn vị (VND · count · ratio · score_10 · position · nights)
peer_value số đối chuẩn Booking trả kèm, để so với nhóm tương đương
period_start · period_end khoảng mà con số này đo
window nhãn cửa sổ: 12m · 90d · lifetime
basis cách tính: stay_date · report_window · cumulative
source_page · source_field truy ngược tới đúng trang và đúng trường JSON
Column Meaning
snapshot_date the pull date, not the date of the figure
channel · slug · external_id join key to dim_property.csv
metric metric name, snake_case
value · unit value + unit (VND · count · ratio · score_10 · position · nights)
peer_value the Booking benchmark figure returned alongside, for comparison with the equivalent group
period_start · period_end the span this figure measures
window window label: 12m · 90d · lifetime
basis how it is calculated: stay_date · report_window · cumulative
source_page · source_field trace back to the exact page and the exact JSON field

Khoá tự nhiên: (snapshot_date, channel, slug, metric, period_start, period_end). Nạp lại cùng khoá thì thay giá trị, không đẻ dòng trùng — ota-metrics.py append lo việc đó.

Natural key: (snapshot_date, channel, slug, metric, period_start, period_end). Loading again with the same key replaces the value rather than creating a duplicate row — ota-metrics.py append takes care of that.

🔴 Bẫy chết người: mỗi chỉ số có CỬA SỔ ĐO RIÊNG🔴 Deadly trap: each metric has its OWN MEASUREMENT WINDOW

Nhóm chỉ số Cửa sổ Tính theo
revenue · room_nights · adr 12 tháng ngày Ở, chỉ gồm khách đã ở xong
search_impressions · page_views · ctr · conversion · bookings · rank_in_city · property_page_score 90 ngày cửa sổ báo cáo của Ranking Dashboard
review_count · review_score trọn đời luỹ kế
Metric group Window Calculated by
revenue · room_nights · adr 12 months the stay date, counting only guests who have already checked out
search_impressions · page_views · ctr · conversion · bookings · rank_in_city · property_page_score 90 days the Ranking Dashboard's reporting window
review_count · review_score lifetime cumulative

⇒ Chia revenue (12 tháng) cho bookings (90 ngày) là ra một con số vô nghĩa. Analyst phải WHERE window = '12m' trước khi so sánh hay cộng. Cột window tồn tại chính vì lý do đó.

⇒ Dividing revenue (12 months) by bookings (90 days) gives a meaningless number. The analyst must WHERE window = '12m' before comparing or summing. The window column exists for exactly that reason.

Lịch sử TỪ KHI MỞ LISTING — window = 1m và alltimeHistory FROM THE LISTING OPEN DATE — window = 1m and alltime

Cửa sổ 12 tháng ở trên là mặc định của trang, không phải giới hạn của dữ liệu. Trang doanh thu đọc khoảng ngày từ query string, nên nới bằng URL chứ không phải bấm date-picker (ô đó không nhận chữ gõ vào):

The 12-month window above is the page's default, not a limit of the data. The revenue page reads the date range from the query string, so widen it through the URL rather than the date picker (that box does not accept typed text):

statistics/sales_insights.html?hotel_id=<id>&fromDate=2015-01-01&untilDate=<hôm nay>
   &granularity=MONTHLY&reservationType=STAYED&showTotals=true
statistics/sales_insights.html?hotel_id=<id>&fromDate=2015-01-01&untilDate=<today>
   &granularity=MONTHLY&reservationType=STAYED&showTotals=true

Đặt fromDate sớm hơn mọi listing là được — Booking không báo lỗi, chỉ cắt về mốc sớm nhất nó phục vụ. Payload salesInsightsGranular trả một điểm mỗi tháng, salesInsightsTotal trả tổng của đúng khoảng đã xin.

Set fromDate earlier than every listing and that is enough — Booking reports no error; it just cuts it back to the earliest point it serves. The salesInsightsGranular payload returns one point per month, while salesInsightsTotal returns the total for the exact range requested.

⚠️ Mốc sàn là của TÀI KHOẢN, không phải của từng listing. Xin fromDate=2015-01-01 thì cả bảy căn đều trả chuỗi bắt đầu 2023-06 (40 tháng tính tới 09/2026) — giống hệt nhau, nên đó không thể là ngày mở của từng căn. Chưa xác minh được 2023-06 là giới hạn lưu trữ của Booking hay ngày mở tài khoản đối tác. Các tháng trước lần ở đầu tiên của mỗi căn được đệm bằng 0, không phải khuyết.

⚠️ The floor is set per ACCOUNT, not per listing. Requesting fromDate=2015-01-01 makes all seven properties return a series starting at 2023-06 (40 months up to 09/2026) — identical for all of them, so it cannot be the open date of each property. It has not been verified whether 2023-06 is Booking's storage limit or the date the partner account was opened. Months before each property's first point are padded with 0, not left missing.

⇒ Với danh mục hiện tại chuyện này vô hại: lần ở sớm nhất của mọi căn đều sau 2023-06, nên chuỗi đã phủ trọn lịch sử. Nhưng đừng đọc tháng đầu chuỗi thành "ngày mở listing" — muốn biết ngày mở thì tra chỗ khác.

⇒ For the current portfolio this is harmless: the earliest point of every property is after 2023-06, so the series already covers the whole history. But do not read the first month of the series as the "listing open date" — to know the open date, check somewhere else.

window Một dòng là period_start · period_end
1m một tháng doanh thu / đêm phòng / ADR mốc đầu và cuối của tháng đó
alltime tổng từ khi mở listing tới ngày cào fromDate đã xin · ngày cào
12m ảnh chụp 12 tháng gần nhất, giữ cho liên tục với các mốc cũ 01 của tháng năm ngoái · ngày cào
window One row is period_start · period_end
1m one month of revenue / room nights / ADR the first and last day of that month
alltime total from listing open up to the pull date fromDate requested · pull date
12m snapshot of the last 12 months, kept consistent with earlier pulls 01 of the same month last year · pull date
python3 scripts/ota-metrics-crawl.py --history            # cả 7 căn, từ khi mở
python3 scripts/ota-metrics-crawl.py --history --from 2019-01-01 --only alacarte305
python3 scripts/ota-metrics-crawl.py --history            # all 7 properties, since opening
python3 scripts/ota-metrics-crawl.py --history --from 2019-01-01 --only alacarte305

🔴 1m là chuỗi thật, 12m/alltime là số đã cộng sẵn — đừng trộn. Cộng 1m lại sẽ ra đúng alltime của cùng khoảng; cộng 1m với 12m là tính hai lần. Chuỗi 1m không đổi về quá khứ, nên nó cũng là thứ cho phép đọc xu hướng ngay từ mốc cào đầu tiên, không phải chờ đủ ba tuần.

🔴 1m is a true series; 12m and alltime are pre-summed figures — do not mix them. Adding up 1m gives exactly the alltime of the same range; adding 1m together with 12m counts twice. The 1m series never changes for the past, so it is also what makes it possible to read the trend from the very first pull, without waiting for three weeks of data.

fact_reviews.csv — từng review mộtfact_reviews.csv — one row per review

fact_metrics.csv chỉ giữ hai con số về review (review_count, review_score). Payload gốc có nhiều hơn thế, nên có bảng riêng: ngày ở, sáu điểm thành phần, nhận xét tốt/xấu, quốc tịch, ngôn ngữ, đã trả lời hay chưa.

fact_metrics.csv keeps only two figures about reviews (review_count, review_score). The raw payload holds more than that, so there is a separate table for it: stay date, the six category scores, positive/negative comments, nationality, language, and whether a reply has been posted.

python3 scripts/ota-reviews-extract.py          # dựng lại từ payload ĐÃ CÓ trong _raw/, không cần mạng
node scripts/ota-read-booking-reviews.mjs --out <dir>   # tải mới, rows=500 nên không sót trang sau
python3 scripts/ota-reviews-extract.py          # rebuild from payloads ALREADY in _raw/, no network needed
node scripts/ota-read-booking-reviews.mjs --out <dir>   # download fresh, rows=500 so no later pages are missed

🔴 Điểm thành phần 0 nghĩa là KHÔNG ĐÁNH GIÁ, không phải điểm không. Thang chạy 2,5–10 theo nửa điểm; khách không tiếp xúc hạng mục nào thì ô đó về 0 (vd nhận phòng tự động → không chấm staff). Bảng giữ nguyên 0 vì đó là thứ payload trả về — mọi phép trung bình phải WHERE <cột> > 0, nếu không một ô trống kéo tụt cả danh mục. Đo 23/09/2026: gộp cả ô 0 thì staff ra 9,11 và đội sổ; loại ra thì 9,81 và đứng thứ hai từ trên.

🔴 A component score of 0 means NOT RATED, not zero. The scale runs from 2.5–10 in half-point steps; a guest who had no contact with a category leaves that cell at 0 (e.g. self check-in → staff is not scored). The table keeps the 0 because that is what the payload returns — every average must use WHERE <column> > 0, otherwise one empty cell drags down the whole portfolio. Measured on 23/09/2026: including the 0 cells, staff comes out at 9.11 and at the bottom; excluding them, it is 9.81 and second from the top.

⚠️ Trang reviews.html chỉ nạp 10 review đầu. Căn nào nhiều hơn là bộ cào theo trang mất phần đuôi (alacarte305: pageCount 2, lấy 10/12). Dùng script .mjs ở trên — nó xin thẳng rows=500 qua review/fetch_reviews.json, và phải có &ses=<token> lấy từ tab extranet đang mở, thiếu là Booking đá sang trang đăng nhập dù Chrome vẫn đăng nhập.

⚠️ The reviews.html page only loads the first 10 reviews. For any property with more, the page-based crawler loses the tail (alacarte305: pageCount 2, gets 10 of 12). Use the .mjs script above — it requests rows=500 directly through review/fetch_reviews.json, and it must include &ses=<token> taken from the open extranet tab; without it, Booking redirects to the sign-in page even though Chrome is still signed in.

Không lưu tên khách và số đặt phòng: lớp này để phân tích, không để liên hệ.

Guest names and booking numbers are not stored: this layer is for analysis, not for contacting guests.

Reservation — fact_reservations.csv

Doanh thu và đêm phòng ở trên là số đã cộng. Muốn biết có bao nhiêu ĐƠN, đặt vào lúc nào, ở mấy đêm, huỷ hay không thì phải xuống tầng đơn lẻ, và tầng đó nằm ở trang Reservations.

The revenue and room nights above are summed figures. To know how many RESERVATIONS, booked when, for how many nights, cancelled or not, you have to go down to the individual-reservation level, and that level sits on the Reservations page.

node scripts/ota-read-booking-reservations.mjs          # cào, tự chia cửa sổ theo quý
python3 scripts/ota-reservations-extract.py             # nạp vào fact_reservations.csv
node scripts/ota-read-booking-reservations.mjs          # crawl, splitting the window by quarter automatically
python3 scripts/ota-reservations-extract.py             # load into fact_reservations.csv

✅ Trang GROUP không có hai trần đó — lấy TRỌN lịch sử (đo 26/09/2026)✅ The GROUP page does not have those two caps — pulls the FULL history (measured 26/09/2026)

admin.booking.com/hotel/hoteladmin/groups/reservations/index.html (menu nhóm → Reservations) trả mọi property một lần, không ép 1 năm, không giới hạn 3 tháng: dải nhận phòng 2010–2030 ra 189 đơn = dải 2023–2027; 2010–2022 ra 0; theo ngày đặt / ngày trả cũng 189 ⇒ đó là toàn bộ (đơn sớm nhất đặt 25/12/2024, nhận phòng sớm nhất 09/01/2025). Kiểm chéo: 165/165 đơn của lượt cào theo property có mặt, trang group thêm 24 đơn (23 đơn nhận phòng 2025 mà trang property cắt mất). Nút Download của trang (tạo file sau ~3 phút "Retrieving file") ra Reservations_<from>_<to>.xls khớp 189/189 mã.

admin.booking.com/hotel/hoteladmin/groups/reservations/index.html (group menu → Reservations) returns every property in one go, with no 1-year limit and no 3-month cap: the check-in range 2010–2030 returns 189 reservations = the same as the 2023–2027 range; 2010–2022 returns 0; by booking date or by check-out date it is also 189 ⇒ that is the full set (the earliest reservation was booked on 25/12/2024, the earliest check-in on 09/01/2025). Cross-check: 165/165 reservations from the per-property pull are present, and the group page adds 24 more (23 reservations with check-in in 2025 that the property page cut off). The page's Download button (the file is produced after about 3 minutes of "Retrieving file") gives Reservations_<from>_<to>.xls, matching 189/189 codes.

  • Cào: node scripts/ota-read-booking-group-reservations.mjs [--from 2023-01-01 --to 2027-12-31] → JSON có tên khách ở _private/reservations/<ngày>/ (đã .gitignore, không commit). GraphQL searchReservations, 🔴 pagination.offset là SỐ TRANG (0,1,2…) chứ không phải số dòng; rowsPerPage 30 (200 → lỗi 500).
  • Nạp fact_reservations bằng gộp theo khoá (channel, slug, reservation_id) như ota-reservations-extract.py (đơn đã có thì THAY, giữ lại rooms/is_last_minute cũ khi nguồn group để trống) — ⚠️ 26/09 lần đầu lỡ nối thẳng thành 354 dòng trùng, đã gộp lại 27/09 còn 189 dòng = 189 đơn. Mốc 2026-09-26 là bản trọn đời 189 đơn từ nguồn group (source_file = groups/reservations …); cột rooms và is_last_minute để trống (nguồn không có); đơn không ok ghi price_vnd = 0 như quy ước cũ (giá gốc đơn huỷ còn trong bản _private). Bản CSV không tên khách: _raw/reservations-group/2026-09-26/booking-reservations-all.csv.
  • ⇒ Lượt reservation của /ota-metrics-crawl nên dùng script group; script property chỉ còn cần khi muốn cột rooms.
  • Crawl: node scripts/ota-read-booking-group-reservations.mjs [--from 2023-01-01 --to 2027-12-31] → JSON with guest names in _private/reservations/<date>/ (gitignored, not committed). GraphQL searchReservations; 🔴 pagination.offset is the PAGE NUMBER (0,1,2…), not the row count; rowsPerPage 30 (200 → error 500).
  • Load fact_reservations by merging on the key (channel, slug, reservation_id), as ota-reservations-extract.py does (an existing reservation is REPLACED, keeping the old rooms / is_last_minute when the group source leaves them blank) — ⚠️ on 26/09 the first attempt joined the rows directly and produced 354 duplicate rows; it was merged again on 27/09 down to 189 rows = 189 reservations. The 2026-09-26 mark is the lifetime version with 189 reservations from the group source (source_file = groups/reservations …); the rooms and is_last_minute columns are blank (the source has none); reservations not ok are recorded as price_vnd = 0 per the old convention (the original price of the cancelled reservation is still in the _private version). The CSV without guest names: _raw/reservations-group/2026-09-26/booking-reservations-all.csv.
  • ⇒ The reservation pass of /ota-metrics-crawl should use the group script; the property script is only needed when the rooms column is wanted.

🔴 Hai trần của Booking — đo 23/09/2026, không phải giới hạn của công cụ🔴 Two Booking caps — measured 23/09/2026, not limits of the tool

Trần Biểu hiện
Lùi tối đa 1 năm date_from sớm hơn hôm nay − 1 năm bị ép về đúng mốc đó, không báo lỗi. Xin 2023-06-01 · 2024-01-01 · 2025-01-01 đều thành 2025-09-23. Khoảng nằm hẳn trong quá khứ (2025-01-01→2025-06-30) bị bóp về một ngày. Ép như nhau cho arrival · book · departure.
Mỗi lần hỏi tối đa ~3 tháng Dải 3 tháng trả success: 1. Dải 6 tháng và 12 tháng thì trang hỏng hẳn, không gọi nổi endpoint. Script tự chia cửa sổ quý.
Limit Behaviour
Looks back at most 1 year a date_from earlier than today − 1 year is forced to exactly that point, with no error. Requests for 2023-06-01 · 2024-01-01 · 2025-01-01 all become 2025-09-23. A range lying entirely in the past (2025-01-01→2025-06-30) is squeezed to one day. The same forcing applies to arrival · book · departure.
At most ~3 months per query A 3-month range returns success: 1. 6-month and 12-month ranges break the page completely, and the endpoint cannot be called. The script splits the window by quarter automatically.

⇒ Đơn nhận phòng trước hôm nay − 1 năm là không lấy được. Doanh thu và đêm phòng của giai đoạn đó thì vẫn có (window = 1m, lùi tới 2023-06) — nên số đêm có lịch sử dài hơn số đơn, và hai đường trên cùng một biểu đồ sẽ bắt đầu ở hai thời điểm khác nhau. Nói rõ điều đó trên biểu đồ, đừng để người đọc tưởng trước đó không có đơn nào.

⇒ Reservations checking in before today − 1 year cannot be retrieved. Revenue and room nights for that period are still available (window = 1m, going back to 2023-06) — so the nights series has a longer history than the reservations series, and the two lines on one chart will start at two different points. State that clearly on the chart, so the reader does not think there were no reservations before then.

Ba thứ tưởng làm được mà khôngThree things thought achievable that were not

  • page và perpage trên URL bị bỏ qua — trang luôn gọi page=1&perpage=100.
  • token của endpoint là nonce dùng một lần; phát lại đúng URL đó trả success: 0, nên không tự phân trang bằng fetch được.
  • Chặn fetch/XHR trong trang cũng không bắt được gì (calls:1 mà n:0) — request đi từ realm khác. Đường chạy được là để chrome-grab.mjs bắt ở tầng mạng.
  • page and perpage on the URL are ignored — the page always calls page=1&perpage=100.
  • The endpoint's token is a single-use nonce; replaying that same URL returns success: 0, so pagination cannot be done with fetch alone.
  • Blocking fetch/XHR inside the page also captures nothing (calls:1 but n:0) — the request leaves from another realm. The working path is to let chrome-grab.mjs catch it at the network layer.

Phép kiểm đủCompleteness check

Mỗi cửa sổ tự đối chiếu: cộng price.amount của các đơn nhận được, so với totalPrice mà API trả cho toàn bộ tập lọc. Khớp thì cửa sổ đó chắc chắn không sót trang — mạnh hơn nhiều so với tin vào cờ hasNextPage, vì cờ đó từng trả '' cho cả trang đầy. Cờ complete trong file kết quả là AND của mọi cửa sổ.

Each window checks itself: it adds up price.amount of the reservations received and compares it with the totalPrice the API returns for the whole filter set. If it matches, that window is certainly not missing any page — much stronger than trusting the hasNextPage flag, because that flag once returned '' even for a full page. The complete flag in the result file is the AND of all windows.

fact_funnel.csv — phễu theo KỲfact_funnel.csv — funnel by PERIOD

Cùng dữ liệu phễu với fact_metrics nhưng ở dạng rộng (một dòng đọc thẳng được) và có thêm chiều kỳ: Ranking Dashboard cho chọn 30 · 60 · 90 · 365 ngày, mỗi kỳ một dòng.

The same funnel data as fact_metrics, but in a wide form (one row reads directly) and with an extra period dimension: the Ranking Dashboard allows choosing 30 · 60 · 90 · 365 days, one row for each period.

node scripts/ota-read-booking-funnel.mjs     # đổi bộ chọn kỳ, bắt response, lưu payload thô
python3 scripts/ota-funnel-extract.py        # nạp vào bảng
node scripts/ota-read-booking-funnel.mjs     # change the period selector, capture the response, save the raw payload
python3 scripts/ota-funnel-extract.py        # load into the table
Cột Nghĩa
period_days · period_label kỳ Booking đo; (dò ngược) là dòng suy ra trước khi biết có bộ chọn kỳ
window_start · window_end · lag_days chỉ có ở dòng dò ngược — dashboard có độ trễ ~7–11 ngày
window_method declared-by-booking · derived-exact · derived-approx · unknown
window_ambiguity_days biên xê dịch được bao nhiêu ngày mà vẫn khớp; 0 là chắc
<chỉ số> + <chỉ số>_peer số của mình và của comp set, cùng thang
rank_total tổng số chỗ nghỉ ở thành phố — mẫu số của hạng, KHÔNG phải mức đối chuẩn
Column Meaning
period_days · period_label the Booking period measured; (back-calculated) marks a row inferred before the period selector was known
window_start · window_end · lag_days only in the inferred rows — the dashboard has a lag of ~7–11 days
window_method declared-by-booking · derived-exact · derived-approx · unknown
window_ambiguity_days how many days the boundary can shift and still match; 0 is certain
<metric> + <metric>_peer our figure and the comp set's figure, on the same scale
rank_total total number of properties in the city — the denominator of the rank, NOT a benchmark level

🔴 Các kỳ CHỒNG lên nhau. Kỳ 90 ngày đã bao trùm kỳ 30 ngày — trừ kỳ này cho kỳ kia rồi đọc thành "hai tháng trước" là sai, vì không biết phần chênh rơi vào ngày nào.

🔴 The periods OVERLAP. The 90-day period already covers the 30-day period — subtracting one from the other and reading the result as "two months ago" is wrong, because you cannot tell which days the difference falls on.

🔴 bookings đếm đơn ĐƯỢC ĐẶT trong kỳ, GỒM CẢ đơn sau này huỷ. Nên conversion ở đây là chuyển đổi sang lượt đặt, không phải sang đêm ở. Với tỷ lệ huỷ 53% của danh mục, hai thứ đó cách nhau rất xa — muốn con số thật thì nối sang fact_reservations qua (slug, booked_at) và lọc status = 'ok'.

🔴 bookings counts reservations MADE in the period, INCLUDING those later cancelled. So the conversion here is conversion to bookings made, not to nights stayed. With the portfolio's 53% cancellation rate, the two are very far apart — for the real figure, join to fact_reservations on (slug, booked_at) and filter status = 'ok'.

⚠️ 365 ngày là trần. Xa hơn Booking không phục vụ. Muốn chuỗi thời gian thật của phễu thì phải tự tích luỹ qua từng mốc cào hằng tuần — khác hẳn doanh thu, vốn có sẵn chuỗi tháng lùi tới 2023-06.

⚠️ 365 days is the cap. Going further back is not served by Booking. To get a real time series for the funnel, you must accumulate it yourself across weekly pulls — unlike revenue, which already has a monthly series going back to 2023-06.

booking_ranking.csv — thứ hạng trên trang tìm kiếm CÔNG KHAI booking.com (thêm 26/09/2026)booking_ranking.csv — ranking on the PUBLIC booking.com search page (added 26/09/2026)

Bản đôi của ../metrics-agoda/agoda_ranking.csv (tên do user đặt theo cặp). Nguồn: scripts/ota-booking-search-rank.mjs — mở browser context sạch (không đăng nhập, không lịch sử), bắt GraphQL FullSearch rồi phát lại theo offset; căn nào không lọt vào danh sách thì hỏi riêng (destType: HOTEL) để biết còn phòng không. Chỉ thêm, không sửa. Đây là thứ hạng cho đúng một tìm kiếm; hạng thành phố chính thức 90 ngày (competitiveSetLeaderboard, vd 305 #1.039/3.241) nằm ở Ranking Dashboard extranet — số khác bản chất, đừng trộn.

The twin of ../metrics-agoda/agoda_ranking.csv (the name was set by the user to match the pair). Source: scripts/ota-booking-search-rank.mjs — opens a clean browser context (not logged in, no history), captures the GraphQL FullSearch, then replays it by offset; a property that does not make the list is asked for separately (destType: HOTEL) to find out whether rooms are still available. Append only, never edited. This is the rank for one search only; the official city rank over 90 days (competitiveSetLeaderboard, e.g. 305 #1,039/3,241) sits in the extranet Ranking Dashboard — the numbers differ in nature, so do not mix them.

Cột Nghĩa
search_id · pass_no mã tìm kiếm (A–D, trùng bộ lọc với agoda_ranking ngày 26/09) · lượt đo
dest_id · checkin · checkout · nights · adults · rooms bộ lọc; Đà Nẵng = -3712125
sort · personalization default_top_picks (sắp xếp mặc định Our top picks) · clean_context
total_reported · rows_scanned · unique_ids nbResultsTotal · số dòng đã duyệt · số id khác nhau = trần xem được (~900–1.000)
rank · page_approx · pct_from_top vị trí đầu tiên gặp · trang (25 thẻ/trang) · % tính từ đầu
status ranked · sold_out (Booking báo hết phòng/không vừa bộ lọc) · beyond_cap (còn phòng nhưng không nằm trong ~1.000 dòng xem được) · not_found
price_per_stay_vnd giá trọn kỳ khách thấy trong ô hỏi riêng (chỉ có khi còn phòng)
Column Meaning
search_id · pass_no search ID (A–D, same filters as agoda_ranking on 26/09) · measurement pass
dest_id · checkin · checkout · nights · adults · rooms filters; Da Nang = -3712125
sort · personalization default_top_picks (default sort Our top picks) · clean_context
total_reported · rows_scanned · unique_ids nbResultsTotal · rows scanned · distinct IDs = the visible cap (~900–1,000)
rank · page_approx · pct_from_top first position found · page (25 cards per page) · % counted from the top
status ranked · sold_out (Booking reports no rooms / does not fit the filters) · beyond_cap (rooms available but not within the ~1,000 rows visible) · not_found
price_per_stay_vnd price for the whole stay the guest sees in the separate query box (only when rooms are available)

🔴 Ba bẫy đã đo: (1) tài khoản đăng nhập bị cá nhân hoá — 25AT11 #1 / 41LHC #5 khi đăng nhập, #122–136 / #104 ở context sạch; (2) &offset= trên URL bị bỏ qua, phải đi qua FullSearch; (3) sau ~1.000 kết quả Booking chỉ trả dòng lặp, nên căn chìm sâu hơn mốc đó không đo được thứ hạng, chỉ biết là beyond_cap.

🔴 Three traps measured: (1) the logged-in account is personalised — 25AT11 #1 / 41LHC #5 when signed in, #122–136 / #104 in a clean context; (2) &offset= on the URL is ignored, so you must go through FullSearch; (3) after about 1,000 results Booking returns only repeated rows, so a property buried deeper than that mark cannot have its rank measured; it can only be recorded as beyond_cap.

DùngUsage

python3 scripts/ota-metrics.py log              # nhật ký các lần cào
python3 scripts/ota-metrics.py table            # bảng rộng của mốc mới nhất
python3 scripts/ota-metrics.py trend revenue    # xu hướng một chỉ số, có % thay đổi giữa các mốc
python3 scripts/ota-metrics.py check            # soát: slug lạ · dòng trùng · thiếu cửa sổ · thiếu giá trị
python3 scripts/ota-metrics.py append rows.json # nạp thêm, idempotent
python3 scripts/ota-metrics.py log              # log of the crawls
python3 scripts/ota-metrics.py table            # wide table of the latest snapshot
python3 scripts/ota-metrics.py trend revenue    # trend of one metric, with % change between snapshots
python3 scripts/ota-metrics.py check            # audit: unknown slug · duplicate rows · missing window · missing value
python3 scripts/ota-metrics.py append rows.json # load more, idempotent

Analyst mở thẳng bằng pandas hoặc DuckDB, không cần tool của repo:

Analysts can open it directly with pandas or DuckDB, with no need for the repo's tools:

import pandas as pd
f = pd.read_csv('vault/19-Harthliving-OTA/performance/metrics/fact_metrics.csv')
d = pd.read_csv('vault/19-Harthliving-OTA/performance/metrics/dim_property.csv')
df = f.merge(d, on=['slug','channel'])

# xu hướng doanh thu theo căn
(df[df.metric=='revenue']
   .pivot_table(index='snapshot_date', columns='name', values='value'))

# phễu 90 ngày — LỌC CỬA SỔ TRƯỚC
(df[(df.window=='90d') & df.metric.isin(['search_impressions','page_views','bookings'])]
   .pivot_table(index='name', columns='metric', values='value'))
import pandas as pd
f = pd.read_csv('vault/19-Harthliving-OTA/performance/metrics/fact_metrics.csv')
d = pd.read_csv('vault/19-Harthliving-OTA/performance/metrics/dim_property.csv')
df = f.merge(d, on=['slug','channel'])

# revenue trend by property
(df[df.metric=='revenue']
   .pivot_table(index='snapshot_date', columns='name', values='value'))

# 90-day funnel — FILTER THE WINDOW FIRST
(df[(df.window=='90d') & df.metric.isin(['search_impressions','page_views','bookings'])]
   .pivot_table(index='name', columns='metric', values='value'))
-- DuckDB đọc thẳng CSV, không cần nạp
SELECT slug, metric, value FROM 'fact_metrics.csv'
WHERE window = '12m' AND snapshot_date = (SELECT max(snapshot_date) FROM 'fact_metrics.csv');
-- DuckDB reads the CSV directly, no loading needed
SELECT slug, metric, value FROM 'fact_metrics.csv'
WHERE window = '12m' AND snapshot_date = (SELECT max(snapshot_date) FROM 'fact_metrics.csv');

Vì sao CSV chứ không phải databaseWhy CSV rather than a database

7 listing × ~12 chỉ số × cào hằng tuần ≈ 4.400 dòng/năm. Ở cỡ này CSV thắng tuyệt đối: đọc được bằng mắt, diff được trong git (thấy ngay số nào đổi giữa hai lần cào), mở bằng pandas / DuckDB / Excel, không cần server, không cần migration. Dựng warehouse cho vài nghìn dòng là tự tạo việc bảo trì mà không đổi lại được gì.

7 listings × ~12 metrics × weekly pulls ≈ 4,400 rows per year. At this size CSV wins outright: it can be read by eye, diffed in git (you see straight away which figure changed between two pulls), opened with pandas / DuckDB / Excel, and needs no server and no migration. Building a warehouse for a few thousand rows creates maintenance work and gives nothing back.

Ngưỡng nên đổi: khi vượt ~1 triệu dòng, hoặc khi cần nhiều người ghi đồng thời. Lúc đó chuyển sang Parquet + DuckDB là bước kế tiếp tự nhiên — lược đồ dạng dài này giữ nguyên, không phải viết lại.

The threshold to change: when it passes about 1 million rows, or when several people need to write at the same time. At that point, moving to Parquet + DuckDB is the natural next step — this long-form schema stays the same, with no need to rewrite it.

Nhịp cào đề xuấtProposed crawl rhythm

Hằng tuần, cùng thứ trong tuần — khoảng cách đều thì xu hướng mới đọc được.

Weekly, on the same weekday — only with even intervals can the trend be read.

Một lượt đầy đủ gồm bốn lần cào theo thứ tự, xem /ota-metrics-crawl: chỉ số nền → lịch sử doanh thu (--history) → reservation → phễu nhiều kỳ. Lượt reservation phải chạy trước lượt phễu, vì bộ trích phễu dò ngược cửa sổ bằng fact_reservations.

A full run has four crawls in fixed order, see /ota-metrics-crawl: base metrics → revenue history (--history) → reservations → multi-period funnel. The reservation pass must run before the funnel pass, because the funnel extractor searches back for the window using fact_reservations.

Sau mỗi lần cào nhớ ghi một dòng vào crawl_log.csv: thiếu nhật ký thì sau này không biết khoảng trống trong chuỗi là không cào hay cào mà không có số.

After each pull, remember to write one line into crawl_log.csv: without a log, you cannot later tell whether a gap in the series means not pulled or pulled but no figures were returned.

Lịch sửHistory

Mốc Kênh Căn Dòng Ghi chú
2026-09-23 booking 7 77 Lần cào đầu. 4/7 căn chưa có review nào; A La Carte 404 chưa có doanh thu.
Snapshot Channel Properties Rows Note
2026-09-23 booking 7 77 First pull. 4/7 properties have no reviews yet; A La Carte 404 has no revenue yet.

NguồnSource: performance/metrics/README.md

Tài liệu kỹ thuật khácOther technical documents