Introducing Sleek

10 May 2013

Sleek

For some time before, I have been working on a real-time analytics app for online shops. It got me interested in analytics to some extent.

The analytics engine I've created for ShopStream isn't very generic and tied to how it currently does analytics. Recently, I've had an idea to create a more generic, low(er)-level library for doing analytics in Ruby with MongoDB.

Meet Sleek. It is very simplistic and far from begin feature-rich for now, but I'm just starting. I plan to add more cool stuff to it.

Sleek supports the following:

Here are some examples:

sleek = Sleek[:default]

sleek.record(:purchases, {
  sleek: { timestamp: 1.day.ago },
  customer: { id: 1, name: "First Last", email: "first@last.com" },
  items: [{ sku: "APLIP5", name: "iPhone 5", price: 649_99 }],
  total: 649_99
})

sleek.record(:purchases, {
  customer: { id: 2, name: "Another Customer", email: "first@another.com" },
  items: [{ sku: "APLTD", name: "Thunderbolt Display", price: 1499_99 }],
  total: 1499_99
})

sleek.record(:purchases, {
  customer: { id: 2, name: "Another Customer", email: "first@another.com" },
  items: [{ sku: "APLIP5", name: "iPhone 5", price: 649_99 }],
  total: 649_99
})

# Simply counting all purchases
sleek.queries.count(:purchases)
# => 3

# Calculating average of all purchases
sleek.queries.average(:purchase, target_property: :total)
# => 93332.33333333333

# How many purchases had total greater than $1000?
sleek.queries.count(:purchases, filter: [:total, :gt, 1000_00])
# => 1

# How much did we get in sales yesterday?
sleek.queries.sum(:purchases, target_property: :total, timeframe: :previous_day)
# => 64999

# How much did we make in past 2 days (yesterday and today),
# broken down by days
sleek.queries.sum(:purchases, target_property: :total, timeframe: :this_2_days, interval: :daily)
# => [
#      {:timeframe=>#<Sleek::Timeframe 2013-05-08 21:00:00 UTC..2013-05-09 21:00:00 UTC>, :value=>64999},
#      {:timeframe=>#<Sleek::Timeframe 2013-05-09 21:00:00 UTC..2013-05-10 21:00:00 UTC>, :value=>214998}
#    ]

Discuss this post on HN.

Think your friends would dig this article, too?

Google+

Want to level up your React skills?

Sign up below and I'll send you articles just like this about React straight to your inbox every week or so.

No spam, promise. I hate it as much as you do!
If you need a mobile app built for your business or your idea, there's a chance I could help you with that.
Leave your email here and I will get back to you shortly.