forked from hc2twv/PrbAndres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-data-amat.py
115 lines (113 loc) · 4.04 KB
/
generate-data-amat.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python3
import pandas as pd
import os
import numpy as np
from datetime import datetime
from random import seed
from random import randint
import requests
import json
import time
import argparse
def generate (frecuency, orionEndpoint):
count=0
if orionEndpoint is None:
orionEndpoint="orion:1026"
elif frecuency is None or "":
frecuency=3
df = pd.read_csv("/data/data/original_data_amat_four_checkpoints.csv", sep =",")
df.head()
if count==0:
ORION_ENDPOINT = "http://"+orionEndpoint+"/v2/entities/checkpoint"
headers = {'Content-Type': 'application/json','charset': 'utf-8'}
r = requests.get(url = ORION_ENDPOINT)
if r.status_code!=200 or r.status_code!=201 or r.status_code!=202:
ORION_ENDPOINT = "http://"+orionEndpoint+"/v2/entities/"
ngsiEvent={
'id':'checkpoint',
'type':'checkpoint',
'_id':{
'type':'string',
'value':0
},
'area': {
'type':'string',
'value':0
},
'date':{
'type':'date',
'value':0
},
'checkpoint':{
'type':'string',
'value':0
},
'unique_checkpoint':{
'type':'string',
'value':0
},
'geometry':{
'type':'object',
'value':0
}
}
data = json.dumps(ngsiEvent)
r = requests.post(url = ORION_ENDPOINT, headers = headers, data = data)
ORION_ENDPOINT = "http://"+orionEndpoint+"/v2/entities/checkpoint/attrs"
headers = {'Content-Type': 'application/json','charset': 'utf-8'}
seed(1)
# generate some integers
for _ in range(8736):
value = randint(0, 8736)
record=df.iloc[value]
dateTimeObj=datetime.now()
ngsiEvent={
'_id':{
'type':'string',
'value':record['id']
},
'area': {
'type':'string',
'value':record['area']
},
'date':{
'type':'date',
'value':dateTimeObj.strftime("%d-%b-%Y %H:%M:%S.%f")
},
'checkpoint':{
'type':'string',
'value':int(record['checkpoint'])
},
'unique_checkpoint':{
'type':'string',
'value':record['unique_checkpoint']
},
'geometry':{
'type':'object',
'value':record['geometry'].split("(")[1].split(" ")[0]+","+record['geometry'].split(" ")[2].split(")")[0]
}
}
print ("Start : %s" % time.ctime())
time.sleep( frecuency )
print ("End : %s" % time.ctime())
data = json.dumps(ngsiEvent)
print(data)
r = requests.post(url = ORION_ENDPOINT, headers = headers, data = data)
# extracting response text
#print(r)
pastebin_url = r.text
print("The response is:%s"%pastebin_url)
if __name__== "__main__":
# parser=argparse.ArgumentParser(
# description='''Script for collecting tickets from mongoDB ''',
# epilog="""All's well that ends well.""")
#parser.add_argument('start', type=str, default='2016-01-14', help='Start date for getting tickets!')
#parser.add_argument('end', type=str, default='2016-01-15', help='End date for getting tickets!')
#parser.add_argument('frecuency', type=int, default=5, help='Frecuency for post the tickets to the context broker!')
#parser.add_argument('mongoURI', type=str, default="mongodb://root:example@localhost:27017/", help='mongo uri with format (mongodb://user:password@localhost:27017/) where the dataset is stored!')
#parser.add_argument('orion', type=str, default='localhost:1026', help='host and port of the context broker!')
#args=parser.parse_args()
#os.environ['START_DATE']
frecuency=os.environ['FRECUENCY']
orion=os.environ['ORION_ENDPOINT']
generate(int(frecuency),orion)