Skip to content

Commit

Permalink
misc refactoring and code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Jan 21, 2025
1 parent 1c28eca commit a83ec32
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 84 deletions.
1 change: 1 addition & 0 deletions mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class Schema__MGraph__Node(Type_Safe):
node_data : Schema__MGraph__Node__Data
node_id : Obj_Id
node_type : Type['Schema__MGraph__Node']

22 changes: 0 additions & 22 deletions mgraph_ai/providers/json/actions/MGraph__Json__Obj_Factory.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def create__Model__MGraph__Json__Types(self):
object.__setattr__(types, '__dict__', types_dict)
return types

def create__Model__MGraph__Json__Node(self, data=None):
node = object.__new__(Model__MGraph__Json__Node)
node_dict = dict(data = data or self.json_schema_factory.create__Schema__MGraph__Json__Node())
object.__setattr__(node, '__dict__', node_dict)
return node

def create__Model__MGraph__Json__Node__Value(self):
node = object.__new__(Model__MGraph__Json__Node__Value)
node_dict = dict(data = self.json_schema_factory.create__Schema__MGraph__Json__Node__Value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def __init__(self):
super().__init__()
self.schema_factory = MGraph__Obj_Factory__Schemas()

def create__Schema__MGraph__Json__Node(self):
node = object.__new__(Schema__MGraph__Json__Node)
node_dict = dict(node_data = self.schema_factory.create__Schema__MGraph__Node__Data(),
node_id = self.schema_factory.create__Schema__MGraph__Node().node_id,
node_type = Schema__MGraph__Json__Node)
object.__setattr__(node, '__dict__', node_dict)
return node

def create__Schema__MGraph__Json__Node__Value__Data(self):
data = object.__new__(Schema__MGraph__Json__Node__Value__Data)
data_dict = dict(value = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def format_value(self, value: Any) -> str: #
if isinstance(value, str): # dot specific escaping
escaped = value.replace('"', '\\"')
return f'{escaped}'
return f'"{value}"'
#return f'"{value}"'

def process_node(self, node: Any) -> str: # Process a node and generate DOT representation
node_type = self.get_node_type(node)
Expand Down
2 changes: 2 additions & 0 deletions mgraph_ai/providers/json/models/Model__MGraph__Json__Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
class Model__MGraph__Json__Node(Model__MGraph__Node): # Base model class for JSON nodes
data: Schema__MGraph__Json__Node

def __init__(self, **kwargs):
super().__init__(**kwargs)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_create_all_objects(self):
print()
_.padding = 50
_.measure(self.models_factory.create__Model__MGraph__Json__Types ).print().assert_time__less_than(500)
_.measure(self.models_factory.create__Model__MGraph__Json__Node ).print().assert_time__less_than(3000)
_.measure(self.models_factory.create__Model__MGraph__Json__Node__Value ).print().assert_time__less_than(3000)
_.measure(self.models_factory.create__Model__MGraph__Json__Node__Property ).print().assert_time__less_than(3000)
_.measure(self.models_factory.create__Model__MGraph__Json__Node__Dict ).print().assert_time__less_than(3000)
Expand All @@ -59,6 +60,15 @@ def test_create__Model__MGraph__Json__Types(self):
assert _.obj() == __(node_model_type = type_full_name(Model__MGraph__Json__Node),
edge_model_type = type_full_name(Model__MGraph__Json__Edge))

def test_create__Model__MGraph__Json__Node(self):
node = self.models_factory.create__Model__MGraph__Json__Node()
with node as _:
assert type(_) is Model__MGraph__Json__Node
assert type(_.data) is Schema__MGraph__Json__Node
assert _.obj() == __(data = __(node_data = __(),
node_id = _.data.node_id,
node_type = type_full_name(Schema__MGraph__Json__Node)))

def test_create__Model__MGraph__Json__Node__Value(self):
node = self.models_factory.create__Model__MGraph__Json__Node__Value()
with node as _:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from unittest import TestCase
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Data import Schema__MGraph__Node__Data
from mgraph_ai.providers.json.schemas.Schema__MGraph__Json__Node import Schema__MGraph__Json__Node
from mgraph_ai.providers.json.schemas.Schema__MGraph__Json__Node__Property__Data import Schema__MGraph__Json__Node__Property__Data
from mgraph_ai.providers.json.schemas.Schema__MGraph__Json__Node__Value__Data import Schema__MGraph__Json__Node__Value__Data
from osbot_utils.testing.performance.Performance_Measure__Session import Performance_Measure__Session
from osbot_utils.utils.Objects import __, type_full_name
from osbot_utils.type_safe.Type_Safe import Type_Safe
from osbot_utils.utils.Objects import __, type_full_name, base_types
from mgraph_ai.providers.json.actions.MGraph__Json__Obj_Factory__Schemas import MGraph__Json__Obj_Factory__Schemas
from mgraph_ai.providers.json.schemas.Schema__MGraph__Json__Edge import Schema__MGraph__Json__Edge
from mgraph_ai.providers.json.schemas.Schema__MGraph__Json__Graph import Schema__MGraph__Json__Graph
Expand All @@ -28,17 +31,38 @@ def test_create_all_objects(self):
print()
print()
_.padding = 50
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Value__Data ).print().assert_time__less_than(300)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node ).print().assert_time__less_than(300)
_.measure(Schema__MGraph__Json__Node ).print().assert_time__less_than(300)
print()
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Value__Data ).print().assert_time__less_than(300)
_.measure(Schema__MGraph__Json__Node__Value__Data ).print().assert_time__less_than(300)
print()
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Property__Data).print().assert_time__less_than(300)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Value ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Property ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Dict ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__List ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Edge ).print().assert_time__less_than(2000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Graph__Data ).print().assert_time__less_than(300)
_.measure(self.json_factory.create__Schema__MGraph__Json__Types ).print().assert_time__less_than(500)
_.measure(Schema__MGraph__Json__Node__Property__Data ).print().assert_time__less_than(300)
print()
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Value ).print().assert_time__less_than(1000)
_.measure(Schema__MGraph__Json__Node__Value ).print().assert_time__less_than(300)
print()
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Property ).print().assert_time__less_than(1000)
_.measure(Schema__MGraph__Json__Node__Property ).print().assert_time__less_than(300)
print()
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__Dict ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Node__List ).print().assert_time__less_than(1000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Edge ).print().assert_time__less_than(2000)
_.measure(self.json_factory.create__Schema__MGraph__Json__Graph__Data ).print().assert_time__less_than(300)
_.measure(self.json_factory.create__Schema__MGraph__Json__Types ).print().assert_time__less_than(500)
_.measure(self.json_factory.create__Schema__MGraph__Json__Graph ).print().assert_time__less_than(3000)

def test_create__Schema__MGraph__Json__Node(self):
node = self.json_factory.create__Schema__MGraph__Json__Node()
with node as _:
assert type(_) is Schema__MGraph__Json__Node
assert type(_.node_data) is Schema__MGraph__Node__Data
assert base_types(_) == [Schema__MGraph__Node, Type_Safe, object]
assert _.obj() == __(node_data = __(),
node_id = _.node_id,
node_type = type_full_name(Schema__MGraph__Json__Node))

def test_create__Schema__MGraph__Json__Node__Value__Data(self):
data = self.json_factory.create__Schema__MGraph__Json__Node__Value__Data()
with data as _:
Expand Down

0 comments on commit a83ec32

Please sign in to comment.