commons-metrics 0.0.29__tar.gz → 0.0.31__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.
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/PKG-INFO +1 -1
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/__init__.py +1 -1
- commons_metrics-0.0.31/commons_metrics/connection_database.py +25 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/repositories.py +128 -5
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/s3_file_manager.py +0 -2
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/PKG-INFO +1 -1
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/SOURCES.txt +1 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/setup.py +1 -1
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/LICENSE +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/README.md +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/azure_devops_client.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/cache_manager.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/commons_repos_client.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/database.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/date_utils.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/github_api_client.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/text_simplifier.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/update_design_components.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/util.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/variable_finder.py +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/dependency_links.txt +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/requires.txt +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/top_level.txt +0 -0
- {commons_metrics-0.0.29 → commons_metrics-0.0.31}/setup.cfg +0 -0
|
@@ -12,4 +12,4 @@ from .text_simplifier import TextSimplifier
|
|
|
12
12
|
from .variable_finder import VariableFinder
|
|
13
13
|
|
|
14
14
|
__all__ = ['Util', 'DatabaseConnection', 'ComponentRepository', 'UpdateDesignSystemComponents', 'GitHubAPIClient', 'AzureDevOpsClient', 'S3FileManager', 'CacheManager', 'CommonsReposClient', 'DateUtils', 'TextSimplifier', 'VariableFinder']
|
|
15
|
-
__version__ = '0.0.
|
|
15
|
+
__version__ = '0.0.31'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from lib.commons_metrics.commons_metrics import DatabaseConnection, Util, ComponentRepository
|
|
2
|
+
|
|
3
|
+
class ConnectionDatabase:
|
|
4
|
+
"""Manager for connection with database"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, secret_name: str, logger: str, aws_region: str):
|
|
7
|
+
self.secret_name = secret_name
|
|
8
|
+
self.logger = logger
|
|
9
|
+
self.aws_region = aws_region
|
|
10
|
+
|
|
11
|
+
def get_connection_database_from_secret(self) -> ComponentRepository:
|
|
12
|
+
"""
|
|
13
|
+
Retrieve connection database from AWS secrets manager
|
|
14
|
+
"""
|
|
15
|
+
secret_json = Util.get_secret_aws(self.secret_name, self.logger, self.aws_region)
|
|
16
|
+
db_connection = DatabaseConnection()
|
|
17
|
+
db_connection.connect({
|
|
18
|
+
'host': secret_json["host"],
|
|
19
|
+
'port': secret_json["port"],
|
|
20
|
+
'dbname': secret_json["dbname"],
|
|
21
|
+
'username': secret_json["username"],
|
|
22
|
+
'password': secret_json["password"]
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return ComponentRepository(db_connection)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import List
|
|
2
2
|
|
|
3
3
|
class ComponentRepository:
|
|
4
4
|
"""
|
|
@@ -8,17 +8,48 @@ class ComponentRepository:
|
|
|
8
8
|
self.db = db_connection
|
|
9
9
|
|
|
10
10
|
def save_component(self, technical_name, functional_name, id_type, folder, class_name, status):
|
|
11
|
+
cursor = None
|
|
12
|
+
try:
|
|
13
|
+
cursor = self.db.connection.cursor()
|
|
14
|
+
upsert_query = """
|
|
15
|
+
INSERT INTO schmetrc.component (technical_name, functional_name, type_id, folder, class_name, status)
|
|
16
|
+
VALUES (%s, %s, %s, %s, %s, %s)
|
|
17
|
+
ON CONFLICT (technical_name, type_id)
|
|
18
|
+
DO UPDATE SET
|
|
19
|
+
functional_name = EXCLUDED.functional_name,
|
|
20
|
+
folder = EXCLUDED.folder,
|
|
21
|
+
class_name = EXCLUDED.class_name,
|
|
22
|
+
status = EXCLUDED.status
|
|
23
|
+
RETURNING id;
|
|
24
|
+
"""
|
|
25
|
+
cursor.execute(upsert_query, (technical_name, functional_name, id_type, folder, class_name, status))
|
|
26
|
+
component_id = cursor.fetchone()[0]
|
|
27
|
+
self.db.commit_transaction()
|
|
28
|
+
return component_id
|
|
29
|
+
|
|
30
|
+
except Exception as e:
|
|
31
|
+
self.db.rollback_transaction()
|
|
32
|
+
raise Exception(f"Error saving component '{technical_name}': {str(e)}")
|
|
33
|
+
finally:
|
|
34
|
+
if cursor:
|
|
35
|
+
cursor.close()
|
|
36
|
+
|
|
37
|
+
def save_version(self, version, component_id, creation_date, status):
|
|
11
38
|
cursor = None
|
|
12
39
|
try:
|
|
13
40
|
cursor = self.db.connection.cursor()
|
|
14
41
|
|
|
15
42
|
insert_query = """
|
|
16
|
-
INSERT INTO schmetrc.
|
|
17
|
-
VALUES (%s, %s, %s, %s
|
|
43
|
+
INSERT INTO schmetrc.component_version(version, component_id, creation_date, status)
|
|
44
|
+
VALUES (%s, %s, %s, %s)
|
|
45
|
+
ON CONFLICT (version, component_id)
|
|
46
|
+
DO UPDATE SET
|
|
47
|
+
creation_date = EXCLUDED.creation_date,
|
|
48
|
+
status = EXCLUDED.status
|
|
18
49
|
RETURNING id;
|
|
19
50
|
"""
|
|
20
51
|
|
|
21
|
-
cursor.execute(insert_query, (
|
|
52
|
+
cursor.execute(insert_query, (version, component_id, creation_date, status))
|
|
22
53
|
component_id = cursor.fetchone()[0]
|
|
23
54
|
self.db.commit_transaction()
|
|
24
55
|
|
|
@@ -26,7 +57,7 @@ class ComponentRepository:
|
|
|
26
57
|
|
|
27
58
|
except Exception as e:
|
|
28
59
|
self.db.rollback_transaction()
|
|
29
|
-
raise Exception(f"Error saving
|
|
60
|
+
raise Exception(f"Error saving version '{version}': {str(e)}")
|
|
30
61
|
finally:
|
|
31
62
|
if cursor:
|
|
32
63
|
cursor.close()
|
|
@@ -73,6 +104,61 @@ class ComponentRepository:
|
|
|
73
104
|
if cursor:
|
|
74
105
|
cursor.close()
|
|
75
106
|
|
|
107
|
+
def query_back_components(self, is_required_all_name=False) -> List[dict]:
|
|
108
|
+
"""
|
|
109
|
+
Query back-end components from the database and return a list of dictionaries.
|
|
110
|
+
This method:
|
|
111
|
+
- Opens a DB cursor from `self.db.connection`.
|
|
112
|
+
- Executes a SQL query to select `id` and `technical_name` from `component` table
|
|
113
|
+
where `technical_name` contains the substring 'ms'.
|
|
114
|
+
- Builds a list of components as dictionaries:
|
|
115
|
+
* If `is_required_all_name` is True:
|
|
116
|
+
{'id': <id>, 'name': <technical_name>}
|
|
117
|
+
* If `is_required_all_name` is False:
|
|
118
|
+
{'id': <id>, 'name': <technical_name[6:]>}
|
|
119
|
+
(i.e., the component name is sliced starting at index 6.)
|
|
120
|
+
- Ensures the cursor is closed in a `finally` block.
|
|
121
|
+
|
|
122
|
+
Parameters
|
|
123
|
+
----------
|
|
124
|
+
is_required_all_name : bool, optional
|
|
125
|
+
When True, returns the full `technical_name`. When False, returns the name
|
|
126
|
+
with the first 6 characters removed.
|
|
127
|
+
"""
|
|
128
|
+
cursor = None
|
|
129
|
+
try:
|
|
130
|
+
cursor = self.db.connection.cursor()
|
|
131
|
+
|
|
132
|
+
query = """
|
|
133
|
+
SELECT id, technical_name
|
|
134
|
+
FROM schmetrc.component
|
|
135
|
+
WHERE technical_name LIKE '%-ms-%'
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
cursor.execute(query)
|
|
139
|
+
results = cursor.fetchall()
|
|
140
|
+
|
|
141
|
+
components = []
|
|
142
|
+
for row in results:
|
|
143
|
+
if is_required_all_name:
|
|
144
|
+
components.append({
|
|
145
|
+
'id': row[0],
|
|
146
|
+
'name': row[1],
|
|
147
|
+
})
|
|
148
|
+
else:
|
|
149
|
+
components.append({
|
|
150
|
+
'id': row[0],
|
|
151
|
+
'name': row[1][6:]
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
return components
|
|
155
|
+
|
|
156
|
+
except Exception as e:
|
|
157
|
+
raise Exception(f"Error querying back components : {str(e)}")
|
|
158
|
+
finally:
|
|
159
|
+
if cursor:
|
|
160
|
+
cursor.close()
|
|
161
|
+
|
|
76
162
|
def query_versions_by_type(self, type_id: int) -> list:
|
|
77
163
|
"""
|
|
78
164
|
Consulta versiones de un tipo específico (mobile o web) en la base de datos
|
|
@@ -143,6 +229,43 @@ class ComponentRepository:
|
|
|
143
229
|
if cursor:
|
|
144
230
|
cursor.close()
|
|
145
231
|
|
|
232
|
+
def save_component_roi(self, data: List[dict]):
|
|
233
|
+
"""
|
|
234
|
+
Insert component ROI records into the `component_roi` table and return all ids inserted.
|
|
235
|
+
This method:
|
|
236
|
+
- Acquires a DB cursor from `self.db.connection`.
|
|
237
|
+
- Executes an `INSERT ... RETURNING id` statement for each row in `data`.
|
|
238
|
+
- Calls `cursor.fetchone()` once after the loop to obtain the `id` returned by the
|
|
239
|
+
last executed INSERT.
|
|
240
|
+
- Commits the transaction via `self.db.commit_transaction()` on success.
|
|
241
|
+
- Rolls back the transaction via `self.db.rollback_transaction()` and raises a
|
|
242
|
+
`RuntimeError` with a descriptive message on failure.
|
|
243
|
+
- Ensures the cursor is closed in a `finally` block.
|
|
244
|
+
"""
|
|
245
|
+
cursor = None
|
|
246
|
+
try:
|
|
247
|
+
cursor = self.db.connection.cursor()
|
|
248
|
+
insert_query = """
|
|
249
|
+
INSERT INTO schmetrc.component_roi(component_id, application_code, creation_time, deployment_time,
|
|
250
|
+
saving_hours, cost_hours, date_id)
|
|
251
|
+
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
|
252
|
+
RETURNING id;
|
|
253
|
+
"""
|
|
254
|
+
ids = []
|
|
255
|
+
for row in data:
|
|
256
|
+
cursor.execute(insert_query, (row["component_id"], row["application_code"], row["development_time"],
|
|
257
|
+
row["deployment_time"], row["hours_saving"], row["hours_cost"],
|
|
258
|
+
self.get_or_create_current_month_date()))
|
|
259
|
+
ids.append(cursor.fetchone()[0])
|
|
260
|
+
self.db.commit_transaction()
|
|
261
|
+
return ids
|
|
262
|
+
except Exception as e:
|
|
263
|
+
self.db.rollback_transaction()
|
|
264
|
+
raise RuntimeError(f"Error saving components roi: {str(e)}")
|
|
265
|
+
finally:
|
|
266
|
+
if cursor:
|
|
267
|
+
cursor.close()
|
|
268
|
+
|
|
146
269
|
def get_or_create_current_month_date(self) -> int:
|
|
147
270
|
cursor = None
|
|
148
271
|
try:
|
|
@@ -5,6 +5,7 @@ commons_metrics/__init__.py
|
|
|
5
5
|
commons_metrics/azure_devops_client.py
|
|
6
6
|
commons_metrics/cache_manager.py
|
|
7
7
|
commons_metrics/commons_repos_client.py
|
|
8
|
+
commons_metrics/connection_database.py
|
|
8
9
|
commons_metrics/database.py
|
|
9
10
|
commons_metrics/date_utils.py
|
|
10
11
|
commons_metrics/github_api_client.py
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='commons_metrics',
|
|
5
|
-
version='0.0.
|
|
5
|
+
version='0.0.31',
|
|
6
6
|
description='A simple library for basic statistical calculations',
|
|
7
7
|
#long_description=open('USAGE.md').read(),
|
|
8
8
|
#long_description_content_type='text/markdown',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics/update_design_components.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commons_metrics-0.0.29 → commons_metrics-0.0.31}/commons_metrics.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|