Guest User

Untitled

a guest
May 20th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # map / reduce
  2.         mapFunc = () ->
  3.             days= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
  4.             now = new Date().valueOf()
  5.             key = "#{this.ts.getFullYear()}-#{this.ts.getMonth()+1}-#{this.ts.getDate()}"
  6.             for i in [-9..0]
  7.                 date = new Date(now + i*86400000)
  8.                 formatted = "#{date.getFullYear()}-#{date.getMonth()+1}-#{date.getDate()}"
  9.                 if formatted is key then emit(formatted, {count: 1, day: days[date.getDay()]})
  10.                 else emit(formatted, {count: 0, day: days[date.getDay()]})
  11.         reduceFunc = (key, values) ->
  12.             total = 0
  13.             for value in values
  14.                 total += value.count
  15.                 day = value.day
  16.             return { count: total, day: day }
  17.  
  18. # query
  19.  
  20. query = {to:channel}
  21. params = { out: {inline:1}, query: query, sort: {ts:-1} }
Add Comment
Please, Sign In to add comment