3 Commits

Author SHA1 Message Date
4fa8cf1a69 chore: update analytics data [skip ci] 2025-08-18 03:00:21 +00:00
0f4da3d79b add dict function for services by cloud_env (#46)
All checks were successful
Create Weekly Analytics Stats / run-analytics (push) Successful in 9s
Reviewed-on: #46
Reviewed-by: Gode, Sebastian <sebastian.gode@t-systems.com>
Co-authored-by: tischrei <tino.schreiber@t-systems.com>
Co-committed-by: tischrei <tino.schreiber@t-systems.com>
2025-08-13 13:45:17 +00:00
ed2a5f575e fix file_path (#45)
Reviewed-on: #45
Reviewed-by: Gode, Sebastian <sebastian.gode@t-systems.com>
Co-authored-by: tischrei <tino.schreiber@t-systems.com>
Co-committed-by: tischrei <tino.schreiber@t-systems.com>
2025-08-13 13:15:37 +00:00
7 changed files with 37 additions and 21 deletions

View File

@ -14,7 +14,8 @@
from pathlib import Path from pathlib import Path
import json import json
analytics_path = Path("otc_metadata/analytics/public") BASE_DIR = Path(__file__).resolve().parent
analytics_path = BASE_DIR / "public"
cloud_environments = [ cloud_environments = [
'eu_de', 'eu_de',
@ -24,8 +25,8 @@ analytics_data = {k: [] for k in cloud_environments}
# Open and read the json data files # Open and read the json data files
for env in cloud_environments: for env in cloud_environments:
file_path = analytics_path.joinpath(f"{env}.json") file_path = analytics_path / f"{env}.json"
with open(file_path, 'r') as file: with file_path.open(encoding="utf-8") as file:
analytics_data[env] = json.load(file) analytics_data[env] = json.load(file)

View File

@ -8,5 +8,5 @@
"sfs", "sfs",
"iam", "iam",
"elb", "elb",
"apig" "vpn"
] ]

View File

@ -7,6 +7,6 @@
"rds", "rds",
"iam", "iam",
"elb", "elb",
"cbr", "vpn",
"vpc" "cbr"
] ]

View File

@ -1,2 +0,0 @@
---
name: eu_de

View File

@ -1,2 +0,0 @@
---
name: swiss

View File

@ -17,7 +17,6 @@
# documents/services/service_categories is being merged with # documents/services/service_categories is being merged with
# the content here. # the content here.
--- ---
cloud_environments: []
documents: [] documents: []
service_categories: [] service_categories: []
services: [] services: []

View File

@ -62,20 +62,10 @@ class Services(object):
if other in self._service_data["service_categories"]: if other in self._service_data["service_categories"]:
self._service_data["service_categories"].remove(other) self._service_data["service_categories"].remove(other)
self._service_data["service_categories"].append(other) self._service_data["service_categories"].append(other)
# sort cloud environments by <name>
self._service_data["cloud_environments"] = sorted(
self._service_data["cloud_environments"],
key=lambda x: f"{x.get('name')}",
)
def _rewrite_data(self): def _rewrite_data(self):
otc_metadata.data.rewrite_data("services.yaml", self._service_data) otc_metadata.data.rewrite_data("services.yaml", self._service_data)
@property
def all_cloud_environments(self):
"Cloud Environments data listing."
return copy.deepcopy(self._service_data["cloud_environments"])
@property @property
def all_services(self): def all_services(self):
"Service Categories data listing." "Service Categories data listing."
@ -485,3 +475,33 @@ class Services(object):
res.sort(key=lambda x: x.get("service_title", "").lower()) res.sort(key=lambda x: x.get("service_title", "").lower())
return res return res
def all_services_by_cloud_environment_as_dict(self, cloud_environment, environments):
"""Retrieve all services filtered by cloud_environment
Returns a dict keyed by service_type.
"""
res = {}
if not (environments and cloud_environment):
raise Exception(
"No cloud_environment or environments specified in function all_services_by_cloud_environment."
)
for srv in self.all_services:
for srv_cloud_environment in srv.get("cloud_environments", []):
if srv_cloud_environment.get("name") == cloud_environment:
for environment in environments:
if srv_cloud_environment.get("visibility") == environment:
service_type = srv.get("service_type")
if service_type:
res[service_type] = srv
break
res = dict(
sorted(
res.items(),
key=lambda item: item[1].get("service_type", "").lower()
)
)
return res