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.
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package reporting
|
|
|
|
// AggregateType defines how a metric should be aggregated.
|
|
type AggregateType string
|
|
|
|
const (
|
|
AggregateCount AggregateType = "count"
|
|
AggregateAverage AggregateType = "average"
|
|
)
|
|
|
|
// MetricDefinition describes a single reporting metric.
|
|
// Reference: Chatwoot Reports::ReportMetricRegistry
|
|
type MetricDefinition struct {
|
|
AggregateType AggregateType
|
|
RawEventName string // maps to ReportingEvent.Name
|
|
RollupMetric RollupMetric
|
|
SummaryKey string // key used in summary output
|
|
}
|
|
|
|
// ReportMetricRegistry provides the catalog of all supported reporting metrics.
|
|
// Reference: Chatwoot ReportMetricRegistry — defines all metrics with their aggregate type,
|
|
// raw event name, rollup metric, and summary key.
|
|
var ReportMetricRegistry = map[string]MetricDefinition{
|
|
"avg_first_response_time": {
|
|
AggregateType: AggregateAverage,
|
|
RawEventName: "first_response",
|
|
RollupMetric: MetricFirstResponse,
|
|
SummaryKey: "avg_first_response_time",
|
|
},
|
|
"avg_resolution_time": {
|
|
AggregateType: AggregateAverage,
|
|
RawEventName: "resolution_time",
|
|
RollupMetric: MetricResolutionTime,
|
|
SummaryKey: "avg_resolution_time",
|
|
},
|
|
"resolutions_count": {
|
|
AggregateType: AggregateCount,
|
|
RawEventName: "resolutions_count",
|
|
RollupMetric: MetricResolutionsCount,
|
|
SummaryKey: "resolutions_count",
|
|
},
|
|
"reply_time": {
|
|
AggregateType: AggregateAverage,
|
|
RawEventName: "reply_time",
|
|
RollupMetric: MetricReplyTime,
|
|
SummaryKey: "reply_time",
|
|
},
|
|
"first_response": {
|
|
AggregateType: AggregateAverage,
|
|
RawEventName: "first_response",
|
|
RollupMetric: MetricFirstResponse,
|
|
SummaryKey: "first_response",
|
|
},
|
|
"resolution_time": {
|
|
AggregateType: AggregateAverage,
|
|
RawEventName: "resolution_time",
|
|
RollupMetric: MetricResolutionTime,
|
|
SummaryKey: "resolution_time",
|
|
},
|
|
"bot_resolutions_count": {
|
|
AggregateType: AggregateCount,
|
|
RawEventName: "bot_resolutions_count",
|
|
RollupMetric: MetricBotResolutionsCount,
|
|
SummaryKey: "bot_resolutions_count",
|
|
},
|
|
"bot_handoffs_count": {
|
|
AggregateType: AggregateCount,
|
|
RawEventName: "bot_handoffs_count",
|
|
RollupMetric: MetricBotHandoffsCount,
|
|
SummaryKey: "bot_handoffs_count",
|
|
},
|
|
}
|
|
|
|
// GetMetricDefinition returns the metric definition for a given metric key.
|
|
func GetMetricDefinition(key string) (MetricDefinition, bool) {
|
|
def, ok := ReportMetricRegistry[key]
|
|
return def, ok
|
|
}
|
|
|
|
// AllMetricKeys returns all registered metric keys.
|
|
func AllMetricKeys() []string {
|
|
keys := make([]string, 0, len(ReportMetricRegistry))
|
|
for k := range ReportMetricRegistry {
|
|
keys = append(keys, k)
|
|
}
|
|
return keys
|
|
} |