Revision 633333336437 () - Diff

Link to this snippet: https://friendpaste.com/6n5skP4QKfAGZNGMcYPHAR
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32016.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_user_episode?include_docs=true&limit=1&key=%5B%2219d601e09560c3096c857dc97833abd9%22%2C+%229be5b4638392f1e21880e266d4da2845%22%5D 200
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.11806.548>] Duplicates of document `8c40fc1a160920a958b95e8d111aabb0` detected in view group `_design/users`, database `mygpo` - view rebuild, from scratch, is required
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.11804.548>] ** Generic server <0.11804.548> terminating
** Last message in was {'EXIT',<0.11806.548>,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>}}
** When Server state == {file,
{file_descriptor,prim_file,{#Port<0.10242013>,70}},
4944417161}
** Reason for termination ==
** {view_duplicated_id,<<"8c40fc1a160920a958b95e8d111aabb0">>}

[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.11804.548>] {error_report,<0.31.0>,
{<0.11804.548>,crash_report,
[[{initial_call,{couch_file,init,['Argument__1']}},
{pid,<0.11804.548>},
{registered_name,[]},
{error_info,
{exit,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>},
[{gen_server,terminate,6},
{proc_lib,init_p_do_apply,3}]}},
{ancestors,[<0.164.0>,<0.163.0>]},
{messages,[]},
{links,[]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,610},
{stack_size,24},
{reductions,813809184}],
[]]}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.31996.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_ref_urls?include_docs=true&limit=1&key=%5B%22123648da92647ac2a6aa6779295bc040%22%2C+%22http%3A%2F%2Fwww.cbc.ca%2Fpodcasting%2Fincludes%2Fspark.xml%22%2C+%22http%3A%2F%2Fpodcast.cbc.ca%2Fmp3%2Fpodcasts%2Fspark_20100613_33816.mp3%22%5D 200
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.164.0>] ** Generic server <0.164.0> terminating
** Last message in was {'EXIT',<0.11806.548>,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>}}
** When Server state == {group_state,undefined,<<"mygpo">>,
{"/var/lib/couchdb",<<"mygpo">>,
{group,
<<53,2,238,250,177,14,34,184,223,68,148,80,27,54,51,
55>>,
nil,<<"_design/users">>,<<"javascript">>,[],
[{view,0,0,0,
[<<"history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
nil,[],[]},
{view,1,0,0,
[<<"device_history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n if(action.device == null)\n {\n return;\n }\n\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
nil,[],[]},
{view,2,0,0,
[<<"episode_states_by_podcast_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.podcast, doc.episode, doc.user], null);\n }\n}">>,
nil,[],[]},
{view,3,0,0,
[<<"episode_states_by_user_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.episode], null);\n }\n}">>,
nil,[],[]},
{view,4,0,0,
[<<"episode_states_by_ref_urls">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.podcast_ref_url, doc.ref_url], null);\n }\n}">>,
nil,[],[]},
{view,5,0,0,
[<<"episode_actions_podcast_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([\n doc.user,\n doc.podcast,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
nil,[],[]},
{view,6,0,0,
[<<"episode_actions_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
nil,[],[]},
{view,7,0,0,
[<<"episode_actions">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
nil,[],[]},
{view,8,0,0,
[<<"episode_actions_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n doc.podcast,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
nil,[],[]},
{view,9,0,0,
[<<"chapters_by_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.chapters)\n {\n var chapter = doc.chapters[n];\n emit([doc.episode, doc.user], chapter);\n }\n }\n}">>,
nil,[],[]},
{view,10,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
nil,
[{<<"listeners_by_episode">>,<<"_count">>}],
[]},
{view,11,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, day], doc.user);\n return;\n }\n }\n }\n}">>,
nil,
[{<<"listeners_by_podcast">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,12,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
nil,
[{<<"listeners_by_podcast_episode">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,13,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions == null || doc.actions.length == 0)\n {\n return;\n }\n\n function sortByStarted(a, b)\n {\n var x = a.started;\n var y = b.started;\n return ((x < y) ? -1 : ((x > y) ? 1 : 0));\n }\n\n function hasTimeValues(action)\n {\n return ((action != null) && (action.started != null) && (action.playmark != null));\n }\n\n var actions = doc.actions.slice(0); // creates a copy\n actions = actions.filter(hasTimeValues);\n actions.sort(sortByStarted);\n\n var played_parts = [];\n var flat_date = null;\n\n for(var n in actions)\n {\n var action = actions[n];\n\n if(flat_date == null)\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n continue;\n }\n\n if(action.started <= flat_date.end && action.playmark >= flat_date.end)\n {\n flat_date.end = action.playmark;\n }\n else if(action.started >= flat_date.start && action.playmark <= flat_date.end)\n {\n // part already contained\n continue;\n }\n else\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n }\n }\n\n if (played_parts.length == 0)\n {\n return;\n }\n\n var sections = [];\n for(var n in played_parts)\n {\n var part = played_parts[n];\n sections.push(part.start);\n sections.push(part.end);\n }\n\n emit([doc.podcast, doc.episode, doc.user], sections);\n }\n}">>,
nil,
[{<<"episode_heatmap">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n function flatten(arr)\n {\n var flattened = []\n for(var n in arr)\n {\n for(var x in arr[n])\n {\n flattened.push(arr[n][x]);\n }\n }\n return flattened\n };\n\n function sortNumerical(a, b)\n {\n if(a < b)\n {\n return -1;\n }\n else if (a > b)\n {\n return 1;\n }\n else\n {\n return 0;\n }\n };\n\n function mergeBorders(borders, maxBorders)\n {\n last = null;\n newBorders = [];\n\n lastBorder = borders[borders.length-1];\n minDist = lastBorder / maxBorders;\n\n for(var n in borders)\n {\n border = borders[n];\n\n if(last == null)\n {\n }\n else if (border == lastBorder)\n {\n }\n else if ((border - last) < minDist)\n {\n continue;\n }\n\n newBorders.push(border);\n last = border;\n }\n\n return newBorders;\n };\n\n var all_borders = [];\n\n if (rereduce)\n {\n for(var n in values)\n {\n all_borders.push(values[n].borders);\n }\n }\n else\n {\n all_borders = values;\n }\n\n var borders = flatten(all_borders);\n borders = unique(borders);\n borders.sort(sortNumerical);\n borders = mergeBorders(borders, 50);\n\n var heatmap = [];\n\n for(var n=0; n<borders.length-1; n++)\n {\n heatmap.push(0);\n }\n\n for(var n in values)\n {\n j = 0;\n var length = 0;\n var increment = 1;\n\n if(rereduce)\n {\n length = values[n].borders.length-1;\n increment = 1;\n }\n else\n {\n length = values[n].length;\n increment = 2;\n }\n\n\n for(var i=0; i<length; i+=increment)\n {\n var from = 0;\n var until = 0;\n\n if(rereduce)\n {\n from = values[n].borders[i];\n until = values[n].borders[i+1];\n }\n else\n {\n from = values[n][i];\n until = values[n][i+1];\n }\n\n while(borders[j] < from)\n {\n j++;\n }\n\n while(borders[j] < until)\n {\n if(rereduce)\n {\n heatmap[j++] += values[n].heatmap[i];\n }\n else\n {\n heatmap[j++] += 1;\n }\n }\n }\n }\n\n return {heatmap: heatmap, borders: borders};\n}">>}],
[]},
{view,14,0,0,
[<<"episode_states">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions.length < 1)\n {\n return;\n }\n\n action = doc.actions[doc.actions.length-1];\n\n action_obj = {\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([doc.user, doc.podcast, doc.episode], action_obj);\n }\n}">>,
nil,[],[]},
{view,15,0,0,
[<<"podcast_states_by_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.podcast, doc.user], null);\n }\n}">>,
nil,[],[]},
{view,16,0,0,
[<<"podcast_states_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.user, doc.podcast], null);\n }\n}">>,
nil,[],[]},
{view,17,0,0,
[<<"podcast_states_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var affected_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n if (affected_devices.indexOf(action.device) == -1)\n {\n affected_devices.push(action.device);\n }\n }\n\n for(var n in affected_devices)\n {\n var device = affected_devices[n];\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
nil,[],[]},
{view,18,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n\n if(doc.settings == null || doc.settings.public_subscription == null)\n {\n var is_public = true;\n }\n else\n {\n var is_public = doc.settings.public_subscription;\n }\n\n emit([doc.user, is_public, doc.podcast, device], null);\n }\n }\n}">>,
nil,
[{<<"subscribed_podcasts_by_user">>,
<<"_count">>}],
[]},
{view,19,0,0,
[<<"subscribed_podcasts_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
nil,[],[]},
{view,20,0,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([doc.podcast, doc.user, device], null);\n }\n }\n}">>,
nil,
[{<<"subscriptions_by_podcast">>,<<"_count">>}],
[]},
{view,21,0,0,
[<<"suggestions_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"Suggestions\")\n {\n emit(doc.user, null);\n }\n}">>,
nil,[],[]},
{view,22,0,0,
[<<"favorite_episodes_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == 'EpisodeUserState')\n {\n if (doc.settings && doc.settings.is_favorite)\n {\n emit(doc.user, {_id: doc.episode});\n }\n }\n}">>,
nil,[],[]}],
{[]},
nil,0,0,nil,nil}},
{group,
<<53,2,238,250,177,14,34,184,223,68,148,80,27,54,51,
55>>,
<0.165.0>,<<"_design/users">>,<<"javascript">>,[],
[{view,0,154765697,0,
[<<"history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
{btree,<0.165.0>,
{174516124054,{34264651,[]},9575427003},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,1,154765697,0,
[<<"device_history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n if(action.device == null)\n {\n return;\n }\n\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
{btree,<0.165.0>,
{174516131543,{33941072,[]},10984289352},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,2,154765665,0,
[<<"episode_states_by_podcast_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.podcast, doc.episode, doc.user], null);\n }\n}">>,
{btree,<0.165.0>,
{174515962272,{21276414,[]},1661977208},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,3,154765665,0,
[<<"episode_states_by_user_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.episode], null);\n }\n}">>,
{btree,<0.165.0>,
{174515973619,{21276414,[]},1299411882},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,4,154765665,0,
[<<"episode_states_by_ref_urls">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.podcast_ref_url, doc.ref_url], null);\n }\n}">>,
{btree,<0.165.0>,
{174516011233,{21276414,[]},2257232263},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,5,154765697,0,
[<<"episode_actions_podcast_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([\n doc.user,\n doc.podcast,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516139789,{33677961,[]},7161312350},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,6,154765697,0,
[<<"episode_actions_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516147469,{33677961,[]},6763096451},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,7,154765697,0,
[<<"episode_actions">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516153644,{33677961,[]},6485662706},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,8,154765697,0,
[<<"episode_actions_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n doc.podcast,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516161371,{33677961,[]},6781675859},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,9,0,0,
[<<"chapters_by_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.chapters)\n {\n var chapter = doc.chapters[n];\n emit([doc.episode, doc.user], chapter);\n }\n }\n}">>,
{btree,<0.165.0>,
{65286549651,{253,[]},13900},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,10,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515602943,{2882075,[2882075]},199075115},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_episode">>,<<"_count">>}],
[]},
{view,11,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515607726,{2882075,[745247]},160815714},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_podcast">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,12,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515613550,{2882075,[1020610]},244659839},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_podcast_episode">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,13,154765697,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions == null || doc.actions.length == 0)\n {\n return;\n }\n\n function sortByStarted(a, b)\n {\n var x = a.started;\n var y = b.started;\n return ((x < y) ? -1 : ((x > y) ? 1 : 0));\n }\n\n function hasTimeValues(action)\n {\n return ((action != null) && (action.started != null) && (action.playmark != null));\n }\n\n var actions = doc.actions.slice(0); // creates a copy\n actions = actions.filter(hasTimeValues);\n actions.sort(sortByStarted);\n\n var played_parts = [];\n var flat_date = null;\n\n for(var n in actions)\n {\n var action = actions[n];\n\n if(flat_date == null)\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n continue;\n }\n\n if(action.started <= flat_date.end && action.playmark >= flat_date.end)\n {\n flat_date.end = action.playmark;\n }\n else if(action.started >= flat_date.start && action.playmark <= flat_date.end)\n {\n // part already contained\n continue;\n }\n else\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n }\n }\n\n if (played_parts.length == 0)\n {\n return;\n }\n\n var sections = [];\n for(var n in played_parts)\n {\n var part = played_parts[n];\n sections.push(part.start);\n sections.push(part.end);\n }\n\n emit([doc.podcast, doc.episode, doc.user], sections);\n }\n}">>,
{btree,<0.165.0>,
{174516182266,
{710222,
[{[{<<"heatmap">>,
[502747,472976,420462,394372,378930,367863,
278749,260118,226577,197559,142217,114262,
17976]},
{<<"borders">>,
[0,53893900,55948338,59075545,61846547,
64402477,68750666,80158983,83051922,
86398351,90634192,96316257,99695977,
102195099]}]}]},
76966115},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"episode_heatmap">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n function flatten(arr)\n {\n var flattened = []\n for(var n in arr)\n {\n for(var x in arr[n])\n {\n flattened.push(arr[n][x]);\n }\n }\n return flattened\n };\n\n function sortNumerical(a, b)\n {\n if(a < b)\n {\n return -1;\n }\n else if (a > b)\n {\n return 1;\n }\n else\n {\n return 0;\n }\n };\n\n function mergeBorders(borders, maxBorders)\n {\n last = null;\n newBorders = [];\n\n lastBorder = borders[borders.length-1];\n minDist = lastBorder / maxBorders;\n\n for(var n in borders)\n {\n border = borders[n];\n\n if(last == null)\n {\n }\n else if (border == lastBorder)\n {\n }\n else if ((border - last) < minDist)\n {\n continue;\n }\n\n newBorders.push(border);\n last = border;\n }\n\n return newBorders;\n };\n\n var all_borders = [];\n\n if (rereduce)\n {\n for(var n in values)\n {\n all_borders.push(values[n].borders);\n }\n }\n else\n {\n all_borders = values;\n }\n\n var borders = flatten(all_borders);\n borders = unique(borders);\n borders.sort(sortNumerical);\n borders = mergeBorders(borders, 50);\n\n var heatmap = [];\n\n for(var n=0; n<borders.length-1; n++)\n {\n heatmap.push(0);\n }\n\n for(var n in values)\n {\n j = 0;\n var length = 0;\n var increment = 1;\n\n if(rereduce)\n {\n length = values[n].borders.length-1;\n increment = 1;\n }\n else\n {\n length = values[n].length;\n increment = 2;\n }\n\n\n for(var i=0; i<length; i+=increment)\n {\n var from = 0;\n var until = 0;\n\n if(rereduce)\n {\n from = values[n].borders[i];\n until = values[n].borders[i+1];\n }\n else\n {\n from = values[n][i];\n until = values[n][i+1];\n }\n\n while(borders[j] < from)\n {\n j++;\n }\n\n while(borders[j] < until)\n {\n if(rereduce)\n {\n heatmap[j++] += values[n].heatmap[i];\n }\n else\n {\n heatmap[j++] += 1;\n }\n }\n }\n }\n\n return {heatmap: heatmap, borders: borders};\n}">>}],
[]},
{view,14,154765697,0,
[<<"episode_states">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions.length < 1)\n {\n return;\n }\n\n action = doc.actions[doc.actions.length-1];\n\n action_obj = {\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([doc.user, doc.podcast, doc.episode], action_obj);\n }\n}">>,
{btree,<0.165.0>,
{174516189474,{21272181,[]},6229489915},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,15,154760981,0,
[<<"podcast_states_by_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.podcast, doc.user], null);\n }\n}">>,
{btree,<0.165.0>,
{174505609463,{284567,[]},22510141},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,16,154760981,0,
[<<"podcast_states_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.user, doc.podcast], null);\n }\n}">>,
{btree,<0.165.0>,
{174505613746,{284567,[]},20394449},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,17,154760998,0,
[<<"podcast_states_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var affected_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n if (affected_devices.indexOf(action.device) == -1)\n {\n affected_devices.push(action.device);\n }\n }\n\n for(var n in affected_devices)\n {\n var device = affected_devices[n];\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174505728883,{403564,[]},30533795},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,18,154765309,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n\n if(doc.settings == null || doc.settings.public_subscription == null)\n {\n var is_public = true;\n }\n else\n {\n var is_public = doc.settings.public_subscription;\n }\n\n emit([doc.user, is_public, doc.podcast, device], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515117982,{299330,[299330]},26781332},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"subscribed_podcasts_by_user">>,<<"_count">>}],
[]},
{view,19,154765309,0,
[<<"subscribed_podcasts_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515121176,{299330,[]},22969037},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,20,154765309,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([doc.podcast, doc.user, device], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515124209,{299330,[299330]},35024813},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"subscriptions_by_podcast">>,<<"_count">>}],
[]},
{view,21,154688024,0,
[<<"suggestions_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"Suggestions\")\n {\n emit(doc.user, null);\n }\n}">>,
{btree,<0.165.0>,
{173686983396,{24329,[]},1334860},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,22,154679416,0,
[<<"favorite_episodes_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == 'EpisodeUserState')\n {\n if (doc.settings && doc.settings.is_favorite)\n {\n emit(doc.user, {_id: doc.episode});\n }\n }\n}">>,
{btree,<0.165.0>,
{173529044751,{3201,[]},280464},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]}],
{[]},
{btree,<0.165.0>,
{174516118537,[],9103498326},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_btree.5.93788370>,nil,snappy},
154765811,0,nil,nil},
<0.32066.573>,<0.11806.548>,true,
[{{<0.31998.573>,#Ref<0.0.10599.159587>},154765812},
{{<0.32018.573>,#Ref<0.0.10599.159130>},154765812}],
<0.167.0>,false}
** Reason for termination ==
** {view_duplicated_id,<<"8c40fc1a160920a958b95e8d111aabb0">>}

[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.32018.573>] Uncaught server error: {view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>}
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.31998.573>] Uncaught server error: {view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.31997.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_ref_urls?include_docs=true&limit=1&key=%5B%2288270d2e57b685fea74bf2a747f02236%22%2C+%22http%3A%2F%2Fwww.marklevinshow.com%2Frss%2Filevin.xml%22%2C+%22http%3A%2F%2Fpodloc.andomedia.com%2FdloadTrack.mp3%3Fprm%3D2069xhttp%3A%2F%2Fpodfuse-dl.andomedia.com%2F800185%2Fpodfuse-origin.andomedia.com%2Fcitadel_origin%2Fpods%2Fmarklevin%2FLevin11012011.mp3%22%5D 200
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32012.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_ref_urls?include_docs=true&limit=1&key=%5B%2288270d2e57b685fea74bf2a747f02236%22%2C+%22http%3A%2F%2Fwww.city-journal.org%2Fcjpodcasts.xml%22%2C+%22http%3A%2F%2Fwww.city-journal.org%2Fmp3%2F2009-03-04-Breitbart_Klavan.mp3%22%5D 200
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.164.0>] {error_report,<0.31.0>,
{<0.164.0>,crash_report,
[[{initial_call,{couch_view_group,init,['Argument__1']}},
{pid,<0.164.0>},
{registered_name,[]},
{error_info,
{exit,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>},
[{gen_server,terminate,6},
{proc_lib,init_p_do_apply,3}]}},
{ancestors,[<0.163.0>]},
{messages,
[{'$gen_cast',
{partial_update,<0.32066.573>,
{group,
<<53,2,238,250,177,14,34,184,223,68,148,80,27,54,
51,55>>,
<0.165.0>,<<"_design/users">>,<<"javascript">>,
[],
[{view,0,154765697,0,
[<<"history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
{btree,<0.165.0>,
{174516124054,{34264651,[]},9575427003},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,1,154765697,0,
[<<"device_history">>],
<<"function(doc)\n{\n function processEpisodeAction(action)\n {\n if(action.device == null)\n {\n return;\n }\n\n action_obj = {\n type: \"Episode\",\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n function processSubscriptionAction(action)\n {\n action_obj = {\n type: \"Subscription\",\n podcast_url: doc.ref_url,\n podcast_id: doc.podcast,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n device_id: action.device,\n }\n\n emit([doc.user, action.device, action_obj.timestamp], action_obj);\n }\n\n\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n processEpisodeAction(doc.actions[n]);\n }\n }\n if(doc.doc_type == \"PodcastUserState\")\n {\n for(var n in doc.actions)\n {\n processSubscriptionAction(doc.actions[n]);\n }\n }\n}">>,
{btree,<0.165.0>,
{174516131543,{33941072,[]},10984289352},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,2,154765665,0,
[<<"episode_states_by_podcast_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.podcast, doc.episode, doc.user], null);\n }\n}">>,
{btree,<0.165.0>,
{174515962272,{21276414,[]},1661977208},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,3,154765665,0,
[<<"episode_states_by_user_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.episode], null);\n }\n}">>,
{btree,<0.165.0>,
{174515973619,{21276414,[]},1299411882},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,4,154765665,0,
[<<"episode_states_by_ref_urls">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n emit([doc.user, doc.podcast_ref_url, doc.ref_url], null);\n }\n}">>,
{btree,<0.165.0>,
{174516011233,{21276414,[]},2257232263},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,5,154765697,0,
[<<"episode_actions_podcast_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([\n doc.user,\n doc.podcast,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516139789,{33677961,[]},7161312350},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,6,154765697,0,
[<<"episode_actions_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action.device,\n action_obj.timestamp,\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516147469,{33677961,[]},6763096451},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,7,154765697,0,
[<<"episode_actions">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516153644,{33677961,[]},6485662706},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,8,154765697,0,
[<<"episode_actions_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.actions)\n {\n action = doc.actions[n];\n\n action_obj = {\n podcast: doc.podcast_ref_url,\n episode: doc.ref_url,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n emit([\n doc.user,\n doc.podcast,\n action_obj.timestamp\n ], action_obj\n );\n }\n }\n}">>,
{btree,<0.165.0>,
{174516161371,{33677961,[]},6781675859},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,9,0,0,
[<<"chapters_by_episode">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n in doc.chapters)\n {\n var chapter = doc.chapters[n];\n emit([doc.episode, doc.user], chapter);\n }\n }\n}">>,
{btree,<0.165.0>,
{65286549651,{253,[]},13900},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,10,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515602943,{2882075,[2882075]},199075115},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_episode">>,<<"_count">>}],
[]},
{view,11,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515607726,{2882075,[745247]},160815714},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_podcast">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,12,154765459,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n for(var n=doc.actions.length-1; n>=0; n--)\n {\n var action = doc.actions[n];\n if(action.action == \"play\")\n {\n var day = action.timestamp.slice(0, 10);\n emit([doc.podcast, doc.episode, day], doc.user);\n return;\n }\n }\n }\n}">>,
{btree,<0.165.0>,
{174515613550,{2882075,[1020610]},244659839},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"listeners_by_podcast_episode">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n if (rereduce)\n {\n return sum(values)\n }\n {\n /* We count one per user, not per play-event */\n val = unique(values);\n return val.length;\n }\n}">>}],
[]},
{view,13,154765697,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions == null || doc.actions.length == 0)\n {\n return;\n }\n\n function sortByStarted(a, b)\n {\n var x = a.started;\n var y = b.started;\n return ((x < y) ? -1 : ((x > y) ? 1 : 0));\n }\n\n function hasTimeValues(action)\n {\n return ((action != null) && (action.started != null) && (action.playmark != null));\n }\n\n var actions = doc.actions.slice(0); // creates a copy\n actions = actions.filter(hasTimeValues);\n actions.sort(sortByStarted);\n\n var played_parts = [];\n var flat_date = null;\n\n for(var n in actions)\n {\n var action = actions[n];\n\n if(flat_date == null)\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n continue;\n }\n\n if(action.started <= flat_date.end && action.playmark >= flat_date.end)\n {\n flat_date.end = action.playmark;\n }\n else if(action.started >= flat_date.start && action.playmark <= flat_date.end)\n {\n // part already contained\n continue;\n }\n else\n {\n flat_date = {start: action.started, end: action.playmark};\n played_parts.push(flat_date);\n }\n }\n\n if (played_parts.length == 0)\n {\n return;\n }\n\n var sections = [];\n for(var n in played_parts)\n {\n var part = played_parts[n];\n sections.push(part.start);\n sections.push(part.end);\n }\n\n emit([doc.podcast, doc.episode, doc.user], sections);\n }\n}">>,
{btree,<0.165.0>,
{174516182266,
{710222,
[{[{<<"heatmap">>,
[502747,472976,420462,394372,378930,
367863,278749,260118,226577,197559,
142217,114262,17976]},
{<<"borders">>,
[0,53893900,55948338,59075545,61846547,
64402477,68750666,80158983,83051922,
86398351,90634192,96316257,99695977,
102195099]}]}]},
76966115},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"episode_heatmap">>,
<<"function (keys, values, rereduce)\n{\n function unique(arr) {\n var a = [];\n var l = arr.length;\n for(var i=0; i<l; i++) {\n for(var j=i+1; j<l; j++) {\n if (arr[i] === arr[j])\n j = ++i;\n }\n a.push(arr[i]);\n }\n return a;\n };\n\n function flatten(arr)\n {\n var flattened = []\n for(var n in arr)\n {\n for(var x in arr[n])\n {\n flattened.push(arr[n][x]);\n }\n }\n return flattened\n };\n\n function sortNumerical(a, b)\n {\n if(a < b)\n {\n return -1;\n }\n else if (a > b)\n {\n return 1;\n }\n else\n {\n return 0;\n }\n };\n\n function mergeBorders(borders, maxBorders)\n {\n last = null;\n newBorders = [];\n\n lastBorder = borders[borders.length-1];\n minDist = lastBorder / maxBorders;\n\n for(var n in borders)\n {\n border = borders[n];\n\n if(last == null)\n {\n }\n else if (border == lastBorder)\n {\n }\n else if ((border - last) < minDist)\n {\n continue;\n }\n\n newBorders.push(border);\n last = border;\n }\n\n return newBorders;\n };\n\n var all_borders = [];\n\n if (rereduce)\n {\n for(var n in values)\n {\n all_borders.push(values[n].borders);\n }\n }\n else\n {\n all_borders = values;\n }\n\n var borders = flatten(all_borders);\n borders = unique(borders);\n borders.sort(sortNumerical);\n borders = mergeBorders(borders, 50);\n\n var heatmap = [];\n\n for(var n=0; n<borders.length-1; n++)\n {\n heatmap.push(0);\n }\n\n for(var n in values)\n {\n j = 0;\n var length = 0;\n var increment = 1;\n\n if(rereduce)\n {\n length = values[n].borders.length-1;\n increment = 1;\n }\n else\n {\n length = values[n].length;\n increment = 2;\n }\n\n\n for(var i=0; i<length; i+=increment)\n {\n var from = 0;\n var until = 0;\n\n if(rereduce)\n {\n from = values[n].borders[i];\n until = values[n].borders[i+1];\n }\n else\n {\n from = values[n][i];\n until = values[n][i+1];\n }\n\n while(borders[j] < from)\n {\n j++;\n }\n\n while(borders[j] < until)\n {\n if(rereduce)\n {\n heatmap[j++] += values[n].heatmap[i];\n }\n else\n {\n heatmap[j++] += 1;\n }\n }\n }\n }\n\n return {heatmap: heatmap, borders: borders};\n}">>}],
[]},
{view,14,154765697,0,
[<<"episode_states">>],
<<"function(doc)\n{\n if(doc.doc_type == \"EpisodeUserState\")\n {\n if(doc.actions.length < 1)\n {\n return;\n }\n\n action = doc.actions[doc.actions.length-1];\n\n action_obj = {\n podcast_url: doc.podcast_ref_url,\n episode_url: doc.ref_url,\n podcast_id: doc.podcast,\n episode_id: doc.episode,\n action: action.action,\n timestamp: action.timestamp.slice(0, action.timestamp.length-1),\n }\n\n if(action.device != null)\n {\n action_obj[\"device_id\"] = action.device;\n }\n if(action.started != null)\n {\n action_obj[\"started\"] = action.started;\n }\n if(action.playmark != null)\n {\n action_obj[\"position\"] = action.playmark;\n }\n if(action.total != null)\n {\n action_obj[\"total\"] = action.total;\n }\n\n\n emit([doc.user, doc.podcast, doc.episode], action_obj);\n }\n}">>,
{btree,<0.165.0>,
{174516189474,{21272181,[]},6229489915},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,15,154760981,0,
[<<"podcast_states_by_podcast">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.podcast, doc.user], null);\n }\n}">>,
{btree,<0.165.0>,
{174505609463,{284567,[]},22510141},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,16,154760981,0,
[<<"podcast_states_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n emit([doc.user, doc.podcast], null);\n }\n}">>,
{btree,<0.165.0>,
{174505613746,{284567,[]},20394449},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,17,154760998,0,
[<<"podcast_states_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var affected_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n if (affected_devices.indexOf(action.device) == -1)\n {\n affected_devices.push(action.device);\n }\n }\n\n for(var n in affected_devices)\n {\n var device = affected_devices[n];\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174505728883,{403564,[]},30533795},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,18,154765309,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n\n if(doc.settings == null || doc.settings.public_subscription == null)\n {\n var is_public = true;\n }\n else\n {\n var is_public = doc.settings.public_subscription;\n }\n\n emit([doc.user, is_public, doc.podcast, device], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515117982,{299330,[299330]},26781332},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"subscribed_podcasts_by_user">>,
<<"_count">>}],
[]},
{view,19,154765309,0,
[<<"subscribed_podcasts_by_device">>],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([device, doc.podcast], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515121176,{299330,[]},22969037},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,20,154765309,0,[],
<<"function(doc)\n{\n if(doc.doc_type == \"PodcastUserState\")\n {\n var subscribed_devices = [];\n\n for(var n in doc.actions)\n {\n var action = doc.actions[n];\n\n if(action.action == \"subscribe\")\n {\n subscribed_devices.push(action.device);\n }\n else\n {\n var index = subscribed_devices.indexOf(action.device);\n subscribed_devices.splice(index, 1);\n }\n }\n\n for(var n in subscribed_devices)\n {\n var device = subscribed_devices[n];\n\n if(doc.disabled_devices && (doc.disabled_devices.indexOf(device) > -1))\n {\n continue;\n }\n\n emit([doc.podcast, doc.user, device], null);\n }\n }\n}">>,
{btree,<0.165.0>,
{174515124209,{299330,[299330]},35024813},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[{<<"subscriptions_by_podcast">>,<<"_count">>}],
[]},
{view,21,154688024,0,
[<<"suggestions_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == \"Suggestions\")\n {\n emit(doc.user, null);\n }\n}">>,
{btree,<0.165.0>,
{173686983396,{24329,[]},1334860},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]},
{view,22,154679416,0,
[<<"favorite_episodes_by_user">>],
<<"function(doc)\n{\n if(doc.doc_type == 'EpisodeUserState')\n {\n if (doc.settings && doc.settings.is_favorite)\n {\n emit(doc.user, {_id: doc.episode});\n }\n }\n}">>,
{btree,<0.165.0>,
{173529044751,{3201,[]},280464},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_view.less_json_ids.2>,
#Fun<couch_view_group.10.26766604>,snappy},
[],[]}],
{[]},
{btree,<0.165.0>,
{174516118537,[],9103498326},
#Fun<couch_btree.3.71804109>,
#Fun<couch_btree.4.115144917>,
#Fun<couch_btree.5.93788370>,nil,snappy},
154765812,0,nil,nil}}}]},
{links,[<0.165.0>,<0.123.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,28657},
{stack_size,24},
{reductions,279415648}],
[]]}}
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.165.0>] ** Generic server <0.165.0> terminating
** Last message in was {'EXIT',<0.164.0>,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>}}
** When Server state == {file,{file_descriptor,prim_file,{#Port<0.2656>,24}},
174516257850}
** Reason for termination ==
** {view_duplicated_id,<<"8c40fc1a160920a958b95e8d111aabb0">>}

[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.165.0>] {error_report,<0.31.0>,
{<0.165.0>,crash_report,
[[{initial_call,{couch_file,init,['Argument__1']}},
{pid,<0.165.0>},
{registered_name,[]},
{error_info,
{exit,
{view_duplicated_id,
<<"8c40fc1a160920a958b95e8d111aabb0">>},
[{gen_server,terminate,6},
{proc_lib,init_p_do_apply,3}]}},
{ancestors,[<0.164.0>,<0.163.0>]},
{messages,[]},
{links,[<0.167.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,2584},
{stack_size,24},
{reductions,131338932620}],
[{neighbour,
[{pid,<0.167.0>},
{registered_name,[]},
{initial_call,
{couch_ref_counter,init,['Argument__1']}},
{current_function,{gen_server,loop,6}},
{ancestors,[<0.164.0>,<0.163.0>]},
{messages,[]},
{links,[<0.165.0>]},
{dictionary,[]},
{trap_exit,false},
{status,waiting},
{heap_size,2584},
{stack_size,9},
{reductions,656072244}]}]]}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32010.573>] 83.169.6.40 - - GET /mygpo/_design/core/_view/podcasts_by_id?key=%225c156ecbf8c7df16b999c8fe7ff8e942%22&include_docs=true 200
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.31996.573>] Uncaught error in HTTP request: {exit,
{noproc,
{gen_server,call,
[<0.165.0>,
{pread_iolist,
73832222373},
infinity]}}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32018.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_actions?startkey=%5B%228cc9a038c211a5176e7d5383c4af3b79%22%2C+%221970-01-01T00%3A00%3A00%22%5D&endkey=%5B%228cc9a038c211a5176e7d5383c4af3b79%22%2C+%222012-04-17T06%3A01%3A36%22%5D 500
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.31998.573>] 83.169.20.177 - - GET /mygpo/_design/users/_view/listeners_by_episode?endkey=%5B%2213a71e4257b823a76cd198de2d18508e%22%2C+%7B%7D%5D&group=true&group_level=1&reduce=true&startkey=%5B%2213a71e4257b823a76cd198de2d18508e%22%2C+null%5D 500
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.32012.573>] Uncaught error in HTTP request: {exit,
{noproc,
{gen_server,call,
[<0.165.0>,
{pread_iolist,
35471780464},
infinity]}}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32014.573>] 83.169.6.40 - - GET /mygpo/_design/core/_view/podcasts_by_id?key=%22018c39faf7f11fb9691c66118259a26e%22&include_docs=true 200
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.31996.573>] Stacktrace: [{gen_server,call,3},
{couch_file,pread_iolist,2},
{couch_file,pread_binary,2},
{couch_file,pread_term,2},
{couch_btree,get_node,2},
{couch_btree,stream_node,7},
{couch_btree,stream_kp_node,7},
{couch_btree,stream_kp_node,8}]
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.31996.573>] Uncaught server error: {noproc,
{gen_server,call,
[<0.165.0>,
{pread_iolist,73832222373},
infinity]}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32012.573>] Stacktrace: [{gen_server,call,3},
{couch_file,pread_iolist,2},
{couch_file,pread_binary,2},
{couch_file,pread_term,2},
{couch_btree,get_node,2},
{couch_btree,stream_node,7},
{couch_btree,stream_kp_node,7},
{couch_btree,stream_kp_node,8}]
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.31996.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_ref_urls?include_docs=true&limit=1&key=%5B%22123648da92647ac2a6aa6779295bc040%22%2C+%22http%3A%2F%2Fwww.cbc.ca%2Fpodcasting%2Fincludes%2Fspark.xml%22%2C+%22http%3A%2F%2Fpodcast.cbc.ca%2Fmp3%2Fpodcasts%2Fspark_20100613_33816.mp3%22%5D 500
[Tue, 17 Apr 2012 06:02:54 GMT] [error] [<0.32012.573>] Uncaught server error: {noproc,
{gen_server,call,
[<0.165.0>,
{pread_iolist,35471780464},
infinity]}}
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32012.573>] 71.19.150.86 - - GET /mygpo/_design/users/_view/episode_states_by_ref_urls?include_docs=true&limit=1&key=%5B%2288270d2e57b685fea74bf2a747f02236%22%2C+%22http%3A%2F%2Fwww.city-journal.org%2Fcjpodcasts.xml%22%2C+%22http%3A%2F%2Fwww.city-journal.org%2Fmp3%2F2009-03-04-Breitbart_Klavan.mp3%22%5D 500
[Tue, 17 Apr 2012 06:02:54 GMT] [info] [<0.32017.573>] 83.169.20.177 - - PUT /mygpo/87870b03cac96dfe08791e34fcebed78 201