Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
39659b1f
Commit
39659b1f
authored
Feb 11, 2020
by
Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed node list for clusters
parent
e5010b4c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
29 deletions
+29
-29
cluster.py
...mmunity-detection-microservice/app/db/entities/cluster.py
+12
-12
test_cluster.py
...ommunity-detection-microservice/app/tests/test_cluster.py
+17
-17
No files found.
src/data-hub/community-detection-microservice/app/db/entities/cluster.py
View file @
39659b1f
...
@@ -4,15 +4,15 @@ from datetime import date, datetime
...
@@ -4,15 +4,15 @@ from datetime import date, datetime
class
Cluster
:
class
Cluster
:
def
__init__
(
self
,
cluster_label
:
int
=
None
,
cluster
s
:
List
=
None
):
def
__init__
(
self
,
cluster_label
:
int
=
None
,
node
s
:
List
=
None
):
self
.
cluster_label
=
cluster_label
self
.
cluster_label
=
cluster_label
self
.
clusters
=
cluster
s
self
.
nodes
=
node
s
class
LocationCluster
(
Cluster
):
class
LocationCluster
(
Cluster
):
def
__init__
(
self
,
cluster_label
:
int
=
None
,
cluster
s
:
List
=
None
,
def
__init__
(
self
,
cluster_label
:
int
=
None
,
node
s
:
List
=
None
,
location_dict
:
Dict
=
None
,
from_db
=
False
):
location_dict
:
Dict
=
None
,
from_db
=
False
):
super
()
.
__init__
(
cluster_label
,
cluster
s
)
super
()
.
__init__
(
cluster_label
,
node
s
)
self
.
id
=
f
'{self.cluster_label}'
self
.
id
=
f
'{self.cluster_label}'
if
location_dict
is
not
None
:
if
location_dict
is
not
None
:
...
@@ -22,14 +22,14 @@ class LocationCluster(Cluster):
...
@@ -22,14 +22,14 @@ class LocationCluster(Cluster):
return
{
return
{
"id"
:
self
.
id
,
"id"
:
self
.
id
,
"cluster_label"
:
self
.
cluster_label
,
"cluster_label"
:
self
.
cluster_label
,
"
clusters"
:
json
.
dumps
(
self
.
clusters
)
if
for_db
else
self
.
cluster
s
"
nodes"
:
json
.
dumps
(
self
.
nodes
)
if
for_db
else
self
.
node
s
}
}
def
from_serializable_dict
(
self
,
location_dict
:
Dict
,
from_db
=
False
):
def
from_serializable_dict
(
self
,
location_dict
:
Dict
,
from_db
=
False
):
self
.
id
=
location_dict
[
"id"
]
self
.
id
=
location_dict
[
"id"
]
self
.
cluster_label
=
location_dict
[
"cluster_label"
]
self
.
cluster_label
=
location_dict
[
"cluster_label"
]
self
.
clusters
=
json
.
loads
(
location_dict
[
"cluster
s"
])
\
self
.
nodes
=
json
.
loads
(
location_dict
[
"node
s"
])
\
if
from_db
else
location_dict
[
"
cluster
s"
]
if
from_db
else
location_dict
[
"
node
s"
]
def
__repr__
(
self
):
def
__repr__
(
self
):
return
json
.
dumps
(
self
.
to_serializable_dict
())
return
json
.
dumps
(
self
.
to_serializable_dict
())
...
@@ -39,9 +39,9 @@ class LocationCluster(Cluster):
...
@@ -39,9 +39,9 @@ class LocationCluster(Cluster):
class
TimeCluster
(
Cluster
):
class
TimeCluster
(
Cluster
):
def
__init__
(
self
,
date
:
date
=
None
,
hour
:
int
=
None
,
cluster_label
:
int
=
None
,
cluster
s
:
List
=
None
,
def
__init__
(
self
,
date
:
date
=
None
,
hour
:
int
=
None
,
cluster_label
:
int
=
None
,
node
s
:
List
=
None
,
time_dict
:
Dict
=
None
,
from_db
=
False
):
time_dict
:
Dict
=
None
,
from_db
=
False
):
super
()
.
__init__
(
cluster_label
,
cluster
s
)
super
()
.
__init__
(
cluster_label
,
node
s
)
self
.
date
=
date
self
.
date
=
date
self
.
hour
=
hour
self
.
hour
=
hour
self
.
id
=
f
'{self.date}-{self.hour}-{self.cluster_label}'
self
.
id
=
f
'{self.date}-{self.hour}-{self.cluster_label}'
...
@@ -55,7 +55,7 @@ class TimeCluster(Cluster):
...
@@ -55,7 +55,7 @@ class TimeCluster(Cluster):
"date"
:
str
(
self
.
date
),
"date"
:
str
(
self
.
date
),
"hour"
:
self
.
hour
,
"hour"
:
self
.
hour
,
"cluster_label"
:
self
.
cluster_label
,
"cluster_label"
:
self
.
cluster_label
,
"
clusters"
:
json
.
dumps
(
self
.
clusters
)
if
for_db
else
self
.
cluster
s
"
nodes"
:
json
.
dumps
(
self
.
nodes
)
if
for_db
else
self
.
node
s
}
}
def
from_serializable_dict
(
self
,
time_dict
:
Dict
,
from_db
=
False
):
def
from_serializable_dict
(
self
,
time_dict
:
Dict
,
from_db
=
False
):
...
@@ -63,8 +63,8 @@ class TimeCluster(Cluster):
...
@@ -63,8 +63,8 @@ class TimeCluster(Cluster):
self
.
date
=
datetime
.
strptime
(
time_dict
[
"date"
],
'
%
Y-
%
m-
%
d'
)
.
date
()
self
.
date
=
datetime
.
strptime
(
time_dict
[
"date"
],
'
%
Y-
%
m-
%
d'
)
.
date
()
self
.
hour
=
time_dict
[
"hour"
]
self
.
hour
=
time_dict
[
"hour"
]
self
.
cluster_label
=
time_dict
[
"cluster_label"
]
self
.
cluster_label
=
time_dict
[
"cluster_label"
]
self
.
clusters
=
json
.
loads
(
time_dict
[
"cluster
s"
])
\
self
.
nodes
=
json
.
loads
(
time_dict
[
"node
s"
])
\
if
from_db
else
time_dict
[
"
cluster
s"
]
if
from_db
else
time_dict
[
"
node
s"
]
def
__repr__
(
self
):
def
__repr__
(
self
):
return
json
.
dumps
(
self
.
to_serializable_dict
())
return
json
.
dumps
(
self
.
to_serializable_dict
())
...
...
src/data-hub/community-detection-microservice/app/tests/test_cluster.py
View file @
39659b1f
...
@@ -15,7 +15,7 @@ class TestCluster(unittest.TestCase):
...
@@ -15,7 +15,7 @@ class TestCluster(unittest.TestCase):
c
=
Cluster
(
1
,
[
1
,
2
,
3
])
c
=
Cluster
(
1
,
[
1
,
2
,
3
])
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
class
TestLocationCluster
(
unittest
.
TestCase
):
class
TestLocationCluster
(
unittest
.
TestCase
):
...
@@ -27,30 +27,30 @@ class TestLocationCluster(unittest.TestCase):
...
@@ -27,30 +27,30 @@ class TestLocationCluster(unittest.TestCase):
self
.
assertEqual
(
'1'
,
c
.
id
)
self
.
assertEqual
(
'1'
,
c
.
id
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_init_dictArgument
(
self
):
def
test_init_dictArgument
(
self
):
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
cluster
s'
:
[
1
,
2
,
3
]}
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
node
s'
:
[
1
,
2
,
3
]}
c
=
LocationCluster
(
location_dict
=
dict_
)
c
=
LocationCluster
(
location_dict
=
dict_
)
self
.
assertEqual
(
'123'
,
c
.
id
)
self
.
assertEqual
(
'123'
,
c
.
id
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_init_dictArgument_fromDb
(
self
):
def
test_init_dictArgument_fromDb
(
self
):
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
cluster
s'
:
'[1, 2, 3]'
}
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
node
s'
:
'[1, 2, 3]'
}
c
=
LocationCluster
(
location_dict
=
dict_
,
from_db
=
True
)
c
=
LocationCluster
(
location_dict
=
dict_
,
from_db
=
True
)
self
.
assertEqual
(
'123'
,
c
.
id
)
self
.
assertEqual
(
'123'
,
c
.
id
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_to_serializable_dict_noDb
(
self
):
def
test_to_serializable_dict_noDb
(
self
):
c_dict
=
self
.
c
.
to_serializable_dict
()
c_dict
=
self
.
c
.
to_serializable_dict
()
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
clusters
,
c_dict
[
'cluster
s'
])
self
.
assertEqual
(
self
.
c
.
nodes
,
c_dict
[
'node
s'
])
def
test_from_serializable_dict_noDb
(
self
):
def
test_from_serializable_dict_noDb
(
self
):
new_c
=
LocationCluster
()
new_c
=
LocationCluster
()
...
@@ -59,12 +59,12 @@ class TestLocationCluster(unittest.TestCase):
...
@@ -59,12 +59,12 @@ class TestLocationCluster(unittest.TestCase):
self
.
assertEqual
(
self
.
c
.
id
,
new_c
.
id
)
self
.
assertEqual
(
self
.
c
.
id
,
new_c
.
id
)
self
.
assertEqual
(
str
(
self
.
c
),
str
(
new_c
))
self
.
assertEqual
(
str
(
self
.
c
),
str
(
new_c
))
def
test_to_serializable_dict_db_json
Cluster
s
(
self
):
def
test_to_serializable_dict_db_json
Node
s
(
self
):
c_dict
=
self
.
c
.
to_serializable_dict
(
for_db
=
True
)
c_dict
=
self
.
c
.
to_serializable_dict
(
for_db
=
True
)
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
clusters
,
json
.
loads
(
c_dict
[
'cluster
s'
]))
self
.
assertEqual
(
self
.
c
.
nodes
,
json
.
loads
(
c_dict
[
'node
s'
]))
def
test_from_serializable_dict_fromDb
(
self
):
def
test_from_serializable_dict_fromDb
(
self
):
new_c
=
LocationCluster
()
new_c
=
LocationCluster
()
...
@@ -88,10 +88,10 @@ class TestTimeCluster(unittest.TestCase):
...
@@ -88,10 +88,10 @@ class TestTimeCluster(unittest.TestCase):
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_init_dictArgument
(
self
):
def
test_init_dictArgument
(
self
):
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
cluster
s'
:
[
1
,
2
,
3
],
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
node
s'
:
[
1
,
2
,
3
],
'date'
:
str
(
self
.
date_
),
'hour'
:
14
}
'date'
:
str
(
self
.
date_
),
'hour'
:
14
}
c
=
TimeCluster
(
time_dict
=
dict_
)
c
=
TimeCluster
(
time_dict
=
dict_
)
...
@@ -99,10 +99,10 @@ class TestTimeCluster(unittest.TestCase):
...
@@ -99,10 +99,10 @@ class TestTimeCluster(unittest.TestCase):
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_init_dictArgument_fromDb
(
self
):
def
test_init_dictArgument_fromDb
(
self
):
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
cluster
s'
:
'[1, 2, 3]'
,
dict_
=
{
'id'
:
'123'
,
'cluster_label'
:
1
,
'
node
s'
:
'[1, 2, 3]'
,
'date'
:
str
(
self
.
date_
),
'hour'
:
14
}
'date'
:
str
(
self
.
date_
),
'hour'
:
14
}
c
=
TimeCluster
(
time_dict
=
dict_
,
from_db
=
True
)
c
=
TimeCluster
(
time_dict
=
dict_
,
from_db
=
True
)
...
@@ -110,14 +110,14 @@ class TestTimeCluster(unittest.TestCase):
...
@@ -110,14 +110,14 @@ class TestTimeCluster(unittest.TestCase):
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
self
.
date_
,
c
.
date
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
14
,
c
.
hour
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
(
1
,
c
.
cluster_label
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
cluster
s
)
self
.
assertEqual
([
1
,
2
,
3
],
c
.
node
s
)
def
test_to_serializable_dict_noDb
(
self
):
def
test_to_serializable_dict_noDb
(
self
):
c_dict
=
self
.
c
.
to_serializable_dict
()
c_dict
=
self
.
c
.
to_serializable_dict
()
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
clusters
,
c_dict
[
'cluster
s'
])
self
.
assertEqual
(
self
.
c
.
nodes
,
c_dict
[
'node
s'
])
self
.
assertEqual
(
self
.
c
.
date
,
datetime
.
strptime
(
self
.
assertEqual
(
self
.
c
.
date
,
datetime
.
strptime
(
c_dict
[
'date'
],
'
%
Y-
%
m-
%
d'
)
.
date
())
c_dict
[
'date'
],
'
%
Y-
%
m-
%
d'
)
.
date
())
self
.
assertEqual
(
self
.
c
.
hour
,
c_dict
[
'hour'
])
self
.
assertEqual
(
self
.
c
.
hour
,
c_dict
[
'hour'
])
...
@@ -129,12 +129,12 @@ class TestTimeCluster(unittest.TestCase):
...
@@ -129,12 +129,12 @@ class TestTimeCluster(unittest.TestCase):
self
.
assertEqual
(
self
.
c
.
id
,
new_c
.
id
)
self
.
assertEqual
(
self
.
c
.
id
,
new_c
.
id
)
self
.
assertEqual
(
str
(
self
.
c
),
str
(
new_c
))
self
.
assertEqual
(
str
(
self
.
c
),
str
(
new_c
))
def
test_to_serializable_dict_fromDb_json
Cluster
s
(
self
):
def
test_to_serializable_dict_fromDb_json
Node
s
(
self
):
c_dict
=
self
.
c
.
to_serializable_dict
(
for_db
=
True
)
c_dict
=
self
.
c
.
to_serializable_dict
(
for_db
=
True
)
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
id
,
c_dict
[
'id'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
cluster_label
,
c_dict
[
'cluster_label'
])
self
.
assertEqual
(
self
.
c
.
clusters
,
json
.
loads
(
c_dict
[
'cluster
s'
]))
self
.
assertEqual
(
self
.
c
.
nodes
,
json
.
loads
(
c_dict
[
'node
s'
]))
self
.
assertEqual
(
self
.
c
.
date
,
datetime
.
strptime
(
self
.
assertEqual
(
self
.
c
.
date
,
datetime
.
strptime
(
c_dict
[
'date'
],
'
%
Y-
%
m-
%
d'
)
.
date
())
c_dict
[
'date'
],
'
%
Y-
%
m-
%
d'
)
.
date
())
self
.
assertEqual
(
self
.
c
.
hour
,
c_dict
[
'hour'
])
self
.
assertEqual
(
self
.
c
.
hour
,
c_dict
[
'hour'
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment