Add 1174. Immediate Food Delivery II solution#271
Conversation
📝 WalkthroughWalkthrough顧客の最初の注文に対し「即座配送」割合を求めるPandas版とPostgreSQL版の解説ドキュメントを追加し、SVGフローチャートと可視化のガイドライン文書も新規追加しました。 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_pandas.md:
- Around line 92-96: The current selection of first_orders using a min-based
filter can include multiple rows per customer when a customer has tied minimal
order_date; instead, ensure only one "first" order per customer is counted by
switching to the idxmin() approach (use the index of the per-customer minimum
order_date to select a single row) or by deduping the resulting first_orders
with drop_duplicates(subset=['customer_id', 'order_date']) before computing
is_immediate; update the logic around first_orders and the subsequent
is_immediate/percentage computation to reference the single-row-per-customer
result (look for first_orders, transform('min'), idxmin(), and is_immediate in
the diff).
- Line 51: The calculation for percentage can divide by zero when
len(is_immediate) == 0; update the logic around the percentage assignment
(variable percentage) to guard against an empty series/DataFrame (is_immediate)
by checking is_immediate.empty (or len(is_immediate) == 0) and setting
percentage to a safe value (e.g., 0.0 or float('nan')) otherwise perform the
existing calculation rounded to 2 decimals; modify the block that computes
percentage to include this conditional guard referencing percentage and
is_immediate.
- Line 66: The code mutates the input DataFrame by assigning delivery['rn']
which causes side effects; instead compute the rank without modifying the
original by either operating on a copy of delivery or using DataFrame.assign to
produce a new DataFrame (e.g., create a new variable from
delivery.assign(rn=...) and then filter where rn == 1), referencing the same
grouping by 'customer_id' and ranking on 'order_date' so all logic
(groupby('customer_id')['order_date'].rank(method='first', ascending=True))
remains but never writes back into the original delivery object.
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 63-69: The AVG-based expression can return NULL when first_orders
has no rows, so wrap the aggregation in COALESCE to return 0.0 instead;
specifically update the SELECT that computes immediate_percentage (ROUND(100.0 *
AVG(is_immediate::int), 2) AS immediate_percentage) to use
COALESCE(AVG(is_immediate::int), 0.0) so the query yields 0.00 instead of NULL
for empty result sets.
- Around line 37-44: The query that computes immediate_percentage can return
NULL when the table is empty; update the SELECT that references SUM(CASE...) /
COUNT(*) (the immediate_percentage expression that queries first_orders filtered
by rn = 1) to explicitly handle NULL/zero by wrapping the whole ROUND(...)
expression with COALESCE(..., 0.0) (or otherwise check COUNT(*) = 0) so the
query returns 0.0 instead of NULL for empty result sets.
- Fix Step 3/4 SVG: increase viewBox height and reposition summary text below table rows to prevent overlap - Fix copy button CSS: add !important overrides and broader selectors to ensure Prism.js copy-to-clipboard buttons are visible with Tailwind CSS preflight reset - Fix flowchart SVG arrows: reduce marker refX (9->5) so arrowheads are not hidden behind nodes, increase viewBox (950->1000), reposition merge point and lower nodes for proper spacing - Add SVG flowchart guidelines workflow for future reference
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.agent/workflows/svg_flowchart_guidelines.md:
- Around line 19-23: The fenced code block containing "viewBox height =
header_height + (row_count × row_height) + summary_text_spacing + padding"
violates MD031; add a blank line immediately before the opening ``` and a blank
line immediately after the closing ``` so the fence is separated from
surrounding text (update the markdown around that fenced block in
svg_flowchart_guidelines.md).
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 88-93: Guard against division-by-zero when computing
immediate_percentage: replace the denominator COUNT(*) in the ROUND expression
with NULLIF(COUNT(*), 0) and wrap the whole division with COALESCE(..., 0) so
the query on first_orders returns 0.00 when the table is empty; update the
expression that uses ROUND and COUNT(*) FILTER (WHERE is_immediate) accordingly.
| 2. **For dynamic data tables**, calculate viewBox height based on number of rows: | ||
| ``` | ||
| viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding | ||
| ``` | ||
|
|
There was a problem hiding this comment.
フェンス前後の空行が必要です(MD031)。
markdownlint の指摘どおり、フェンスの前後に空行を入れてください。
🧹 修正案
-2. **For dynamic data tables**, calculate viewBox height based on number of rows:
- ```
- viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
- ```
+2. **For dynamic data tables**, calculate viewBox height based on number of rows:
+
+ ```
+ viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
+ ```📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 2. **For dynamic data tables**, calculate viewBox height based on number of rows: | |
| ``` | |
| viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding | |
| ``` | |
| 2. **For dynamic data tables**, calculate viewBox height based on number of rows: |
🧰 Tools
🪛 markdownlint-cli2 (0.20.0)
[warning] 20-20: Fenced code blocks should be surrounded by blank lines
(MD031, blanks-around-fences)
🤖 Prompt for AI Agents
In @.agent/workflows/svg_flowchart_guidelines.md around lines 19 - 23, The
fenced code block containing "viewBox height = header_height + (row_count ×
row_height) + summary_text_spacing + padding" violates MD031; add a blank line
immediately before the opening ``` and a blank line immediately after the
closing ``` so the fence is separated from surrounding text (update the markdown
around that fenced block in svg_flowchart_guidelines.md).
- Fix MD031 markdown linting in svg_flowchart_guidelines.md by adding blank lines around fenced code block - Add NULLIF/COALESCE to postgre.md DISTINCT ON solution to guard against division by zero when first_orders is empty, returning 0.00 instead of NULL or error
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 88-96: The COALESCE fallback value is formatted
inconsistently—change the literal in the SELECT that defines
immediate_percentage from 0.00 to 0.0 so numeric-literal formatting matches the
earlier 0.0 usage; update the COALESCE(...) AS immediate_percentage expression
that uses NULLIF(COUNT(*), 0) and COUNT(*) FILTER (WHERE is_immediate) to return
0.0 instead of 0.00.
- Fine-tune flowchart merge point arrows (HTML): adjust horizontal endpoints from 440/460 to 435/465 and vertical endpoints from 800/910 to 795/895 for better visual alignment - Fix numeric literal consistency (postgre.md): change COALESCE fallback from 0.00 to 0.0 to match earlier 100.0 formatting style
10d723b — 初期の4つのビジュアル修正 (HTML + ワークフロー)
ef7c383 — MD031準拠 + ゼロ除算対策 (ワークフロー + postgre.md)
9456f54 — 矢印の位置調整 + 数値リテラルの一貫性 (HTML + postgre.md)
MD031 マークダウンリント修正 — svg_flowchart_guidelines.md のコードブロック前後に空行を追加
ゼロ除算対策 — Immediate_Food_Delivery_II_postgre.md の ソリューションに と を追加し、 が空の場合でも を返すように修正
pandas: ゼロ除算のガード追加、副作用(DataFrame変異)の防止、重複除去処理の追加。
postgre: 集計結果が空の場合に対応するための COALESCE 追加。