This builder wants to answer: "Is there a correlation between an uptick in Google Trends' Interest Over Time metric and MNL-BCD flight/BCD hotel price surges leading up to the Bacolod MassKara Festival in October?"
- Budget-conscious Travelers: To identify optimal advance-booking windows and avoid peak airfare surges.
- Local Bacolod Businesses & Vendors: To track real-time tourist demand signals to be used for data-driven business descisions in anticipation of the event.
- Data Researchers: As a reference implementation for cross-correlating search intent with regional travel price metrics.
Run these commands from the repository root.
pip install -r requirements.txtCreate a .env file in the project root:
SERPAPI_API_KEY=your_serpapi_key
APIFY_API_KEY=your_apify_key
No ingestion (use stored data) (Recommended):
python scripts/run_pipeline.pyWith ingestion (get latest data):
python scripts/run_pipeline.py --with-ingestpython scripts/ingest.py(optional via--with-ingest) — pulls raw flights, hotels, and Google Trends JSONL intodata/raw/.python scripts/transform.py— cleans raw data, runs validation checks, and buildsdata/processed/masskara/analysis/master.csv.python scripts/run_sql_analysis.py— refreshesmasskara.dband runs SQL business queries (scripts/queries.sql).python scripts/run_path_b_analysis.py— computes Path B segmentation and KPI tables and saves reusable outputs tooutput/:output/kpi_daily_metrics.csv(daily FPPR, LBPI, and 1-day price velocities)output/kpi_cohort_scorecard.csv(executive KPI scorecard by lead-time cohort)output/kpi_lag_correlation.csv(0–3 day lagged Spearman correlations)output/segmentation_cohort_buzz_summary.csv(2D Lead-Time Cohort × Search Buzz summary)output/figures/*.png(Week 16 EDA & insight charts)
- Stakeholder deliverable:
notebooks/week_19_stakeholder_brief.ipynb(plain-language 1-page policy brief).
- Observational Quotes Only: Prices come from daily SerpApi/Apify Google Flights and Google Hotels snapshots; they reflect publicly listed quotes rather than actual airline seat counts or hotel room occupancy.
- Pagination Ceiling: Scraper quote counts (~20 results) reflect API pagination limits and are excluded from KPI calculations.
- Confounding with Lead Time:
days_to_festivalacts as a common confounder—search interest and late-stage airfare surges peak together in the final 7 days, so correlation does not imply direct causation. - Sample Size in Surge Window: The final
<=7dcohort spans 6 observation days, so medians are prioritized over means to limit outlier skew.
python scripts/ingest.pypython scripts/transform.pypython scripts/run_sql_analysis.pypython scripts/run_path_b_analysis.pyThe main metrics this builder wishes to track are categorized into three distinct layers:
-Peak Search Index (0-100): The maximum search volume score registered leading up to the festival, indicating the highest point of public curiosity. This is NOT the actual number of searches as Google Trends Interest Over Time (IOT) data scales on 0-100 with 100 being the highest number of searches and the rest being scaled relative to that peak.
-Interest Velocity (Week-over-Week): The percentage change in search volume between consecutive weeks to identify sudden inflection points or viral spikes.
-Cumulative Search Volume: The area under the curve (total sum of search values) over the pre-festival tracking window to measure total sustained interest.
-Festival Price Premium: The percentage difference between average MNL-BCD flight ticket prices or hotel room rates during the festival target dates for October 9-13 versus standard baseline periods gathered beforehand from the rolling price record.
-Minimum Price Escalation: Track how the lowest available one-way flight price shifts as the collection date gets closer to October 9, and then past it with rolling dates once the event has ended.
-Cross-Correlation Coefficient: A statistical measure (Spearman's) evaluating how closely fluctuations in Google Trends scores track with flight and hotel price jumps.
-Lag Time to Surge (Lead Time): The time gap (in days) between an initial spike in search interest and the subsequent upward movement in airfares and accommodation rates. Look at it in day-level shifts (e.g., does a spike in Google Trends on Day T trigger a price jump on Day T+2 or T+3?)—people rarely search for a festival term and book a flight within the exact same hour; there is usually a consideration window.
All data ingestion and transformation pipelines are located under scripts/:
- Ingestion:
python scripts/ingest.py(pulls raw data intodata/raw/) - Transformation & Mart Building:
python scripts/transform.py(cleans raw data and produces the analytical master dataset indata/processed/masskara/analysis/master.csv) - Automation: Both pipelines are scheduled via GitHub Actions (
.github/workflows/ingest.ymldaily at 18:20 UTC, and.github/workflows/transform.ymlat 22:20 UTC).
- Name: SERP API
- URL: https://serpapi.com/playground
- Format: json
- Coverage: flight prices (by cheapest), hotel prices (by Google Search 'relevance'), interest over time metric
- Why it fits the problem: SERP API directly scrapes Google Flight, Hotel, and Trends search results
- Known limitations: free tier is limited to 250 request per month (should need around 90)
- Name: kaix/google-hotels-scraper
- URL: https://console.apify.com/actors/H1scmbaCSREtaQDQU
- Format: JSONL
- Coverage: hotel prices, date
- Why it could still work: directly scrapes Google Hotel
- Known limitations: $5 Free limit. ~$0.1/1k Hotels
- Name: johnvc/Google-Flights-Data-Scraper-Flight-and-Price-Search
- URL: https://console.apify.com/actors/1dYHRKkEBHBPd0JM7
- Format: JSONL
- Coverage: flight prices, date
- Why it could still work: directly scrapes google flights
- Known limitations: $5 Free limit. ~$30/1000 Pages
- Name: data_xplorer/google-trends-fast-scraper
- URL: https://console.apify.com/actors/nWhM7vTPu16lcwuIg/
- Format: JSONL
- Coverage: interest over time metric, date
- Why it could still work: directly scrapes Google Trends interest over time results
- Known limitations: $5 Free limit. ~$2/1k Results
data/raw/*.jsonl
|
v
`transform.py`
|
+-- `cleaned_flights.csv`
+-- `cleaned_hotels.csv`
+-- `cleaned_trends.csv`
+-- `master.csv`
File: data/processed/cleaned_flights.csv
- Grain: One row per flight option collected on a specific date.
- Identifier: The combination of
datetime_collected,collection_mode,flight_number, anddeparture_time. - Purpose: Stores cleaned MNL-to-BCD flight quotes.
| Column | Meaning |
|---|---|
datetime_collected |
Date the quote was collected |
status |
Ingestion result, such as success |
primary_source |
Whether the quote came from SerpApi |
collection_mode |
rolling baseline or festival_target |
total_duration |
Total flight duration in minutes |
price |
One-way fare in PHP |
type |
Flight type, such as one-way |
target_date |
Festival target travel date, when applicable |
airline |
Airline name |
flight_number |
Flight identifier |
airplane |
Aircraft type |
travel_class |
Cabin class |
departure_airport |
Origin airport code |
departure_time |
Scheduled departure timestamp |
arrival_airport |
Destination airport code |
arrival_time |
Scheduled arrival timestamp |
leg_duration |
Duration of the first flight leg |
File: data/processed/cleaned_hotels.csv
- Grain: One row per hotel quote collected for a specific stay window.
- Identifier: The combination of
datetime_collected,collection_mode,hotel_name, andcheck_in. - Purpose: Stores cleaned Bacolod hotel rates.
| Column | Meaning |
|---|---|
datetime_collected |
Date the quote was collected |
status |
Ingestion result |
primary_source |
Whether the quote came from SerpApi |
collection_mode |
rolling baseline or festival_target |
hotel_name |
Accommodation name |
lowest_rate |
Original hotel rate string |
check_in |
Stay check-in date |
check_out |
Stay check-out date |
target_date |
Festival target date, when applicable |
price_php |
Cleaned numeric hotel price in PHP |
File: data/processed/cleaned_trends.csv
- Grain: One row per Google Trends observation date within an ingestion snapshot.
- Identifier: The combination of
datetime_collected,timestamp, andcollection_mode. - Purpose: Stores cleaned Google Trends interest values for
Masskara.
| Column | Meaning |
|---|---|
datetime_collected |
Date the trends data was collected |
status |
Ingestion result |
primary_source |
Whether the data came from SerpApi |
collection_mode |
Trends collection mode |
timestamp |
Date represented by the trends observation |
value |
Google Trends interest index from 0 to 100 |
File: data/processed/masskara/analysis/master.csv
- Grain: One row per observation date.
- Primary key:
date_collected. - Purpose: Combines trends, flight, and hotel metrics for analysis.
The master dataset contains:
- Daily Google Trends search scores
- Festival and rolling flight price summaries
- Festival and rolling hotel price summaries
- Flight and hotel price premiums
- Seven-day trends velocity
- One-, two-, and three-day trends lags
- One-day flight and hotel price changes
- Days remaining until the festival
| Raw issue | Cleaning action | Result |
|---|---|---|
| Nested flight legs | Extracted the first flight leg into separate columns | Airline, airports, times, and duration can be analyzed as normal columns |
Currency strings such as ₱1,211 |
Removed currency symbols and commas, then converted to numeric values | Stored as price_php |
| Invalid numeric values | Converted with pd.to_numeric(..., errors="coerce") |
Invalid values become NaN and are excluded from aggregate calculations |
| Missing festival target dates in rolling records | Preserved as empty values | Rolling records remain distinguishable from festival-target records |
| Raw flight metadata not needed for price analysis | Removed nested blobs such as flights, booking_token, and airline_logo |
Processed files remain smaller and easier to query |
| Different source date ranges | Joined trends with flight observations using an inner join | The master dataset contains dates with active flight and trend observations |
Validation is implemented in scripts/transform.py.
The transformation checks that:
- The master dataset is not empty.
date_collectedcontains no null values.date_collectedis unique in the master dataset.- Google Trends scores are within the range 0 to 100.
- Festival and rolling prices are positive when present.
collection_modecontains onlyrollingorfestival_target.days_to_festivalis not negative.- The same raw input produces the same processed output when the transform script is run repeatedly.
Expected missing values include:
target_datefor rolling records- Initial lag values for the first one to three observation dates
- Initial seven-day velocity values
- Price fields when a source returns no usable quote
SQL analysis is documented in scripts/queries.sql and executed by:
python scripts/run_sql_analysis.pyThe queries answer these business questions:
- What is the difference between festival and rolling flight and hotel prices?
- How do festival flight prices change as the travel date approaches?
- How does Google Trends search interest align with festival flight prices?
- Which airline offers the lowest festival flight prices?
The SQL runner refreshes:
`masskara.db`
and prints the query results in the terminal.
All notebooks are found under notebooks/. Jupyter analysis is done sequentially:
notebooks/week_8_sql.ipynbnotebooks/week_9_pandas_profiling.ipynbnotebooks/week_10_transformations.ipynbnotebooks/week_13_descriptive_stats.ipynbnotebooks/week_14_eda_visualization.ipynbnotebooks/week_15_inference.ipynbnotebooks/week_16_insights.ipynbnotebooks/week_17_segmentation.ipynbnotebooks/week_18_kpis.ipynbnotebooks/week_19_stakeholder_brief.ipynb
| Issue / Raw State | Action Taken | Rationale |
|---|---|---|
Nested Flight Legs (flights) |
Unnested first flight leg into explicit columns (airline, flight_number, departure/arrival airport & times). |
Tabular models cannot query nested JSON lists; separating legs allows airline pricing breakdowns. |
Hotel Rates as Currency Strings ("₱1,211") |
Stripped ₱, commas, and whitespace using regex r"[^\d.]", then cast to float. |
Financial metrics (min, mean, median, velocity) require native numeric types. |
Missing target_date in Rolling Scrapes |
Kept as NaN / empty for rolling rows, populated only for festival_target. |
Rolling scrapes measure the next-day baseline and have no fixed October target date. Preserving NaN prevents false grouping. |
Multi-Leg Flight Blobs (booking_token, airline_logo) |
Dropped from processed output. | Token payloads and SVG URLs add noise and bloated file size without analytical value for price surge modeling. |
| Unequal Time Horizons Across Sources | Merged on date_collected using inner for flights/trends and left for hotels. |
Trend data extends back to June, but flight/hotel scrapers only started September 2. Restricting the master mart to active scraper observation dates eliminates 90+ days of empty price rows. |
- Primary Key Integrity:
date_collectedhas zero nulls (isna().sum() == 0) and is 100% unique (nunique() == len(df)). - Domain Range Boundaries:
trend_search_scoreis strictly asserted to fall within[0, 100].- All flight fares and hotel nightly rates must be strictly positive (
> 0).
- Category Integrity:
collection_modemust only ever containfestival_targetorrolling. - Lead Time Sanity:
days_to_festivalmust remain positive (>= 0) leading up to October 9, 2026. - Idempotence & Reproducibility: Running
python scripts/transform.pymultiple times on identical raw inputs produces the exact same deterministic dataset without row duplications or side effects.
The presentation layer will be built as a single-page application divided into three clear analytical modules:
-
The Executive Snapshot (Metric Cards)
- High-level metric callouts showing current median flight prices (MNL-BCD), current median hotel rates, this week's Interest Over Time value, and the overall correlation score.
-
The Surge Timeline (Interactive Line Chart)
- A dual-axis time-series chart mapping
trends_velocitydirectly againsttravel_price_velocityandhotel_price_velocityacross a rolling 90-day window to visually isolate the price lag following an Interest Over Time spike.
- A dual-axis time-series chart mapping
-
The Traveler's Action Center (Summary Data Table)
- A structured data table outputting the programmatic results for booking window strategies:
travel_lead_time,hotel_lead_time,travel_cooldown_time, andhotel_cooldown_time.
- A structured data table outputting the programmatic results for booking window strategies:
-
As MassKara is usually held in October, this builder hopes to have already collected (Phase 2) and cleaned (Phase 3) data ranging as far back as August.
-
This builder would've liked to do an analysis of the previous MassKara festival to contrast with the upcoming one, but SerpApi's Google Hotels and Google Flights scraper cannot view historical prices. (even tho the
vs. same period previous yearfeature is in the page)