Mihai A
Mihai A

Reputation: 37

Data Studio Community Connectors: Combine time and non-time based metrics

I'm building a connector that connects to an API that offers endpoints for both time series-based metrics (such as 'number of users per day'), as well as static metrics (such as 'project status').

If I am to build a single connector, I would have to insert the static metrics within the time series values, right?

So, if my schema is

[{name=day}, {name=users}, {name=status}]

then my values would look like

['20181101', 150, '85%']
['20181102', 125, '85%']
['20181103', 134, '85%']
['20181104', 185, '85%']
['20181105', 111, '85%']
['20181106', 123, '85%']

since the 'status' field is not time-dependent.

While this seems to work, this looks pretty inefficient. Is there anything I'm missing, or should I build a separate connector for the static metrics endpoints?

Thanks!

Upvotes: 1

Views: 129

Answers (1)

Alex D
Alex D

Reputation: 48

It sounds like you are trying to merge two independent tables, from your description. If you have a time series data with dates, and a separate series of project status without dates, then split your connector to return two different series.

The method getSchema passes a request object, since it is beyond the getConfig() call. That schema can thus be split depending on the parameter. E.g.:

   function getSchema(request){
       switch(request.configParams.myTableOption){
           case 'tableOption1': 
               return mySchemaObject.tableOption1;
           case 'tableOption1': 
               return mySchemaObject.tableOption1;
       }
    }

Super simplified, of course, but that should provide a much more flexible connector, which can return different table types. You also have to similarly split getData() to return the right data, but that same configParam carries through subsequent requests for that connector, so you can rely on it to do so there as well.

Upvotes: 1

Related Questions