watchOS - Show realtime departure data on complication - watchkit

I have an public transport app with realtime departure data for trains.
I would like to add a complication that shows the departure time of the next train.
Is it possible to show (or refresh) realtime data on a complication? For example, showing "3 min. to station X." The data could change every minute, based on info that comes from the public transport API.
How should I accomplish this on watchOS 2 or watchOS 3?
I know the ETA app shows travel times in a complication, but I'm not sure how they achieve that.

Are realtime updates possible?
Complications aren't designed to show realtime data. Frequent updates can affect energy efficiency and impact the battery (on both watch and phone).
To minimize power usage, ClockKit asks you to provide as much data as you have available and then caches the data and renders it when needed.
While there is no fixed number of times a complication timeline can be reloaded, the complication data source is subject to a daily execution time budget.
If your app’s data changes frequently, it might be difficult to provide enough data to display in a complication. Worse, if you refresh your complication data too frequently, you may exceed your execution time budget and your complication might not be updated until the following day.
Once the daily budget is exhausted, calls to reloadTimeline (and extendTimeline) do nothing.
If your complication has already exceeded its allotted daily budget for execution time, calls to this method do nothing. Call this method sparingly.
How can a complication display relative times?
You can use a CLKRelativeDateTextProvider to create a formatted relative time that can change on a minute-by-minute basis.
A CLKRelativeDateTextProvider object creates a formatted string that conveys the difference in time between the current date and a date that you specify. You use a relative date text provider to implement timers or other relative time values in an efficient way. Instead of using multiple timeline entries to replicate a countdown timer, create a single timeline entry with a relative date text provider. When the user views the clock face, ClockKit automatically updates the relative time value in your complication, providing up-to-date time information.
How could a complication be frequently updated?
You could use a complication push update (either from a remote server, or locally from the phone in iOS 10).
There is a limit of 50 complication push updates per day.
You could fetch data on the phone and use transferCurrentComplicationUserInfo.
In watchOS 2, this was only subject to the daily budget. In watchOS 3, this is now limited to 50 transfers per day.
See Is transferCurrentComplicationUserInfo more suitable for complication update? for more details.
In watchOS 2, you could use getNextRequestedUpdateDate to schedule the next time to update your complication.
This can't occur more often than every ten minutes.
Note that watchOS 3 apps should be upgraded to use background refresh app tasks. The main benefit is that background tasks would be able to do more than merely update your complication. They can also handle fetching data, updating your model once the data arrives, as well as updating your dock snapshot.
Finally, you can schedule a manual update. In watchOS 3, the recommended way to do this would via a background refresh app task.
The task budget permits 4 tasks per hour. See scheduleBackgroundRefresh for more details.
Note that background refresh app tasks must not use more than 10% CPU.
Recommended WWDC 2016 sessions
208 What's New in watchOS 3 introduces some of these topics.
804 Designing Great Apple Watch Experiences discusses when and why to update your watch apps.
218 Keeping Your Watch App Up to Date provides details about using background tasks to update your complication, app, and dock snapshot.
As mentioned in the talks, you should schedule your updates around the times when they would be needed.
For your use case, examples would be only when public transit is running, and only when the regularly scheduled departure times would be affected by a delay.
Apple sample code
Apple provides WatchBackgroundRefresh sample code demonstrating how to use WKRefreshBackgroundTask to update WatchKit apps in the background.
To update any active complication within a background task, you would simply add code to reload (or extend) the timeline:
let complicationServer = CLKComplicationServer.sharedInstance()
for complication in activeComplications {
complicationServer.reloadTimelineForComplication(complication)
}

Related

Firestore Batchwrites is updating Fieldvalue Increment multiple times if device is switched from offline to online and clear running my application

Today I found an error about Firestore Batchwrite in my stock control application.
My database structure was designed to store the order detail information in one collection (orders) and in other collection (report_monthly for count purposes) for monthly reports, I stored the quantity information such as total no of stocks, price, and debts.
The problem was this morning I make offline orders of stocks of about 20-25 orders. After I switch my phone from offline to online instantly, I can see the numbers are increasing (clearly firebase is updating the data) but I suddenly clear the app from working like clear recent apps in the android system. Then when I re-run(open) my app, these data are incorrect. Although the data in order collection(orders) is correct, the report number of quantity value in the monthly collection(report_monthly) was somehow repeated increment.
I tested this process multiple times with my friend and still facing the problems. I also tested without using BatchWrite. In that case, I can still see the issues but some of Fieldvalue increments are right and some are wrong not like in BatchWrite which is the whole list of Fieldvalue increments is wrong.
Can someone suggest to me how can I handle this kind of problem?

How can I change the graph interval in Live Metrics Stream

The current interval of 1 second and max of 60 seconds is too small and issues may be missed.
When viewing the live metrics stream page of Application Insights the interval on all graphs are 1 second, and it only goes up to 60 seconds. I am trying to use this as a monitoring page to keep an eye on recently released or updated function apps. For this I need to be able to change the interval to view more data at once without having to keep watch on it. Right now if we don't keep watch on it every minute we may miss something important.
I have searched the Microsoft documentation, the git repository, stackoverflow, and various other sites trying to find my answer but the only thing I found was from over 4 years ago and I would hope that this has changed since then.
Live Metrics Stream allows to peek at what's going one right now with 1 second resolution. But it doesn't persist data anywhere. So, data is only stored in UX (browser) and right now only for 60 seconds.
For bigger intervals it might make sense to refer to other Application Insights experiences (including Analytics).

Updating an Apple Watch's complication's content at midnight

I've add my complication entries and this all seems to work well - each complication entry is scheduled for midnight.
I'm testing the time change by setting my Mac's date to the following day where I'm expecting my complication to update to the next entry.
However, it only updates the entry when I open and close my app. I'm expecting to see it automatically change like the other standard complications do. Is this some behaviour I need to go out of my way to implement? I'd expect an automatic change as per the docs.
I've found the following:
ClockKit begins displaying a timeline entry precisely at the time specified by the entry’s date property.
But surely this is a greater than check too? I tried setting it exactly to midnight but (surprisingly) this doesn't work either.
Any help is appreciated.
Additionally, I found the following regarding updating the timeline, but I would have thought this would be for changing the timeline entries as oppose to just refreshing the complication for the current timeline:
During a background app refresh task. You can schedule background tasks to periodically update your watchOS content. This works best when your data changes at predictable times.
The Watch Simulator appears to have some quirks around handling of times. In particular, it doesn’t seem to obey time changes on the underlying system until you relaunch it.
Relaunch the Simulator after changing the system clock and check on your Complication then. If you want to test the transition to the next day specifically, you can set the system time to 11:58 pm and wait for it to cut over.

Firebase Analytics User time for performing actions

I would like to measure how long (on average) users are performing certain actions in my app. For example, the time it takes for a user to add an item to the cart till the time to purchase the items. Can Firebase analytics track these time differences? If so, how can I get a report out of it or add it to my dashboard.
I know this can be done using traces in Performance monitoring, but I want to know these time differences not to troubleshoot performance issues but rather behavioral issues for my users.

NetSuite case ageing notification

Below question is related to NetSuite Support Module.
We want to send an email notification to the support rep assigned to the case if the time since last modification of the case has exceeded 48 hours. This notification needs to be sent for each case as soon as it ages over 48 hours since last modification,
I tried a saved search notifiaction, but that does not work as the case which exceeds 48 hours is not a new record.
I am not able to figure out what the trigger would be for a workflow or a script to make this notification work.
Any ideas?
Thanks
Use a workflow
make initiation "Scheduled"
use a condition that the Case is not closed or whatever works for you
under Saved Search set up a search that ids cases older than 48 hours
the saved search will run every half an hour and pick up your aging cases.
To finish this you need to decide if the same case will get another every half an hour until it's been dealt with. If so the workflow can end when the email goes out. If not then the workflow needs to go into some state waiting for the next escalation or waiting for some delay until you can ping the assignee again.

Resources