Skip to content

Commit fb09681

Browse files
committed
merge branche + changing conf structure for commmunity + fixing bug when running the same extraction again
1 parent 5ce4285 commit fb09681

8 files changed

Lines changed: 49 additions & 30 deletions

File tree

algorithms/GraphAnalysis.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ def _run_graph_generation(self) -> None:
7676
final_fmt = out.final_file_format
7777

7878
if gt.user_user:
79-
if getattr(p, "is_community", False) and getattr(p, "community_file", ""):
80-
df = pd.read_csv(p.community_file)
79+
comm_cfg = getattr(p, "community", None)
80+
if comm_cfg and getattr(comm_cfg, "is_community", False) and getattr(comm_cfg, "community_file", ""):
81+
df = pd.read_csv(comm_cfg.community_file)
8182
user_community_map = dict(
8283
zip(df["user_id"].astype(int), df["community"].astype(int))
8384
)
8485

8586
# ── automatical selection of strategy ──────────────────────────
86-
strategy_name = getattr(p, "community_strategy")
87-
batch_size = getattr(p, "community_batch_size")
87+
strategy_name = getattr(comm_cfg, "community_strategy")
88+
batch_size = getattr(comm_cfg, "community_batch_size")
8889

8990
if strategy_name == "batch":
9091
strategy = CommunityUserBatchStrategy(user_community_map)
@@ -113,7 +114,7 @@ def _run_graph_generation(self) -> None:
113114
fast_rt_threshold=p.fast_rt_threshold,
114115
strategy=strategy,
115116
is_community_run=is_comm,
116-
community_file_path=getattr(p, "community_file", None) if is_comm else None,
117+
community_file_path=getattr(comm_cfg, "community_file", None) if is_comm else None,
117118
load_snapshot_status=p.load_snapshot.status if p.load_snapshot else False,
118119
load_snapshot_tmp_path=p.load_snapshot.tmp_path if p.load_snapshot else ""
119120
)

algorithms/graph/extraction.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ def _process_work_item(self, worker_id: int, work_item,
386386

387387
def run(self, checkpoint_every: int = 500,
388388
max_users: Optional[int] = None, n_workers: int = 4) -> None:
389+
if self.load_snapshot_status and self.load_snapshot_tmp_path:
390+
snapshot_basename = os.path.basename(
391+
self.load_snapshot_tmp_path.rstrip(os.sep))
392+
if snapshot_basename:
393+
self.id = snapshot_basename
394+
395+
# Check if already complete
396+
final_dir = os.path.join(self.output_file_path, self.id)
397+
metadata_file = os.path.join(final_dir, "metadata.json")
398+
if self.load_snapshot_status and os.path.exists(metadata_file):
399+
self.logger.info(
400+
f"Final output metadata.json found at '{metadata_file}'. "
401+
"Extraction and merge have already completed for this snapshot. Skipping.")
402+
return
403+
389404
self.logger.info(
390405
f"[GraphGenerationUser] Starting extraction. "
391406
f"Run ID: {self.id} Format: {self.file_format}")
@@ -405,10 +420,6 @@ def run(self, checkpoint_every: int = 500,
405420
skipped = self.strategy.exclude_users(processed)
406421
self.logger.info(
407422
f"Excluded {skipped} users from strategy processing queue.")
408-
snapshot_basename = os.path.basename(
409-
self.load_snapshot_tmp_path.rstrip(os.sep))
410-
if snapshot_basename:
411-
self.id = snapshot_basename
412423

413424
work_items = self.strategy.partition_work(
414425
collection, n_workers, max_users, self.logger)

config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ class LoadSnapshot(BaseModel):
8989
status: bool = False
9090
tmp_path: str = ""
9191

92+
class CommunityExtractionConfig(BaseModel):
93+
is_community: bool = False
94+
community_file: str = ""
95+
community_strategy: str = "linear"
96+
community_batch_size: int = 500
97+
9298
class GraphParameters(BaseModel):
9399
checkpoint_every: int = 5000
94100
n_workers: int = 4
95101
fast_rt_threshold: int = 60
96-
is_community: bool
97-
community_file: str
98-
community_strategy: str
99-
community_batch_size: int
102+
community: CommunityExtractionConfig = CommunityExtractionConfig()
100103
load_snapshot: Optional[LoadSnapshot] = LoadSnapshot()
101104
input: SourceInput
102105
graph_type: GraphTypes

properties/prop.ipazia.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ graph_generation:
88
checkpoint_every: 100
99
n_workers: 64
1010
fast_rt_threshold: 60
11-
is_community: true
12-
community_file: "/app/resources/communities_rp_0.4.csv"
13-
community_strategy: "shard" # "batch" | "shard" | "linear"
14-
community_batch_size: 100
11+
community:
12+
is_community: true
13+
community_file: "/app/resources/communities_rp_0.4.csv"
14+
community_strategy: "shard" # "batch" | "shard" | "linear"
15+
community_batch_size: 100
1516
input:
1617
type: "json"
1718
conf:

properties/prop.local.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ graph_generation:
88
checkpoint_every: 500
99
n_workers: 4
1010
fast_rt_threshold: 60
11-
is_community: false
12-
community_file: "./resources/communities.csv"
13-
community_strategy: "linear" # "batch" | "shard" | "linear"
14-
community_batch_size: 500
11+
community:
12+
is_community: false
13+
community_file: "./resources/communities.csv"
14+
community_strategy: "linear" # "batch" | "shard" | "linear"
15+
community_batch_size: 500
1516
input:
1617
type: "mongo"
1718
conf:

properties/prop.template.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ graph_generation:
2121
checkpoint_every: 5000
2222
n_workers: 4
2323
fast_rt_threshold: 60
24-
is_community: false
25-
community_file: "./resources/communities.csv"
26-
community_strategy: "linear" # "batch" | "shard" | "linear"
27-
community_batch_size: 500
24+
community:
25+
is_community: false
26+
community_file: "./resources/communities.csv"
27+
community_strategy: "linear" # "batch" | "shard" | "linear"
28+
community_batch_size: 500
2829
input:
2930
type: "json" # "mongo", "json", "csv"
3031
conf:

properties/prop.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ graph_generation:
1111
checkpoint_every: 100
1212
n_workers: 8
1313
fast_rt_threshold: 60
14-
is_community: true
15-
community_file: "./resources/communities_rp_0.4.csv"
16-
community_strategy: "shard" # "batch" | "shard" | "linear"
17-
community_batch_size: 100
14+
community:
15+
is_community: true
16+
community_file: "./resources/communities_rp_0.4.csv"
17+
community_strategy: "shard" # "batch" | "shard" | "linear"
18+
community_batch_size: 100
1819
input:
1920
type: "json"
2021
conf:
@@ -38,7 +39,7 @@ graph_generation:
3839
user_user: true
3940
load_snapshot:
4041
status: true
41-
tmp_path: "./resources/tmp/48ca37c8507711f1abea9c29764a0d1b"
42+
tmp_path: "./resources/tmp/9e5ab1a1507f11f1b8329c29764a0d1b"
4243
output:
4344
path: "./resources/"
4445
graph_file_name:

resources/filtered.pkl

-69 MB
Binary file not shown.

0 commit comments

Comments
 (0)