quick-pp 0.2.66__tar.gz → 0.2.68__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. {quick_pp-0.2.66 → quick_pp-0.2.68}/.gitignore +1 -0
  2. {quick_pp-0.2.66 → quick_pp-0.2.68}/PKG-INFO +1 -1
  3. {quick_pp-0.2.66 → quick_pp-0.2.68}/pyproject.toml +1 -1
  4. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/__init__.py +1 -1
  5. quick_pp-0.2.68/quick_pp/database/db_connector.py +95 -0
  6. quick_pp-0.2.68/quick_pp/database/models.py +156 -0
  7. quick_pp-0.2.68/quick_pp/database/objects.py +456 -0
  8. quick_pp-0.2.68/quick_pp/database/setup_postgresql_db.sql +171 -0
  9. quick_pp-0.2.68/quick_pp/database/setup_sqlite_db.sql +163 -0
  10. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/las_handler.py +150 -54
  11. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/qaqc.py +2 -2
  12. quick_pp-0.2.68/quick_pp/rock_physics/__init__.py +0 -0
  13. quick_pp-0.2.66/quick_pp/objects.py +0 -216
  14. {quick_pp-0.2.66 → quick_pp-0.2.68}/LICENSE +0 -0
  15. {quick_pp-0.2.66 → quick_pp-0.2.68}/README.md +0 -0
  16. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/__init__.py +0 -0
  17. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/exceptions.py +0 -0
  18. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/fastapi_mlflow/__init__.py +0 -0
  19. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/fastapi_mlflow/_mlflow_types.py +0 -0
  20. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/fastapi_mlflow/applications.py +0 -0
  21. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/fastapi_mlflow/exceptions.py +0 -0
  22. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/fastapi_mlflow/predictors.py +0 -0
  23. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/main.py +0 -0
  24. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/mlflow_model_deployment.py +0 -0
  25. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/router.py +0 -0
  26. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/lithology_hc_correction.py +0 -0
  27. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/lithology_ssc.py +0 -0
  28. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/lithology_vsh_gr.py +0 -0
  29. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/permeability_choo.py +0 -0
  30. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/permeability_others.py +0 -0
  31. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/porosity.py +0 -0
  32. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/ressum.py +0 -0
  33. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_archie.py +0 -0
  34. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_b.py +0 -0
  35. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_qv.py +0 -0
  36. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_rw.py +0 -0
  37. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_temp_grad.py +0 -0
  38. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/schemas/saturation_waxman_smits.py +0 -0
  39. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/chat.py +0 -0
  40. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/las_handler.py +0 -0
  41. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/lithology.py +0 -0
  42. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/permeability.py +0 -0
  43. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/porosity.py +0 -0
  44. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/reservoir_summary.py +0 -0
  45. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/services/saturation.py +0 -0
  46. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/static/favicon.ico +0 -0
  47. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/static/logo.png +0 -0
  48. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/template/chat.html +0 -0
  49. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/api/template/home.html +0 -0
  50. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/cli.py +0 -0
  51. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/config.py +0 -0
  52. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/core_calibration.py +0 -0
  53. {quick_pp-0.2.66/quick_pp/machine_learning → quick_pp-0.2.68/quick_pp/database}/__init__.py +0 -0
  54. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/fluid_type.py +0 -0
  55. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/__init__.py +0 -0
  56. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/carbonate.py +0 -0
  57. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/multi_mineral.py +0 -0
  58. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/sand_shale.py +0 -0
  59. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/sand_silt_clay.py +0 -0
  60. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/lithology/thin_beds.py +0 -0
  61. {quick_pp-0.2.66/quick_pp/plotter → quick_pp-0.2.68/quick_pp/machine_learning}/__init__.py +0 -0
  62. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/config.py +0 -0
  63. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/feature_engineering.py +0 -0
  64. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/mock_data/mock_data.parquet +0 -0
  65. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/predict_pipeline.py +0 -0
  66. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/train_pipeline.py +0 -0
  67. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/machine_learning/utils.py +0 -0
  68. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/permeability.py +0 -0
  69. {quick_pp-0.2.66/quick_pp/rock_physics → quick_pp-0.2.68/quick_pp/plotter}/__init__.py +0 -0
  70. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/plotter/plotter.py +0 -0
  71. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/plotter/well_log.py +0 -0
  72. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/plotter/well_log_config.py +0 -0
  73. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/porosity.py +0 -0
  74. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/ressum.py +0 -0
  75. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/rock_physics/geomechanics.py +0 -0
  76. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/rock_physics/geophysics.py +0 -0
  77. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/rock_physics/rpm.py +0 -0
  78. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/rock_type.py +0 -0
  79. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/saturation.py +0 -0
  80. {quick_pp-0.2.66 → quick_pp-0.2.68}/quick_pp/utils.py +0 -0
@@ -121,3 +121,4 @@ data/*
121
121
  chainlit*
122
122
  .files**
123
123
  **_info**
124
+ **/quick_pp.db*
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quick-pp
3
- Version: 0.2.66
3
+ Version: 0.2.68
4
4
  Summary: Python package to assist in providing quick-look/ preliminary petrophysical estimation.
5
5
  Project-URL: Homepage, https://github.com/imranfadhil/quick_pp
6
6
  Author-email: Imran Fadhil <imranfadhil@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quick-pp"
7
- version = "0.2.66"
7
+ version = "0.2.68"
8
8
  description = "Python package to assist in providing quick-look/ preliminary petrophysical estimation."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -20,4 +20,4 @@ logging.getLogger("mlflow").setLevel(logging.WARNING)
20
20
 
21
21
  __author__ = """Imran Fadhil"""
22
22
  __email__ = 'imranfadhil@gmail.com'
23
- __version__ = '0.2.66' # Need to be updated manually when releasing a new version/ change in pyproject.toml
23
+ __version__ = '0.2.68' # Need to be updated manually when releasing a new version/ change in pyproject.toml
@@ -0,0 +1,95 @@
1
+ import os
2
+ from contextlib import contextmanager
3
+ from typing import Generator
4
+
5
+ from sqlalchemy import create_engine
6
+ from sqlalchemy.engine import Engine
7
+ from sqlalchemy.orm import Session, sessionmaker
8
+
9
+
10
+ class DBConnector:
11
+ """
12
+ Manages database connections and sessions using SQLAlchemy.
13
+
14
+ This class follows a singleton-like pattern for the engine and session maker
15
+ to ensure that there is only one engine instance per application, which is
16
+ a recommended practice for SQLAlchemy.
17
+ """
18
+
19
+ _engine: Engine | None = None
20
+ _Session: sessionmaker[Session] | None = None
21
+
22
+ def __init__(self, db_url: str | None = None):
23
+ """
24
+ Initializes the DBConnector. If an engine already exists, it does nothing.
25
+
26
+ Args:
27
+ db_url (str | None): The database connection URL. If not provided,
28
+ it will try to use the QPP_DATABASE_URL environment
29
+ variable. Defaults to a local SQLite database
30
+ if the environment variable is not set.
31
+ """
32
+ if DBConnector._engine is not None:
33
+ return
34
+
35
+ if db_url is None:
36
+ # Default to a local SQLite DB if no URL is provided.
37
+ db_url = os.environ.get("QPP_DATABASE_URL", "sqlite:///./data/quick_pp.db")
38
+
39
+ DBConnector._engine = create_engine(db_url, pool_pre_ping=True)
40
+ DBConnector._Session = sessionmaker(
41
+ autocommit=False, autoflush=False, bind=DBConnector._engine
42
+ )
43
+
44
+ @contextmanager
45
+ def get_session(self) -> Generator[Session, None, None]:
46
+ """
47
+ Provides a transactional scope around a series of operations.
48
+
49
+ This context manager ensures that the session is properly closed.
50
+ It will also roll back the transaction if an exception occurs.
51
+ """
52
+ if DBConnector._Session is None:
53
+ raise RuntimeError("DBConnector not initialized. Call __init__ first.")
54
+
55
+ session: Session = DBConnector._Session()
56
+ try:
57
+ yield session
58
+ session.commit()
59
+ except Exception:
60
+ session.rollback()
61
+ raise
62
+ finally:
63
+ session.close()
64
+
65
+ def run_sql_script(self, script_path: str):
66
+ """
67
+ Executes an SQL script file.
68
+
69
+ Args:
70
+ script_path (str): The path to the SQL script file.
71
+ """
72
+ if DBConnector._engine is None:
73
+ raise RuntimeError("DBConnector not initialized. Call __init__ first.")
74
+
75
+ with open(script_path, 'r') as f:
76
+ sql_script = f.read()
77
+
78
+ with DBConnector._engine.connect() as connection:
79
+ raw_connection = connection.connection
80
+ raw_connection.executescript(sql_script)
81
+
82
+ def setup_db(self):
83
+ """
84
+ Setup quick_pp database.
85
+ """
86
+ script_dir = os.path.dirname(__file__)
87
+ db_type = "sqlite" if "sqlite" in DBConnector._engine.url.drivername else "postgresql"
88
+ if db_type == "sqlite":
89
+ sql_script = "setup_sqlite_db.sql"
90
+ elif db_type == "postgresql":
91
+ sql_script = "setup_postgresql_db.sql"
92
+ else:
93
+ raise ValueError(f"Unsupported database type: {db_type}")
94
+
95
+ self.run_sql_script(os.path.join(script_dir, sql_script))
@@ -0,0 +1,156 @@
1
+ from datetime import datetime
2
+ from typing import List, Optional, Dict, Any
3
+
4
+ from sqlalchemy import (
5
+ Integer,
6
+ String,
7
+ JSON,
8
+ REAL,
9
+ Text,
10
+ ForeignKey,
11
+ UniqueConstraint,
12
+ CheckConstraint,
13
+ )
14
+ from sqlalchemy.orm import declarative_base, relationship, Mapped, mapped_column
15
+
16
+ Base = declarative_base()
17
+
18
+
19
+ class User(Base):
20
+ __tablename__ = "users"
21
+
22
+ user_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
23
+ username: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
24
+ email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
25
+ hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
26
+ created_at: Mapped[datetime] = mapped_column(Text, default=datetime.now, nullable=False)
27
+
28
+ projects: Mapped[List["Project"]] = relationship("Project", back_populates="creator")
29
+ project_memberships: Mapped[List["ProjectMember"]] = relationship("ProjectMember", back_populates="user")
30
+ audit_logs: Mapped[List["AuditLog"]] = relationship("AuditLog", back_populates="user")
31
+
32
+ def __repr__(self):
33
+ return f"<User(user_id={self.user_id}, username='{self.username}')>"
34
+
35
+
36
+ class Project(Base):
37
+ __tablename__ = "projects"
38
+
39
+ project_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
40
+ name: Mapped[str] = mapped_column(String(255), nullable=False)
41
+ description: Mapped[Optional[str]] = mapped_column(Text)
42
+ created_by: Mapped[Optional[int]] = mapped_column(ForeignKey("users.user_id", ondelete="SET NULL"))
43
+ created_at: Mapped[datetime] = mapped_column(Text, default=datetime.now, nullable=False)
44
+ updated_at: Mapped[datetime] = mapped_column(Text, default=datetime.now, onupdate=datetime.now, nullable=False)
45
+
46
+ creator: Mapped[Optional["User"]] = relationship("User", back_populates="projects")
47
+ members: Mapped[List["ProjectMember"]] = relationship("ProjectMember", back_populates="project")
48
+ wells: Mapped[List["Well"]] = relationship("Well", back_populates="project", cascade="all, delete-orphan")
49
+
50
+ def __repr__(self):
51
+ return f"<Project(project_id={self.project_id}, name='{self.name}')>"
52
+
53
+
54
+ class ProjectMember(Base):
55
+ __tablename__ = "project_members"
56
+
57
+ project_id: Mapped[int] = mapped_column(ForeignKey("projects.project_id", ondelete="CASCADE"), primary_key=True)
58
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.user_id", ondelete="CASCADE"), primary_key=True)
59
+ role: Mapped[str] = mapped_column(String(50), nullable=False, default="viewer")
60
+
61
+ __table_args__ = (
62
+ CheckConstraint(role.in_(['admin', 'editor', 'viewer']), name='role_check'),
63
+ )
64
+
65
+ project: Mapped["Project"] = relationship("Project", back_populates="members")
66
+ user: Mapped["User"] = relationship("User", back_populates="project_memberships")
67
+
68
+ def __repr__(self):
69
+ return f"<ProjectMember(project_id={self.project_id}, user_id={self.user_id}, role='{self.role}')>"
70
+
71
+
72
+ class Well(Base):
73
+ __tablename__ = "wells"
74
+
75
+ well_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
76
+ project_id: Mapped[int] = mapped_column(ForeignKey("projects.project_id", ondelete="CASCADE"), nullable=False)
77
+ name: Mapped[str] = mapped_column(String(255), nullable=False)
78
+ uwi: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
79
+ depth_uom: Mapped[Optional[str]] = mapped_column(String(50))
80
+
81
+ header_data: Mapped[Optional[Dict[str, Any]]] = mapped_column("header_data", JSON)
82
+ config_data: Mapped[Optional[Dict[str, Any]]] = mapped_column("config_data", JSON)
83
+
84
+ created_at: Mapped[datetime] = mapped_column(Text, default=datetime.now, nullable=False)
85
+ updated_at: Mapped[datetime] = mapped_column(Text, default=datetime.now, onupdate=datetime.now)
86
+
87
+ project: Mapped["Project"] = relationship("Project", back_populates="wells")
88
+ curves: Mapped[List["Curve"]] = relationship("Curve", back_populates="well", cascade="all, delete-orphan")
89
+
90
+ def __repr__(self):
91
+ return f"<Well(well_id={self.well_id}, name='{self.name}', uwi='{self.uwi}')>"
92
+
93
+
94
+ class Curve(Base):
95
+ __tablename__ = "curves"
96
+
97
+ curve_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
98
+ well_id: Mapped[int] = mapped_column(ForeignKey("wells.well_id", ondelete="CASCADE"), nullable=False)
99
+ mnemonic: Mapped[str] = mapped_column(String(100), nullable=False)
100
+ unit: Mapped[Optional[str]] = mapped_column(String(50))
101
+ description: Mapped[Optional[str]] = mapped_column(Text)
102
+ data_type: Mapped[str] = mapped_column(String(50), nullable=False, default='numeric')
103
+
104
+ __table_args__ = (
105
+ UniqueConstraint("well_id", "mnemonic", name="uq_well_id_mnemonic"),
106
+ CheckConstraint(data_type.in_(['numeric', 'text']), name='data_type_check'),
107
+ )
108
+
109
+ well: Mapped["Well"] = relationship("Well", back_populates="curves")
110
+ data: Mapped[List["CurveData"]] = relationship("CurveData", back_populates="curve", cascade="all, delete-orphan")
111
+
112
+ def __repr__(self):
113
+ return f"<Curve(curve_id={self.curve_id}, well_id={self.well_id}, mnemonic='{self.mnemonic}')>"
114
+
115
+
116
+ class CurveData(Base):
117
+ __tablename__ = "curve_data"
118
+
119
+ curve_data_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
120
+ curve_id: Mapped[int] = mapped_column(ForeignKey("curves.curve_id", ondelete="CASCADE"), nullable=False)
121
+ depth: Mapped[float] = mapped_column(REAL, nullable=False)
122
+ value_numeric: Mapped[Optional[float]] = mapped_column(REAL)
123
+ value_text: Mapped[Optional[str]] = mapped_column(Text)
124
+
125
+ __table_args__ = (
126
+ UniqueConstraint("curve_id", "depth", name="uq_curve_id_depth"),
127
+ CheckConstraint(
128
+ "(value_numeric IS NOT NULL AND value_text IS NULL) OR "
129
+ "(value_numeric IS NULL AND value_text IS NOT NULL) OR "
130
+ "(value_numeric IS NULL AND value_text IS NULL)",
131
+ name="check_one_value_is_null"
132
+ )
133
+ )
134
+
135
+ curve: Mapped["Curve"] = relationship("Curve", back_populates="data")
136
+
137
+ def __repr__(self):
138
+ return f"<CurveData(curve_id={self.curve_id}, depth={self.depth}, " \
139
+ f"num={self.value_numeric}, txt='{self.value_text}')>"
140
+
141
+
142
+ class AuditLog(Base):
143
+ __tablename__ = "audit_log"
144
+
145
+ log_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
146
+ user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.user_id", ondelete="SET NULL"))
147
+ action: Mapped[str] = mapped_column(String(10), nullable=False)
148
+ table_name: Mapped[str] = mapped_column(String(100), nullable=False)
149
+ record_id: Mapped[Optional[str]] = mapped_column(Text)
150
+ timestamp: Mapped[datetime] = mapped_column(Text, default=datetime.now, nullable=False)
151
+ changes: Mapped[Optional[Dict[str, Any]]] = mapped_column("changes", JSON)
152
+
153
+ user: Mapped[Optional["User"]] = relationship("User", back_populates="audit_logs")
154
+
155
+ def __repr__(self):
156
+ return f"<AuditLog(log_id={self.log_id}, table='{self.table_name}', action='{self.action}')>"