1 2let scaled_color = ({ 3 d, 4 min = 0, 5 max = 1, 6 colors = ["#70f4ff", "#fbfbfb", "#ff8763"], //["#c6311b", "#676767", "#3390f7"] 7 revert = false 8}) => { 9 let dom = [-100, 0, 0.5, 1, 100] 10 if (revert) { 11 dom = [100, 1, 0.5, 0, -100] 12 } 13 let v = d3.scaleLinear().domain(dom).range([colors[0], colors[0], colors[1], colors[2], colors[2]]) 14 return v((d - min) / (max - min)) 15} 16 17var app = new Vue({ 18 el: '#app', 19 data: { 20 season: season, 21 next_gw: gw, 22 // 23 points_data: undefined, 24 // 25 loading: false, 26 ready: false, 27 players: [], 28 teams: teams_ordered, 29 gameweeks: gameweeks, 30 elements: elements, 31 // selection 32 team_selected: undefined, 33 gw_selected: undefined, 34 pos_selected: "", 35 scaled_color: scaled_color, 36 show_pts: false 37 }, 38 computed: { 39 filtered_players() { 40 if (this.team_selected == undefined || this.gw_selected == undefined) { return []} 41 if (!(this.gw_selected in this.points_data)) { return []} 42 let filtered = this.points_data[this.gw_selected] 43 let player_ids = this.elements.filter(i => (this.team_selected == "all" || i.team == this.team_selected) && (this.pos_selected == "" || parseInt(this.pos_selected) == i.element_type)).map(i => i.id) 44 filtered = filtered.filter(i => player_ids.includes(i.id)) 45 filtered = _.orderBy(filtered, ['player.element_type', 'total_min', 'total_pts'], ['asc', 'desc', 'desc']) 46 let lineup_count = _.countBy(filtered, 'player.element_type') 47 let ctr = {1: 1, 2: 1, 3: 1, 4: 1} 48 filtered.forEach((p) => { 49 let pos = p.player.element_type 50 let cnt = ctr[pos] 51 ctr[pos] += 1 52 let pos_tot = lineup_count[pos] 53 p.x = 122 / (pos_tot + 1) * cnt - 17; 54 p.y = (pos - 1) * 35 + 3; 55 }) 56 return filtered 57 }, 58 filtered_by_season_players() { 59 if (this.team_selected == undefined) { return []} 60 let players = this.elements.filter(i => (this.team_selected == "all" || i.team == this.team_selected) && (this.pos_selected == "" || parseInt(this.pos_selected) == i.element_type)) 61 let overall_total = 0 62 players.forEach((p) => { 63 p.min_data = {} 64 p.pts_data = {} 65 p.total_min = 0 66 p.total_pts = 0 67 p.matches_played = 0 68 for (let w of this.gameweeks) { 69 let entry = w in this.points_data ? this.points_data[w].find(i => i.id == p.id) : undefined 70 if (entry == undefined) { 71 p.min_data[w] = 0 72 p.pts_data[w] = 0 73 } 74 else { 75 p.matches_played += 1 76 p.min_data[w] = entry.total_min 77 p.total_min += entry.total_min 78 if (w == this.next_gw) { 79 overall_total += entry.total_min 80 } 81 p.pts_data[w] = entry.total_pts 82 p.total_pts += entry.total_pts 83 } 84 85 } 86 p.muted = p.total_min == 0 87 }) 88 players.forEach((p) => { 89 p.overall_total = overall_total 90 p.min_per_game = p.total_min / (p.matches_played > 0 ? p.matches_played : 1) 91 p.pts_per_game = p.total_pts / (p.matches_played > 0 ? p.matches_played : 1) 92 }) 93 players = _.orderBy(players, ['element_type', 'total_min', 'id'], ['asc', 'desc', 'asc']) 94 return players 95 }, 96 team_played() { 97 if (this.team_selected == undefined || _.isEmpty(this.filtered_by_season_players)) { return true} 98 return this.filtered_by_season_players[0].overall_total > 0 99 }, 100 team_selected_name() { 101 if (this.team_selected == undefined) { return ""} 102 if (this.team_selected == "all") { return "All" } 103 return this.teams[this.team_selected-1].name 104 }, 105 team_computed: { 106 get: () => { 107 return app.team_selected 108 }, 109 set: (v) => { 110 app.remove_dt() 111 app.team_selected = v 112 app.load_dt() 113 } 114 }, 115 pos_computed: { 116 get: () => { 117 return app.pos_selected 118 }, 119 set: (v) => { 120 app.remove_dt() 121 app.pos_selected = v 122 app.load_dt() 123 } 124 } 125 }, 126 methods: { 127 remove_dt() { 128 $("#value_table").DataTable().destroy(); 129 }, 130 load_dt() { 131 this.$nextTick(() => { 132 let table = $("#value_table").DataTable({ 133 "order": [], 134 "lengthChange": false, 135 "pageLength": 100, 136 "searching": false, 137 "info": false, 138 "paging": false, 139 "columnDefs": [] 140 }); 141 table.cells("td").invalidate().draw(); 142 }) 143 }, 144 invalidate_cache() { 145 this.$nextTick(() => { 146 var table = $("#value_table").DataTable(); 147 table.cells("td").invalidate().draw(); 148 }) 149 }, 150 togglePt(e) { 151 this.remove_dt() 152 this.show_pts = e.currentTarget.checked 153 this.load_dt() 154 } 155 } 156}) 157 158 159async function get_points() { 160 return $.ajax({ 161 type: "GET", 162 url: `data/${season}/points.json`, 163 async: true, 164 dataType: "json", 165 success: (data) => {
166 Object.values(data).forEach((w) => w.forEach((p) => { 167 p.player = elements.find(i => i.id == p.id) 168 p.minutes = p.e.map(i => i.stats?.find(j => j.identifier == 'minutes')?.value ?? 90) 169 p.total_min = getSum(p.minutes) 170 p.full_time = p.total_min == p.e.length * 90 171 p.total_pts = getSum(p.e.map(i => i.stats.map(j => j.points)).flat()) 172 })) 173 app.points_data = data; 174 }, 175 error: (xhr, status, error) => { 176 console.log(error); 177 console.error(xhr, status, error); 178 } 179 }); 180} 181 182$(document).ready(() => { 183 Promise.all([ 184 get_points() 185 ]).then((values) => { 186 app.ready = true 187 app.load_dt() 188 }) 189 .catch((error) => { 190 console.error("An error has occured: " + error); 191 }); 192})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.