How to observe the removal of a model from the Firebase Database? - ios

I use Firebase Database, I have a list of cards, I need to monitor some cards if they are deleted. I tried to do this with ref.observe (.childRemoved), but this is not appropriate for my case, since some data can be deleted by the cardholder, and then this block will fire several times, I need to watch if the entire card was deleted. How can I do that?
My reference
let ref = FIRDatabase.database().reference().child(MainGateways.cards.rawValue).child(card.id)
My cards structure
"cards": {
"-Khv9rUVwErNHBzXcruO": {
"additionalInfo": {
"note": ""
},
"dateProperties": {
"day": "Flex",
"isFlexDate": true,
"isFlexTime": true,
"iso8601": "",
"time": ""
},
"interestedUsers": {
"NfM26A2YcPUFz8rfYa23Kr3mjCO2": {
"isApproved": false,
"isNew": true,
"isoDate": "2017-04-17T13:08:41+04:00",
"userID": "NfM26A2YcPUFz8rfYa23Kr3mjCO2",
"userItchableName": "Alexsander K."
}
},
"isNewPendingRequest": true,
"isPrivateStatus": false,
"isTest": false,
"ownerID": "1Cix149ThIOG1ULPVjyy0LyTxbe2",
"peopleProperties": {
"availableSeats": 1,
"numberOfPeople": 1,
"numberOfPeopleDescription": "1 person"
},
"title": "Genius Lounge and Sake Bar",
"userName": "Tim C.",
"version": 1
},
I also tried to make such a link, but then this block works if any card was removed from the list.
guard let ref = FIRDatabase.database().reference().child(MainGateways.cards.rawValue).child(card.id).parent else { return }

Look into Cloud Functions for Firebase. Using that, you can write JavaScript code that acts in response to database changes at the path you specify. This allows you to write logic independent of the client app to react to changes in the database.

Related

MS Graph API GetActivitiesByInterval gives blank itemActivitySet

Busy writing some implementation on the beta branch of MS Graph API.
Using GetActivitiesByInterval, it brings back the activity stats (how many activities / how many actors) but no activity sets (itemActivitySet)
{
"StartDateTime": "2023-01-12T00:00:00+00:00",
"EndDateTime": "2023-01-12T23:59:59+00:00",
"Access": {
"ActionCount": 4,
"ActorCount": 1,
"AdditionalData": {
"timeSpentInSeconds": 0
},
"ODataType": "microsoft.graph.itemActionStat"
},
"Create": null,
"Delete": null,
"Edit": null,
"Move": null,
"IsTrending": null,
"IncompleteData": {
"MissingDataBeforeDateTime": null,
"WasThrottled": false,
"AdditionalData": {
"resultsPending": false,
"notSupported": false
},
"ODataType": "microsoft.graph.incompleteData"
},
"Activities": null,
"Id": null,
"ODataType": "#microsoft.graph.itemActivityStat",
"AdditionalData": {
"aggregationInterval": "None"
}
}
There were definitely activities on those, a comment, a rename and a move. I can check those activities are on SharePoint.
I've also tried adding query option expand=activities on returning the drive item but that gives back an empty set (not null, just no data filled with "[],")
There also doesn't seem to be a hidden list called "userActivityFeedHiddenList" in SharePoint that I could use to reference activities for a particular file.
I've googled quite a bit to try and get as much information and went through quite a number of SO posts (hence all the things I tried) but none has worked.
Any suggestions?

Can't read data from Firebase Realtime database by issuing a GET request. Always returns null

Task is simple, but I couldn't find any solution though.
Here is the request I'm sending https://graf-24561-default-rtdb.firebaseio.com/graf-24561-default-rtdb.json
Rules for reading and writing:
{
"rules": {
".read": "now < 1651165200000", // 2022-4-29
".write": "now < 1651165200000", // 2022-4-29
}
}
Data in code:
[
{
"name": "0002 М ( мрамор) 8м пленка с\/м\/20 DEKORON ",
"price": 209.7
},
{
"name": "0007 М ( мрамор) 8м пленка с\/м\/20 DEKORON ",
"price": 209.7
},
{
"name": "0008-2 А (дуб темный) 8м пленка с\/м \/20",
"price": 232.84
},
{
"name": "0008-3 А (темн.махагон) 8м пленка с\/м \/20 ",
"price": 209.7
}
]
The graf-24561-default-rtdb that you see in the root of the JSON in the screenshot is the name of your database, and is not part of the data structure.
So to get the entire database, the URL would be:
https://graf-24561-default-rtdb.firebaseio.com/.json
It may read a bit weird with that .json at the end, but is the correct syntax.

How To Convert "created_timestamp" Value To A Valid Date In Python

I'm currently working on a Twitter bot that automatically reply messages, I'm doing this by using tweepy (the official python twitter library)
I need to filter messages based on the created time as I don't want to reply same message twice. Now the problem is that the API endpoint returns created_timestamp as string representation of positive integers.
Below is an example of data returned as per the doc
{
"next_cursor": "AB345dkfC",
"events": [
{ "id": "110", "created_timestamp": "1639919665615", ... },
{ "id": "109", "created_timestamp": "1639865141987", ... },
{ "id": "108", "created_timestamp": "1639827437833", ... },
{ "id": "107", "created_timestamp": "1639825389806", ... },
{ "id": "106", "created_timestamp": "1639825389796", ... },
{ "id": "105", "created_timestamp": "1639825389768", ... },
...
]
}
My question is "How do I convert the created_timestamp to a valid date using python" ?.
You might play with timestamps on this resource
And in your case could use methods like:
timestamp = int('timestamp_string')
datetime.fromtimestamp(timestamp, tz=None)
date.fromtimestamp(timestamp)
From the datetime standard library. But integers after the first line are already well comparable if the task is to distinguish differences between the timestamps.

GAS - create google slide scribble line with script

I would like to create a line with some point array with google-slide-api script. but I do not found any document about how to do it.
Then I create a line with scribble tool manually then read it by google-slide-api. I got below output:
- Slide #1 contains 1 elements.
elem #0 - {
"line": {
"lineProperties": {
"dashStyle": "SOLID",
"endArrow": "NONE",
"lineFill": {
"solidFill": {
"alpha": 1,
"color": {
"themeColor": "DARK2"
}
}
},
"startArrow": "NONE",
"weight": {
"magnitude": 9525,
"unit": "EMU"
}
}
},
"objectId": "gf0b4bb3376_0_2",
"size": {
"height": {
"magnitude": 786825,
"unit": "EMU"
},
"width": {
"magnitude": 763325,
"unit": "EMU"
}
},
"transform": {
"scaleX": 1,
"scaleY": 1,
"translateX": 1196175,
"translateY": 777044.3325,
"unit": "EMU"
}
}
That means google slide actual create it as a line type but nothing special to define the data points! then it's not possible to create the same from the output json data.
Answer:
Unfortunately, this isn't currently possible.
More Information:
As explained by Iamblichus in this answer, the Slides API does not support this kind of line, and as you have pointed out smoothing between separate lines does not work.
Feature Request:
You can however let Google know that this is a feature that is important for access to their APIs, and that you would like to request they implement it.
Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services, I'd urge you to make a feature request there. The best component to file this under would be the Google Slides component, with the Feature Request template.

Create a sensor with SensorDataUnitType

I'm trying to create a new device with sensor(s).
This is the payload I'm sending to create the new device:
{"Name":"DeviceABC","HardwareId":"D4xxx425","SpaceId":"xxxx-xxx-xx-xx-xxx","Status":"Provisioned","CreateIoTHubDevice":false,"Properties":[{"Name":"VendorName","Value":"MyVendor"},{"Name":"VendorDeviceId","Value":"D4xxx19425"},{"Name":"VendorDeviceType","Value":"electricity"}],"Sensors":[{"pollRate":0,"id":null,"dataType":"Json","dataUnitType":"KilowattHourEnergy","deviceId":null,"portType":null,"port":"electricity","spaceId":null,"type":"Classic"}]}
In this case I want to use a built in type. KWh
{
"id": 186,
"category": "SensorDataUnitType",
"name": "KilowattHourEnergy",
"disabled": false,
"logicalOrder": 0,
"friendlyName": "kWh"
}
The SensorDataType is :
{
"id": 314,
"spaceId": "xxxx-xx-xxx-xx-xxxx",
"category": "SensorDataType",
"name": "Json",
"disabled": false,
"logicalOrder": 0
}
When I do this for other devices without specifying a dataUnitType in the sensor object, it works fine. But as soon as I include it i get this:
{
"error": {
"code": "400.600.000.000",
"message": "Invalid datatype/dataunittype combination used on sensor."
}}
There seems to be a naming convention between SensorDataType and SensorDataUnitType. The convention is that the SensorDataUnitType needs to end with the full SensorDataType. In your example you have:
"dataType":"Json",
"dataUnitType":"KilowattHourEnergy",
But according to the convention it should be
"dataType":"Json",
"dataUnitType":"KilowattHourEnergyJson",
Of course you can't just change KilowattHourEnergy because it's in a system ontology. So to get it working I had to create KilowattHourEnergyJson as a new type.
I guess the most complete answer would include that in your case the SensorDataType probably shouldn't be JSON but should be Energy.

Resources