-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
203 additions
and
104 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
dags/common/models/library/library_cern_publication_records.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sqlalchemy import Column, DateTime, Float, Integer, func | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class LibraryCernPublicationRecords(Base): | ||
__tablename__ = "library_cern_publication_records" | ||
|
||
year = Column(Integer, primary_key=True) | ||
publications_total_count = Column(Float) | ||
conference_proceedings_count = Column(Float) | ||
non_journal_proceedings_count = Column(Float) | ||
created_at = Column(DateTime, default=func.now()) | ||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) |
14 changes: 14 additions & 0 deletions
14
dags/common/models/library/library_new_items_in_the_institutional_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from sqlalchemy import Column, DateTime, Float, Integer, func | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class LibraryNewItemsInTheInstitutionalRepository(Base): | ||
__tablename__ = "library_items_in_the_institutional_repository" | ||
|
||
year = Column(Integer, primary_key=True) | ||
inspire_arxiv_records = Column(Float) | ||
inspire_curators_records = Column(Float) | ||
created_at = Column(DateTime, default=func.now()) | ||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sqlalchemy import Column, DateTime, Float, Integer, func | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class OAGoldenOpenAccess(Base): | ||
__tablename__ = "oa_golden_open_access" | ||
|
||
year = Column(Integer, primary_key=True) | ||
cern_read_and_publish = Column(Float) | ||
cern_individual_apcs = Column(Float) | ||
scoap3 = Column(Float) | ||
other = Column(Float) | ||
other_collective_models = Column(Float) | ||
created_at = Column(DateTime, default=func.now()) | ||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from sqlalchemy import Column, DateTime, Float, Integer, func | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class OAOpenAccess(Base): | ||
__tablename__ = "oa_open_access" | ||
|
||
year = Column(Integer, primary_key=True) | ||
closed_access = Column(Float) | ||
bronze_open_access = Column(Float) | ||
green_open_access = Column(Float) | ||
gold_open_access = Column(Float) | ||
created_at = Column(DateTime, default=func.now()) | ||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from airflow.decorators import task | ||
from airflow.hooks.postgres_hook import PostgresHook | ||
from executor_config import kubernetes_executor_config | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
|
||
def get_session(conn_id: str): | ||
hook = PostgresHook(postgres_conn_id=conn_id) | ||
engine = hook.get_sqlalchemy_engine() | ||
return sessionmaker(bind=engine)() | ||
|
||
|
||
def sqlalchemy_task(conn_id: str): | ||
def decorator(func): | ||
@task(executor_config=kubernetes_executor_config) | ||
def wrapper(*args, **kwargs): | ||
session = get_session(conn_id) | ||
try: | ||
result = func(*args, session=session, **kwargs) | ||
session.commit() | ||
return result | ||
except SQLAlchemyError as e: | ||
session.rollback() | ||
raise e | ||
finally: | ||
session.close() | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.