Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
package reporting
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// TimeseriesPoint represents a single data point in a timeseries.
|
|
type TimeseriesPoint struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Value float64 `json:"value"`
|
|
}
|
|
|
|
// AggregateResult holds a single aggregate value for a metric.
|
|
type AggregateResult struct {
|
|
Metric string `json:"metric"`
|
|
Value float64 `json:"value"`
|
|
}
|
|
|
|
// SummaryResult holds the summary (totals/averages) for a metric over a range.
|
|
type SummaryResult struct {
|
|
Metric string `json:"metric"`
|
|
Total float64 `json:"total"`
|
|
Average float64 `json:"average"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
// DataSourceParams defines the parameters for a data source query.
|
|
// Reference: Chatwoot Reports::DataSource — for(account, metric, dimension_type, dimension_id,
|
|
// range, group_by, timezone_offset, business_hours)
|
|
type DataSourceParams struct {
|
|
AccountID uint
|
|
Metric string
|
|
DimensionType DimensionType
|
|
DimensionID uint
|
|
Since time.Time
|
|
Until time.Time
|
|
GroupBy string // day, week, month
|
|
TimezoneOffset int // hours offset from UTC
|
|
BusinessHours bool
|
|
}
|
|
|
|
// DataSource is the interface for fetching report data (timeseries, aggregate, summary).
|
|
// Reference: Chatwoot Reports::DataSource base class.
|
|
type DataSource interface {
|
|
// Timeseries returns a time-bucketed series of data points.
|
|
Timeseries(params DataSourceParams) ([]TimeseriesPoint, error)
|
|
// Aggregate returns a single aggregate value for the metric.
|
|
Aggregate(params DataSourceParams) (*AggregateResult, error)
|
|
// Summary returns total, average, and count for the metric over the range.
|
|
Summary(params DataSourceParams) (*SummaryResult, error)
|
|
}
|
|
|
|
// RawDataSource queries raw reporting_events for timeseries/aggregate/summary.
|
|
// Reference: Chatwoot Reports::RawDataSource
|
|
type RawDataSource struct{}
|
|
|
|
// NewRawDataSource creates a new raw data source.
|
|
func NewRawDataSource() *RawDataSource {
|
|
return &RawDataSource{}
|
|
}
|
|
|
|
// Note: Timeseries, Aggregate, Summary implementations on RawDataSource will be
|
|
// wired through ReportingService which holds the DB connection.
|
|
// The DataSource interface allows swapping between RawDataSource and RollupDataSource. |