Get item usage with custom range that goes over a year

298
1
04-25-2021 05:24 PM
KerryKang
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. 

 

Cheers,

 

Kerry

0 Kudos
1 Reply
AdamR
by
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 :(

FYI:

from arcgis.gis import GIS
from IPython.display import display
gis = GIS("home")
items = gis.content.search(query="type:Web Apps")
for item in items:
   try:
      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
         display(item)
   except:
      pass

 

0 Kudos