Example #1
0
def generate_datapoint(arg):
    numeric_msg = math_pb2.Numeric()
    numeric_msg.value = float(arg) * 2
    return datapoint_pb2.Datapoint(
        stream="command.numeric.result",
        numeric=numeric_msg,
        timestamp=int(time.time() * 1000),
    )
Example #2
0
    "registered":
    "Sunday, May 20, 2018 1:49 AM",
    "latitude":
    "16.917591",
    "longitude":
    "149.179144",
    "tags": ["quis", "esse", "Lorem", "deserunt", "sunt"],
    "friends": [{
        "id": 0,
        "name": "Castillo Huffman"
    }, {
        "id": 1,
        "name": "Martha Montoya"
    }, {
        "id": 2,
        "name": "Taylor Foley"
    }],
    "greeting":
    "Hello, Potter! You have 8 unread messages.",
    "favoriteFruit":
    "strawberry"
})

json = text_pb2.Json()
json.value = jsonData
data_point = datapoint_pb2.Datapoint(stream="test.json.grpc",
                                     json=json,
                                     timestamp=int(time.time() * 1000),
                                     tags={"Region": "Laurelhurst"})
agent.PostData(data_point)
Example #3
0
import time

import grpc
from formant.protos.agent.v1 import agent_pb2_grpc
from formant.protos.model.v1 import datapoint_pb2, navigation_pb2

channel = grpc.insecure_channel("localhost:5501")
agent = agent_pb2_grpc.AgentStub(channel)

geo = navigation_pb2.Location()
geo.latitude = 37.8199
geo.longitude = -122.4783
geo_datapoint = datapoint_pb2.Datapoint(stream="test.gps",
                                        location=geo,
                                        timestamp=int(time.time() * 1000))
response = agent.PostData(geo_datapoint)
Example #4
0
import grpc
from formant.protos.agent.v1 import agent_pb2, agent_pb2_grpc
from formant.protos.model.v1 import datapoint_pb2, math_pb2
from grpc_status import rpc_status

path = os.path.dirname(os.path.realpath(__file__))
channel = grpc.insecure_channel("localhost:5501")
agent = agent_pb2_grpc.AgentStub(channel)

datapoints = []
for x in range(0, 20):
    numeric_msg = math_pb2.Numeric()
    numeric_msg.value = random.uniform(0, 1)
    data_point = datapoint_pb2.Datapoint(
        stream="test.numeric", numeric=numeric_msg, timestamp=int(time.time() * 1000)
    )
    datapoints.append(data_point)
    # force some throttling errors to see error handling
    time.sleep(0.001)

request = agent_pb2.PostDataMultiRequest(datapoints=datapoints)

try:
    agent.PostDataMulti(request)
# catch rpcError
except grpc.RpcError as e:
    status = rpc_status.from_call(e)
    for post_data_multi_error in status.details:
        if post_data_multi_error.Is(agent_pb2.PostDataMultiError.DESCRIPTOR):
            # unpack error details into proto agent_pb2.PostDataMultiError
Example #5
0
import os
import time

import grpc

from formant.protos.agent.v1 import agent_pb2_grpc
from formant.protos.model.v1 import datapoint_pb2, file_pb2

path = os.path.dirname(os.path.realpath(__file__))
channel = grpc.insecure_channel("localhost:5501")
agent = agent_pb2_grpc.AgentStub(channel)

file_datapoint = file_pb2.File()
file_path = "%s/../../data/planets.csv" % path
file_datapoint.url = file_path
file_datapoint.filename = "planets.csv"
request = datapoint_pb2.Datapoint(stream="test.file",
                                  file=file_datapoint,
                                  timestamp=int(time.time() * 1000))
agent.PostData(request)
Example #6
0
    )


if command.request.id != "":
    print("Received command request:\n%s" % command)

    if command.request.command == "my_command":
        # example command which ingests a numeric datapoint
        # equal to twice the input value
        response = commands_pb2.CommandResponse(
            datapoint=generate_datapoint(command.request.text),
            request_id=command.request.id,
        )
        response.success = True
    else:
        text = text_pb2.Text()
        text.value = "command not supported"
        datapoint = datapoint_pb2.Datapoint(
            stream="command.error", text=text, timestamp=int(time.time() * 1000)
        )
        response = commands_pb2.CommandResponse(
            datapoint=datapoint, request_id=command.request.id
        )
        response.success = False

    request = agent_pb2.SendCommandResponseRequest(response=response)
    agent.SendCommandResponse(request)
    print("Sent command response\n%s" % request)
else:
    print("No pending command requests found.")
Example #7
0
import random
import time

import grpc
from formant.protos.agent.v1 import agent_pb2_grpc
from formant.protos.model.v1 import datapoint_pb2, math_pb2

path = os.path.dirname(os.path.realpath(__file__))
channel = grpc.insecure_channel("localhost:5501")
agent = agent_pb2_grpc.AgentStub(channel)

numeric_msg1 = math_pb2.NumericSetEntry()
numeric_msg1.value = random.uniform(0, 1000)
numeric_msg1.label = "frequency"
numeric_msg1.unit = "Hz"

numeric_msg2 = math_pb2.NumericSetEntry()
numeric_msg2.value = random.uniform(0, 100)
numeric_msg2.label = "usage"
numeric_msg2.unit = "percent"

numericset_msg = math_pb2.NumericSet()
numericset_msg.numerics.append(numeric_msg1)
numericset_msg.numerics.append(numeric_msg2)

data_point = datapoint_pb2.Datapoint(
    stream="test.numeric_set",
    numeric_set=numericset_msg,
    timestamp=int(time.time() * 1000),
)
agent.PostData(data_point)
Example #8
0
import time

import grpc
from formant.protos.agent.v1 import agent_pb2_grpc
from formant.protos.model.v1 import datapoint_pb2, text_pb2

channel = grpc.insecure_channel("localhost:5501")
agent = agent_pb2_grpc.AgentStub(channel)

text = text_pb2.Text()
text.value = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
data_point = datapoint_pb2.Datapoint(
    stream="test.text.grpc",
    text=text,
    timestamp=int(time.time() * 1000),
    tags={"Region": "NorthAmerica"},
)
agent.PostData(data_point)