MCPcopy Create free account
hub / github.com/RocketMap/RocketMap / processSeen

Function processSeen

static/js/statistics.js:100–165  ·  view source on GitHub ↗
(seen)

Source from the content-addressed store, hash-verified

98}
99
100function processSeen (seen) {
101 var i
102 var total = seen.total
103 var shown = []
104
105 seen.pokemon.sort(function (a, b) {
106 var sort = document.getElementById('sort')
107 var order = document.getElementById('order')
108
109 if (order.options[order.selectedIndex].value === 'desc') {
110 var tmp = b
111 b = a
112 a = tmp
113 }
114
115 if (sort.options[sort.selectedIndex].value === 'id') {
116 return a['pokemon_id'] - b['pokemon_id']
117 } else if (sort.options[sort.selectedIndex].value === 'name') {
118 if (a['pokemon_name'].toLowerCase() < b['pokemon_name'].toLowerCase()) {
119 return 1
120 }
121 if (a['pokemon_name'].toLowerCase() > b['pokemon_name'].toLowerCase()) {
122 return -1
123 }
124 return 0
125 } else {
126 // Default to count
127 if (a['count'] === b['count']) { // Same count: order by id
128 return b['pokemon_id'] - a['pokemon_id']
129 }
130 return a['count'] - b['count']
131 }
132 })
133
134 for (i = seen.pokemon.length - 1; i >= 0; i--) {
135 var item = seen.pokemon[i]
136 var percentage = (item['count'] / total * 100).toFixed(4)
137 var lastSeen = new Date(item['disappear_time'])
138 lastSeen = lastSeen.getHours() + ':' +
139 ('0' + lastSeen.getMinutes()).slice(-2) + ':' +
140 ('0' + lastSeen.getSeconds()).slice(-2) + ' ' +
141 lastSeen.getDate() + ' ' +
142 monthArray[lastSeen.getMonth()] + ' ' +
143 lastSeen.getFullYear()
144 var location = (item['latitude'] * 1).toFixed(7) + ', ' + (item['longitude'] * 1).toFixed(7)
145 if (!$('#seen_' + item['pokemon_id']).length) {
146 addElement(item['pokemon_id'], item['pokemon_name'])
147 }
148 $('#count_' + item['pokemon_id']).html('<strong>Seen:</strong> ' + item['count'].toLocaleString() + ' (' + percentage + '%)')
149 $('#lastseen_' + item['pokemon_id']).html('<strong>Last Seen:</strong> ' + lastSeen)
150 $('#location_' + item['pokemon_id']).html('<strong>Location:</strong> ' + location)
151 $('#seen_' + item['pokemon_id']).show()
152 // Reverting to classic javascript here as it's supposed to increase performance
153 document.getElementById('seen_container').insertBefore(document.getElementById('seen_' + item['pokemon_id']), document.getElementById('seen_container').childNodes[0])
154 shown.push(item['pokemon_id'])
155 }
156
157 // Hide any unneeded items

Callers 1

updateStatMapFunction · 0.85

Calls 1

addElementFunction · 0.85

Tested by

no test coverage detected