I have been creating an automatic report generation script that will take data from a user usage report and put into a google sheet. My script has been running fine so far but the data that I get back seems a little odd to me.
I generate reports from a function I created called report raw. I am new to coding so go easy but this is how I am pulling information. I then put it into a dictionary and use that dictionary to create reports over several days. The idea of the report is to track usage of google apps to create another way to look at attendance. For instance, the report will look at every weekday, compare each day, and then make a metric based on their usage.
def report_raw(date_entry,userkey, parameters,rep,maxresults):
date = Date()
creds = google_authenticate()
service = build('admin', 'reports_v1', credentials=creds)
user_log = {}
fieldnames = config_settings('d:/data/reports/data.csv','')[0]['Fieldnames']
#this calls the API to generate a user report with specific variables
results = service.userUsageReport().get(userKey='all',date=date_entry, maxResults = maxresults).execute()
if 'usageReports' not in results:
return 'data is not ready for export'
else:
for result in results.get('usageReports'):
email = result['entity']['userEmail']
activities = result['parameters']
user_log[email] = {}
for activity in activities:
for fieldname in fieldnames:
if activity['name'] == fieldname:
for key,value in activity.items():
if key == 'name':
x = value
user_log[email][x] = value
user_log['date'] = {'date' : str(date_entry), 'weekday' : date.today.weekday()}
return user_log
The problem I am running into is that if I generate a report for a specific date like 2021-01-25 I will get interaction and login times for 2021-01-26 on some users whereas most others stick within the 2021-01-25 time frame. When I generate the next day's report, in this case 2021-01-26, the users who showed activity on 2021-01-26 don't have a change in value. On top of this some users have a interaction time for 1970-01-01(which I am assuming means they have never interacted with the service since it has started tracking their info as that is the start of Unix time). I wanted to know if anyone has played around with user usage reports and if there is a mistake in how I am generating the report. Thanks!