diff --git a/internal/log/usagelogger.go b/internal/log/usagelogger.go index 60b250462..a00b0f193 100644 --- a/internal/log/usagelogger.go +++ b/internal/log/usagelogger.go @@ -37,6 +37,8 @@ type StatVarLog struct { StatVarDCID string `json:"stat_var_dcid"` // List of all facets that provided results for the given statVar. Facets []*FacetLog `json:"facets"` + // The number of entities included in this statVar's results. + NumSeries int `json:"num_series"` } // Full log with all information for the current query. @@ -123,6 +125,8 @@ func MakeStatVarLogs(observationResponse *pbv2.ObservationResponse) ([]*StatVarL if _, ok := statVarsByDcid[variable]; !ok { statVarsByDcid[variable] = &StatVarLog{ StatVarDCID: variable, + // capturing the number of entities for this statVar + NumSeries: len(varObs.ByEntity), } } diff --git a/internal/server/handler_v2_test.go b/internal/server/handler_v2_test.go index f84e85097..3b4bad478 100644 --- a/internal/server/handler_v2_test.go +++ b/internal/server/handler_v2_test.go @@ -182,7 +182,7 @@ func TestObservationInternal(t *testing.T) { Dcids: []string{"country/USA"}, }, }, - shared.QueryTypeExistence, + shared.QueryTypeExistenceByEntity, &pbv2.ObservationResponse{ ByVariable: map[string]*pbv2.VariableObservation{ "Count_Person": {}, diff --git a/internal/server/v2/observation/observation.go b/internal/server/v2/observation/observation.go index c5b2d8e72..e0ccc0354 100644 --- a/internal/server/v2/observation/observation.go +++ b/internal/server/v2/observation/observation.go @@ -167,13 +167,13 @@ func ObservationCore( // Have both entity.dcids and variable.dcids. Check existence cache. res, err := Existence( ctx, store, cachedata, variable.GetDcids(), entity.GetDcids()) - return res, shared.QueryTypeExistence, err + return res, shared.QueryTypeExistenceByVar, err } // TODO: Support appending entities from entity.expression // Only have entity.dcids, fetch variables for each entity. res, err := Variable(ctx, store, entity.GetDcids()) - return res, shared.QueryTypeExistence, err + return res, shared.QueryTypeExistenceByEntity, err } } return &pbv2.ObservationResponse{}, "", nil diff --git a/internal/server/v2/shared/shared.go b/internal/server/v2/shared/shared.go index cba4407dc..7a8e3a9ae 100644 --- a/internal/server/v2/shared/shared.go +++ b/internal/server/v2/shared/shared.go @@ -43,8 +43,10 @@ const ( QueryTypeValue QueryType = "value" // Fetches information about a given facet. QueryTypeFacet QueryType = "facet" - // Checks if a given statVar has information for a given entity. - QueryTypeExistence QueryType = "existence" + // Checks if a given statVar has information for a given set of entities AND variables. + QueryTypeExistenceByVar QueryType = "existence-var" + // Checks if a given statVar has ANY statVars for a given set of entities + QueryTypeExistenceByEntity QueryType = "existence-entity" // Calculates a value from other fetches. QueryTypeDerived QueryType = "derived" )