diff --git a/api/adapter.py b/api/adapter.py index ed96207..cd65c59 100644 --- a/api/adapter.py +++ b/api/adapter.py @@ -17,6 +17,9 @@ def json_report_wrapper(report_id, result_query, params, exceptions): if report_id == 'ir_a1': return _json_ir_a1(result_query, params, exceptions) + if report_id == 'ir_a4': + return _json_ir_a4(result_query, params, exceptions) + if report_id == 'cr_j1': return _json_cr_j1(result_query, params, exceptions) @@ -611,6 +614,97 @@ def _json_ir_a1(result_query_reports_ir_a1, params, exceptions): return json_results +def _json_ir_a4(result_query_reports_ir_a4, params, exceptions): + begin_date, ed_discard = cleaner.get_start_and_last_days(params.get('begin_date', '')) + bd_discard, end_date = cleaner.get_start_and_last_days(params.get('end_date', '')) + + json_results = { + "Report_Header": { + "Created": datetime.now().isoformat(), + "Created_By": "Scientific Electronic Library Online SUSHI API", + "Customer_ID": params.get('customer', ''), + "Report_ID": params.get('report_db_params', {}).report_id, + "Release": params.get('report_db_params', {}).release, + "Report_Name": params.get('report_db_params', {}).name, + "Institution_Name": params.get('institution_name', ''), + "Institution_ID": [{ + "Type": "ISNI", + "Value": params.get('institution_id', '') + }], + }, + "Report_Filters": [{ + "Name": "Begin_Date", + "Value": str(begin_date) + }, { + "Name": "End_Date", + "Value": str(end_date) + }], + "Report_Attributes": [{ + "Name": "Attributes_To_Show", + "Value": "Data_Type|Access_Method" + }], + "Exceptions": exceptions, + "Report_Items": [] + } + + report_items = {} + + for r in result_query_reports_ir_a4: + article_doi = getattr(r, 'articleDOI', '') + if article_doi not in report_items and article_doi != '': + report_items[article_doi] = { + 'Item': article_doi, + 'Publisher': r.journalPublisher, + 'Publisher_ID': [], + 'Platform': params.get('platform', ''), + 'Authors': '', + 'Publication_Date': r.articleYOP, + 'Article_Version': '', + 'DOI': article_doi, + 'Proprietary_ID': '', + 'Print_ISSN': '', + 'Online_ISSN': '', + 'URI': '', + 'Parent_Title': r.journalTitle, + 'Parent_DOI': '', + 'Parent_Proprietary_ID': '', + 'Parent_Print_ISSN': r.printISSN, + 'Parent_Online_ISSN': r.onlineISSN, + 'Parent_URI': r.journalURI, + 'Parent_Data_Type': 'Journal', + 'Item_ID': r.articlePID, + 'Data_Type': 'Article', + 'Access_Type': 'Open Access', + 'Access_Method': 'Regular', + 'Performance': []} + + if params['granularity'] == 'monthly': + begin_date, end_date = cleaner.get_start_and_last_days(r.yearMonth) + + elif params['granularity'] == 'totals': + begin_date, ed_discard = cleaner.get_start_and_last_days(r.beginDate) + bd_discard, end_date = cleaner.get_start_and_last_days(r.endDate) + + for m in ['Total_Item_Requests', 'Unique_Item_Requests']: + metric_name = m[0].lower() + m[1:].replace('_', '') + + performance_m = { + 'Period': { + 'Begin_Date': str(begin_date), + 'End_Date': str(end_date) + }, + 'Instance': { + 'Metric_Type': m, + 'Count': str(getattr(r, metric_name)) + } + } + report_items[article_doi]['Performance'].append(performance_m) + + json_results['Report_Items'] = [ri for ri in report_items.values() if ri['Parent_Title']] + + return json_results + + def _json_cr_j1(result_query_reports_cr_j1, params, exceptions): json_results = { "Report_Header": { @@ -864,6 +958,9 @@ def tsv_report_wrapper(request, report_id, result_query, params, exceptions): if report_id == 'ir_a1': return _tsv_report_ir_a1(result_query, params, exceptions) + if report_id == 'ir_a4': + return _tsv_report_ir_a4(result_query, params, exceptions) + if report_id == 'cr_j1': return _tsv_report_cr_j1(result_query, params, exceptions) @@ -1111,6 +1208,86 @@ def _tsv_report_ir_a1(result_query, params, exceptions): return output +def _tsv_report_ir_a4(result_query, params, exceptions): + begin_date, bd_discard = cleaner.get_start_and_last_days(params['begin_date']) + ed_discard, end_date = cleaner.get_start_and_last_days(params['end_date']) + + params['begin_date'] = begin_date + params['end_date'] = end_date + + result = {'headers': _tsv_header(params, exceptions)} + + article2values = {} + article2description = {} + yms = ['Reporting_Period_Total'] + + for ri in result_query: + if ri.articleDOI: + article_key = ri.articleDOI + article_description = (ri.printISSN, ri.onlineISSN, ri.journalTitle, ri.journalURI, ri.journalPublisher, ri.journalCollection, ri.articlePID, ri.articleYOP, ri.articleDOI) + + article2description[article_key] = article_description + + tir = getattr(ri, 'totalItemRequests') + uir = getattr(ri, 'uniqueItemRequests') + + if article_key not in article2values: + article2values[article_key] = {'Reporting_Period_Total': (0, 0)} + + if params['granularity'] == 'monthly': + year_month = cleaner.handle_str_date(ri.yearMonth, str_format=False).strftime('%b-%Y') + if year_month not in yms: + yms.append(year_month) + + if year_month not in article2values[article_key]: + article2values[article_key][year_month] = 0 + + article2values[article_key][year_month] = (tir, uir) + + article2values[article_key]['Reporting_Period_Total'] = tuple(map(sum, zip(article2values[article_key]['Reporting_Period_Total'], (tir, uir)))) + + output = {'rows': []} + for k in values.TSV_REPORT_DEFAULT_HEADERS: + output['rows'].append([k, result['headers'][k]]) + + output['rows'].append(values.TSV_REPORT_IR_A4_ROWS + yms) + + for doi in article2values: + for j, metric_name in enumerate(['Total_Item_Requests', 'Unique_Item_Requests']): + line = [ + doi, + article2description[doi][4], + '', + 'SciELO SUSHI API', + '', + article2description[doi][7], + '', + article2description[doi][8], + '', + '', + '', + '', + article2description[doi][2], + '', + '', + '', + '', + article2description[doi][0], + article2description[doi][1], + article2description[doi][3], + '', + metric_name + ] + + for ym in yms: + ym_v = str(article2values[doi].get(ym, (0, 0))[j]) + line.append(ym_v) + + output['rows'].append(line) + + return output + + def _tsv_report_tr_j1(result_query, params, exceptions): result = {'headers': _tsv_header(params, exceptions)} diff --git a/api/libs/db.py b/api/libs/db.py index e495f17..8498709 100644 --- a/api/libs/db.py +++ b/api/libs/db.py @@ -40,7 +40,7 @@ def get_dates_not_ready(begin_date, end_date, collection, report_id): else: return [] - elif report_id in ('gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1'): + elif report_id in ('gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1', 'ir_a4',): if status_column: not_read_dates = DBSession.query(AggrStatus).filter(and_(AggrStatus.collection == collection, getattr(AggrStatus, status_column) == 0, diff --git a/api/libs/validator.py b/api/libs/validator.py index c7ea965..08a0477 100644 --- a/api/libs/validator.py +++ b/api/libs/validator.py @@ -107,7 +107,7 @@ def validate_parameters(params, expected_params_list=[]): def validate_parameters_according_to_report(report_id, params): validation_results = {'errors': []} - if report_id in ('ir_a1',): + if report_id in ('ir_a1', 'ir_a4',): if 'issn' not in params and 'pid' not in params: validation_results['errors'].append(errors.error_required_filter_missing('issn or pid')) diff --git a/api/models/sql_declarative.py b/api/models/sql_declarative.py index 9f58848..91bcfbe 100644 --- a/api/models/sql_declarative.py +++ b/api/models/sql_declarative.py @@ -281,6 +281,7 @@ class AggrStatus(Base): collection = Column(VARCHAR(3), nullable=False, primary_key=True) date = Column(DATE, nullable=False, primary_key=True) + status_aggr_article_journal_year_month_metric = Column(BOOLEAN, default=False) status_aggr_article_language_year_month_metric = Column(BOOLEAN, default=False) status_aggr_journal_language_year_month_metric = Column(BOOLEAN, default=False) status_aggr_journal_geolocation_year_month_metric = Column(BOOLEAN, default=False) @@ -288,6 +289,26 @@ class AggrStatus(Base): status_aggr_journal_geolocation_yop_year_month_metric = Column(BOOLEAN, default=False) +class AggrArticleJournalYearMonthMetric(Base): + __tablename__ = 'aggr_article_journal_year_month_metric' + __table_args__ = (UniqueConstraint('collection', 'year_month', 'article_id', 'journal_id', name='uni_col_art_jou_ymm_aajymm'),) + __table_args__ += (Index('idx_ymaj_id', 'year_month', 'article_id', 'journal_id'),) + __table_args__ += (Index('idx_yj_id', 'year_month', 'journal_id'),) + __table_args__ += (Index('idx_j_id', 'journal_id'),) + + id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True) + + collection = Column(VARCHAR(3), nullable=False, primary_key=True) + article_id = Column(INTEGER(unsigned=True), ForeignKey('counter_article.id', name='idarticle_aajymm')) + journal_id = Column(INTEGER(unsigned=True), ForeignKey('counter_journal.id', name='idjournal_aajymm')) + year_month = Column(VARCHAR(7), nullable=False) + + total_item_requests = Column(INTEGER, nullable=False) + total_item_investigations = Column(INTEGER, nullable=False) + unique_item_requests = Column(INTEGER, nullable=False) + unique_item_investigations = Column(INTEGER, nullable=False) + + class AggrArticleLanguageYearMonthMetric(Base): __tablename__ = 'aggr_article_language_year_month_metric' __table_args__ = (UniqueConstraint('collection', 'year_month', 'article_id', 'language_id', name='uni_col_art_lan_ymm_aalymm'),) diff --git a/api/static/sql/procedures_v2_gr_j1.sql b/api/static/sql/procedures_v2_gr_j1.sql index 8668d1a..e061954 100644 --- a/api/static/sql/procedures_v2_gr_j1.sql +++ b/api/static/sql/procedures_v2_gr_j1.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE PROCEDURE V2_GR_J1_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J1_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgymm.journal_id as journalID, @@ -35,7 +35,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J1_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J1_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgymm.journal_id as journalID, @@ -70,7 +70,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J1_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J1_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgymm.journal_id as journalID, @@ -109,7 +109,7 @@ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J1_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J1_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgymm.journal_id as journalID, diff --git a/api/static/sql/procedures_v2_gr_j4.sql b/api/static/sql/procedures_v2_gr_j4.sql index 152ce69..dfa0c4d 100644 --- a/api/static/sql/procedures_v2_gr_j4.sql +++ b/api/static/sql/procedures_v2_gr_j4.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J4_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -38,7 +38,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J4_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -76,7 +76,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J4_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -117,7 +117,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_GR_J4_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -157,7 +157,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_GR_J4_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -197,7 +197,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_GR_J4_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -236,7 +236,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_JOURNAL_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_GR_J4_JOURNAL_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajgyymm.journal_id as journalID, @@ -279,7 +279,7 @@ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_GR_J4_JOURNAL_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_GR_J4_JOURNAL_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajgyymm.journal_id as journalID, diff --git a/api/static/sql/procedures_v2_ir_a4.sql b/api/static/sql/procedures_v2_ir_a4.sql new file mode 100644 index 0000000..54e6744 --- /dev/null +++ b/api/static/sql/procedures_v2_ir_a4.sql @@ -0,0 +1,195 @@ +DELIMITER $$ +CREATE PROCEDURE V2_IR_A4_JOURNAL_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collectionAcronym varchar(3), IN collectionAcronymExtra varchar(3), IN yearOfPublication varchar(4)) +BEGIN + SELECT + GROUP_CONCAT(DISTINCT journalCollection) AS journalCollection, + GROUP_CONCAT(DISTINCT journalTitle) AS journalTitle, + GROUP_CONCAT(DISTINCT journalURI) AS journalURI, + GROUP_CONCAT(DISTINCT journalPublisher) AS journalPublisher, + cj2.print_issn AS printISSN, + cj2.online_issn AS onlineISSN, + GROUP_CONCAT(DISTINCT articlePID) AS articlePID, + articleDOI, + articleYOP, + yearMonth, + SUM(total_item_requests) AS totalItemRequests, + SUM(unique_item_requests) AS uniqueItemRequests + FROM + ( + SELECT + cjc.collection AS journalCollection, + cjc.idjournal_jc, + cjc.title AS journalTitle, + cjc.uri AS journalURI, + cjc.publisher_name AS journalPublisher, + ca.yop as articleYOP, + ca.pid AS articlePID, + cac.doi AS articleDOI, + aajymm.`year_month` AS yearMonth, + total_item_requests, + unique_item_requests + FROM + aggr_article_journal_year_month_metric aajymm + JOIN + counter_article ca ON ca.id = aajymm.article_id + JOIN + counter_journal_collection cjc ON cjc.idjournal_jc = aajymm.journal_id + JOIN + counter_article_code cac ON ca.pid = cac.pid_v3 + WHERE + aajymm.journal_id = ( + SELECT + id + FROM + counter_journal cj + WHERE + cj.print_issn = issn OR + cj.online_issn = issn OR + cj.pid_issn = issn + LIMIT 1 + ) AND + cjc.collection = ca.collection AND + cjc.collection in (collectionAcronym, collectionAcronymExtra) AND + ca.yop = yearOfPublication + UNION + SELECT + cjc.collection AS journalCollection, + cjc.idjournal_jc, + cjc.title AS journalTitle, + cjc.uri AS journalURI, + cjc.publisher_name AS journalPublisher, + ca.yop as articleYOP, + ca.pid AS articlePID, + cac.doi AS articleDOI, + aajymm.`year_month` AS yearMonth, + total_item_requests, + unique_item_requests + FROM + aggr_article_journal_year_month_metric aajymm + JOIN + counter_article ca ON ca.id = aajymm.article_id + JOIN + counter_journal_collection cjc ON cjc.idjournal_jc = aajymm.journal_id + JOIN + counter_article_code cac ON ca.pid = cac.pid_v2 + WHERE + aajymm.journal_id = ( + SELECT + id + FROM + counter_journal cj + WHERE + cj.print_issn = issn OR + cj.online_issn = issn OR + cj.pid_issn = issn + LIMIT 1 + ) AND + cjc.collection = ca.collection AND + cjc.collection in (collectionAcronym, collectionAcronymExtra) AND + ca.yop = yearOfPublication + ) AS T1 + JOIN counter_journal cj2 ON cj2.id = idjournal_jc + GROUP BY + articleDOI, + yearMonth + ; +END $$ +DELIMITER ; + +DELIMITER $$ +CREATE PROCEDURE V2_IR_A4_JOURNAL_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collectionAcronym varchar(3), IN collectionAcronymExtra varchar(3), IN yearOfPublication varchar(4)) +BEGIN + SELECT + GROUP_CONCAT(DISTINCT journalCollection) AS journalCollection, + GROUP_CONCAT(DISTINCT journalTitle) AS journalTitle, + GROUP_CONCAT(DISTINCT journalURI) AS journalURI, + GROUP_CONCAT(DISTINCT journalPublisher) AS journalPublisher, + cj2.print_issn AS printISSN, + cj2.online_issn AS onlineISSN, + GROUP_CONCAT(DISTINCT articlePID) AS articlePID, + articleDOI, + articleYOP, + MIN(T1.yearMonth) AS beginDate, + MAX(T1.yearMonth) AS endDate, + SUM(total_item_requests) AS totalItemRequests, + SUM(unique_item_requests) AS uniqueItemRequests + FROM + ( + SELECT + cjc.collection AS journalCollection, + cjc.idjournal_jc, + cjc.title AS journalTitle, + cjc.uri AS journalURI, + cjc.publisher_name AS journalPublisher, + ca.yop as articleYOP, + ca.pid AS articlePID, + cac.doi AS articleDOI, + aajymm.`year_month` AS yearMonth, + total_item_requests, + unique_item_requests + FROM + aggr_article_journal_year_month_metric aajymm + JOIN + counter_article ca ON ca.id = aajymm.article_id + JOIN + counter_journal_collection cjc ON cjc.idjournal_jc = aajymm.journal_id + JOIN + counter_article_code cac ON ca.pid = cac.pid_v3 + WHERE + aajymm.journal_id = ( + SELECT + id + FROM + counter_journal cj + WHERE + cj.print_issn = issn OR + cj.online_issn = issn OR + cj.pid_issn = issn + LIMIT 1 + ) AND + cjc.collection = ca.collection AND + cjc.collection in (collectionAcronym, collectionAcronymExtra) AND + ca.yop = yearOfPublication + UNION + SELECT + cjc.collection AS journalCollection, + cjc.idjournal_jc, + cjc.title AS journalTitle, + cjc.uri AS journalURI, + cjc.publisher_name AS journalPublisher, + ca.yop as articleYOP, + ca.pid AS articlePID, + cac.doi AS articleDOI, + aajymm.`year_month` AS yearMonth, + total_item_requests, + unique_item_requests + FROM + aggr_article_journal_year_month_metric aajymm + JOIN + counter_article ca ON ca.id = aajymm.article_id + JOIN + counter_journal_collection cjc ON cjc.idjournal_jc = aajymm.journal_id + JOIN + counter_article_code cac ON ca.pid = cac.pid_v2 + WHERE + aajymm.journal_id = ( + SELECT + id + FROM + counter_journal cj + WHERE + cj.print_issn = issn OR + cj.online_issn = issn OR + cj.pid_issn = issn + LIMIT 1 + ) AND + cjc.collection = ca.collection AND + cjc.collection in (collectionAcronym, collectionAcronymExtra) AND + ca.yop = yearOfPublication + ) AS T1 + JOIN counter_journal cj2 ON cj2.id = idjournal_jc + GROUP BY + articleDOI + ; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/api/static/sql/procedures_v2_lr_j1.sql b/api/static/sql/procedures_v2_lr_j1.sql index bacf78d..1e8a854 100644 --- a/api/static/sql/procedures_v2_lr_j1.sql +++ b/api/static/sql/procedures_v2_lr_j1.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE PROCEDURE V2_LR_J1_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J1_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlymm.journal_id as journalID, @@ -37,7 +37,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J1_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J1_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlymm.journal_id as journalID, @@ -74,7 +74,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J1_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J1_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlymm.journal_id as journalID, @@ -115,7 +115,7 @@ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J1_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J1_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlymm.journal_id as journalID, diff --git a/api/static/sql/procedures_v2_lr_j4.sql b/api/static/sql/procedures_v2_lr_j4.sql index 9ec41b9..0ca7437 100644 --- a/api/static/sql/procedures_v2_lr_j4.sql +++ b/api/static/sql/procedures_v2_lr_j4.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J4_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -40,7 +40,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J4_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -80,7 +80,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J4_JOURNAL_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -124,7 +124,7 @@ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3)) +CREATE PROCEDURE V2_LR_J4_JOURNAL_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -166,7 +166,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_LR_J4_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -208,7 +208,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_LR_J4_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -249,7 +249,7 @@ END $$ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_JOURNAL_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_LR_J4_JOURNAL_YOP_MONTHLY(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajlyymm.journal_id as journalID, @@ -294,7 +294,7 @@ DELIMITER ; DELIMITER $$ -CREATE PROCEDURE V2_LR_J4_JOURNAL_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), collection_extra varchar(3), yop varchar(4)) +CREATE PROCEDURE V2_LR_J4_JOURNAL_YOP_TOTALS(IN beginDate varchar(7), IN endDate varchar(7), IN issn varchar(9), IN collection varchar(3), IN collection_extra varchar(3), IN yop varchar(4)) BEGIN SELECT ajlyymm.journal_id as journalID, diff --git a/api/utils.py b/api/utils.py index 83ebe18..45b2363 100644 --- a/api/utils.py +++ b/api/utils.py @@ -82,7 +82,7 @@ def get_granularity_and_mode(params): def check_filter_by_yop(report_id, params): yop = params.get('yop', '') - if report_id in ['lr_j4', 'gr_j4', 'ir_a1']: + if report_id in ['lr_j4', 'gr_j4', 'ir_a1', 'ir_a4',]: if yop.isdigit(): return True @@ -116,7 +116,7 @@ def format_error_messages(exceptions: list): def set_collection_extra(report_id, attrs): - if report_id in ('cr_j1', 'gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1'): + if report_id in ('cr_j1', 'gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1', 'ir_a4',): if attrs['collection'] == 'scl': attrs.update({'collection_extra': 'nbr'}) @@ -138,7 +138,7 @@ def wrapper_call_report(report_id, params): else: procedure_name, params_names = values.GRANULARITY_MODE_REPORT_TO_PROCEDURE_AND_PARAMETERS.get(granularity, {}).get(mode, {}).get(report_id, ('', [])) - if report_id in ('gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1',): + if report_id in ('gr_j1', 'lr_j1', 'gr_j4', 'lr_j4', 'lr_a1', 'ir_a4',): params['begin_date'] = cleaner.handle_str_date(params['begin_date'], year_month_only=True) params['end_date'] = cleaner.handle_str_date(params['end_date'], year_month_only=True) diff --git a/api/values.py b/api/values.py index 3fbe702..b27b135 100644 --- a/api/values.py +++ b/api/values.py @@ -65,6 +65,9 @@ DB_CALL_IR_A1_JOURNAL_TOTALS = 'CALL IR_A1_JOURNAL_TOTALS("%s", "%s", "%s", "%s", "%s")' DB_CALL_IR_A1_JOURNAL_MONTHLY = 'CALL IR_A1_JOURNAL_MONTHLY("%s", "%s", "%s", "%s", "%s")' +DB_CALL_V2_IR_A4_JOURNAL_YOP_TOTALS = 'CALL V2_IR_A1_JOURNAL_TOTALS("%s", "%s", "%s", "%s", "%s", "%s")' +DB_CALL_V2_IR_A4_JOURNAL_YOP_MONTHLY = 'CALL V2_IR_A1_JOURNAL_MONTHLY("%s", "%s", "%s", "%s", "%s", "%s")' + DB_CALL_V2_TR_J1_JOURNAL_TOTALS = 'CALL V2_TR_J1_JOURNAL_TOTALS("%s", "%s", "%s", "%s")' DB_CALL_V2_TR_J1_JOURNAL_MONTHLY = 'CALL V2_TR_J1_JOURNAL_MONTHLY("%s", "%s", "%s", "%s")' @@ -112,6 +115,7 @@ REPORT_ID_TO_COLUMN_STATUS = { 'cr_j1': 'status_sushi_journal_metric', 'ir_a1': 'status_sushi_article_metric', + 'ir_a4': 'status_aggr_article_journal_year_month_metric', 'tr_j1': 'status_sushi_journal_metric', 'tr_j4': 'status_sushi_journal_yop_metric', 'lr_j1': 'status_aggr_journal_language_year_month_metric', @@ -170,6 +174,7 @@ 'lr_j4': (DB_CALL_V2_LR_J4_JOURNAL_TOTALS, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra']), 'tr_j1': (DB_CALL_V2_TR_J1_JOURNAL_TOTALS, ['begin_date', 'end_date', 'issn', 'collection']), 'yop': { + 'ir_a4': (DB_CALL_V2_IR_A4_JOURNAL_YOP_TOTALS, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), 'gr_j4': (DB_CALL_V2_GR_J4_JOURNAL_YOP_TOTALS, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), 'lr_j4': (DB_CALL_V2_LR_J4_JOURNAL_YOP_TOTALS, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), } @@ -198,6 +203,7 @@ 'lr_j4': (DB_CALL_V2_LR_J4_JOURNAL_MONTHLY, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra']), 'tr_j1': (DB_CALL_V2_TR_J1_JOURNAL_MONTHLY, ['begin_date', 'end_date', 'issn', 'collection']), 'yop': { + 'ir_a4': (DB_CALL_V2_IR_A4_JOURNAL_YOP_MONTHLY, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), 'gr_j4': (DB_CALL_V2_GR_J4_JOURNAL_YOP_MONTHLY, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), 'lr_j4': (DB_CALL_V2_LR_J4_JOURNAL_YOP_MONTHLY, ['begin_date', 'end_date', 'issn', 'collection', 'collection_extra', 'yop']), } @@ -370,5 +376,30 @@ 'Metric_Type', ] +TSV_REPORT_IR_A4_ROWS = [ + 'Item', + 'Publisher', + 'Publisher_ID', + 'Platform', + 'Authors', + 'Publication_Date', + 'Article_Version', + 'DOI', + 'Proprietary_ID', + 'Print_ISSN', + 'Online_ISSN', + 'URI', + 'Parent_Title', + 'Parent_Authors', + 'Parent_Article_Version', + 'Parent_DOI', + 'Parent_Proprietary_ID', + 'Parent_Print_ISSN', + 'Parent_Online_ISSN', + 'Parent_URI', + 'Access_Type', + 'Metric_Type', +] + MIN_YEAR = 1900 MAX_YEAR = 2100 diff --git a/docs/guide.md b/docs/guide.md index a28063a..6e25d5e 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -373,7 +373,7 @@ _Total Item Investigations_ é uma métrica que contabiliza cada clique que apre Nas estruturas da Rede SciELO foram implantados três relatórios COUNTER Release 5 e três extensões. Os relatórios responsáveis por obter dados agregados por periódico são **TR_J1**, **LR_J1**, **GR_J1** e **TR_J4**, sendo este último considerando o ano de publicação dos documentos. Os dados agregados por artigo são representados pelo relatório **IR_A1**. Dados agregados para uma coleção inteira são representados por relatórios **CR_J1**. Observe que, originalmente, não existem relatórios **GR_J1**, **LR_J1** e **CR_J1** no Project COUNTER R5 - essas foram extensões implementadas e contextualizadas ao Programa SciELO. #### Item Master Report A1 (IR_A1) -Relatórios **IR_A1** fornecem um resumo da atividade relacionada ao conteúdo no nível de artigo. É um meio de avaliar o impacto que um artigo possui, em termos de acesso. É preciso conhecer o identificador único de um artigo (os códigos PID, no âmbito SciELO) em todas as coleções das quais faz parte. É possível obter, por coleção, os acessos relacionados a um periódico. Para isso, basta informar os parâmetros `issn` e `yop` (ano de publicação). +Relatórios **IR_A1** fornecem um resumo da atividade relacionada ao conteúdo no nível de artigo. É um meio de avaliar o impacto que um artigo possui, em termos de acesso. É preciso conhecer o identificador único de um artigo (os códigos PID, no âmbito SciELO) em todas as coleções das quais faz parte. É possível obter, por coleção, os acessos relacionados a um periódico. Para isso, basta informar os parâmetros `issn` e `yop` (ano de publicação). A versão dois desse relatório está sob o código **IR_A4**. Assim, é possível informar o parâmetro _api=v2_ em conjunto com os valores de `issn` e `yop` para obter os dados agregando-se os resultados por coleção (independentemente da quantidade de sites que a ela estão associados) - para isso, basta usar o código `ir_a4`, ao invés de `ir_a1`. #### Title Master Report J1 (TR_J1) Relatórios **TR_J1** abordam o acesso a conteúdo no nível de periódico, excluindo documentos Gold Open Access. A métrica Unique Item Requests, no contexto desse relatório, fornece uso comparável em plataformas de periódicos, reduzindo o efeito inflacionário que ocorre quando um texto completo em HTML é exibido automaticamente e o usuário acessa a versão em PDF. A métrica Total Item Requests mostra a atividade geral relacionada ao periódico. É preciso informar o código ISSN de um periódico, caso deseja-se saber apenas os dados a ele referentes. Na situação em que essa informação é omitida, são retornados dados de todos os periódicos da coleção. diff --git a/setup.py b/setup.py index bea7351..6583c3f 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( name='scielo-sushiapi', - version='0.9.4', + version='0.9.5.0', packages=find_packages( exclude=["*.tests", "*.tests.*", "tests.*", "tests", "docs"] ),