-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
80 lines (60 loc) · 1.86 KB
/
test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
CoNexDat
Grupo de investigación de redes complejas y comunicación de datos
Facultad de Ingenieria
Universidad de Buenos Aires, Argentina
@author: Gabriel Davila Revelo
"""
import argparse
import exploration
import defaults
import threading
import time
import pymongo, mongo
import json
import os
import logging
import socket
def uploadColletion(collection, srcFile):
with open(srcFile) as file:
data = []
maxLines = 10000
counter =0
for line in file:
counter+=1
try:
data.append(json.loads(line))
except Exception as e:
print(("<MongoDB> " + "JSON: " + str(e)))
continue
if counter == maxLines:
try:
collection.insert_many(data, ordered = False)
except pymongo.errors.BulkWriteError as e:
print("<MongoDB> " + e.details['writeErrors'][0]['errmsg'])
data =[]
break
counter=0
data=[]
if data:
try:
collection.insert_many(data)
except pymongo.errors.BulkWriteError as e:
print("<MongoDB> " + e.details['writeErrors'][0]['errmsg'])
pass
return
print("<MongoDB> Start Uploading data")
rttFile = 'results/rtt_raspberrypi.json'
pathFile = 'results/path_raspberrypi.json'
uri_mongodb='mongodb://rttExplorer:rttExplorer@localhost:12345/rttExploration'
client = pymongo.MongoClient(uri_mongodb)
db = client.rttExploration
collection = db.rtt
print("<MongoDB> Uploading rtt data...")
uploadColletion(collection, rttFile)
collection = db.path
print("<MongoDB> Uploading path data...")
uploadColletion(collection, pathFile)
print("<MongoDB> Data Uploaded")