Skip to content

Commit db9b76c

Browse files
committed
fixed issues with monthly views and downloads stats
1 parent f32e978 commit db9b76c

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

reports/dataset.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,35 @@ def add_dataset(self, datasets, dataverse_identifier, dataset_id, dataset_identi
104104
dataset_metrics_options = ['viewsUnique', 'viewsMonth', 'viewsTotal', 'downloadsUnique', 'downloadsMonth', 'downloadsTotal']
105105
for dataset_metrics_option in dataset_metrics_options:
106106
self.logger.debug("Calling endpoint for dataset metric: " + dataset_metrics_option)
107-
if dataset_metrics_option == 'viewsMonth' or dataset_metrics_option == 'downloadsMonth':
108-
dataset_metrics_response = self.dataverse_api.get_dataset_metric(identifier=dataset_id,option=dataset_metrics_option,doi=dataset_identifier,date=last_month)
107+
if dataset_metrics_option == 'viewsMonth':
108+
dataset_metrics_response = self.dataverse_api.get_dataset_metric(identifier=dataset_id,option='viewsTotal',doi=dataset_identifier,date=last_month)
109+
elif dataset_metrics_option == 'downloadsMonth':
110+
dataset_metrics_response = self.dataverse_api.get_dataset_metric(identifier=dataset_id,option='downloadsTotal',doi=dataset_identifier,date=last_month)
109111
else:
110112
dataset_metrics_response = self.dataverse_api.get_dataset_metric(identifier=dataset_id,option=dataset_metrics_option,doi=dataset_identifier)
111113

112114
dataset_metrics_json = dataset_metrics_response.json()
113-
if dataset_metrics_json['status'] == 'OK' and dataset_metrics_option in dataset_metrics_json['data']:
114-
self.logger.info("MDC metric (" + dataset_metrics_option + "): " + str(dataset_metrics_json['data'][dataset_metrics_option]))
115-
dataset[dataset_metrics_option] = dataset_metrics_json['data'][dataset_metrics_option]
115+
if dataset_metrics_json['status'] == 'OK':
116+
if dataset_metrics_option == 'viewsMonth':
117+
if 'viewsTotal' in dataset_metrics_json['data']:
118+
self.logger.info("MDC metric (" + dataset_metrics_option + "): " + str(dataset_metrics_json['data']['viewsTotal']))
119+
dataset[dataset_metrics_option] = dataset_metrics_json['data']['viewsTotal']
120+
else:
121+
self.logger.debug("Unable to find viewsTotal in response.")
122+
elif dataset_metrics_option == 'downloadsMonth':
123+
if 'downloadsTotal' in dataset_metrics_json['data']:
124+
self.logger.info("MDC metric (" + dataset_metrics_option + "): " + str(dataset_metrics_json['data']['downloadsTotal']))
125+
dataset[dataset_metrics_option] = dataset_metrics_json['data']['downloadsTotal']
126+
else:
127+
self.logger.debug("Unable to find downloadsTotal in response.")
128+
elif dataset_metrics_option in dataset_metrics_json['data']:
129+
self.logger.info("MDC metric (" + dataset_metrics_option + "): " + str(dataset_metrics_json['data'][dataset_metrics_option]))
130+
dataset[dataset_metrics_option] = dataset_metrics_json['data'][dataset_metrics_option]
131+
else:
132+
self.logger.error("Unable to find dataset metric in response.")
116133
else:
117-
self.logger.debug("Call was unsuccessfull.")
134+
self.logger.error("API call was unsuccessful.")
135+
self.logger.error(dataset_metrics_json)
118136
dataset[dataset_metrics_option] = 0
119137

120138
# Use dataverse_database to retrieve cumulative download count of file in this dataset

0 commit comments

Comments
 (0)