Skip to content

Commit

Permalink
type hints, docstrings; RSRC class inherits from Node
Browse files Browse the repository at this point in the history
  • Loading branch information
jjCode01 committed Mar 24, 2024
1 parent 31cf747 commit d989ee1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 12 additions & 10 deletions xerparser/schemas/rsrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
# rsrc.py

from typing import Any

from xerparser.schemas._node import Node
from xerparser.schemas.udftype import UDFTYPE


class RSRC:
class RSRC(Node):
"""
A class to represent a Resource.
"""

def __init__(self, **data) -> None:
def __init__(self, **data: str) -> None:
super().__init__()
self.uid: str = data["rsrc_id"]
self.clndr_id: str = data["clndr_id"]
self.name: str = data["rsrc_name"]
self.parent_rsrc_id: str = data["parent_rsrc_id"]
self.short_name: str = data["rsrc_short_name"]
self.type: str = data["rsrc_type"]
self.user_defined_fields: dict[UDFTYPE, Any] = {}

def __eq__(self, __o: "RSRC") -> bool:
return all(
(
self.name == __o.name,
self.short_name == __o.short_name,
self.type == __o.type,
)
)
self.full_code == __o.full_code

def __hash__(self) -> int:
return hash((self.name, self.short_name, self.type))
return hash(self.full_code)

@property
def full_code(self) -> str:
return ".".join(reversed([node.short_name for node in self.lineage]))
10 changes: 9 additions & 1 deletion xerparser/src/xer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, xer_file_contents: str) -> None:
self.notebook_topics: dict[str, MEMOTYPE] = self._get_attr("MEMOTYPE")
self.project_code_types: dict[str, PCATTYPE] = self._get_attr("PCATTYPE")
self.project_code_values: dict[str, PCATVAL] = self._get_proj_code_values()
self.resources: dict[str, RSRC] = self._get_attr("RSRC")
self.resources: dict[str, RSRC] = self._get_rsrcs()
self.sched_options: dict[str, SCHEDOPTIONS] = self._get_attr("SCHEDOPTIONS")
self.udf_types: dict[str, UDFTYPE] = self._get_attr("UDFTYPE")
self.projects = self._get_projects()
Expand Down Expand Up @@ -147,6 +147,14 @@ def _get_relationships(self) -> dict[str, TASKPRED]:
for rel in self.tables.get("TASKPRED", [])
}

def _get_rsrcs(self) -> dict[str, RSRC]:
rsrcs: dict[str, RSRC] = self._get_attr("RSRC")
for rsrc in rsrcs.values():
if rsrc.parent_rsrc_id:
rsrc.parent = rsrcs[rsrc.parent_rsrc_id]
rsrc.parent.addChild(rsrc)
return rsrcs

def _get_tasks(self) -> dict[str, TASK]:
return {
task["task_id"]: self._set_task(**task)
Expand Down

0 comments on commit d989ee1

Please sign in to comment.