This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aggregation.txt
155 lines (136 loc) · 8.25 KB
/
Aggregation.txt
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
//Aggregation : Nombre de fois qu'un champion a été séléctionné, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1 } },
{ $unwind: "$participants" },
{ $group: { _id: "$participants.championId", total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionPick" }
])
//Aggregation : Nombre de fois qu'un champion a été séléctionné au Top, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1 } },
{ $unwind: "$participants" },
{ $group: { _id: { $cond: [{ $eq: ["$participants.timeline.lane","TOP"] },"$participants.championId",-1] }, total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionPickTop" }
])
//Aggregation : Nombre de fois qu'un champion a été séléctionné au Bottom, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1 } },
{ $unwind: "$participants" },
{ $group: { _id: { $cond: [{ $eq: ["$participants.timeline.lane","BOTTOM"] },"$participants.championId",-1] }, total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionPickBottom" }
])
//Aggregation : Nombre de fois qu'un champion a été séléctionné au middle, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1 } },
{ $unwind: "$participants" },
{ $group: { _id: { $cond: [{ $eq: ["$participants.timeline.lane","MIDDLE"] },"$participants.championId",-1] }, total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionPickMiddle" }
])
//Aggregation : Nombre de fois qu'un champion a été séléctionné en Jungle, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1 } },
{ $unwind: "$participants" },
{ $group: { _id: { $cond: [{ $eq: ["$participants.timeline.lane","JUNGLE"] },"$participants.championId",-1] }, total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionPickJungle" }
])
//Aggregation : Renvoie un object contenant le nombre de champion qui ont été joué dans toute les données
db.ChampionPick.aggregate([
{ $group: { _id: '', total: { $sum: "$total" } } },
{ $project: { _id: 0, total: '$total' } },
{ $out: "totalChampion" }
])
//Aggregation : Pourcentage de victoire d'un champion, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1} },
{ $unwind: "$participants" },
{ $group: { _id: "$participants.championId", total: { $sum: 1 }, totalWin: { $sum: { $cond: { if: "$participants.stats.winner", then: 1, else: 0 } } } } },
{ $project: { _id: 1, total: 1, pourcentageDeWin: { $divide: [ "$totalWin", "$total"] } } },
{ $sort: { pourcentageDeWin: -1 } },
{ $out: "PourcentageDeWin" }
])
//Aggregation : Nombre de fois qu'un champion a été ban, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, teams: 1} },
{ $unwind: "$teams" },
{ $unwind: "$teams.bans" },
{ $group: { _id: "$teams.bans.championId", total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "ChampionBan" }
])
//Aggregation : Renvoie un object contenant le nombre de champion bans qui ont été ban dans toutes les données
db.ChampionBan.aggregate([
{ $group: { _id: '', total: { $sum: "$total" } } },
{ $project: { _id: 0, total: '$total' } },
{ $out: "totalChampionBan" }
])
//Aggregation : Nombre de fois qu'une rune a été utilisé, classé par ordre decroissant
db.data.aggregate([
{ $project: { _id: 0, participants: 1} },
{ $unwind: "$participants" },
{ $project: { _id: 0, runes: "$participants.runes"} },
{ $unwind: "$runes" },
{ $group: { _id: "$runes.runeId", total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "topRunes" }
])
//Aggregation : Uniquement les stats plus le calcul du KDA
db.data.aggregate([
{ $project: { _id: 0, participants: 1} },
{ $unwind: "$participants" },
{ $project: { _id: 0, stats: "$participants.stats", KDA: { $divide: [ { $add: ["$participants.stats.kills", "$participants.stats.assists"] }, { $cond: [{ $eq: ["$participants.stats.deaths",0] },1,"$participants.stats.deaths"] } ] } } },
{ $sort: { KDA: -1 } },
{ $out: "statsPlayer" }],
{
allowDiskUse: true
}
)
//Aggregation : Les statistiques du joueur moyen
db.statsPlayer.aggregate([
{ $group: { _id: 'PlayerMoyen', KDA: {$avg: "$KDA"}, wardsKilled: {$avg: "$stats.wardsKilled"}, wardsPlaced: {$avg: "$stats.wardsPlaced"}, physicalDamageTaken: {$avg: "$stats.physicalDamageTaken"}, magicDamageTaken: {$avg: "$stats.magicDamageTaken"}, totalDamageTaken: {$avg: {$add: ["$stats.physicalDamageTaken","$stats.magicDamageTaken","$stats.trueDamageTaken"]}}, physicalDamageDealt: {$avg: "$stats.physicalDamageDealt"}, magicDamageDealt: {$avg: "$stats.magicDamageDealt"},totalDamageDealt: {$avg: {$add: ["$stats.physicalDamageDealt","$stats.magicDamageDealt","$stats.trueDamageDealt"]}}, physicalDamageDealtToChampions: {$avg: "$stats.physicalDamageDealtToChampions"}, magicDamageDealtToChampions: {$avg: "$stats.magicDamageDealtToChampions"},totalDamageDealtToChampions: {$avg: {$add: ["$stats.physicalDamageDealtToChampions","$stats.magicDamageDealtToChampions","$stats.trueDamageDealtToChampions"]}}, pentaKills: {$avg: "$stats.pentaKills"}, quadraKills: {$avg: "$stats.quadraKills"}, tripleKills: {$avg: "$stats.tripleKills"}, doubleKills: {$avg: "$stats.doubleKills"}, kills: {$avg: "$stats.kills"}, champLevel: {$avg: "$stats.champLevel"}, deaths: {$avg: "$stats.deaths"}, assists: {$avg: "$stats.assists"}, minionsKilled: {$avg: "$stats.minionsKilled"}, neutralMinionsKilled: {$avg: "$stats.neutralMinionsKilled"}, goldEarned: {$avg: "$stats.goldEarned"}, goldSpent: {$avg: "$stats.goldSpent"} } },
{ $out: "PlayerMoyen" }],
{
allowDiskUse: true
}
)
//Aggregation : Contient les rangs des personnes qui jouent dans notre base
db.data.aggregate([
{ $project: { _id: 0, participants: 1} },
{ $unwind: "$participants" },
{ $group: { _id: { $ifNull: ["$participants.highestAchievedSeasonTier", 'Level < 30']}, total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "Ranking" }
])
//7 jours en timestamp : 604800
//(new Date()/1000) - 604800 = Date courante moins 7 jours
//(new Date("2016-02-29T00:00:00.000Z")/1000) - 604800
//1 jour = 86400
db.data.find({date: {$exists: true}}).forEach(function(obj) {
obj.date = new NumberInt(obj.date);
db.data.save(obj);
});
var currentdate = new Date()
db.data.aggregate([
{ $match: { date: { $gt: (currentdate/1000) - 604800, $lt: (currentdate/1000)} } },
{ $group: { _id: { $cond: [ {$gt: ["$date",(currentdate/1000)-86400]},'1 jour', {$cond: [{$gt: ["$date",(currentdate/1000)-172800]},'2 jours',{ $cond: [{$gt:["$date",(currentdate/1000)-259200]},'3 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-345600]},'4 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-432000]},'5 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-518400]},'6 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-604800]},'7 jours','plus de 7 jours']}]}]}]}]}]}]}, total: { $sum: 1} } },
{ $sort: { _id: -1 } },
{ $out: "Data7Jours" }
])
db.data.aggregate([
{ $project: { _id: 0, participants: 1, date: 1} },
{ $match: { date: { $gt: (currentdate/1000) - 604800, $lt: (currentdate/1000)} } },
{ $unwind: "$participants" },
{ $group: { _id: { $cond: [ {$gt: ["$date",(currentdate/1000)-86400]},'1 jour', {$cond: [{$gt: ["$date",(currentdate/1000)-172800]},'2 jours',{ $cond: [{$gt:["$date",(currentdate/1000)-259200]},'3 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-345600]},'4 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-432000]},'5 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-518400]},'6 jours',{$cond: [{$gt: ["$date",(currentdate/1000)-604800]},'7 jours','plus de 7 jours']}]}]}]}]}]}]}, totalPartie: { $sum: 1}, totalDamageDealt: { $sum: "$participants.stats.totalDamageDealt" }, totalDamageDealtToChampions: { $sum: "$participants.stats.totalDamageDealtToChampions" }, totalDamageTaken: { $sum: "$participants.stats.totalDamageTaken" }, totaldeaths: { $sum: "$participants.stats.deaths" }, totalkills: { $sum: "$participants.stats.kills" }, totalgoldEarned: { $sum: "$participants.stats.goldEarned" } } },
{ $out: "Data7Joursgold" }
])
//Nombre de games par type de partie
db.data.aggregate([
{ $project: { _id: 0, queueType: 1} },
{ $group: { _id: "$queueType" , total: { $sum:1 } } },
{ $sort: { total: -1 } },
{ $out: "queueType" }
])