Skip to content

Commit 8442da0

Browse files
committed
add support for time-based networks
1 parent 2d411aa commit 8442da0

File tree

3 files changed

+61
-139
lines changed

3 files changed

+61
-139
lines changed

examples/data/test_data_nodes.csv

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
id,name,lat,lng,weight
2-
1,Stephanie,-6.7589,105.8671,20
3-
2,Teresa,47.7675,21.24,14
4-
3,Theresa,29.28065,105.70568,11
5-
4,Phyllis,-37.46025,-63.58537,11
6-
5,Ann,-6.23,106.0752,19
7-
6,Jennifer,-6.5465,105.8728,10
8-
7,Jacqueline,15.31667,-91.61667,11
9-
8,Julie,61.79682,25.70457,12
10-
9,Louise,61.19472,62.86889,10
11-
10,Wanda,-31.38333,-57.96667,19
1+
id,name,lat,lng,weight,year_start,year_stop
2+
1,Stephanie,-6.7589,105.8671,20,2005,2008
3+
2,Teresa,47.7675,21.24,14,2006,2009
4+
3,Theresa,29.28065,105.70568,11,2005,2008
5+
4,Phyllis,-37.46025,-63.58537,11,2006,2010
6+
5,Ann,-6.23,106.0752,19,2006,2011
7+
6,Jennifer,-6.5465,105.8728,10,2007,2012
8+
7,Jacqueline,15.31667,-91.61667,11,2009,2010
9+
8,Julie,61.79682,25.70457,12,2008,2010
10+
9,Louise,61.19472,62.86889,10,2007,2009
11+
10,Wanda,-31.38333,-57.96667,19,2009,2012

examples/topogram.py

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,62 @@
33

44
from topogram_client import TopogramAPIClient
55
from random import randint
6+
from csv import DictReader
67

78
# credentials
89
TOPOGRAM_URL = "http://localhost:3000" # "https://app.topogram.io"
910
1011
PASSWORD = "password"
1112

12-
1313
# data
14-
NODES_COUNT = 5
15-
EDGES_COUNT = 8
14+
my_nodes = []
1615
my_edges = []
1716

18-
my_nodes = [{
19-
"data" : {
20-
"id": str(i),
21-
"name" : "Node %s"%i
22-
}
23-
}for i in range(0,NODES_COUNT+1)]
24-
25-
for n in range(0,EDGES_COUNT):
26-
src = str(randint(0,NODES_COUNT))
27-
tgt = str(randint(0,NODES_COUNT))
28-
edge = {
29-
"data" : {
30-
"source" : src,
31-
"target" : tgt,
32-
"weight" : 5,
33-
"name" : "Edge from %s to %s"%(src, tgt)
34-
}
35-
}
36-
my_edges.append(edge)
17+
with open('data/test_data_nodes.csv') as f :
18+
reader = DictReader(f)
19+
for n in reader :
20+
node = {
21+
"id" : n["id"],
22+
"name" : n["name"],
23+
"lat" : float(n["lat"]),
24+
"lng" : float(n["lng"]),
25+
"weight" : float(n["weight"]),
26+
"start" : n["year_start"],
27+
"end" : n["year_stop"]
28+
}
29+
my_nodes.append({ "data" : node })
3730

38-
print my_edges
3931
print my_nodes
4032

41-
# connect to the topogram instance
42-
topogram = TopogramAPIClient(TOPOGRAM_URL)
43-
44-
# create a new user
45-
# topogram.create_user(USER, PASSWORD)
33+
with open('data/test_data_edges.csv') as f :
34+
reader = DictReader(f)
35+
for e in reader :
36+
edge = {
37+
"source" : e["source"],
38+
"target" : e["target"],
39+
"weight" : float(e["weight"])
40+
}
41+
my_edges.append({ "data" : edge })
4642

47-
# login a new user if needed
48-
# topogram.user_login(USER, PASSWORD)
43+
# print my_edges
4944

5045
def create_topogram(title, nodes, edges):
5146

5247
print "Creating topogram '%s'"%title
5348

54-
r = topogram.create_topogram(title)
55-
print r
56-
print r["data"]
49+
try :
50+
r = topogram.create_topogram(title)
51+
except ValueError:
52+
print '> Topogram already exists'
53+
r = topogram.get_topogram_by_name(title)
54+
5755
topogram_ID = r["data"]["_id"]
56+
print "topogram ID : %s"%topogram_ID
5857

5958
# get and backup existing nodes and edges
6059
existing_nodes = topogram.get_nodes(topogram_ID)["data"]
6160
existing_edges = topogram.get_edges(topogram_ID)["data"]
6261

63-
6462
# clear existing graph
6563
if len(existing_nodes):
6664
topogram.delete_nodes([n["_id"] for n in existing_nodes])
@@ -70,11 +68,27 @@ def create_topogram(title, nodes, edges):
7068
print "%s edges deleted"%len(existing_edges)
7169

7270
r = topogram.create_nodes(topogram_ID, nodes)
71+
print r
7372
print "%s nodes created."%len(r["data"])
7473
r = topogram.create_edges(topogram_ID, edges)
7574
print "%s edges created."%len(r["data"])
7675

77-
print "done. Topogram has been updated. Check it at %s/topograms/%s/view"%(TOPOGRAM_URL, topogram_ID)
76+
print "done. Topogram has been updated. Check it at %s/topograms/%s"%(TOPOGRAM_URL, topogram_ID)
77+
78+
# connect to the topogram instance (pass debug=True params for more info )
79+
topogram = TopogramAPIClient(TOPOGRAM_URL) #, debug=True)
80+
81+
# create a new user
82+
try :
83+
topogram.create_user(USER, PASSWORD)
84+
except ValueError:
85+
print "> User has already been created."
86+
87+
# login a new user if needed
88+
resp_user_login = topogram.user_login(USER, PASSWORD)
89+
print resp_user_login
7890

91+
assert(resp_user_login["status"] == "success")
92+
assert(resp_user_login["status_code"] == 200)
7993

80-
create_topogram("Test", my_nodes, my_edges)
94+
create_topogram("Geo-time network", my_nodes, my_edges)

examples/topogram_with_geo.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)