I'm starting a new project that involves some IoT devices sending every 5 minutes their status and other info to AWS IoT.
The structure of the message is the following:
{
"SNC":"C_SN_15263217541",
"STATUS":"enable",
"PLANT":{
"PNAME":"nomeimpianto",
"DVS":{
"SD":[{
"SDSN":"LD_SN_15263987543",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125",
"ALCODE":"201",
"ALDESC":"assenza scarico"
},
{
"SDSN":"LD_SN_15263987543",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125",
"ALCODE":"201",
"ALDESC":"assenza scarico"
},
{
"SDSN":"LD_SN_15263997545",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15263997545",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15123987543",
"TT":"30/11/17 4:37 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
},
{
"SDSN":"LD_SN_15123987543",
"TT":"30/11/17 4:39 PM",
"STATUS":"Enable",
"TON":"3sec",
"TOFF":"6min",
"QTAC":"125"
}
]
}
}
}
I created a rule that inserts the message on DynamoDB, and it's working nicely, but I'd need to create, for each message received, one row for each item in PLANT.DVS.SD.
My DynamoDB table has as hashkey the field PLANT.DVS.SD[x].SDSN and as sort field PLANT.DVS.SD[x].TT.
I tried with a DynamoDBv2 rule and I managed only to create one row per message with the whole array, but it's not what I'm looking for.
So basically the problem is that I don't know how to structure the SQL statement in the rule definition.
I know that PLANT.DVS.SD's max length is 12, so the only idea that I've got is to create 12 IoT rules that insert on DynamoDB only the element at a specific position. Although if there is a better way to solve this problem dynamically, it'd be appreciated!
Related
I've tried following this and this and this, but I'm having issues getting the data from a string array.
I have my state set as
businessHours = : [
"Monday: 7:00 AM – 7:00 PM",
"Tuesday: 7:00 AM – 7:00 PM",
"Wednesday: 7:00 AM – 7:00 PM",
"Thursday: 7:00 AM – 7:00 PM",
"Friday: 7:00 AM – 7:00 PM",
"Saturday: 7:00 AM – 7:00 PM",
"Sunday: Closed"
]
This only gets me the first element from the array
ForEach(businessHours.indices) {
Text(self.businessHours[$0])
}
This fails
ForEach(businessHours.indices) {
Text(self.businessHours)
}
This works in the console
for businesshour in businessHours {
print("Hours: \(businesshour).")
}
What am I doing wrong here?
Here is a demo that works. Tested with Xcode 12 / iOS 14
struct DemoView: View {
let businessHours = [
"Monday: 7:00 AM – 7:00 PM",
"Tuesday: 7:00 AM – 7:00 PM",
"Wednesday: 7:00 AM – 7:00 PM",
"Thursday: 7:00 AM – 7:00 PM",
"Friday: 7:00 AM – 7:00 PM",
"Saturday: 7:00 AM – 7:00 PM",
"Sunday: Closed"
]
var body: some View {
VStack {
ForEach(businessHours.indices) {
Text(self.businessHours[$0])
}
}
}
}
There is a much simpler way..
When you have an array where the values are separated by ", " you can divide the array with this comma symbol
For Example: I have a user model with food. Food is an array, which looks similar like this:
user.food = ["Banana", "Strawberry", "Apple"]
You noticed: Every item is separated by the comma.
Now you can simply use
Text(user.food.joined(separator: ", "))
.multilineTextAlignment(.trailing)
.padding()
Et voilá :)
I figured it out.
(0..<businessHours.count, id: \.self) { index in
Text(self.businessHours[index])
}
Apologies if this is not worded and formatted correctly, I am fresh out of bootcamp.
My app queries a Facebook users page for analytic data using the following endpoint:
{page_id}/insights/?since=08/01/2020&until=08/07/2020&metric=page_engaged_users
The data i receive back is:
{
"data":[
{
"name":"page_engaged_users",
"period":"day",
"values":[
{
"value":0,
"end_time":"2020-08-02T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-03T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-04T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-05T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-06T07:00:00+0000"
}
],
"title":"Daily Page Engaged Users",
"description":"Daily: The number of people who engaged with your Page. Engagement includes any click or story created. (Unique Users)",
"id":"137088133587412/insights/page_engaged_users/day"
},
{
"name":"page_engaged_users",
"period":"week",
"values":[
{
"value":0,
"end_time":"2020-08-02T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-03T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-04T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-05T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-06T07:00:00+0000"
}
],
"title":"Weekly Page Engaged Users",
"description":"Weekly: The number of people who engaged with your Page. Engagement includes any click or story created. (Unique Users)",
"id":"137088133587412/insights/page_engaged_users/week"
},
{
"name":"page_engaged_users",
"period":"days_28",
"values":[
{
"value":0,
"end_time":"2020-08-02T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-03T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-04T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-05T07:00:00+0000"
},
{
"value":0,
"end_time":"2020-08-06T07:00:00+0000"
}
],
"title":"28 Days Page Engaged Users",
"description":"28 Days: The number of people who engaged with your Page. Engagement includes any click or story created. (Unique Users)",
"id":"137088133587412/insights/page_engaged_users/days_28"
}
],
"paging":{
"previous":"https://graph.facebook.com/v8.0/137088133587412/insights?access_token=EAAKPk7foIPMBAGtZCNNZBPVXyOZA6zzLV4Ni7YagWXDJ2dKpzWWiasedbVMKeFBBfB1W5tm2OH7zTMJhJe6IqDkhxNq6MhYfehB8ZC3Uem5QqLWKYFAQt8s97pZBgQTpRXCiz2BZBZCtecMOnwEzJhzcAmcBzQpjX5J9FQlvM6QfDO46Jz6MbDCLZBB10osuiInywsJsTb2jZCwZDZD&pretty=1&since=1595833200&until=1596265200&metric=page_engaged_users",
"next":"https://graph.facebook.com/v8.0/137088133587412/insights?access_token=EAAKPk7foIPMBAGtZCNNZBPVXyOZA6zzLV4Ni7YagWXDJ2dKpzWWiasedbVMKeFBBfB1W5tm2OH7zTMJhJe6IqDkhxNq6MhYfehB8ZC3Uem5QqLWKYFAQt8s97pZBgQTpRXCiz2BZBZCtecMOnwEzJhzcAmcBzQpjX5J9FQlvM6QfDO46Jz6MbDCLZBB10osuiInywsJsTb2jZCwZDZD&pretty=1&since=1596697200&until=1597129200&metric=page_engaged_users"
}
}
Values are all zero as the page doesn't have any views as I am
testing.
For some reason the data is returned in 3 seperate objects (day, week
& 28_days), not sure why its returned like that when i give it a range
but thats not the main question at hand.
My understanding of the data returned is that for the first value, the data is for 08/01/2020 (the 1st of august, a Saturday), denoted by "end_time" which is set for the start of 08/02/2020 (the start of 2nd of august, midnight 00:00).
The data returned only includes 5 results, spanning 08/01/2020 - 08/05/2020 (Saturday the 1st of august to Thursday the 5th of august).
I could understand if it only included 6 days (given a 7 day range) as it may be taking the 7th day as the end point, but it stops on the 5th day, needless to say I am extremely confused.
Why don't I have 7 days worth of data or at least 6 days?
I'm clearly not understanding a fundamental concept here.
Using sandbox key and transaction id when I'm creating the user using json flavour. This api will response me the customerProfileId and customerPaymentProfileIdList in the list there is one id. Can we create it multiples? if yes, Then what is the json string I have to send to generate multiple customerPaymentProfileIds. If no, Then please expalin why I'm not sending the array to the api. Or how to create the multiple payment profiles using authrization.net.
Now I'm sending this json:-
{
"createCustomerProfileRequest": {
"merchantAuthentication": {
"name": "name",
"transactionKey": "transaction_key"
},
"profile": {
"merchantCustomerId": "This is a+fdstring",
"description": "This is a description.",
"email": "RuldaRam#gmail.com",
"paymentProfiles": {
"customerType": "individual",
"billTo":{
"firstName":"Puneet",
"lastName":"Jindal",
"address":"Mohali",
"city":"Banglore",
"state":"Delhi",
"zip":"10001"
},
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "2020-12",
"cardCode":"123"
}
}
}
},
"validationMode": "testMode"
}
}
Developer link
I also tried to do it like this
My response body data:
"slots": {
"deliverySlots.today.text": {
"list": [
{
"pos": "004",
"deliverySlotCode": "8800652143353",
"deliveryDate": "Mar 20",
"beginTime": "10 am",
"endTime": "12 pm",
"dayOfWeek": "Tuesday",
"selected": false,
"expired": true,
"isAvailable": true
}
]
}
}
I would like to save the value of the isAvailable property into an environment variable. How can I set this value?
Given the data that you posted, you could add something like this to the Tests tab to create the variable.
var my_value = pm.response.json().slots['deliverySlots.today.text'].list[0].isAvailable
pm.environment.set('my_var', my_value)
This will only set the value that is in position 0 in your list array.
This part of the route deliverySlots.today.text needs to be wrapped in brackets [] as you cannot use the same dot notions to parse the JSON. It's quite a terrible naming convention so if you have any say over it, i'd recommend changing it.
I'm trying to get the attending_count on facebook graph API. I know that going throug /event-id?fields=attending_count I will have this info available but when trying this inside the venue /venue-id/events?fields=attending_count this is not being displayed.
Here is what i'm trying:
https://graph.facebook.com/v2.2/217733628398158/events?fields=id,cover,name,venue,description,ticket_uri,start_time,attending_count&access_token=....
Any ideas?
There's no attending_count field on the Event object, but there is an attending edge:
https://developers.facebook.com/docs/graph-api/reference/v2.2/event#readfields
https://developers.facebook.com/docs/graph-api/reference/v2.2/event/attending#read
Why are you trying to get the attending_count on the Venue's Page ID? That doesn't make much sense.
You can use the summary to get the absolute count of attendees like this
/217733628398158/events?fields=id,cover,name,venue,description,ticket_uri,start_time,attending.summary(true).limit(1)
To reduce the amount of data returned by the Graph API I added the .limit(1) which is only returning one attendee per event, but producing the summary count anyway. If you need the whole list, remove the limit parameter.
So, it returns
{
"data": [
{
"id": "326299167565639",
"cover": {
"cover_id": "839491946113340",
"source": "https://scontent-a.xx.fbcdn.net/hphotos-xpa1/t31.0-8/s720x720/10547740_839491946113340_540194689313513221_o.jpg",
"offset_y": 28,
"offset_x": 0
},
"name": "Feeling This • Histórias de verão",
"venue": {
"name": "Lima e Silva, 1037, Porto Alegre"
},
"description": "ARE YOU FEELING THIS?\nÉ a nostalgia da estação quente que tá batendo!\n\nFaça aqui a sua história de verão.\nThese are the best days of our lives!\n\n-\n\nIngressos:\nR$15 com Feeling Cup!*\nR$20 na lista* <http://goo.gl/1I9vV8>\nR$25 na hora\n\n* Lista encerra às 20h do dia da festa. \n* Válido para entrada até 00h\n\n\nQuer comemorar seu aniversário na FEELING THIS? Entre em contato através do e-mail cucko#cucko.com.br para saber das vantagens.",
"ticket_uri": "https://www.facebook.com/ajax/events/ticket.php?event_id=326299167565639&source=12&ext=1421830108&hash=ATX8w7CCSBVhKO6G",
"start_time": "2015-02-04T22:00:00-0200",
"attending": {
"data": [
{
"name": "Foo Pretenders",
"rsvp_status": "attending",
"id": "1395261354109384"
}
],
"paging": {
"cursors": {
"after": "TVRBd01EQTROelkxT1RnMk9UYzBPakUwTWpNd09UUTBNREE2TVRZMU1EZzBPRGsyT0RRNE5UZ3g=",
"before": "TVRBd01EQTROelkxT1RnMk9UYzBPakUwTWpNd09UUTBNREE2TVRZMU1EZzBPRGsyT0RRNE5UZ3g="
},
"next": "https://graph.facebook.com/v2.2/326299167565639/attending?summary=true&limit=1&after=TVRBd01EQTROelkxT1RnMk9UYzBPakUwTWpNd09UUTBNREE2TVRZMU1EZzBPRGsyT0RRNE5UZ3g="
},
"summary": {
"count": 634
}
}
},
....
]
There are 634 people attending the specific event.