Can I record workout data to GoogleFit from WearOS app? - wear-os

I'm making a fitness wearOS app.
I want to record workouts completed with the app to GoogleFit.
Is there a way to do that from WearOS?
I start a workout using HealthServices:
suspend fun startExercise() {
val dataTypes = setOf(
DataType.HEART_RATE_BPM,
DataType.LOCATION
)
val aggregateDataTypes = setOf(
DataType.DISTANCE,
DataType.TOTAL_CALORIES
)
val config = ExerciseConfig.builder()
.setExerciseType(ExerciseType.RUNNING)
.setDataTypes(dataTypes)
.setAggregateDataTypes(aggregateDataTypes)
.setShouldEnableAutoPauseAndResume(false)
.setShouldEnableGps(true)
.build()
HealthServices.getClient(this /*context*/)
.exerciseClient
.startExercise(config)
.await()
}
(Code is from this example https://developer.android.com/training/wearables/health-services/active#start)
I was expecting if I would start/end a workout with HealthServices it would auto-magically sync the data to GoogleFit(Apple does this with for HealthKit).
So, can I record workout data to GoogleFit from a WearOS app?

To add to the Yuri's comment that this isn't possible automatically, the SessionClient is probably what you'd want in order to do this manually. The flow would be:
Collect data with Health Services
Transform
Insert session with SessionClient
The insert a session snippet in the Google Fit docs is a relevant example, as it both sets the session type (in this case, running) and then also adds the underlying data (instead of doing that separately with HistoryClient).
Update: You may also wish to take a look at Health Connect, which was recently announced.

Related

Can I store sensitive data in a Vert.x context in a Quarkus application?

I am looking for a place to store some request scoped attributes such as user id using a Quarkus request filter. I later want to retrieve these attributes in a Log handler and put them in the MDC logging context.
Is Vertx.currentContext() the right place to put such request attributes? Or can the properties I set on this context be read by other requests?
If this is not the right place to store such data, where would be the right place?
Yes ... and no :-D
Vertx.currentContext() can provide two type of objects:
root context shared between all the concurrent processing executed on this event loop (so do NOT share data)
duplicated contexts, which are local to the processing and its continuation (you can share in these)
In Quarkus 2.7.2, we have done a lot of work to improve our support of duplicated context. While before, they were only used for HTTP, they are now used for gRPC and #ConsumeEvent. Support for Kafka and AMQP is coming in Quarkus 2.8.
Also, in Quarkus 2.7.2, we introduced two new features that could be useful:
you cannot store data in a root context. We detect that for you and throw an UnsupportedOperationException. The reason is safety.
we introduced a new utility class ( io.smallrye.common.vertx.ContextLocals to access the context locals.
Here is a simple example:
AtomicInteger counter = new AtomicInteger();
public Uni<String> invoke() {
Context context = Vertx.currentContext();
ContextLocals.put("message", "hello");
ContextLocals.put("id", counter.incrementAndGet());
return invokeRemoteService()
// Switch back to our duplicated context:
.emitOn(runnable -> context.runOnContext(runnable))
.map(res -> {
// Can still access the context local data
String msg = ContextLocals.<String>get("message").orElseThrow();
Integer id = ContextLocals.<Integer>get("id").orElseThrow();
return "%s - %s - %d".formatted(res, msg, id);
});
}

How to get GCP Audit Log status programmatically

I'm trying to get a list of Audit Logs similar to what is displayed in Google console page (IAM/Audit Logs) using the Golang API GetIamPolicy as described here:
https://cloud.google.com/resource-manager/reference/rest/v1/projects/getIamPolicy
If one service has at least one of its Log Types set (Data Read, Data Write or Admin Read), GetIamPolicy will return it, but if it does not have any set then the service is omitted from the response.
As an example, if my project has three services A, B and C and A has Data Read enabled, B has Admin Read enabled and C doesn't have anything enabled, GetIamPolicy will only return A and B.
GetIamPolicyRequest struct seems to have fields designed for this scenario (NullFields and ForceSendFields), but I couldn't make it work. Example:
rb := &cloudresourcemanager.GetIamPolicyRequest{}
rb.ForceSendFields = []string{"LogType"}
rb.NullFields = []string{"LogType"}
policyOptions := &cloudresourcemanager.GetPolicyOptions{}
policyOptions.ForceSendFields = []string{"LogType"}
policyOptions.NullFields = []string{"LogType"}
policyOptions.RequestedPolicyVersion = 3
rb.Options = policyOptions
Any ideas on how to retrieve the missing services?

How to add trace id to each logs in go micro service

I wanted to add trace id to logging done for each request to the micro service.I want this in similar as for springboot application we can set trace id in MDC and fetch it and use it while logging.
I have done some research and I found that MDC equivalent in go lang is context. So, I have set the trace id in my context. Now the problem is where ever I have to log with trace id ,I need to pass context to that function which is very ugly way. I am looking for a better solution for this problem.
func HandlerFunction(f gin.HandlerFunc) gin.HandlerFunc{
    return func(cxt *gin.Context) {
reqraceId := cxt.Request.Header.Get("trace-id")
        requid , _ := uuid.NewRandom()
        if reqTraceId == "" {
            c.Request.Header.Set("trace-id", requid.String())
        }
        f(c)
    }
}
It might be worth reading up on context.Context particularly this article which has a section that says:
At Google, we require that Go programmers pass a Context parameter as the first argument to every function on the call path between incoming and outgoing requests.
TL;DR - it's fine to pass the context, but what's the best way?
There's two main patterns
Ask the context to give you a logger
Give the logger the context
Context can be used to store values:
context.WithValue(ctx, someKey, someValue)
This means we can either do:
somepackage.Log(ctx).Info("hello world")
// or
sompackage.Info(ctx, "hello world")
The implementation of these two sample APIs could interact with the context to retrieve the values required with out needing to worry about the extra information that would have been in MDC at any of the logging call sites.
From my side I found that using the default log package we could set a prefix as log.SetPrefix(traceId), doing so, the log will print the trace id as the prefix in the actual and sub-functions/structs.
import (
"log"
"github.com/google/uuid"
)
func (hdl *HTTPHandler) example() {
var traceId string = uuid.NewString()
log.SetPrefix(traceId + " - ")
log.SetFlags(log.LstdFlags)
// ...
// ...
log.Println("......")
}
This issue can also be solved using a dependency injection container.
We can implement "request-scoped" injections, and as a result, for each request, we will recreate all dependency tree that uses request-scoped dependency(logger, error reporter, clients which send requests to another service with context propagation).
But as I understood using dependency injection containers is not a best practice in go and not an "idiomatic" way.
Also, this approach can have some performance and memory issues since we will recreate objects for each request.

how can I get ALL records from route53?

how can I get ALL records from route53?
referring code snippet here, which seemed to work for someone, however not clear to me: https://github.com/aws/aws-sdk-ruby/issues/620
Trying to get all (I have about ~7000 records) via resource record sets but can't seem to get the pagination to work with list_resource_record_sets. Here's what I have:
route53 = Aws::Route53::Client.new
response = route53.list_resource_record_sets({
start_record_name: fqdn(name),
start_record_type: type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
})
response.last_page?
response = response.next_page until response.last_page?
I verified I'm hooked into right region, I see the record I'm trying to get (so I can delete later) in aws console, but can't seem to get it through the api. I used this: https://github.com/aws/aws-sdk-ruby/issues/620 as a starting point.
Any ideas on what I'm doing wrong? Or is there an easier way, perhaps another method in the api I'm not finding, for me to get just the record I need given the hosted_zone_id, type and name?
The issue you linked is for the Ruby AWS SDK v2, but the latest is v3. It also looks like things may have changed around a bit since 2014, as I'm not seeing the #next_page or #last_page? methods in the v2 API or the v3 API.
Consider using the #next_record_name and #next_record_type from the response when #is_truncated is true. That's more consistent with how other paginations work in the Ruby AWS SDK, such as with DynamoDB scans for example.
Something like the following should work (though I don't have an AWS account with records to test it out):
route53 = Aws::Route53::Client.new
hosted_zone = ? # Required field according to the API docs
next_name = fqdn(name)
next_type = type
loop do
response = route53.list_resource_record_sets(
hosted_zone_id: hosted_zone,
start_record_name: next_name,
start_record_type: next_type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
)
records = response.resource_record_sets
# Break here if you find the record you want
# Also break if we've run out of pages
break unless response.is_truncated
next_name = response.next_record_name
next_type = response.next_record_type
end

TestComplete_JavaScripting_how to hide web url path while performing any operation for any object in script

I'm new to use Testcomplete , i'm using javascripts to automate my code, below are sample script ( converted one recorded first then converted into jscript) and in this scripts what i observe that TestComplete identified and captured the object element by using complete web url path not on only object specific .
efunction Test_Login {var UserName, Password, TestEnv;UserName = "XYZ";Pwd = "XYZXYZ";TestEnv = "https://test.Env.com/";Browsers.Item(btChrome).Run("TestEnv",1);Aliases.browser.pageTestenvCom.formFrmlogincomponent.textboxUsername.SetText("UserName");Aliases.browser.pageTestenvCom.formFrmlogincomponent.passwordboxPassword.SetText("Pwd");Aliases.browser.pageTestenvCom.formFrmlogincomponent.buttonLogin.ClickButton();}e
what i means lets see below example of login page
thank you
Whenever we record any Test case in Test-Complete, it stores all the object in the Naming Repository and then access the same.
This helps test-complete in easily recognisation of object and can improve the speed of test-case, in case there are multiple objects visible on screen
You can go through following link for more info on Name Mapping.
https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html

Resources