1 import ENV from 'app-client/config/environment'; |
1 import ENV from 'app-client/config/environment'; |
2 import _ from 'lodash/lodash'; |
2 import _ from 'lodash/lodash'; |
3 import * as constants from 'corpus-common-addon/utils/constants'; |
3 import * as constants from 'corpus-common-addon/utils/constants'; |
4 import Collection from 'ember-cli-mirage/orm/collection'; |
|
5 |
4 |
6 export default function() { |
5 export default function() { |
7 |
6 |
8 // These comments are here to help you get started. Feel free to delete them. |
7 // These comments are here to help you get started. Feel free to delete them. |
9 |
8 |
29 this.get('/documents/:id/transcript', ({transcripts}, request) => { |
28 this.get('/documents/:id/transcript', ({transcripts}, request) => { |
30 let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
29 let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
31 return transcripts.find(id).transcript; |
30 return transcripts.find(id).transcript; |
32 }); |
31 }); |
33 |
32 |
34 this.get('/stats/languages', ({languages}, request) => { |
33 this.get('/stats/languages', 'languages'); |
35 let qParams = request.queryParams['discourse']; |
|
36 if(qParams) { |
|
37 var res = []; |
|
38 let allLanguages = languages.all().models; |
|
39 let i=0; |
|
40 while(i<allLanguages.length && res.length < (allLanguages.length/Math.pow(2,qParams.length))) { |
|
41 let d = allLanguages[i++]; |
|
42 d.count = Math.max(Math.floor(d.count / 2), 1); |
|
43 res.push(d); |
|
44 } |
|
45 |
|
46 return new Collection('language', res); |
|
47 } else { |
|
48 return languages.all(); |
|
49 } |
|
50 |
|
51 }); |
|
52 |
34 |
53 this.get('/stats/geostats', 'geostats'); |
35 this.get('/stats/geostats', 'geostats'); |
54 |
36 |
55 this.get('/stats/themes', 'themes'); |
37 this.get('/stats/themes', 'themes'); |
56 |
38 |
57 this.get('/stats/discourses', ({discourses}, request) => { |
39 this.get('/stats/discourses', 'discourses'); |
58 |
|
59 let qParams = request.queryParams['discourse']; |
|
60 if(qParams) { |
|
61 var res = []; |
|
62 let allDiscourses = discourses.all().models; |
|
63 let i=0; |
|
64 while(i<allDiscourses.length && res.length < (allDiscourses.length/Math.pow(2,qParams.length))) { |
|
65 let d = allDiscourses[i++]; |
|
66 if(!_.contains(request.queryParams.discourse, d.id)) { |
|
67 d.count = Math.max(Math.floor(d.count / 2), 1); |
|
68 res.push(d); |
|
69 } |
|
70 } |
|
71 |
|
72 return new Collection('discourse', res); |
|
73 } else { |
|
74 return discourses.all(); |
|
75 } |
|
76 }); |
|
77 |
40 |
78 this.get('/stats/datestats', 'datestats'); |
41 this.get('/stats/datestats', 'datestats'); |
79 |
42 |
80 this.get('/stats/dateminmax', 'dateminmax'); |
43 this.get('/stats/dateminmax', 'dateminmax'); |
81 |
44 |