|
70 | 70 | # is equivalent to atomx.get('advertiser/42/profiles')
|
71 | 71 |
|
72 | 72 |
|
| 73 | +You can also use a class or instance of :mod:`atomx.models` in a get requests. |
| 74 | +E.g. all of those api calls request the same resource: |
| 75 | + |
| 76 | +.. code-block:: python |
| 77 | +
|
| 78 | + from atomx.models import Advertiser |
| 79 | +
|
| 80 | + atomx.get('advertiser/42') # all in 1 string |
| 81 | + atomx.get('advertiser', 42) # model, id split up |
| 82 | + atomx.get(Advertiser, 42) # using :class:`atomx.models.Advertiser` |
| 83 | + atomx.get(Advertiser(42)) # using instance of :class:`atomx.models.Advertiser` |
| 84 | +
|
| 85 | +
|
73 | 86 | Or get all domains where the hostname contains `atom`:
|
74 | 87 |
|
75 | 88 | .. code-block:: python
|
@@ -183,16 +196,22 @@ to create a report.
|
183 | 196 |
|
184 | 197 | .. code-block:: python
|
185 | 198 |
|
186 |
| - # reporting example |
| 199 | + from datetime import datetime, timedelta |
| 200 | +
|
| 201 | + now = datetime.utcnow() |
| 202 | + last_week = now - timedelta(days=7) |
| 203 | +
|
187 | 204 | # get a report for a specific publisher
|
188 |
| - report = atomx.report(scope='publisher', groups=['hour'], metrics=['impressions', 'clicks'], where=[['publisher_id', '==', 42]], from_='2015-02-08 00:00:00', to='2015-02-09 00:00:00', timezone='America/Los_Angeles') |
189 |
| - # check if report is ready |
190 |
| - print(report.is_ready) |
| 205 | + report = atomx.report(scope='publisher', groups=['hour'], metrics=['impressions', 'clicks'], where=[['publisher_id', '==', 42]], from_=last_week, to=now, timezone='America/Los_Angeles') |
| 206 | +
|
| 207 | + report.length # get the number of rows returned |
| 208 | + report.totals # get the total values |
| 209 | +
|
191 | 210 | # if pandas is installed you can get the pandas dataframe with `report.pandas`
|
192 | 211 | # you can also get the report csv in `report.content` without pandas
|
193 | 212 | df = report.pandas # A datetime index is automatically set when group by a hour/day/month.
|
194 | 213 | # calculate mean, median, std per hour
|
195 |
| - means = df.resample('H', how=['mean', 'median', 'std']) |
| 214 | + means = df.resample('H').apply(['mean', 'median', 'std']) |
196 | 215 | # and plot impression and clicks per day
|
197 | 216 | means['impressions'].plot()
|
198 | 217 | means['clicks'].plot()
|
|
0 commit comments