Skip to content

Commit

Permalink
Fixed top and bottom values for objectId as date.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaljurecko committed Jul 12, 2017
1 parent ad8e23c commit 7871466
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion analysis/stages/03group/groupInDB/topBottom_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ func ValueFreqComputation(options *group.Options) *expr.Pipeline {
nameField := expr.Field(analysis.BsonId, group.BsonFieldName)
typeField := expr.Field(analysis.BsonId, analysis.BsonFieldType)

allowedTypes := group.TopBottomValuesTypes[:]
// Allows objectId to be processed as a date,
// value is converted in "prepareFields" function
if options.ProcessObjectIdAsDate {
allowedTypes = append(allowedTypes, "objectId")
}

p.AddStage("match", bson.M{
(analysis.BsonId + "." + analysis.BsonFieldType): bson.M{"$in": group.TopBottomValuesTypes},
(analysis.BsonId + "." + analysis.BsonFieldType): bson.M{"$in": allowedTypes},
})

//if options.MaxItemsForFreqAnalysis > 0 {
Expand Down
30 changes: 30 additions & 0 deletions analysis/stages/03group/tests/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,8 @@ func RunTestObjectIdAsDate(t *testing.T, stageFactory group.StageFactory) {
options.StoreMinMaxAvgValue = true
options.StoreWeekdayHistogram = true
options.StoreHourHistogram = true
options.StoreTopNValues = 3
options.StoreBottomNValues = 3
options.ValueHistogramMaxRes = 1000

expected := []interface{}{
Expand All @@ -1285,6 +1287,34 @@ func RunTestObjectIdAsDate(t *testing.T, stageFactory group.StageFactory) {
Min: helpers.ParseDate("2017-04-16T23:59:59+00:00"),
Max: helpers.ParseDate("2017-04-25T21:57:13+00:00"),
},
TopNValues: analysis.ValueFreqSlice{
{
Count: 1,
Value: helpers.ParseDate("2017-04-16T23:59:59+00:00"),
},
{
Count: 1,
Value: helpers.ParseDate("2017-04-24T12:54:57+00:00"),
},
{
Count: 1,
Value: helpers.ParseDate("2017-04-25T21:57:13+00:00"),
},
},
BottomNValues: analysis.ValueFreqSlice{
{
Count: 1,
Value: helpers.ParseDate("2017-04-20T05:45:57+00:00"),
},
{
Count: 1,
Value: helpers.ParseDate("2017-04-17T00:00:01+00:00"),
},
{
Count: 1,
Value: helpers.ParseDate("2017-04-18T10:00:00+00:00"),
},
},
WeekdayHistogram: &analysis.WeekdayHistogram{
1, // sunday
2, // monday
Expand Down

0 comments on commit 7871466

Please sign in to comment.