Add CampaignDeliverySummary module for aggregating delivery data#483
Add CampaignDeliverySummary module for aggregating delivery data#483
Conversation
#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
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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 |
There was a problem hiding this comment.
I haven't seen this before what does it do?
There was a problem hiding this comment.
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?
#476
Describe your changes
This module provides a data structure to consolidate campaign delivery information into a summary format suitable for various use cases.
Checklist before requesting a review
about this update in the description above.