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
|
|
} |