topologicpy 0.4.11__tar.gz → 0.4.13__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. {topologicpy-0.4.11/src/topologicpy.egg-info → topologicpy-0.4.13}/PKG-INFO +1 -1
  2. {topologicpy-0.4.11 → topologicpy-0.4.13}/pyproject.toml +1 -2
  3. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/DGL.py +27 -5
  4. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Dictionary.py +13 -0
  5. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/EnergyModel.py +18 -1
  6. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Graph.py +0 -1
  7. topologicpy-0.4.13/src/topologicpy/Neo4j.py +499 -0
  8. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Plotly.py +234 -5
  9. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Topology.py +49 -25
  10. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/__init__.py +1 -1
  11. {topologicpy-0.4.11 → topologicpy-0.4.13/src/topologicpy.egg-info}/PKG-INFO +1 -1
  12. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy.egg-info/SOURCES.txt +1 -5
  13. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy.egg-info/requires.txt +0 -1
  14. topologicpy-0.4.11/src/topologicpy/Graph_Export.py +0 -858
  15. topologicpy-0.4.11/src/topologicpy/Neo4jGraph.py +0 -311
  16. topologicpy-0.4.11/src/topologicpy/Process.py +0 -1368
  17. topologicpy-0.4.11/src/topologicpy/SQL.py +0 -48
  18. topologicpy-0.4.11/src/topologicpy/UnitTest.py +0 -29
  19. {topologicpy-0.4.11 → topologicpy-0.4.13}/LICENSE +0 -0
  20. {topologicpy-0.4.11 → topologicpy-0.4.13}/MANIFEST.in +0 -0
  21. {topologicpy-0.4.11 → topologicpy-0.4.13}/README.md +0 -0
  22. {topologicpy-0.4.11 → topologicpy-0.4.13}/setup.cfg +0 -0
  23. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Aperture.py +0 -0
  24. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Cell.py +0 -0
  25. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/CellComplex.py +0 -0
  26. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Cluster.py +0 -0
  27. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Color.py +0 -0
  28. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Context.py +0 -0
  29. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Edge.py +0 -0
  30. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Face.py +0 -0
  31. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Grid.py +0 -0
  32. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Helper.py +0 -0
  33. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Honeybee.py +0 -0
  34. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Matrix.py +0 -0
  35. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Polyskel.py +0 -0
  36. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Shell.py +0 -0
  37. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Speckle.py +0 -0
  38. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Vector.py +0 -0
  39. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Vertex.py +0 -0
  40. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/Wire.py +0 -0
  41. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic/__init__.py +0 -0
  42. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
  43. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
  44. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
  45. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
  46. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
  47. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
  48. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
  49. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  50. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
  51. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  52. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  53. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  54. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
  55. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
  56. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  57. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  58. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  59. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  60. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  61. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
  62. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
  63. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
  64. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
  65. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
  66. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
  67. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
  68. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
  69. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
  70. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
  71. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
  72. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
  73. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
  74. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
  75. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
  76. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
  77. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
  78. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/__init__.py +0 -0
  79. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
  80. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
  81. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
  82. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
  83. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy.egg-info/dependency_links.txt +0 -0
  84. {topologicpy-0.4.11 → topologicpy-0.4.13}/src/topologicpy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: topologicpy
3
- Version: 0.4.11
3
+ Version: 0.4.13
4
4
  Summary: An Advanced Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
5
5
  Author-email: Wassim Jabi <wassim.jabi@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/wassimj/TopologicPy
@@ -3,7 +3,7 @@ requires = ["setuptools>=61"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "topologicpy"
6
- version = "0.4.11"
6
+ version = "0.4.13"
7
7
  authors = [
8
8
  { name="Wassim Jabi", email="wassim.jabi@gmail.com" },
9
9
  ]
@@ -17,7 +17,6 @@ classifiers = [
17
17
  ]
18
18
  dependencies = [
19
19
  "numpy",
20
- "scipy",
21
20
  "tqdm",
22
21
  "plotly",
23
22
  ]
@@ -1901,7 +1901,7 @@ class DGL:
1901
1901
  hl_widths : list , optional
1902
1902
  The list of hidden layer widths. A list of [16, 32, 16] means that the model will have 3 hidden layers with number of neurons in each being 16, 32, 16 respectively from input to output. The default is [32].
1903
1903
  conv_layer_type : str , optional
1904
- THe desired type of the convultion layer. The options are "Classic", "GraphConv", "GINConv", "SAGEConv", "TAGConv", "DGN". It is case insensitive. The default is "SAGEConv".
1904
+ The desired type of the convolution layer. The options are "Classic", "GraphConv", "GINConv", "SAGEConv", "TAGConv", "DGN". It is case insensitive. The default is "SAGEConv".
1905
1905
  pooling : str , optional
1906
1906
  The desired type of pooling. The options are "AvgPooling", "MaxPooling", or "SumPooling". It is case insensitive. The default is "AvgPooling".
1907
1907
  batch_size : int , optional
@@ -1911,7 +1911,7 @@ class DGL:
1911
1911
  use_gpu : bool , optional
1912
1912
  If set to True, the model will attempt to use the GPU. The default is False.
1913
1913
  loss_function : str , optional
1914
- The desired loss function. The optionals are "Cross-Entropy" or "Negative Log Likelihood". It is case insensitive. The default is "Cross-Entropy".
1914
+ The desired loss function. The options are "Cross-Entropy" or "Negative Log Likelihood". It is case insensitive. The default is "Cross-Entropy".
1915
1915
 
1916
1916
  Returns
1917
1917
  -------
@@ -2334,7 +2334,7 @@ class DGL:
2334
2334
  yTitle : str , optional
2335
2335
  The Y-axis title. The default is "Accuracy and Loss".
2336
2336
  ySpacing : float , optional
2337
- THe Y-axis spacing. The default is 0.1.
2337
+ The Y-axis spacing. The default is 0.1.
2338
2338
  useMarkers : bool , optional
2339
2339
  If set to True, markers will be displayed. The default is False.
2340
2340
  chartType : str , optional
@@ -2512,7 +2512,29 @@ class DGL:
2512
2512
  Returns
2513
2513
  -------
2514
2514
  dict
2515
- A dictionary containing the model data.
2515
+ A dictionary containing the model data. The keys in the dictionary are:
2516
+ 'Model Type'
2517
+ 'Optimizer'
2518
+ 'CV Type'
2519
+ 'Split'
2520
+ 'K-Folds'
2521
+ 'HL Widths'
2522
+ 'Conv Layer Type'
2523
+ 'Pooling'
2524
+ 'Learning Rate'
2525
+ 'Batch Size'
2526
+ 'Epochs'
2527
+ 'Training Accuracy'
2528
+ 'Validation Accuracy'
2529
+ 'Testing Accuracy'
2530
+ 'Training Loss'
2531
+ 'Validation Loss'
2532
+ 'Testing Loss'
2533
+ 'Accuracies' (Classifier and K-Fold only)
2534
+ 'Max Accuracy' (Classifier and K-Fold only)
2535
+ 'Losses' (Regressor and K-fold only)
2536
+ 'min Loss' (Regressor and K-fold only)
2537
+
2516
2538
 
2517
2539
  """
2518
2540
  from topologicpy.Helper import Helper
@@ -2578,7 +2600,7 @@ class DGL:
2578
2600
  labelKey : str , optional
2579
2601
  The label key to use. The default is "value".
2580
2602
  key : str , optional
2581
- The node attributes key. THe default is 'node_attr'.
2603
+ The node attributes key. The default is 'node_attr'.
2582
2604
 
2583
2605
  Returns
2584
2606
  -------
@@ -74,6 +74,19 @@ class Dictionary(topologic.Dictionary):
74
74
  stl_values.append(topologic.DoubleAttribute(value))
75
75
  elif isinstance(value, str):
76
76
  stl_values.append(topologic.StringAttribute(value))
77
+ elif isinstance(value, tuple):
78
+ value = list(value)
79
+ l = []
80
+ for v in value:
81
+ if isinstance(v, bool):
82
+ l.append(topologic.IntAttribute(v))
83
+ elif isinstance(v, int):
84
+ l.append(topologic.IntAttribute(v))
85
+ elif isinstance(v, float):
86
+ l.append(topologic.DoubleAttribute(v))
87
+ elif isinstance(v, str):
88
+ l.append(topologic.StringAttribute(v))
89
+ stl_values.append(topologic.ListAttribute(l))
77
90
  elif isinstance(value, list):
78
91
  l = []
79
92
  for v in value:
@@ -3,6 +3,7 @@ import topologic
3
3
  from topologicpy.Topology import Topology
4
4
  from topologicpy.Dictionary import Dictionary
5
5
 
6
+ import shutil
6
7
  import math
7
8
  from collections import OrderedDict
8
9
  import os
@@ -664,7 +665,7 @@ class EnergyModel:
664
665
  return list(OrderedDict( (x,1) for x in columnNames ).keys()) #Making a unique list and keeping its order
665
666
 
666
667
  @staticmethod
667
- def Run(model, weatherFilePath: str = None, osBinaryPath : str = None, outputFolder : str = None):
668
+ def Run(model, weatherFilePath: str = None, osBinaryPath : str = None, outputFolder : str = None, removeFiles : bool = False):
668
669
  """
669
670
  Runs an energy simulation.
670
671
 
@@ -678,6 +679,8 @@ class EnergyModel:
678
679
  The path to the openstudio binary.
679
680
  outputFolder : str
680
681
  The path to the output folder.
682
+ removeFiles : bool , optional
683
+ If set to True, the working files are removed at the end of the process. The default is False.
681
684
 
682
685
  Returns
683
686
  -------
@@ -686,8 +689,22 @@ class EnergyModel:
686
689
 
687
690
  """
688
691
  import os
692
+ import time
693
+ def deleteOldFiles(path):
694
+ onemonth = (time.time()) - 30 * 86400
695
+ try:
696
+ for filename in os.listdir(path):
697
+ if os.path.getmtime(os.path.join(path, filename)) < onemonth:
698
+ if os.path.isfile(os.path.join(path, filename)):
699
+ os.remove(os.path.join(path, filename))
700
+ elif os.path.isdir(os.path.join(path, filename)):
701
+ shutil.rmtree((os.path.join(path, filename)))
702
+ except:
703
+ pass
689
704
  if not weatherFilePath:
690
705
  weatherFilePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "assets", "EnergyModel", "GBR_London.Gatwick.037760_IWEC.epw")
706
+ if removeFiles:
707
+ deleteOldFiles(outputFolder)
691
708
  pbar = tqdm(desc='Running Simulation', total=100, leave=False)
692
709
  utcnow = datetime.utcnow()
693
710
  timestamp = utcnow.strftime("UTC-%Y-%m-%d-%H-%M-%S")
@@ -1953,7 +1953,6 @@ class Graph:
1953
1953
  The created graph.
1954
1954
 
1955
1955
  """
1956
-
1957
1956
  if not isinstance(vertices, list):
1958
1957
  return None
1959
1958
  if not isinstance(edges, list):
@@ -0,0 +1,499 @@
1
+ import topologic
2
+ import time
3
+ import random
4
+ import sys, subprocess
5
+
6
+ try:
7
+ import py2neo
8
+ from py2neo import NodeMatcher,RelationshipMatcher
9
+ from py2neo.data import spatial as sp
10
+ except:
11
+ call = [sys.executable, '-m', 'pip', 'install', 'py2neo', '-t', sys.path[0]]
12
+ subprocess.run(call)
13
+ try:
14
+ import py2neo
15
+ from py2neo import NodeMatcher,RelationshipMatcher
16
+ from py2neo.data import spatial as sp
17
+ except:
18
+ print("Neo4j - Error: Could not import pandas")
19
+
20
+ class Neo4j:
21
+
22
+ @staticmethod
23
+ def NodeToVertex(node):
24
+ """
25
+ Converts the input neo4j node to a topologic vertex.
26
+
27
+ Parameters
28
+ ----------
29
+ node : Neo4j.Node
30
+ The input neo4j node.
31
+
32
+ Returns
33
+ -------
34
+ topologic.Vertex
35
+ The output topologic vertex.
36
+
37
+ """
38
+ from topologicpy.Vertex import Vertex
39
+ from topologicpy.Topology import Topology
40
+ from topologicpy.Dictionary import Dictionary
41
+
42
+ if ('x' in node.keys()) and ('y' in node.keys()) and ('z' in node.keys()) or ('X' in node.keys()) and ('Y' in node.keys()) and ('Z' in node.keys()):
43
+ x = node['x']
44
+ y = node['y']
45
+ z = node['z']
46
+ vertex = Vertex.ByCoordinates(x, y, z)
47
+ else:
48
+ x = random.uniform(0, 1000)
49
+ y = random.uniform(0, 1000)
50
+ z = random.uniform(0, 1000)
51
+ vertex = Vertex.ByCoordinates(x, y, z)
52
+ keys = list(node.keys())
53
+ values = list(node.values())
54
+ d = Dictionary.ByKeysValues(keys, values)
55
+ vertex = Topology.SetDictionary(vertex, d)
56
+ return vertex
57
+
58
+
59
+ @staticmethod
60
+ def NodesByCypher(neo4jGraph, cypher):
61
+ dataList = neo4jGraph.run(cypher).data()
62
+ nodes = []
63
+ for data in dataList:
64
+ path = data['p']
65
+ nodes += list(path.nodes)
66
+ return nodes
67
+
68
+ @staticmethod
69
+ def NodesBySubGraph(subGraph):
70
+ data = subGraph.data()
71
+ nodes = []
72
+ for data in subGraph:
73
+ path = data['p']
74
+ nodes += list(path.nodes)
75
+ return nodes
76
+
77
+ @staticmethod
78
+ def SubGraphByCypher(neo4jGraph, cypher):
79
+ return neo4jGraph.run(cypher).to_subgraph()
80
+
81
+ @staticmethod
82
+ def SubGraphExportToGraph(subGraph):
83
+ """
84
+ Exports the input neo4j graph to a topologic graph.
85
+
86
+ Parameters
87
+ ----------
88
+ subGraph : Neo4j.SubGraph
89
+ The input neo4j subgraph.
90
+
91
+ Returns
92
+ -------
93
+ topologic.Graph
94
+ The output topologic graph.
95
+
96
+ """
97
+ from topologicpy.Vertex import Vertex
98
+ from topologicpy.Edge import Edge
99
+ from topologicpy.Topology import Topology
100
+ from topologicpy.Dictionary import Dictionary
101
+ from topologicpy.Graph import Graph
102
+
103
+ def randomVertex(vertices, minDistance):
104
+ flag = True
105
+ while flag:
106
+ x = random.uniform(0, 1000)
107
+ y = random.uniform(0, 1000)
108
+ z = random.uniform(0, 1000)
109
+ v = Vertex.ByCoordinates(x, y, z)
110
+ test = False
111
+ if len(vertices) < 1:
112
+ return v
113
+ for vertex in vertices:
114
+ d = Vertex.Distance(v, vertex)
115
+ if d < minDistance:
116
+ test = True
117
+ break
118
+ if test == False:
119
+ return v
120
+ else:
121
+ continue
122
+
123
+ nodes = subGraph.nodes
124
+ relationships = list(subGraph.relationships)
125
+ vertices = []
126
+ edges = []
127
+ for node in nodes:
128
+ #Check if they have X, Y, Z coordinates
129
+ if ('x' in node.keys()) and ('y' in node.keys()) and ('z' in node.keys()) or ('X' in node.keys()) and ('Y' in node.keys()) and ('Z' in node.keys()):
130
+ x = node['x']
131
+ y = node['y']
132
+ z = node['z']
133
+ vertex = Vertex.ByCoordinates(x, y, z)
134
+ else:
135
+ vertex = randomVertex(vertices, 1)
136
+ keys = list(node.keys())
137
+ keys.append("identity")
138
+ values = [node.identity]
139
+ for key in keys:
140
+ values.append(node[key])
141
+ d = Dictionary.ByKeysValues(keys, values)
142
+ vertex = Topology.SetDictionary(vertex, d)
143
+ vertices.append(vertex)
144
+ for relationship in relationships:
145
+ keys = list(relationship.keys())
146
+ keys.append("identity")
147
+ values = [relationship.identity]
148
+ for key in keys:
149
+ values.append(node[key])
150
+ sv = vertices[nodes.index(relationship.start_node)]
151
+ ev = vertices[nodes.index(relationship.end_node)]
152
+ edge = Edge.ByVertices([sv, ev])
153
+ if relationship.start_node['name']:
154
+ sv_name = relationship.start_node['name']
155
+ else:
156
+ sv_name = 'None'
157
+ if relationship.end_node['name']:
158
+ ev_name = relationship.end_node['name']
159
+ else:
160
+ ev_name = 'None'
161
+ d = Dictionary.ByKeysValues(["relationship_type", "from", "to"], [relationship.__class__.__name__, sv_name, ev_name])
162
+ if d:
163
+ _ = Topology.SetDictionary(edge, d)
164
+ edges.append(edge)
165
+ return Graph.ByVerticesEdges(vertices,edges)
166
+
167
+ @staticmethod
168
+ def ExportToGraph(neo4jGraph):
169
+ """
170
+ Exports the input neo4j graph to a topologic graph.
171
+
172
+ Parameters
173
+ ----------
174
+ neo4jGraph : Neo4j.Graph
175
+ The input neo4j graph.
176
+
177
+ Returns
178
+ -------
179
+ topologic.Graph
180
+ The output topologic graph.
181
+
182
+ """
183
+ from topologicpy.Vertex import Vertex
184
+ from topologicpy.Edge import Edge
185
+ from topologicpy.Topology import Topology
186
+ from topologicpy.Dictionary import Dictionary
187
+ from topologicpy.Graph import Graph
188
+
189
+ def randomVertex(vertices, minDistance):
190
+ flag = True
191
+ while flag:
192
+ x = random.uniform(0, 1000)
193
+ y = random.uniform(0, 1000)
194
+ z = random.uniform(0, 1000)
195
+ v = Vertex.ByCoordinates(x, y, z)
196
+ test = False
197
+ if len(vertices) < 1:
198
+ return v
199
+ for vertex in vertices:
200
+ d = Vertex.Distance(v, vertex)
201
+ if d < minDistance:
202
+ test = True
203
+ break
204
+ if test == False:
205
+ return v
206
+ else:
207
+ continue
208
+
209
+ node_labels = neo4jGraph.schema.node_labels
210
+ relationship_types = neo4jGraph.schema.relationship_types
211
+ node_matcher = NodeMatcher(neo4jGraph)
212
+ relationship_matcher = RelationshipMatcher(neo4jGraph)
213
+ vertices = []
214
+ edges = []
215
+ nodes = []
216
+ for node_label in node_labels:
217
+ nodes = nodes + (list(node_matcher.match(node_label)))
218
+ for node in nodes:
219
+ #Check if they have X, Y, Z coordinates
220
+ if ('x' in node.keys()) and ('y' in node.keys()) and ('z' in node.keys()) or ('X' in node.keys()) and ('Y' in node.keys()) and ('Z' in node.keys()):
221
+ x = node['x']
222
+ y = node['y']
223
+ z = node['z']
224
+ vertex = Vertex.ByCoordinates(x, y, z)
225
+ else:
226
+ vertex = randomVertex(vertices, 1)
227
+ keys = list(node.keys())
228
+ values = []
229
+ for key in keys:
230
+ values.append(node[key])
231
+ d = Dictionary.ByKeysValues(keys, values)
232
+ vertex = Topology.SetDictionary(vertex, d)
233
+ vertices.append(vertex)
234
+ for node in nodes:
235
+ for relationship_type in relationship_types:
236
+ relationships = list(relationship_matcher.match([node], r_type=relationship_type))
237
+ for relationship in relationships:
238
+ sv = vertices[nodes.index(relationship.start_node)]
239
+ ev = vertices[nodes.index(relationship.end_node)]
240
+ edge = Edge.ByVertices([sv, ev])
241
+ if relationship.start_node['name']:
242
+ sv_name = relationship.start_node['name']
243
+ else:
244
+ sv_name = 'None'
245
+ if relationship.end_node['name']:
246
+ ev_name = relationship.end_node['name']
247
+ else:
248
+ ev_name = 'None'
249
+ d = Dictionary.ByKeysValues(["relationship_type", "from", "to"], [relationship_type, sv_name, ev_name])
250
+ if d:
251
+ _ = Topology.SetDictionary(edge, d)
252
+ edges.append(edge)
253
+ return Graph.ByVerticesEdges(vertices,edges)
254
+
255
+ @staticmethod
256
+ def AddGraph(neo4jGraph, graph, labelKey=None, relationshipKey=None, bidirectional=True, deleteAll=True, tolerance=0.0001):
257
+ """
258
+ Adds the input topologic graph to the input neo4j graph
259
+
260
+ Parameters
261
+ ----------
262
+ neo4jGraph : Neo4j.Graph
263
+ The input neo4j graph.
264
+ graph : topologic.Graph
265
+ The input topologic graph.
266
+ categoryKey : str
267
+ The category key in the dictionary under which to look for the category value.
268
+ tolerance : float , optional
269
+ The desired tolerance. The default is 0.0001.
270
+
271
+ Returns
272
+ -------
273
+ Neo4j.Graph
274
+ The input neo4j graph with the input topologic graph added to it.
275
+
276
+ """
277
+ from topologicpy.Vertex import Vertex
278
+ from topologicpy.Topology import Topology
279
+ from topologicpy.Graph import Graph
280
+ from topologicpy.Dictionary import Dictionary
281
+ gmt = time.gmtime()
282
+ timestamp = str(gmt.tm_zone)+"_"+str(gmt.tm_year)+"_"+str(gmt.tm_mon)+"_"+str(gmt.tm_wday)+"_"+str(gmt.tm_hour)+"_"+str(gmt.tm_min)+"_"+str(gmt.tm_sec)
283
+ vertices = Graph.Vertices(graph)
284
+ edges = Graph.Edges(graph)
285
+ tx = neo4jGraph.begin()
286
+ nodes = []
287
+ for i in range(len(vertices)):
288
+ vDict = Topology.Dictionary(vertices[i])
289
+ keys = Dictionary.Keyus(vDict)
290
+ values = Dictionary.Values(vDict)
291
+ keys.append("x")
292
+ keys.append("y")
293
+ keys.append("z")
294
+ keys.append("timestamp")
295
+ keys.append("location")
296
+ values.append(vertices[i].X())
297
+ values.append(vertices[i].Y())
298
+ values.append(vertices[i].Z())
299
+ values.append(timestamp)
300
+ values.append(sp.CartesianPoint([vertices[i].X(),vertices[i].Y(),vertices[i].Z()]))
301
+ zip_iterator = zip(keys, values)
302
+ pydict = dict(zip_iterator)
303
+ if labelKey == 'None':
304
+ nodeName = "TopologicGraphVertex"
305
+ else:
306
+ nodeName = str(values[keys.index(labelKey)])
307
+ n = py2neo.Node(nodeName, **pydict)
308
+ neo4jGraph.cypher.execute("CREATE INDEX FOR (n:%s) on (n.name)" %
309
+ n.nodelabel)
310
+ tx.create(n)
311
+ nodes.append(n)
312
+ for i in range(len(edges)):
313
+ e = edges[i]
314
+ sv = e.StartVertex()
315
+ ev = e.EndVertex()
316
+ sn = nodes[Vertex.Index(sv, vertices, tolerance)]
317
+ en = nodes[Vertex.Index(ev, vertices, tolerance)]
318
+ relationshipType = Dictionary.ValueAtKey(ed, relationshipKey)
319
+ if not (relationshipType):
320
+ relationshipType = "Connected To"
321
+ snen = py2neo.Relationship(sn, relationshipType, en)
322
+ tx.create(snen)
323
+ snen = py2neo.Relationship(en, relationshipType, sn)
324
+ tx.create(snen)
325
+ neo4jGraph.commit(tx)
326
+ return neo4jGraph
327
+
328
+
329
+ @staticmethod
330
+ def ByParameters(url, username, password):
331
+ """
332
+ Returns a Neo4j graph by the input parameters.
333
+
334
+ Parameters
335
+ ----------
336
+ url : str
337
+ The URL of the server.
338
+ username : str
339
+ The username to use for logging in.
340
+ password : str
341
+ The password to use for logging in.
342
+
343
+ Returns
344
+ -------
345
+ Neo4j.Graph
346
+ The returned Neo4j graph.
347
+
348
+ """
349
+ return py2neo.Graph(url, auth=(username, password))
350
+
351
+ @staticmethod
352
+ def DeleteAll(neo4jGraph):
353
+ """
354
+ Deletes all entities in the input Neo4j graph.
355
+
356
+ Parameters
357
+ ----------
358
+ neo4jGraph : Neo4j Graph
359
+ The input Neo4jGraph.
360
+
361
+ Returns
362
+ -------
363
+ Neo4J Graph
364
+ The returned empty graph.
365
+
366
+ """
367
+ neo4jGraph.delete_all()
368
+ return neo4jGraph
369
+
370
+ @staticmethod
371
+ def NodeLabels(neo4jGraph):
372
+ """
373
+ Returns all the node labels used in the input neo4j graph.
374
+
375
+ Parameters
376
+ ----------
377
+ neo4jGraph : Newo4j.Graph
378
+ The input neo4j graph.
379
+
380
+ Returns
381
+ -------
382
+ list
383
+ The list of node labels used in the input neo4j graph.
384
+
385
+ """
386
+ return list(neo4jGraph.schema.node_labels)
387
+
388
+ @staticmethod
389
+ def RelationshipTypes(neo4jGraph):
390
+ """
391
+ Returns all the relationship types used in the input neo4j graph.
392
+
393
+ Parameters
394
+ ----------
395
+ neo4jGraph : Newo4j.Graph
396
+ The input neo4j graph.
397
+
398
+ Returns
399
+ -------
400
+ list
401
+ The list of relationship types used in the input neo4j graph.
402
+
403
+ """
404
+ return list(neo4jGraph.schema.relationship_types)
405
+
406
+ @staticmethod
407
+ def SetGraph(neo4jGraph, graph, labelKey=None, relationshipKey=None, bidirectional=True, deleteAll=True, tolerance=0.0001):
408
+ """
409
+ Sets the input topologic graph to the input neo4jGraph.
410
+
411
+ Parameters
412
+ ----------
413
+ neo4jGraph : Neo4j.Graph
414
+ The input neo4j graph.
415
+ graph : topologic.Graph
416
+ The input topologic graph.
417
+ labelKey : str , optional
418
+ The dictionary key under which to find the vertex's label value. The default is None which means the vertex gets the name 'TopologicGraphVertex'.
419
+ relationshipKey : str , optional
420
+ The dictionary key under which to find the edge's relationship value. The default is None which means the edge gets the relationship type 'Connected To'.
421
+ bidirectional : bool , optional
422
+ If set to True, the edges in the neo4j graph are set to be bi-drectional.
423
+ deleteAll : bool , optional
424
+ If set to True, all previous entities are deleted before adding the new entities.
425
+ tolerance : float , optional
426
+ The desired tolerance. The default is 0.0001.
427
+
428
+ Returns
429
+ -------
430
+ neo4jGraph : TYPE
431
+ The input neo4j graph with the input topologic graph added to it.
432
+
433
+ """
434
+ from topologicpy.Vertex import Vertex
435
+ from topologicpy.Graph import Graph
436
+ from topologicpy.Topology import Topology
437
+ from topologicpy.Dictionary import Dictionary
438
+
439
+ import time
440
+ gmt = time.gmtime()
441
+ timestamp = str(gmt.tm_zone)+"_"+str(gmt.tm_year)+"_"+str(gmt.tm_mon)+"_"+str(gmt.tm_wday)+"_"+str(gmt.tm_hour)+"_"+str(gmt.tm_min)+"_"+str(gmt.tm_sec)
442
+
443
+ vertices = Graph.Vertices(graph)
444
+ edges = Graph.Edges(graph)
445
+ tx = neo4jGraph.begin()
446
+ nodes = []
447
+ for i in range(len(vertices)):
448
+ vDict = Topology.Dictionary(vertices[i])
449
+ if not vDict:
450
+ keys = []
451
+ values = []
452
+ else:
453
+ keys = Dictionary.Keys(vDict)
454
+ if not keys:
455
+ keys = []
456
+ values = Dictionary.Values(vDict)
457
+ if not values:
458
+ values = []
459
+ keys.append("x")
460
+ keys.append("y")
461
+ keys.append("z")
462
+ keys.append("timestamp")
463
+ keys.append("location")
464
+ values.append(vertices[i].X())
465
+ values.append(vertices[i].Y())
466
+ values.append(vertices[i].Z())
467
+ values.append(timestamp)
468
+ values.append(sp.CartesianPoint([vertices[i].X(),vertices[i].Y(),vertices[i].Z()]))
469
+ zip_iterator = zip(keys, values)
470
+ pydict = dict(zip_iterator)
471
+ if (labelKey == 'None') or (not (labelKey)):
472
+ nodeName = "TopologicGraphVertex"
473
+ else:
474
+ nodeName = str(Dictionary.ValueAtKey(vDict, labelKey))
475
+ n = py2neo.Node(nodeName, **pydict)
476
+ tx.create(n)
477
+ nodes.append(n)
478
+ for i in range(len(edges)):
479
+ e = edges[i]
480
+ sv = e.StartVertex()
481
+ ev = e.EndVertex()
482
+ sn = nodes[Vertex.Index(vertex=sv, vertices=vertices, strict=False, tolerance=tolerance)]
483
+ en = nodes[Vertex.Index(vertex=ev, vertices=vertices, strict=False, tolerance=tolerance)]
484
+ ed = Topology.Dictionary(e)
485
+ if relationshipKey:
486
+ relationshipType = Dictionary.ValueAtKey(ed, relationshipKey)
487
+ else:
488
+ relationshipType = "Connected To"
489
+ if not (relationshipType):
490
+ relationshipType = "Connected To"
491
+ snen = py2neo.Relationship(sn, relationshipType, en)
492
+ tx.create(snen)
493
+ if bidirectional:
494
+ snen = py2neo.Relationship(en, relationshipType, sn)
495
+ tx.create(snen)
496
+ if deleteAll:
497
+ neo4jGraph.delete_all()
498
+ neo4jGraph.commit(tx)
499
+ return neo4jGraph