Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add endpoint for Campaign Overview Statistics #7545

Merged
merged 7 commits into from
Sep 25, 2024

Conversation

kjohnson
Copy link
Member

@kjohnson kjohnson commented Sep 19, 2024

Related GIVE-1221
Related GIVE-1222

Description

This PR adds the GET \give-api\v2\campaign-overview-statistics endpoint for fetching campaign statistics, such as Amount Raised, Donation Count, and Donor Count.

If a range in days (rangeInDays) is provided then a pair of values are returned to include the previous period of the range.

Affects

  • Campaigns\CampaignDonationQuery has been updated with support for immutability.

  • Framework\Support\Facades\DateTime\TemporalFacade has been updated to include new helper methods withStartOfDay and withEndOfDay, which set the appropriate time for inclusively querying dates in a range. Additionally, the immutableOrClone method has been added to encapsulate support for immutability that accounts for either DateTime or DateTimeImmutable, both of which implement the DateTimeInterface.

  • Framework\Support\Facades\DateTime\Temporal has been updated with available methods using @method annotations in the docblock.

Visuals

// "All time"
[
    [
        'amountRaised' => 20,
        'donationCount' => 2,
        'donorCount' => 2,
    ],
]
// Period of time with previous period
[
    [
        // Current period
        'amountRaised' => 20,
        'donationCount' => 2,
        'donorCount' => 2,
    ],
    [
        // Previous period
        'amountRaised' => 10,
        'donationCount' => 1,
        'donorCount' => 1,
    ],
]

Pre-review Checklist

  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Self Review of code and UX completed

@kjohnson kjohnson changed the base branch from develop to epic/campaigns September 19, 2024 15:38
@kjohnson kjohnson marked this pull request as ready for review September 19, 2024 16:05
Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@kjohnson Great work! I left a few comments related to some minor changes, but also would like to suggest something that I think would be helpful.

I think we need to add a dateRange property in the route returns, something like this:

// "All time"
[
    [
        'dateRange' => ['startDate' => '0', 'endDate' => '0']
        'amountRaised' => 20,
        'donationCount' => 2,
        'donorCount' => 2,
    ],
]
// Period of time with previous period
[
    [
        // Current period
        'dateRange' => ['startDate' => 'value', 'endDate' => 'value']
        'amountRaised' => 20,
        'donationCount' => 2,
        'donorCount' => 2,
    ],
    [
        // Previous period
        'dateRange' => ['startDate' => 'value', 'endDate' => 'value']
        'amountRaised' => 10,
        'donationCount' => 1,
        'donorCount' => 1,
    ],
]

I was checking the code using PHP XDebug and took a while to understand the testReturnsPeriodStatisticsWithPreviousPeriod() without this information, so I think it can be used in future debug sessions and also can be helpful to have this information on the JS side.

src/Campaigns/Routes/CampaignOverviewStatistics.php Outdated Show resolved Hide resolved
src/Campaigns/Routes/CampaignOverviewStatistics.php Outdated Show resolved Hide resolved
src/Campaigns/Routes/CampaignOverviewStatistics.php Outdated Show resolved Hide resolved
@kjohnson
Copy link
Member Author

@glaubersilva the intention of the data format is to be a queue of data, so the current is always first and moves backwards one period per item in the array. This could be better documented or made more clear.

Copy link
Contributor

@glaubersilva glaubersilva left a comment

Choose a reason for hiding this comment

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

@kjohnson Great work!

@kjohnson kjohnson merged commit 155924a into epic/campaigns Sep 25, 2024
20 checks passed
@kjohnson kjohnson deleted the feature/campaign-overview-statistics branch September 25, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants