-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
78 lines (67 loc) · 2.46 KB
/
client.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
import zmq
import sys
import time
import re
import ConfigParser
from informers.circle_inform import *
from informers.line_inform import *
from pymongo import MongoClient
from datetime import datetime
from pprint import pprint
client = MongoClient()
db = client['commands']
print db
commands = db['new_commands']
print commands
config = ConfigParser.RawConfigParser()
config.read('config.ini')
client_port = config.get('devices', 'client')
line_server_port = config.get('server-client', 'line-server')
circle_server_port = config.get('server-client', 'circle-server')
username = sys.argv[1]
context = zmq.Context()
sock_circle = context.socket(zmq.REQ)
sock_line = context.socket(zmq.REQ)
sock_geo_mapper = context.socket(zmq.PUB)
sock_geo_mapper.connect("tcp://127.0.0.1:"+client_port)
sock_line.connect("tcp://127.0.0.1:"+line_server_port)
sock_circle.connect("tcp://127.0.0.1:"+circle_server_port)
units = ["cm","mm","km","is","an","us","kg","of","at"]
print "Client Started"
prob = []
print "[Line,Circle]"
while True:
get_commands = commands.find_one_and_delete({"username": username})
if get_commands is not None:
print get_commands
input_sentence = str(get_commands["command"])
if str(get_commands["command"]) == "exit":
sys.exit()
sock_line.send(input_sentence)
max_output_line = sock_line.recv()
max_output_line = eval(max_output_line)
prob_line = float(max_output_line["prob"])
prob.append(prob_line)
sock_circle.send(input_sentence)
max_output_circle = sock_circle.recv()
max_output_circle = eval(max_output_circle)
prob_circle = float(max_output_circle["prob"])
prob.append(prob_circle)
print prob
maximum = 0.7
index = -1
for i in range(0,len(prob)):
if prob[i] >= maximum:
maximum = prob[i]
index = i
prob = []
if (index == 0):
processed_dict_line = line_info(input_sentence,str(max_output_line))
sock_geo_mapper.send("%s@%s" % (username, str(processed_dict_line)))
print processed_dict_line
if (index == 1):
processed_dict_circle = circle_info(input_sentence,str(max_output_circle))
sock_geo_mapper.send("%s@%s" % (username, str(processed_dict_circle)))
print processed_dict_circle
if (index == -1):
print "Unknown Input can execute - "+input_sentence