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

Introduce EDD_Stats class #1376

Closed
pippinsplugins opened this issue Jul 19, 2013 · 16 comments
Closed

Introduce EDD_Stats class #1376

pippinsplugins opened this issue Jul 19, 2013 · 16 comments

Comments

@pippinsplugins
Copy link
Contributor

We need to finally have a full stats API that allows us to:

  • Get earnings by date
  • Get sales by date
  • Get sales / earnings of a product
  • Get sales / earnings of a product for a date
  • Others

We have some various functions for these but no full-fledged API.

This API should be used in Reports / Graphs, EDD_API class, and anywhere else that retrieves / shows stats.

@pippinsplugins
Copy link
Contributor Author

I might also suggest that we write a EDD_Graph class.

@pippinsplugins
Copy link
Contributor Author

Debating on whether this should also allow sale data to be retrieved in the same way, as opposed to just sale stats.

pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
pippinsplugins added a commit that referenced this issue Aug 3, 2013
@chriscct7
Copy link
Member

Yes. That would be insanely useful
On Aug 2, 2013 10:47 PM, "Pippin Williamson" notifications@github.com
wrote:

Debating on whether this should also allow sale data to be retrieved in
the same way, as opposed to just sale stats.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1376#issuecomment-22047178
.

@pippinsplugins
Copy link
Contributor Author

If I do that, I want to rename it. Votes on what to name it?

@chriscct7
Copy link
Member

There should be 2 ones. One for statistics abd one called edd sales
On Aug 2, 2013 11:03 PM, "Pippin Williamson" notifications@github.com
wrote:

If I do that, I want to rename it. Votes on what to name it?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1376#issuecomment-22047369
.

@pippinsplugins
Copy link
Contributor Author

I do like the idea of an EDD_Sales class that makes it easy to get sales data by date and also does all of the grunt work of retrieving sale meta.

It should be able to get sales for the whole store AND specific products.

pippinsplugins added a commit that referenced this issue Aug 5, 2013
pippinsplugins added a commit that referenced this issue Aug 5, 2013
pippinsplugins added a commit that referenced this issue Aug 5, 2013
pippinsplugins added a commit that referenced this issue Aug 5, 2013
…new instance in order to retrieve stats for different date ranges. #1376
@pippinsplugins
Copy link
Contributor Author

Stats can now be retrieved like so:

$stats = new EDD_Stats;

// Sales for this month:
echo $stats->get_sales( 0, 'this_month' );

// Earnings for August 2, 2013
echo $stats->get_earnings( 0, 'August 2, 2013' );

// Sales for download 44 from July 2 to August 5, 2013

echo $stats->get_sales( 44, 'July 2, 2013', 'August 5, 2013' );

The first parameter is the download ID to retrieve stats for, the second is the start date, and the third is the end date.

Dates can be passed as date strings, predefined date ranges (last_year, this_week, etc), timestamps, and human readable dates.

Predefined date options are:

  • today
  • yesterday
  • this_week
  • last_week
  • this_month
  • last_month
  • this_quarter
  • last_quarter
  • this_year
  • last_year

@chriscct7
Copy link
Member

🍪

@pippinsplugins
Copy link
Contributor Author

We now have a get_best_selling( $number ) method for this too that returns an array of download IDs and sale counts.

@pippinsplugins
Copy link
Contributor Author

The classes have been refactored a bit. There is now the EDD_Stats class, which is simply the base class, and then the EDD_Payment_Stats class, which is used for getting the actual earnings and sale stats.

$stats = new EDD_Payment_Stats;

// Sales for this month:
echo $stats->get_sales( 0, 'this_month' );

// Earnings for August 2, 2013
echo $stats->get_earnings( 0, 'August 2, 2013' );

// Sales for download 44 from July 2 to August 5, 2013

echo $stats->get_sales( 44, 'July 2, 2013', 'August 5, 2013' );

@spencerfinnell
Copy link
Contributor

Why is count_where and payments_where the exact same thing? Why not just have one called filter_where or something that can act as a callback for all instances where a date is being queried?

@pippinsplugins
Copy link
Contributor Author

Because they're not actually the same. The columns are referenced differently.

@spencerfinnell
Copy link
Contributor

Nevermind... nothing to see here... :P

@pippinsplugins
Copy link
Contributor Author

The get_earnings() function isn't quite correct for individual product earnings. It gets the payments that included the specified product, but it's still adding the earnings of all items included in each of the found payments.

@pippinsplugins
Copy link
Contributor Author

The lifetime best selling function isn't working correctly. According to the live EDD site, PDF Invoices is the best selling extension: http://screencloud.net/v/rBXZ - while I know @sunnyratilal would love that to be true, it's not.

@chriscct7
Copy link
Member

Well in @sunnyratilal's mind there isn't anything wrong with that function. Maybe we could hardcode something like:
if ($chris == author_on_site($chris_id)){
return $chris;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants