Scala - reformatting hash-map - scala

I have some Python code that processes a fairly complex hashmap (Example Input), restructures it and creates (Example Output) a simplified version of it. I'm looking for the best way to tackle this with Scala, i.e. built in or external libs? I'm new to Scala and just getting to grips with it, so some guidance here would be really helpful.
This was fairly easy to do using Python and I'm hoping that will be the with Scala.
Input:
data_in = {
'map': {
'stats': {
'uphosts': u'3',
'timestr': u'Thu Mar 20 18:18:09 2014',
'downhosts': u'0',
'totalhosts': u'3',
'elapsed': u'1.71'
},
'scaninfo': {
u'tcp': {
'services': u'80,443',
'method': u'syn'
}
},
'command_line': u'command goes here'
},
'scan': {
u'2a00:2384:0:208f::15': {
'status': {
'state': u'up',
'reason': u'nd-response'
},
'hostname': u'static.xyz.com',
'vendor': {
u'00:0C:67:99:6f:96': u'VMware'
},
'addresses': {
u'mac': u'00:gf:29:99:6D:96',
u'ipv6': u'a848:2384:0:3456::15'
},
u'tcp': {
80: {
'product': '',
'state': u'open',
'version': '',
'name': u'http',
'conf': u'3',
'extrainfo': '',
'reason': u'syn-ack',
'cpe': ''
},
443: {
'product': '',
'state': u'open',
'version': '',
'name': u'https',
'conf': u'3',
'script': {
u'ssl-cert': u'place holder'
},
'extrainfo': '',
'reason': u'syn-ack',
'cpe': ''
}
}
},
u'2a00:2384:0:208f::16': {
'status': {
'state': u'up',
'reason': u'nd-response'
},
'hostname': u'static.edf.com',
'vendor': {
u'00:0C:55:AE:33:ff': u'VMware'
},
'addresses': {
u'mac': u'00:54:29:fg:55:0F',
u'ipv6': u'8938:8584:0:8685::16'
},
u'tcp': {
80: {
'product': '',
'state': u'open',
'version': '',
'name': u'http',
'conf': u'3',
'extrainfo': '',
'reason': u'syn-ack',
'cpe': ''
},
443: {
'product': '',
'state': u'open',
'version': '',
'name': u'https',
'conf': u'3',
'script': {
u'ssl-cert': u'place holder'
},
'extrainfo': '',
'reason': u'syn-ack',
'cpe': ''
}
}
}
}
}
Required output:
data_out_1 = [
{'address': u'2a00:2384:0:208f::15',
'hostname': u'static.xyz.com',
'ports': {80: {'reason': u'syn-ack', 'state': u'open'},
443: {'reason': u'syn-ack',
'ssl_cert': u'place holder',
'state': u'open'}}},
{'address': u'2a00:2384:0:208f::16',
'hostname': u'static.edf.com',
'ports': {80: {'reason': u'syn-ack', 'state': u'open'},
443: {'reason': u'syn-ack',
'ssl_cert': u'place holder',
'state': u'open'}}}]

That isn't typesafe.
Hashmaps can't store different types of data*. Start by creating datastructures to hold the input data (case classes will help here).
So your stats object might look like
case class Stats(uphosts: Int, timeStr: Datetime, downhosts: Int, totalHosts: Int, elapsed:Double)
ignoring subtyping here for the moment.

Related

ipycytoscape, draw subgraph

I'm noob in ipycytoscape and Jupyter and seems need help. I'm trying to find a sutable way to show/draw subgraph after I click by node.
For example.
I have graph with node1---node2---node3 . I click by node1 and want to show
node1 --- node2.1 - node2.2 node2.3 --- node3.
Don't know how to make this. Tried to find in Google but coudn't find any suitable approach.
This is my simplest code for this. I no idea how to show and aftger hide (expand and collapse) subgraph. This code don't have this part.
I heard something about layouts but couldn't find sutable example for ipycytoscape.
Any ideas are welcome.
import ipycytoscape
import ipywidgets as widgets
import networkx as nx
counter = 0 # need to make new nodes with uniq id
data = {
'nodes': [
{ 'data': { 'id': 'desktop', 'name': 'Cytoscape', 'href': 'http://cytoscape.org' } },
{ 'data': { 'id': 'a', 'name': 'Grid', 'href': 'http://cytoscape.org', 'parent': 'Cola' } },
{ 'data': { 'id': 'c', 'name': 'Popper', 'href': 'http://cytoscape.org', 'parent': 'Cola' } },
{ 'data': { 'id': 'b', 'name': 'Cola', 'href': 'http://cytoscape.org' } },
{ 'data': { 'id': 'js', 'name': 'Cytoscape.js', 'href': 'http://js.cytoscape.org' } }
],
'edges': [
{'data': { 'source': 'desktop', 'target': 'js' }},
{'data': { 'source': 'a', 'target': 'b' }},
{'data': { 'source': 'a', 'target': 'c' }},
{'data': { 'source': 'b', 'target': 'c' }},
{'data': { 'source': 'js', 'target': 'b' }}
]
}
custom_inherited = ipycytoscape.CytoscapeWidget()
custom_inherited.graph.add_graph_from_json(data)
custom_inherited.set_style([{
'selector': 'node',
'css': {
'content': 'data(name)',
'text-valign': 'center',
'color': 'white',
'text-outline-width': 2,
'text-outline-color': 'green',
'background-color': 'green'
}
},
{
'selector': 'node[classes = "collapsed-childS"]',
'css': {
'background-color': 'red',
'line-color': 'blue',
'target-arrow-color': 'red',
'source-arrow-color': 'red',
'text-outline-color': 'red'
},
}
])
# When I click to node by mouse I add some nodes. I made this because don't know how to show and hide subgraph. The question in this place.
def paint_blue(event):
global counter
for node in cytoscapeobj.graph.nodes:
if node.data['id'] == event['data']['id']:
auxNode = node
auxNode.data['classes'] = "collapsed-childS"
station_NUR = ipycytoscape.Node()
station_NUR.data['id'] = "NUR" + str(counter)
station_NUR.data['name'] = station_NUR.data['id']
station_NUR.data['classes'] = "collapsed-childS"
station_FRA = ipycytoscape.Node()
station_FRA.data['id'] = "FRA" + str(counter)
station_FRA.data['name'] = station_FRA.data['id']
station_FRA.data['classes'] = "collapsed-childS"
new_edge1 = ipycytoscape.Edge()
new_edge1.data['id'] = "line6" + str(counter)
new_edge1.data['source'] = station_NUR.data['id']
new_edge1.data['target'] = station_FRA.data['id']
new_edge2 = ipycytoscape.Edge()
new_edge2.data['id'] = "line7" + str(counter)
new_edge2.data['source'] = station_NUR.data['id']
new_edge2.data['target'] = auxNode.data['id']
custom_inherited.graph.add_node(station_NUR)
custom_inherited.graph.add_node(station_FRA)
custom_inherited.graph.add_edges([new_edge1,new_edge2])
counter = counter + 1
custom_inherited.on('node', 'click', paint_blue)
custom_inherited

How can I query all when using Pymongo, group? not using accumulation?

I am making a restful api based on flask and Pymongo. Been trying to query data in a specific shape but having a hard time querying it. Below is my query code.
def track_route(from_time, to_time):
doc = myCol.aggregate([
{"$match":{
"MessageTime":{"$gt": from_time},
"MessageTime":{"$lt": to_time}
}},
{"$group":{
"_id":'$MMSI',
"$MMSI":{"accumulator1":"$ROT"}
}},
{"$project":{"_id":0}}
])
doc_list = [i for i in doc]
return doc_list
It returns this.
pymongo.errors.OperationFailure: The field '$MMSI' must be an accumulator object, full error: {'ok': 0.0, 'errmsg': "The field '$MMSI' must be an accumulator object", 'code': 40234, 'codeName': 'Location40234'}
This is the shape that I want to return.
[
{
123456789: [
{
MessageTime: '2021-05-28 17:29:22',
BaseStationID: '999999',
MsgType: '11',
mode: '3',
ROT: '0',
SOG: '0.0',
PosAcc: '0',
lon: '99.32404166666667',
lat: '93.47150833333333',
COG: '99.9',
Heading: '68',
MessageTimeU: '1622190562',
},
{
MessageTime: '2021-05-28 17:48:57',
BaseStationID: '4999314',
MsgType: '11',
mode: '1',
ROT: '0',
SOG: '17.7',
PosAcc: '1',
lon: '99.48246666666667',
lat: '9.980546666666667',
COG: '999.0',
Heading: '341',
MessageTimeU: '1622191737',
},
{
MessageTime: '2021-05-28 13:16:50',
BaseStationID: '999914',
MsgType: '11',
mode: '1',
ROT: '-128',
SOG: '0.1',
PosAcc: '1',
lon: '999.531585',
lat: '99.52044166666666',
COG: '998.2',
Heading: '511',
MessageTimeU: '1622175410',
},
{
MessageTime: '2021-05-28 11:45:43',
BaseStationID: '9903702',
MsgType: '11',
mode: '4',
ROT: '0',
SOG: '9.4',
PosAcc: '0',
lon: '99.51709333333334',
lat: '9.952831833333333',
COG: '00.9',
Heading: '511',
MessageTimeU: '1622169943',
},
],
},
{
234567890: [
{
MessageTime: '2021-05-28 20:59:52',
BaseStationID: '000702',
MsgType: '11',
mode: '1',
ROT: '-128',
SOG: '0.0',
PosAcc: '1',
lon: '00.46612166666667',
lat: '00.507135',
COG: '360.0',
Heading: '511',
MessageTimeU: '1622203192',
},
{
MessageTime: '2021-05-28 09:41:51',
BaseStationID: '0003702',
MsgType: '11',
mode: '1',
ROT: '-128',
SOG: '4.5',
PosAcc: '1',
lon: '00.26525833333334',
lat: '00.44930333333333',
COG: '238.7',
Heading: '511',
MessageTimeU: '1622162511',
},
{
MessageTime: '2021-05-28 17:48:50',
BaseStationID: '0003702',
MsgType: '11',
mode: '3',
ROT: '-128',
SOG: '0.0',
PosAcc: '0',
lon: '00.258005',
lat: '00.41504833333333',
COG: '00.4',
Heading: '511',
MessageTimeU: '1622191730',
},
{
MessageTime: '2021-05-28 14:27:42',
BaseStationID: '0003702',
MsgType: '11',
mode: '4',
ROT: '0',
SOG: '7.1',
PosAcc: '1',
lon: '00.260425',
lat: '00.418685',
COG: '65.0',
Heading: '511',
MessageTimeU: '1622179662',
},
],
},
];
123456789 and 234567890 are the MMSI value and are the key value for sub documents. How can I query in the shape above? It's nested. If cannot, at least the most similar way.
You have some mistakes in your aggregation, you cannot reference a field as a key, you should put a static field name.
This a correct way to group.
db.collection.aggregate({
"$group": {
"_id": "$MMSI",
"a": { //replace that "a" with any field name you want but not for a $ref
"$push": "$$ROOT" // you need to use an accumulator like $push, and the correct form to reference the whole doc is $$ROOT
}
}
}
Then you can map your info as you wanted. You can test the code here
{
"$replaceRoot": {
"newRoot": {
$arrayToObject: {
$map: {
input: [
"$$ROOT"
],
as: "el",
in: {
"k": {
$toString: "$$el._id"
},
"v": "$$el.a"
}
}
}
}
}
}

How to unwind/merge arrays from hierarchical document structure?

I have a nested document structure and I am able to filter it with pluck to show the relevant parts:
Is there an elegant way to merge all entries of the last level to a single array?
Expected result (entries are not unique on purpose):
[
'3425b91f-f019-4db3-ad56-c336bf55279b',
'3d07946e-183d-4992-9acd-676f5122e1b1',
'3425b91f-f019-4db3-ad56-c336bf55279b',
'3d07946e-183d-4992-9acd-676f5122e1b1',
'2cd652a6-4dcd-4920-9592-d4cdc5a034bf',
'70fe1812-e1de-447b-ac4f-d89fead4756d',
'2cd652a6-4dcd-4920-9592-d4cdc5a034bf',
'70fe1812-e1de-447b-ac4f-d89fead4756d'
]
I tried to use
r.table('periods')['regions']['sites']['plants']['product']['process']['technologies'].run()
but it gives the error "Cannot perform bracket on a sequence of sequences".
=> Is there some alternative operator to get a merged sequence instead a "sequence of sequences" for each step?
Something like
r.table('periods').unwind('regions.sites.plants.product.process.technologies')
Here is some python code to create example data:
from rethinkdb import RethinkDB
r = RethinkDB()
r.connect({}).repl()
r.table_create("periods")
def uniqueid():
return r.uuid().run()
periodid_first = uniqueid()
periodid_second = uniqueid()
companyid_2000 = uniqueid()
companyid_2001 = uniqueid()
technologyid_2000_first = uniqueid()
technologyid_2000_second = uniqueid()
technologyid_2001_first = uniqueid()
technologyid_2001_second = uniqueid()
energy_carrierid_2000_first = uniqueid()
energy_carrierid_2000_second = uniqueid()
energy_carrierid_2001_first = uniqueid()
energy_carrierid_2001_second = uniqueid()
periods = [
{
'id': periodid_first,
'start': 2000,
'end': 2000,
# 'sub_periods': [],
'regions': [
{
'id': 'DE',
# 'sub_regions': [],
'sites': [
{
'id': 'first_site_in_germany',
'company': companyid_2000, # => verweist auf periods => companies
'plants': [
{
'id': 'qux',
'product': {
'id': 'Ammoniak',
'process': {
'id': 'SMR+HB',
'technologies': [
technologyid_2000_first, # => verweist auf periods => technologies
technologyid_2000_second
]
}
}
}
]
}
]
},
{
'id': 'FR',
# 'sub_regions': [],
'sites': [
{
'id': 'first_site_in_france',
'company': companyid_2000, # => verweist auf periods => companies
'plants': [
{
'id': 'qux',
'product': {
'id': 'Ammoniak',
'process': {
'id': 'SMR+HB',
'technologies': [
technologyid_2000_first, # => verweist auf periods => technologies
technologyid_2000_second
]
}
}
}
]
}
]
}
],
'companies': [
{
'id': companyid_2000,
'name': 'international_company'
}
],
'technologies': [
{
'id': technologyid_2000_first,
'name': 'SMR',
'specific_cost_per_year': 123,
'specific_energy_consumptions': [
{
'energy_carrier': energy_carrierid_2000_first,
'specific_consumption': 5555
}, # => verweist auf periods => energy_carriers
{
'energy_carrier': energy_carrierid_2000_second,
'energy_consumption': 2333
}
]
},
{
'id': technologyid_2000_second,
'name': 'HB',
'specific_cost_per_year': 1234,
'specific_energy_consumptions': [
{
'energy_carrier': energy_carrierid_2000_first,
'specific_consumption': 555
}, # => verweist auf periods => energy_carriers
{
'energy_carrier': energy_carrierid_2000_second,
'energy_consumption': 233
}
]
}
],
'energy_carriers': [
{
'id': energy_carrierid_2000_first,
'name': 'oil',
'group': 'fuel'
},
{
'id': energy_carrierid_2000_second,
'name': 'gas',
'group': 'fuel'
},
{
'id': uniqueid(),
'name': 'conventional',
'group': 'electricity'
},
{
'id': uniqueid(),
'name': 'green',
'group': 'electricity'
}
],
'networks': [
{
'id': uniqueid(),
'name': 'gas',
'sub_networks': [],
'pipelines': [
]
},
{
'id': uniqueid(),
'name': 'gas',
'sub_networks': [],
'pipelines': [
]
}
]
},
{
'id': periodid_second,
'start': 2001,
'end': 2001,
# 'sub_periods': [],
'regions': [
{
'id': 'DE',
# 'sub_regions': [],
'sites': [
{
'id': 'first_site_in_germany',
'company': companyid_2001, # => verweist auf periods => companies
'plants': [
{
'id': 'qux',
'product': {
'id': 'Ammoniak',
'process': {
'id': 'SMR+HB',
'technologies': [
technologyid_2001_first, # => verweist auf periods => technologies
technologyid_2001_second
]
}
}
}
]
}
]
},
{
'id': 'FR',
# 'sub_regions': [],
'sites': [
{
'id': 'first_site_in_france',
'company': companyid_2001, # => verweist auf periods => companies
'plants': [
{
'id': 'qux',
'product': {
'id': 'Ammoniak',
'process': {
'id': 'SMR+HB',
'technologies': [
technologyid_2001_first, # => verweist auf periods => technologies
technologyid_2001_second
]
}
}
}
]
}
]
}
],
'companies': [
{
'id': companyid_2001,
'name': 'international_company'
}
],
'technologies': [
{
'id': technologyid_2001_first,
'name': 'SMR',
'specific_cost_per_year': 123,
'specific_energy_consumptions': [
{
'energy_carrier': energy_carrierid_2001_first,
'specific_consumption': 5555
}, # => verweist auf periods => energy_carriers
{
'energy_carrier': energy_carrierid_2001_second,
'energy_consumption': 2333
}
]
},
{
'id': technologyid_2001_second,
'name': 'HB',
'specific_cost_per_year': 1234,
'specific_energy_consumptions': [
{
'energy_carrier': energy_carrierid_2001_first,
'specific_consumption': 555
}, # => verweist auf periods => energy_carriers
{
'energy_carrier': energy_carrierid_2001_second,
'energy_consumption': 233
}
]
}
],
'energy_carrieriers': [
{
'id': energy_carrierid_2001_first,
'name': 'oil',
'group': 'fuel'
},
{
'id': energy_carrierid_2001_second,
'name': 'gas',
'group': 'fuel'
},
{
'id': uniqueid(),
'name': 'conventional',
'group': 'electricity'
},
{
'id': uniqueid(),
'name': 'green',
'group': 'electricity'
}
],
'networks': [
{
'id': uniqueid(),
'name': 'gas',
'sub_networks': [],
'pipelines': [
]
},
{
'id': uniqueid(),
'name': 'gas',
'sub_networks': [],
'pipelines': [
]
}
]
}
]
r.table('periods') \
.insert(periods) \
.run()
Related:
RethinkDB: RqlRuntimeError: Cannot perform bracket on a sequence of sequences
Nested concat_map in combination with r.row operator and bracket drill down does the trick:
r.table('periods') \
.concat_map(r.row['regions']) \
.concat_map(r.row['sites']) \
.concat_map(r.row['plants'])['product']['process'] \
.concat_map(r.row['technologies']) \
.run()

Google home device and dialogflow

I have a agent, using V1 dialog flow. Integrated with two Google home devices.
One Google home device is in Europe, one in India. Both the devices are configured ccount. The same account is used to deploy the webhook, deploy and dialogflow agent.
The firmware version is identical.
The agent works perfectly on simulator.
Now when talked on Google home:
Google device in India: When started inovkes, there is a certain pin number which is asked, even when pin is mentioned slowly, spaces are not considered in the dialog flow JSON request pin.original is without spaces, say pin is 12345, JSON request is 12345
Google device in Europe: When started inovkes, there is a certain pin number which is asked, even when pin is mentioned slowly, spaces are considered in the dialog flow JSON request pin.original is with spaces and gets trimmed.
say pin is 12345 but JSON request is 123,
Not sure why this is happening.
Any help, please?
Adding the dialog flow requests.........
DF JSON Request coming to backend from Google Home Device in India - Working Fine
{
data: {
'timestamp': '2018-06-15T17:42:38.261Z',
'id': 'e5acf434-4e03-4c14-b3d9-e8fc98555694',
'status': {
'errorType': 'success', 'code': 200
}
,
'sessionId': '1529084528066',
'originalRequest': {
'source': 'google', 'data': {
'user': {
'userId': '1529084528066', 'locale': 'en-US'
}
,
'surface': {
'capabilities': [{'name': 'actions.capability.MEDIA_RESPONSE_AUDIO'}, {'name': 'actions.capability.AUDIO_OUTPUT'}]
}
,
'isInSandbox': True, 'inputs': [{
'arguments': [{
'name': 'text',
'rawText': 'my pin is 23456',
'textValue': 'my pin is 23456'
}],
'intent': 'actions.intent.TEXT',
'rawInputs': [{'inputType': 'VOICE', 'query': 'my pin is 23456'}]
}], 'conversation': {
'conversationId': '1529084528066',
'conversationToken': '["0748bff2-90d8-4941-8f9f-cf59dd3d009c_id_dialog_context","actions_capability_audio_output","actions_capability_media_response_audio","auth_dialog_context","auth_dialog_params_pin","defaultwelcomeintent-followup","google_assistant_input_type_voice"]',
'type': 'ACTIVE'
}
}
,
'version': '2'
}
,
'lang': 'en-us',
'result': {
'speech': '',
'action': 'DefaultWelcomeIntent.DefaultWelcomeIntent-custom',
'actionIncomplete': False,
'parameters': {
'phone': '1234567890', 'pin': '23456'
}
,
'fulfillment': {
'speech': '', 'messages': [{'speech': '', 'type': 0}]
}
,
'source': 'agent',
'contexts': [{
'name': 'google_assistant_input_type_voice',
'parameters': {
'phone': '1234567890',
'pin': '23456',
'pin.original': '23456',
'phone.original': '12345 67890'
},
'lifespan': 0
}, {
'name': 'actions_capability_audio_output',
'parameters': {
'phone': '1234567890',
'pin': '23456',
'pin.original': '23456',
'phone.original': '12345 67890'
},
'lifespan': 0
}, {
'name': 'auth',
'parameters': {
'phone': '1234567890',
'pin': '23456',
'pin.original': '23456',
'phone.original': '12345 67890'
},
'lifespan': 5
}, {
'name': 'defaultwelcomeintent-followup',
'parameters': {
'phone': '1234567890',
'pin': '23456',
'pin.original': '23456',
'phone.original': '12345 67890'
},
'lifespan': 1
}, {
'name': 'actions_capability_media_response_audio',
'parameters': {
'phone': '1234567890',
'pin': '23456',
'pin.original': '23456',
'phone.original': '12345 67890'
},
'lifespan': 0
}],
'resolvedQuery': 'my pin is 23456',
'score': 1.0,
'metadata': {
'matchedParameters': [{
'prompts': [{'value': 'Please tell us your pin', 'lang': 'en'}],
'required': True,
'name': 'pin',
'value': '$pin',
'dataType': '#sys.phone-number',
'isList': False
}],
'webhookUsed': 'true',
'intentId': '0748bff2-90d8-4941-8f9f-cf59dd3d009c',
'nluResponseTime': 296,
'intentName': 'auth',
'webhookForSlotFillingUsed': 'false',
'isResponseToSlotfilling': False
}
}
}
}
DF JSON Request coming to backend from Google Home Device in Europe - See the pin number issue,
{
data: {
'timestamp': '2018-06-15T13:19:06.014Z',
'id': 'ca0ebb47-8bf1-478b-9c87-c704e0114cf9',
'status': {'errorType': 'success', 'code': 200},
'sessionId': '1529068715507',
'originalRequest': {
'source': 'google',
'data': {
'user': {'userId': '1529068715507', 'locale': 'en-US'},
'surface': {'capabilities': [{'name': 'actions.capability.AUDIO_OUTPUT'}, {'name': 'actions.capability.MEDIA_RESPONSE_AUDIO'}]},
'isInSandbox': True,
'inputs': [{
'arguments': [{
'name': 'text',
'rawText': 'my pin is 2 3 4 5 6',
'textValue': 'my pin is 2 3 4 5 6'
}],
'intent': 'actions.intent.TEXT',
'rawInputs': [{'inputType': 'VOICE', 'query': 'my pin is 2 3 4 5 6'}]
}],
'conversation': {
'conversationId': '1529068715507',
'conversationToken': '["0748bff2-90d8-4941-8f9f-cf59dd3d009c_id_dialog_context","actions_capability_audio_output","actions_capability_media_response_audio","auth_dialog_context","auth_dialog_params_pin","defaultwelcomeintent-followup","google_assistant_input_type_voice"]',
'type': 'ACTIVE'
}
},
'version': '2'
},
'lang': 'en-us',
'result': {
'speech': '',
'action': 'DefaultWelcomeIntent.DefaultWelcomeIntent-custom',
'actionIncomplete': False,
'parameters': {'phone': '1234567890', 'pin': '234'},
'fulfillment': {'speech': '', 'messages': [{'speech': '', 'type': 0}]},
'source': 'agent',
'contexts': [{
'name': 'google_assistant_input_type_voice',
'parameters': {
'phone': '1234567890',
'pin': '234',
'pin.original': '2 3 4',
'phone.original': '123-456-7890'
},
'lifespan': 0
}, {
'name': 'actions_capability_audio_output',
'parameters': {
'phone': '1234567890',
'pin': '234',
'pin.original': '2 3 4',
'phone.original': '123-456-7890'
},
'lifespan': 0
}, {
'name': 'auth',
'parameters': {
'phone': '1234567890',
'pin': '234',
'pin.original': '2 3 4',
'phone.original': '123-456-7890'
},
'lifespan': 5
}, {
'name': 'actions_capability_media_response_audio',
'parameters': {
'phone': '1234567890',
'pin': '234',
'pin.original': '2 3 4',
'phone.original': '123-456-7890'
},
'lifespan': 0
}, {
'name': 'defaultwelcomeintent-followup',
'parameters': {
'phone': '1234567890',
'pin': '234',
'pin.original': '2 3 4',
'phone.original': '123-456-7890'
},
'lifespan': 1
}],
'resolvedQuery': 'my pin is 2 3 4 5 6',
'score': 1.0,
'metadata': {
'matchedParameters': [{
'prompts': [{
'value': 'Please tell us your pin',
'lang': 'en'
}],
'required': True,
'name': 'pin',
'value': '$pin',
'dataType': '#sys.phone-number',
'isList': False
}],
'webhookUsed': 'true',
'intentId': '0748bff2-90d8-4941-8f9f-cf59dd3d009c',
'nluResponseTime': 356,
'intentName': 'auth',
'webhookForSlotFillingUsed': 'false',
'isResponseToSlotfilling': False
}
}
}
}
Even though your locale is the same, your location is different.
I guess, that this influences the interpretation of #sys.phone-number.
So if you would use another dataType (e.g. #sys.number-sequence), I think it would work.
You could probably try this by changing your location in the Google Actions Simulator.
(Training diverse number sequences seems to improve the results.)

Mongodb updating an embedded field

db.employee.insert(
{
_id: 'shop1',
ShopName: 'Londis',
ShopAddress: 'Clea boy',
Owner: 'Tim Byrne',
ShopContactNumber: '0877733121',
Employee: [
{
EmployId: '1',
EmployName: 'Pat Power',
EmployContactNumber: 0876395224,
EmployAddress: 'Lacka Rd',
Salary: 500.00,
Hours: 40,
PayType: 'Cheque',
Wage: 9.00,
EmployeeType: 'Manager'
},
{
EmployId: '2',
EmployName: 'Craig Coad',
EmployContactNumber: 0873347582,
EmployAddress: 'Portlaw',
Salary: 400.00,
Hours: 32,
PayType: 'Bank',
Wage: 8.65,
EmployeeType: 'FloorStaff'
},
{
EmployId: '3',
EmployName: 'Joe Bloggs',
EmployContactNumber: 0861234567,
EmployAddress: 'Waterford',
Salary: 510.00,
Hours: 12,
PayType: 'Cheque',
Wage: 9.50,
EmployeeType: 'Manager'
}]});
I want to update the state of an item for a specific Employee.
For example, I would want to update item 1 to set EmployName = "Patrick Power" for EmployeId = "1" because that employee exists:
db.students.update(
{'_id':'shop1','Employee.EmployId':'1'},
{$set:{'Employee.$.EmployName':'Patrick Power'} }
);
This is what i have been trying to do but it dose not work?
What am i doing wrong ?
This might be helpful to you :
db.collectionName.update({
"_id": "shop1",
'Employee': {
'$elemMatch': {
'EmployId': '1'
}
}
}, {
$set: {
'Employee.$.EmployName': 'Patrick Power'
}
});