You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: alerting_usage.go
    path of file: ./repos/grafana/pkg/services/alerting
    
    the code of the file until where you have to start completion: package alerting

import (
	"context"
	"encoding/json"

	"github.com/grafana/grafana/pkg/services/alerting/models"
	"github.com/grafana/grafana/pkg/services/datasources"
)

// DatasourceAlertUsage is a hash where the key represents the
// Datasource type and the value represents how many alerts
// that use the datasources.
type DatasourceAlertUsage map[string]int

// Us
    
func (e *AlertEngine) mapRulesToUsageStats(ctx context.Context, rules []*models.Alert) (DatasourceAlertUsage, error) {
	// map of datasourceId type and frequency
	typeCount := map[int64]int{}
	for _, a := range rules {
		dss, err := e.parseAlertRuleModel(a.Settings)
		if err != nil {
			e.log.Debug("Could not parse settings for alert rule", "id", a.ID)
			continue
		}

		for _, d := range dss {
			// aggregated datasource usage based on datasource id
			typeCount[d]++
		}
	}

	// map of datsource types and frequency
	result := map[string]int{}
	for k, v := range typeCount {
		query := &datasources.GetDataSourceQuery{ID: k}
		dataSource, err := e.datasourceService.GetDataSource(ctx, query)
		if err != nil {
			return map[string]int{}, nil
		}

		// aggregate datasource usages based on datasource type
		result[dataSource.Type] += v
	}

	return result, nil
}