Get item usage with custom range that goes over a year

04-25-2021 05:24 PM
Occasional Contributor II

Hello all,


I used to check our web apps' usage since the app was created in the mid april in 2020 . Last week, I realized that the usage search only offers up to 1 year range, and had to some manual calculation to get the cumulated total and average usage per day. It was quite inconvenient and I hope to get the number using Python API. 


I searched some resources but I don't see any example which actually used a custom range. Has anyone done it? What all I need is total cumulated number and daily average.  

Even if I cannot do over 1 year, if I can apply custom date range with Python API, I can probably skip manual calculation work. 





0 Kudos
3 Replies
New Contributor II

I've been doing some hocky stuff off Jason's code. I was kinda hoping I could import pandas and use that as a date, something like:

pd.date_range(start='2020-01-01', end='2020-01-06')

but I can't get it to work 😞


from arcgis.gis import GIS
from IPython.display import display
gis = GIS("home")
items ="type:Web Apps")
for item in items:
      itemHistory = item.usage(date_range='1Y', as_df=True)   # <--- Looking in the past 12 months
      total = itemHistory['Usage'].sum()
      if total <20:                                                                           # <--- Less than 20 total views


0 Kudos
New Contributor

Bumping this thread - Has anyone come up with a way to do this yet? I can't seem to find anything that works.

0 Kudos
New Contributor III

Bumping this thread again.  I've gotten custom date ranges to work with this method:

from arcgis.gis import GIS
gis = GIS('home')
item = arcgis.gis.Item(gis, itemid="########################")
date_1 = datetime.datetime(2023,7,2)
date_2 = datetime.datetime(2023,7,20)
usage_stats = item.usage(date_range=(date_1, date_2),as_df=True)

BUT, any custom dates over a year old fail.  Well, technically I don't get an error.  I just get an empty dataframe.  Or an empty dictionary if I use "as_df = False".

Is this the expected behavior, or a bug?  

0 Kudos