Complex Dictionary blocked Xcode compile operation in swift - ios

xCode 7.1 + swift2.1 + iOS 9.0
Code below block the Xcode compile operation.
let dic_1:Dictionary<String,Int> = ["key":200]
print("dic_1---->\(dic_1)")
Has this happened to anyone ?How does this happen?
Thanks for correcting grammer.
I found that it's not the reason the code above.
My origin code is below:
let dic_1 = [
"status": 200,
"info": "1234",
"data":[
"st_id":"st_id",
"st_name":"radiant",
"address":"dire",
"longitude":"122.111",
"latitude":"123.000000",
"is_favorite":"0",
"score":"5",
"thumbnail":"www.baidu.com",
"comment_count":"45612",
"cert_img_url":"www.baidu.com",
"has_inspay":"1",
"has_car_discount":"1",
"has_groupon":"1",
"score_environment":"4.5",
"score_service":"5.0",
"score_oil":"5.0",
"type":"98",
"city":"SHENZHEN",
"show_price_discount":"1",
"is_support_invoice":"1",
"price":[
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
],
"promotions": [
"promotion1",
"promotion1",
"promotion1",
"promotion1"
],
"gpns":[
[
"gpn_id":"75642",
"gpn_name":"gpn_name",
"oil_type":"95",
"price":"180",
"sell_amount":"20000000",
"old_price":"200"
]
],
"discount_items":[
[
"desc":"It's a descrition.",
"disc_type":"1"
]
]
]
]
print("dic_1---->\(dic_1)")
Playground is running running,never figure out anything.So does this happen in iOS project.No error,just running.

You've got a complex nested structure for the data key so Swift's type inference system failed. In my Xcode 7.1.1, it gives a "Type is ambiguous without more context" error.
Give the compiler a hint as to the data type:
let data: [String: Any] = [
"st_id":"st_id",
"st_name":"radiant",
"address":"dire",
"longitude":"122.111",
"latitude":"123.000000",
"is_favorite":"0",
"score":"5",
"thumbnail":"www.baidu.com",
"comment_count":"45612",
"cert_img_url":"www.baidu.com",
"has_inspay":"1",
"has_car_discount":"1",
"has_groupon":"1",
"score_environment":"4.5",
"score_service":"5.0",
"score_oil":"5.0",
"type":"98",
"city":"SHENZHEN",
"show_price_discount":"1",
"is_support_invoice":"1",
"price":[
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
],
"promotions": [
"promotion1",
"promotion1",
"promotion1",
"promotion1"
],
"gpns":[
[
"gpn_id":"75642",
"gpn_name":"gpn_name",
"oil_type":"95",
"price":"180",
"sell_amount":"20000000",
"old_price":"200"
]
],
"discount_items":[
[
"desc":"It's a descrition.",
"disc_type":"1"
]
]
]
let dic_1: [String: Any] = [
"status": 200,
"info": "1234",
"data": data
]

Related

All metrics are not show in influxdb from Telegraf

I have followed multiple documentation but I couldn't receive all the metrics from my JSON file to Influxdb.
My Input json file
{
"apBuildNumber": "04.04.01.0003.1f7fd3ce8896",
"version": "1.0.0",
"sentTimeMs": "1661678671000",
"sciSystemId": "scis1",
"apMac": "54:ec:2f:18:78:4d",
"apSerial": "281915001731",
"apVenue": "test",
"apName": "281915001731",
"apTenantId": "tenant",
"apReport": {},
"apNonCumulativeReport": {},
"apCumulativeReport": {
"cumulativeReportBins": [
{
"binStartTime": 123131232,
"binSampleDurationSec": "10",
"apCumulativeBinNetworksViews": [
{
"pci": [
123,
333
]
}
]
},
{
"binStartTime": 567567577,
"binSampleDurationSec": "10",
"apCumulativeBinNetworksViews": [
{
"pci": [
252,
124
]
}
]
}
]
},
"apAlarmsReport": {}
}
what I have tried :
My telegraf.conf is like this
data_format = "json_v2"
[[inputs.file.json_v2]]
[[inputs.file.json_v2.object]]
path = "apCumulativeReport"
disable_prepend_keys = true
tags = ["cumulativeReportBins_binStartTime"]
[[inputs.file.json_v2.object.field]]
path = "cumulativeReportBins_apCumulativeBinNetworksViews_pci"
type = "int"
Ideally I have to receive all the PCI values from the array but I can see only second element in each PCI array in InfluxDB.
Can someone identify what mistake I'm doing here.

Using data from the first response in the body of the second

I'm trying to combine requests from two services in one endpoint.
The first returns the list of users, like this:
{
"data": [
{ "id": 1, "name": "first", "photo": "employee_photos/key1.png" },
{ "id": 2, "name": "second", "photo": null },
{ "id": 3, "name": "third", "photo": "employee_photos/key3.png" }
]
}
The second is supposed to receive the POST request with the JSON listing photo keys to get the required version URLs.
Request:
{
"keys": [ "employee_photos/key1.png", "employee_photos/key3.png" ],
"versions": [ "small", "large" ]
}
I created a small Lua script to process the response of the first request and collect the list of keys. It looks like this:
function post_employees(request, employeesResponse)
local resp = employeesResponse.load()
local data = resp:data():get("data")
local photo_keys = {}
for i = 0, data:len() - 1, 1 do
local rec = data:get(i)
local id = rec:get("id")
local photo = rec:get("photo")
if photo then
table.insert(photo_keys, photo)
end
end
resp:data():set("photos", table.concat(photo_keys, ","))
end
But then... I can't find a way to use this list of keys in the second request. Is it even possible?

Youtube debug info field details

I am just doing a r&d on youtube video details. When we play a video in youtube and if we do right click, then we can see an option called copy debug info. If we copy that then there are lot of fields comes as below, I am just curious to know the details of these below fields.
{
"ns": "yt",
"el": "detailpage",
"cpn": "TA1LSqRVROm9Q2rb",
"docid": "tPDj7FhbUso",
"ver": 2,
"referrer": "https://www.youtube.com/feed/history",
"cmt": "208.944",
"ei": "Ups5X-iDO8ng4-EP7o6KwAg",
"fmt": "247",
"fs": "0",
"rt": "151.471",
"of": "yuFWq23SkzutVGx461bO4g",
"euri": "",
"lact": 7,
"cl": "326301777",
"mos": 0,
"state": "4",
"vm": "CAEQARgEKiBsUmpoTXRxc1czUTVHZ2RJbmktOXBNdnY3X3JnV3ItNjoyQUdiNlo4T3BuV0tmTXhwbW5wWDZjUDA3X3JPYU5PXzVSd1Bha2szZE9jNEhCY0ZQTkE",
"volume": 100,
"subscribed": "1",
"cbr": "Chrome",
"cbrver": "84.0.4147.125",
"c": "WEB",
"cver": "2.20200814.00.00",
"cplayer": "UNIPLAYER",
"cos": "Macintosh",
"cosver": "10_15_6",
"hl": "en_US",
"cr": "IN",
"len": "268.121",
"fexp": "23744176,23804281,23839597,23856950,23857950,23858057,23859802,23862346,23868323,23880389,23882502,23883098,23884386,23890960,23895671,23900945,23907595,23911055,23915993,23916148,23918272,23918598,23927906,23928508,23930220,23931938,23934047,23934090,23934970,23936412,24631210,3300107,3300133,3300161,3313321,3316358,3316377,3317374,3317643,3318816,3318887,3318889,3319024,9405957,9449243",
"afmt": "251",
"inview": "NaN",
"vct": "208.944",
"vd": "268.121",
"vpl": "207.000-208.944",
"vbu": "204.000-268.121",
"vpa": "1",
"vsk": "0",
"ven": "0",
"vpr": "1",
"vrs": "4",
"vns": "2",
"vec": "null",
"vemsg": "",
"vvol": "1",
"vdom": "1",
"vsrc": "1",
"vw": 1159,
"vh": 652,
"creationTime": 158827.80500000808,
"totalVideoFrames": 128,
"droppedVideoFrames": 0,
"corruptedVideoFrames": 0,
"lct": "208.944",
"lsk": false,
"lmf": false,
"lbw": "993748.652",
"lhd": "0.057",
"lst": "0.000",
"laa": "itag=251,type=3,seg=26,range=3299085-3408885,time=260.0-268.1,off=0,len=109801,end=1,eos=1",
"lva": "itag=247,type=3,seg=53,range=17411843-17472031,time=264.0-268.1,off=0,len=60189,end=1,eos=1",
"lar": "itag=251,type=3,seg=26,range=3299085-3408885,time=260.0-268.1,off=0,len=109801,end=1,eos=1",
"lvr": "itag=247,type=3,seg=53,range=17411843-17472031,time=264.0-268.1,off=0,len=60189,end=1,eos=1",
"lab": "200.001-268.121",
"lvb": "204.000-268.080",
"ismb": 3000000,
"relative_loudness": "-5.140",
"optimal_format": "720p",
"user_qual": "auto",
"debug_videoId": "tPDj7FhbUso",
"0sz": false,
"op": "",
"yof": false,
"dis": "",
"gpu": "Intel(R)_UHD_Graphics_630",
"cgr": true,
"debug_playbackQuality": "hd720",
"debug_date": "Mon Aug 17 2020 02:19:46 GMT+0530 (India Standard Time)"
}
For an example - docid filed is known for the video Id of youtube. Like that I wanna know other field details. If anyone can help me with, that would be great..
I doubt there is a easy way to do this - (AFAIK, no YouTube Data API exposes such values), but, if you really want to check, you can enter to view-source:https://www.youtube.com/watch?v=<VIDEO_ID> - where <VIDEO_ID> is the id of the YouTube video.
There are some values obtained from the copy debug info - but not all of them, I'm affraid.

How to change hash key from array of hashes in ruby?

Given:
data = [
{"votable_id"=>1150, "user_ids"=>"1,2,3,4,5,6,"},
{"votable_id"=>1151, "user_ids"=>"55,66,34,23,56,7,8"}
]
This is the expected result. Array should have first 5 elements.
data = [
{"votable_id"=>1150, "user_ids"=>["1","2","3","4","5"]},
{"votable_id"=>1151, "user_ids"=>["55","66","34","23","56","7",8"]}
]
This is what I tried :
data.map{|x| x['user_ids'] = x['user_ids'].split(',').first(5)}
Any other optimized solution ?
You can also use .map and .tap like this
data.map do |h|
h.tap { |m_h| m_h["user_ids"]= m_h["user_ids"].split(',').first(5)}
end
data = [
{"votable_id"=>1150, "user_ids"=>"1,2,3,4,5,6,"},
{"votable_id"=>1151, "user_ids"=>"55,66,34,23,56,7,8"}
]
Code
h=data.map do |h|
h["user_ids"]=[h["user_ids"].split(',').first(5)].flatten
h
end
p h
Output
[{"votable_id"=>1150, "user_ids"=>["1", "2", "3", "4", "5"]}, {"votable_id"=>1151, "user_ids"=>["55", "66", "34", "23", "56"]}]
data.map { |h| h.merge("user_ids"=>h["user_ids"].split(',').first(5)) }
#=> [{"votable_id"=>1150, "user_ids"=>["1", "2", "3", "4", "5"]},
# {"votable_id"=>1151, "user_ids"=>["55", "66", "34", "23", "56"]}]
See Hash#merge. This leaves data unchanged. To modify (or mutate) data use Hash#merge! (aka update). h.merge(k=>v) is a shortcut for h.merge({ k=>v }).

mosquitto with PAHO publishing and subscribing

I want to send a command line by MQTT from raspberry pi to my laptop. After search i found MQTT launcher 1 ,i want to send python simple_stream.py to run simple_stream script in windows ,but i don't know how to put the program and arguments of my command line ( python simple_stream.py) in launcher.conf file instead of the examples of author , this is launcher.conf file of author
logfile = 'logfile'
mqtt_broker = 'localhost' # default: 'localhost'
mqtt_port = 1883 # default: 1883
mqtt_clientid = 'mqtt-launcher-1'
# mqtt_username = 'jane'
# mqtt_password = 'secret'
topiclist = {
# topic payload value program & arguments
"sys/file" : {
'create' : [ '/usr/bin/touch', '/tmp/file.one' ],
'false' : [ '/bin/rm', '-f', '/tmp/file.one' ],
'info' : [ '/bin/ls', '-l', '/tmp/file.one' ],
},
"prog/pwd" : {
None : [ 'pwd' ],
},
"dev/1" : {
None : [ 'ls', '-l', '/' ],
},
"dev/2" : {
None : [ "/bin/echo", "111", "*", "#!#", "222", "#!#", "333" ],
},
}
can you please help me
Add a line to the sys/file, right after info, that says the following:
'launch' : [ '/usr/bin/python', 'simple_stream.py' ],
This way, when you send the payload 'launch' (without quotes) to the topic sys/file, it will execute the desired python script. Please adjust with the path of your python executable (in linux: 'which python' will tell you the path).
Hope this helps.

Resources