metabase2simplekpi

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 18 Imported by: 0

README

Metabase to SimpleKPI

Synopsis

	m2sCfg := metabase2simplekpi.Config{
		MetabaseConfig:  metabase.Config{...},
		SimplekpiConfig: simplekpiutil.Config{...},
		SimplekpiUserID: 111,
		LoadSimpleKpi:   true,
		Datasets:        []DatasetInfo{},
	}

	err = m2sCfg.InitClients()
	if err != nil {
		log.Fatal(errors.Wrap(err, "E_MS2CFG_InitClients"))
	}

	err = m2sCfg.ExecWriteCSVs()
	if err != nil {
		log.Fatal(errors.Wrap(err, "E_MS2CFG_ExecWriteCSVs"))
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorsToJSON

func ErrorsToJSON(errs []error) ([]byte, error)

func ExecConfig

func ExecConfig(m2sCfg Config, funcSqlResp func(ds DatasetInfo, sr *SqlResponse) error) error

func ExecDataset

func ExecDataset(m2sCfg Config, ds DatasetInfo, funcSqlResp func(ds DatasetInfo, sr *SqlResponse) error) error

func QueryMetabaseTS added in v0.1.1

func QueryMetabaseTS(cfg Config, dsInfo DatasetInfo) (timeseries.TimeSeries, error)

func SqlResponseToTS added in v0.1.1

func SqlResponseToTS(seriesName string, sr *SqlResponse, countColIdx, dateColIdx int) (timeseries.TimeSeries, error)

func SqlResponseToTable

func SqlResponseToTable(sr *SqlResponse, kpiId int64, countColIdx, dateColIdx int) (table.Table, error)

func UpdateSimpleKpi

func UpdateSimpleKpi(cfg Config, dsInfo DatasetInfo) []error

func UpdateSimpleKpiSqlResponse

func UpdateSimpleKpiSqlResponse(cfg Config, dsInfo DatasetInfo, sqlResp *SqlResponse) []error

func UpdateSimpleKpiTS added in v0.1.1

func UpdateSimpleKpiTS(cfg Config, dsInfo DatasetInfo, ts timeseries.TimeSeries) []error

func WriteSQLResponseCSV

func WriteSQLResponseCSV(ds DatasetInfo, sr *SqlResponse) error

Types

type Config

type Config struct {
	MetabaseConfig     mo.Config
	SimplekpiConfig    simplekpiutil.Config
	SimplekpiUserID    int64
	LoadSimpleKpi      bool
	Datasets           []DatasetInfo
	MetabaseHttpClient *http.Client
	SimplekpiApiClient *simplekpi.APIClient
}

Config runs a set of Metabase to SimpleKPI queries. Call Config.InitClients() and then Config.Exec() or Config.ExecWriteCSVs().

func (*Config) AddDatasets

func (cfg *Config) AddDatasets(datasets []DatasetInfo)

func (*Config) Exec

func (cfg *Config) Exec() error

func (*Config) ExecFunc

func (cfg *Config) ExecFunc(funcSqlResp func(ds DatasetInfo, sr *SqlResponse) error) error

func (*Config) ExecWriteCSVs

func (cfg *Config) ExecWriteCSVs() error

func (*Config) InitClients

func (cfg *Config) InitClients() error

func (*Config) InitMetabaseClient

func (cfg *Config) InitMetabaseClient() error

func (*Config) InitSimplekpiClient

func (cfg *Config) InitSimplekpiClient() error

type Constraints

type Constraints struct {
	MaxResults         int `json:"max-results"`
	MaxResultsBareRows int `json:"max-results-bare-rows"`
}

type DatasetInfo

type DatasetInfo struct {
	KpiName             string               `json:"kpiName"`
	MetricName          string               `json:"metricName"`
	MetabaseQueryExec   bool                 `json:"metabaseExec"`
	MetabaseQuery       metabaseutil.SQLInfo `json:"metabaseQuery"`
	SimplekpiUpdateExec bool                 `json:"simplekpiExec"`
	SimplekpiKpiId      int                  `json:"simplekpiKpiId"`
}

DatasetInfo captures information for a single SQL query representing data for a single KPI.

func (*DatasetInfo) Inflate

func (dsi *DatasetInfo) Inflate()

type JSONQuery

type JSONQuery struct {
	Database    int         `json:"database"`
	Type        string      `json:"type"`
	Constraints Constraints `json:"constraints"`
}

type SqlData

type SqlData struct {
	Rows [][]interface{} `json:"rows,omitempty"`
}

type SqlResponse

type SqlResponse struct {
	Context     string    `json:"context,omitempty"`
	Data        SqlData   `json:"data,omitempty"`
	Error       string    `json:"error,omitempty"`
	JSONQuery   JSONQuery `json:"json_query"`
	RowCount    int       `json:"row_count"`
	RunningTime int       `json:"running_time"`
	StartedAt   time.Time `json:"started_at"`
	Status      string    `json:"status,omitempty"`
}

SqlResponse represents a Metabase API SQL response body.

func HTTPResponseToSqlResponse

func HTTPResponseToSqlResponse(resp *http.Response) (*SqlResponse, error)

HTTPResponseToSqlResponse parses a Metabase SQL response.

func QueryMetabase

func QueryMetabase(cfg Config, dsInfo DatasetInfo) (*SqlResponse, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL