Skip to content

Commit 038dfba

Browse files
committed
added capacity assignment status
1 parent 3eade9f commit 038dfba

File tree

4 files changed

+120
-42
lines changed

4 files changed

+120
-42
lines changed

src/sempy_labs/_generate_semantic_model.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ def get_semantic_model_bim(
350350
The Model.bim file for the semantic model.
351351
"""
352352

353-
bimJson = get_semantic_model_definition(dataset=dataset, workspace=workspace, format='TMSL', return_dataframe=False)
353+
bimJson = get_semantic_model_definition(
354+
dataset=dataset, workspace=workspace, format="TMSL", return_dataframe=False
355+
)
354356

355357
if save_to_file_name is not None:
356358
if not lakehouse_attached():
@@ -406,13 +408,15 @@ def get_semantic_model_definition(
406408
A pandas dataframe with the semantic model definition or the file or files comprising the semantic model definition.
407409
"""
408410

409-
valid_formats = ['TMSL', 'TMDL']
411+
valid_formats = ["TMSL", "TMDL"]
410412

411413
format = format.upper()
412-
if format == 'BIM':
414+
if format == "BIM":
413415
format = "TMSL"
414416
if format not in valid_formats:
415-
raise ValueError(f"{icons.red_dot} Invalid format. Valid options: {valid_formats}.")
417+
raise ValueError(
418+
f"{icons.red_dot} Invalid format. Valid options: {valid_formats}."
419+
)
416420

417421
(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
418422

@@ -427,18 +431,14 @@ def get_semantic_model_definition(
427431

428432
if return_dataframe:
429433
return pd.json_normalize(files)
430-
elif format == 'TMSL':
434+
elif format == "TMSL":
431435
payload = next(
432-
(part["payload"] for part in files if part["path"] == "model.bim"),
433-
None
436+
(part["payload"] for part in files if part["path"] == "model.bim"), None
434437
)
435438
return json.loads(_decode_b64(payload))
436439
else:
437440
decoded_parts = [
438-
{
439-
"file_name": part["path"],
440-
"content": _decode_b64(part['payload'])
441-
}
441+
{"file_name": part["path"], "content": _decode_b64(part["payload"])}
442442
for part in files
443443
]
444444

src/sempy_labs/_translations.py

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _clean_text(text, exclude_chars):
5757
columns=["Object Type", "Name", "Description", "Display Folder"]
5858
)
5959

60-
final_df = pd.DataFrame(columns=['Value', 'Translation'])
60+
final_df = pd.DataFrame(columns=["Value", "Translation"])
6161

6262
with connect_semantic_model(
6363
dataset=dataset, readonly=False, workspace=workspace
@@ -68,7 +68,7 @@ def _clean_text(text, exclude_chars):
6868
oDescription = _clean_text(o.Description, exclude_characters)
6969
new_data = {
7070
"Name": o.Name,
71-
"TName": oName,
71+
"TName": oName,
7272
"Object Type": "Table",
7373
"Description": o.Description,
7474
"TDescription": oDescription,
@@ -165,24 +165,29 @@ def _clean_text(text, exclude_chars):
165165
)
166166

167167
df_panda = transDF.toPandas()
168-
df_panda = df_panda[~df_panda[clm].isin([None, ''])][[clm, 'translation']]
168+
df_panda = df_panda[~df_panda[clm].isin([None, ""])][[clm, "translation"]]
169169

170-
df_panda = df_panda.rename(columns={clm: 'value'})
170+
df_panda = df_panda.rename(columns={clm: "value"})
171171
final_df = pd.concat([final_df, df_panda], ignore_index=True)
172172

173173
def set_translation_if_exists(object, language, property, index):
174174

175-
if property == 'Name':
175+
if property == "Name":
176176
trans = object.Name
177-
elif property == 'Description':
177+
elif property == "Description":
178178
trans = object.Description
179-
elif property == 'Display Folder':
179+
elif property == "Display Folder":
180180
trans = object.DisplayFolder
181181

182-
df_filt = final_df[final_df['value'] == trans]
182+
df_filt = final_df[final_df["value"] == trans]
183183
if not df_filt.empty:
184-
translation_value = df_filt['translation'].str[index].iloc[0]
185-
tom.set_translation(object=object, language=language, property=property, value=translation_value)
184+
translation_value = df_filt["translation"].str[index].iloc[0]
185+
tom.set_translation(
186+
object=object,
187+
language=language,
188+
property=property,
189+
value=translation_value,
190+
)
186191

187192
for language in languages:
188193
index = languages.index(language)
@@ -192,23 +197,49 @@ def set_translation_if_exists(object, language, property, index):
192197
)
193198

194199
for t in tom.model.Tables:
195-
set_translation_if_exists(object=t, language=language, property='Name', index=index)
196-
set_translation_if_exists(object=t, language=language, property='Description', index=index)
200+
set_translation_if_exists(
201+
object=t, language=language, property="Name", index=index
202+
)
203+
set_translation_if_exists(
204+
object=t, language=language, property="Description", index=index
205+
)
197206
for c in tom.all_columns():
198-
set_translation_if_exists(object=c, language=language, property='Name', index=index)
199-
set_translation_if_exists(object=c, language=language, property='Description', index=index)
200-
set_translation_if_exists(object=c, language=language, property='Display Folder', index=index)
207+
set_translation_if_exists(
208+
object=c, language=language, property="Name", index=index
209+
)
210+
set_translation_if_exists(
211+
object=c, language=language, property="Description", index=index
212+
)
213+
set_translation_if_exists(
214+
object=c, language=language, property="Display Folder", index=index
215+
)
201216
for c in tom.all_measures():
202-
set_translation_if_exists(object=c, language=language, property='Name', index=index)
203-
set_translation_if_exists(object=c, language=language, property='Description', index=index)
204-
set_translation_if_exists(object=c, language=language, property='Display Folder', index=index)
217+
set_translation_if_exists(
218+
object=c, language=language, property="Name", index=index
219+
)
220+
set_translation_if_exists(
221+
object=c, language=language, property="Description", index=index
222+
)
223+
set_translation_if_exists(
224+
object=c, language=language, property="Display Folder", index=index
225+
)
205226
for c in tom.all_hierarchies():
206-
set_translation_if_exists(object=c, language=language, property='Name', index=index)
207-
set_translation_if_exists(object=c, language=language, property='Description', index=index)
208-
set_translation_if_exists(object=c, language=language, property='Display Folder', index=index)
227+
set_translation_if_exists(
228+
object=c, language=language, property="Name", index=index
229+
)
230+
set_translation_if_exists(
231+
object=c, language=language, property="Description", index=index
232+
)
233+
set_translation_if_exists(
234+
object=c, language=language, property="Display Folder", index=index
235+
)
209236
for c in tom.all_levels():
210-
set_translation_if_exists(object=c, language=language, property='Name', index=index)
211-
set_translation_if_exists(object=c, language=language, property='Description', index=index)
237+
set_translation_if_exists(
238+
object=c, language=language, property="Name", index=index
239+
)
240+
set_translation_if_exists(
241+
object=c, language=language, property="Description", index=index
242+
)
212243

213244
result = pd.DataFrame(
214245
columns=[

src/sempy_labs/admin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
list_capacities_delegated_tenant_settings,
1212
list_access_entities,
1313
list_activity_events,
14+
get_capacity_assignment_status,
1415
)
1516
from sempy_labs.admin._domains import (
1617
list_domains,
@@ -64,4 +65,5 @@
6465
"list_modified_workspaces",
6566
"list_git_connections",
6667
"list_reports",
68+
"get_capacity_assignment_status",
6769
]

src/sempy_labs/admin/_basic_functions.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212
import pandas as pd
1313
from dateutil.parser import parse as dtparser
14-
import urllib.parse
1514

1615

1716
def list_workspaces(
@@ -901,14 +900,20 @@ def _resolve_workspace_name_and_id(
901900
workspace: str | UUID,
902901
) -> Tuple[str, UUID]:
903902

904-
dfW = list_workspaces(workspace=workspace)
905-
try:
906-
workspace_name = dfW["Name"].iloc[0]
907-
workspace_id = dfW["Id"].iloc[0]
908-
except Exception:
909-
raise ValueError(f"{icons.red_dot} The '{workspace}' workspace was not found.")
903+
if workspace is None:
904+
workspace_id = fabric.get_workspace_id()
905+
workspace_name = fabric.resolve_workspace_name(workspace_id)
906+
else:
907+
dfW = list_workspaces(workspace=workspace)
908+
try:
909+
workspace_name = dfW["Name"].iloc[0]
910+
workspace_id = dfW["Id"].iloc[0]
911+
except Exception:
912+
raise ValueError(
913+
f"{icons.red_dot} The '{workspace}' workspace was not found."
914+
)
910915

911-
return workspace_name, workspace_id
916+
return workspace_name, workspace_id
912917

913918

914919
def list_reports(
@@ -988,3 +993,43 @@ def list_reports(
988993
df["Modified Date"] = pd.to_datetime(df["Modified Date"], errors="coerce")
989994

990995
return df
996+
997+
998+
def get_capacity_assignment_status(workspace: Optional[str | UUID] = None):
999+
1000+
(workspace_name, workspace_id) = _resolve_workspace_name_and_id(workspace)
1001+
1002+
df = pd.DataFrame(
1003+
columns=[
1004+
"Status",
1005+
"Activity Id",
1006+
"Start Time",
1007+
"End Time",
1008+
"Capacity Id",
1009+
"Capacity Name",
1010+
]
1011+
)
1012+
1013+
client = fabric.FabricRestClient()
1014+
response = client.get(f"/v1.0/myorg/groups/{workspace_id}/CapacityAssignmentStatus")
1015+
1016+
if response.status_code != 200:
1017+
raise FabricHTTPException(response)
1018+
1019+
v = response.json()
1020+
capacity_id = v.get("capacityId")
1021+
1022+
(capacity_name, capacity_id) = _resolve_capacity_name_and_id(capacity=capacity_id)
1023+
1024+
new_data = {
1025+
"Status": v.get("status"),
1026+
"Activity Id": v.get("activityId"),
1027+
"Start Time": v.get("startTime"),
1028+
"End Time": v.get("endTime"),
1029+
"Capacity Id": capacity_id,
1030+
"Capacity Name": capacity_name,
1031+
}
1032+
1033+
df = pd.concat([df, pd.DataFrame([new_data])], ignore_index=True)
1034+
1035+
return df

0 commit comments

Comments
 (0)