Get title length statistics from within Raven Studio

20 views
Skip to first unread message

Ben

unread,
Mar 26, 2015, 12:33:41 PM3/26/15
to rav...@googlegroups.com
Hey guys,

I wrote a quick index to pull out some stats on total lengths in our database and I'm getting very odd results:

Map:

from p in docs.Projects
select new {
TitleLength = p.Title.Length,
MaxLength = 0,
MinLength = 0,
Count = 1
}

Reduce:

from result in results
group result by 0 into g
let totalLength = g.Sum(x => x.TitleLength)
let totalCount = g.Sum(x => x.Count)
let maxLength = g.Max(x => x.TitleLength)
let minLength = g.Min(x => x.TitleLength)
select new {
TitleLength = totalLength / totalCount,
MaxLength = maxLength,
MinLength = minLength,
Count = totalCount
}


The results are very odd indeed:

{
  "TitleLength": 1.896636619018431E-05,
  "MaxLength": 0.10686838081350422,
  "MinLength": 0.0709223358532835,
  "Count": 9374.0
}

Am I doing anything wrong here?

Tal Weiss

unread,
Mar 26, 2015, 1:33:43 PM3/26/15
to rav...@googlegroups.com

Each time you reduce you divide by the current count. You are driving multiple times.

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tal Weiss

unread,
Mar 26, 2015, 1:53:06 PM3/26/15
to rav...@googlegroups.com

Let's say you got two steps of reduce each reduce has 10 items and total of 100. The length of all titles is 10. So 10*10/10=10 life is good. Than 10*10/100=1 life isn't so good. I would add a field that is total/count and not assign total=total/count it is just not right.

Reply all
Reply to author
Forward
0 new messages