forked from yshin1209/Computational-Medicine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure function python
56 lines (44 loc) · 1.22 KB
/
azure function python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#VS Code
import logging
import json
import azure.functions as func
def main(req) -> str:
logging.info('Python HTTP trigger function processed a request.')
#req_body = req.get_json()
req_body = req.get_body().decode(encoding='UTF-8')
req_body = json.loads(req_body)
x = req_body['x']
y = req_body['y']
p_xy = req_body['p_xy']
p_y = req_body['p_y']
y = p_xy*x + p_y*y
response = {'y':y}
json_response = json.dumps(response)
logging.info(json_response)
return json_response
#Google Colab
import networkx as nx
import matplotlib.pyplot as plt
import requests
import json
N = 100
G = nx.DiGraph()
G.add_node('x')
G.add_node('y')
G.add_edge('x', 'y')
G.nodes['x']['concentration'] = 10
x_conc = G.nodes['x']['concentration']
G.nodes['y']['concentration'] = 0
y_conc = G.nodes['y']['concentration']
p_xy = 0.2
p_y = 0.8
url = 'https://azurefunctionpythonyshin.azurewebsites.net/api/HttpTrigger1?'
for i in range(1,N):
request_body = {"x": x_conc, "y": y_conc, "p_xy": p_xy, "p_y": p_y}
response = requests.post(url, data = json.dumps(request_body))
print (response)
response_body = response.json()
y_conc = response_body['y']
print (y_conc)
nx.draw(G, with_labels=1)
plt.show()