Skip to content

Add CampaignDeliverySummary module for aggregating delivery data#483

Draft
neal-bpm wants to merge 2 commits intomainfrom
vn/campaign-summary
Draft

Add CampaignDeliverySummary module for aggregating delivery data#483
neal-bpm wants to merge 2 commits intomainfrom
vn/campaign-summary

Conversation

@neal-bpm
Copy link
Copy Markdown
Contributor

#476

Describe your changes

This module provides a data structure to consolidate campaign delivery information into a summary format suitable for various use cases.

  • Track total and completed task counts
  • Group assigned deliveries by rider name
  • Collect unassigned deliveries separately
  • Implement Collectable protocol for use with Enum.into/2
  • Include delivery details: dropoff name, status, and item names

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it is a core feature, I have added tests.
  • Are there other PRs or Issues that I should link to here?
  • Will this be part of a product update? If yes, please write one phrase
    about this update in the description above.

#476

This module provides a data structure to consolidate campaign delivery information into a summary format suitable for various use cases.
  * Track total and completed task counts
  * Group assigned deliveries by rider name
  * Collect unassigned deliveries separately
  * Implement Collectable protocol for use with Enum.into/2
  * Include delivery details: dropoff name, status, and item names
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e638a2a6-61ed-40db-ad00-84d4a15e8cfa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vn/campaign-summary

Comment @coderabbitai help to get the list of available commands and usage tips.

  Add name, delivery_start, and delivery_end fields to the struct.
  Add new/1 function that accepts a campaign and pre-populates these metadata fields from campaign.program.name and timestamps.
|> delivery(task)
end

defimpl Collectable do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this before what does it do?

Copy link
Copy Markdown
Contributor Author

@neal-bpm neal-bpm Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By implementing Collectable for CampaignDeliverySummary, we can iterate using

summary = Enum.into(tasks, CampaignDeliverySummary.new(campaign))

Here initial state = CampaignDeliverySummary.new(campaign)

Similar to Enum.reduce pattern

defimpl Collectable do
    defp collect(cds, {:cont, task}), do: @for.add_task(cds, task)
    defp collect(cds, :done), do: cds
    defp collect(_cds, :halt), do: :ok
    def into(tasks), do: {tasks, &collect/2}
 end

Since we are collecting for the same module, we use @for.

def add_task(cds, task) do
    cds
    |> Map.update!(:total, &(&1 + 1))
    |> completed(task)
    |> delivery(task)
  end

Reference: https://hexdocs.pm/elixir/1.19.5/Collectable.html
Is this make sense?

@neal-bpm neal-bpm requested a review from mveytsman March 31, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants