forked from elmaano/sbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
256 lines (235 loc) · 11.5 KB
/
index.html
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
<!doctype html>
<html ng-app="myApp">
<head>
<title>Squad Rating Brute Forcer</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/flatly/bootstrap.min.css" />
</head>
<body ng-controller="MainCtrl">
<div class="container">
<div class="row">
<div class="col-md-12">
<button style="float:right; margin-top: 1rem;" class="btn btn-xs btn-default" ng-click="showHelp = !showHelp">Help</button>
<h1>SBC Rating Brute Forcer ⚽️</h1>
<p><button class="btn btn-xs btn-warning">New features</button></p>
<ul>
<li>You can now enter ratings more quickly by using the <code>x</code> operator, if you have 5 85s you can write <code>85x5</code> or <code>85*5</code> in step #1 below. It will have the same result has writing <code>85,85,85,85,85</code></li>
<li>You can fill in the players prices automatically by fetching the data directly from <a href="https://www.futbin.com/stc/cheapest">Futbin.com</a></li>
</ul>
<div class="alert alert-info" ng-if="showHelp">
<p><strong>How to use this tool</strong></p>
<p>Say you want to complete a squad-building challenge that requires an 84 squad rating, and you have an 85 Verratti and 80 Jesé that you'd like to use.</p>
<br>
<ol>
<li>Verratti and Jesé have ratings of 85 and 80, so you'd enter <code>85,80</code> in step #1 below.</li>
<li>You need to have an 84-rated squad, so your "Target Squad Rating" in step #2 is <code>84</code></li>
<li>The "Player ratings to try" fields are where you set the range for which to generate squad combinations. If you enter 83 to 85, for example, the calculator will calculate all possible combinations that give you an 84 squad rating with 83 to 85 rated players, in addition to your 85 and 80 rated players that you entered in step 1.</li>
<li>Once you press calculate, a table will appear underneath</li>
<li>The table contains the calculated combinations of players (9 in this example), that need to be bought/used in addition to your players from step #1 that will give you your target squad rating (84). Each column is a player rating (<code>83, 84, 85</code> in this case). Each row is a combination that will give you your target squad rating. For example, this example contains a row that has <code>6, ,3</code>. This means that you can use 6 83-rated players and 3 85-rated players (in addition to your current 85 and 80) to get a squad rating of 84.</li>
</ol>
</div>
</div>
<form ng-submit="calculate()">
<div class="col-md-6 col-sm-12">
<div class="card">
<div class="card-block">
<h2>Step 1:</h2>
<small>Enter the ratings of the cards you want to use for this SBC, separated by a comma. Format like <code>85x5</code> or <code>85*5</code> are accepted. (Minimum 1 required)</small><br>
<small>For SBC with brick slots, you can use 0 as rating.</small>
<input type="text" class="form-control" ng-model="squadText" placeholder="81,82,85" required>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="card">
<div class="card-block">
<h2>Step 2:</h2>
<div class="form-inline">
<label>
Target Squad Rating
<input type="number" step="1" ng-init="target=83" ng-model="target" class="form-control">
</label>
<br>
<p>Player ratings to try <br><input type="number" step="1" ng-model="bottom" class="form-control"> to <br><input type="number" step="1" ng-model="top" class="form-control"></p>
<p class="text-danger"><small>Note: Choosing a large range of player ratings will take a long time.</small></p>
</div>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="card">
<div class="card-block">
<h4 style=""><input type="checkbox" class="form-control" style="width:auto;display:inline-block; height: 1em;" name="" ng-model="setPrices"> Step 3: Set prices <small>(Optional)</small> <button class="btn btn-xs btn-warning">New</button></p></h4><p>
<div class="form-inline" ng-if="setPrices">
<button class="btn btn-success" ng-click="getPrices()" type="button" ng-disabled="isGettingPrices">{{ getPricesText }}</button>
<p><small>Note: The data is taken from <a href="https://www.futbin.com/stc/cheapest">Futbin.com</a></small></p>
<br>
<label>
Input prices for each player rating:
</label>
<br>
<input type="number" class="form-control input-sm" ng-model="prices[rating]" placeholder="{{rating}}" ng-repeat="rating in range" required>
</div>
<br>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<button class="btn btn-success" type="submit" ng-hide="running">Calculate</button>
<span ng-show="running">Calculating...</span>
<p>Will try to find combinations of {{ 11-squad.length }} players rated between {{ bottom }}-{{ top }} to join your {{ squad }} rated players to achieve a rating of {{ target }}.</p>
<br><hr>
<!-- Results table -->
<table class="table table-sm table-hover" ng-if="results">
<thead style="border-bottom-style: solid; border-bottom-color: white;">
<tr>
<th ng-repeat="rating in ratingRange"><span style="font-size: 1.5em;">{{ rating }}</span> <small style="font-weight:normal;">rated players</small></th>
<th ng-if="setPrices">Price</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="option in results | orderBy:'price'">
<td ng-repeat="rating in ratingRange">{{ option[rating] || '' }}</td>
<td ng-if="setPrices">{{ option.price || '' }}</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="row">
<div class="col-md-12">
<p class="text-muted">Updated formula based on <a href="https://www.reddit.com/r/FIFA/comments/5osq7k/new_overall_rating_figured_out/">this</a> post by <a href="https://www.reddit.com/user/ChairmanMeowwww">ChairmanMeowwww</a> on reddit</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script src="vendor/combinatorics.js"></script>
<script src="rating.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('MainCtrl', function($scope){
$scope._ = _;
$scope.prices = {};
$scope.range = [];
$scope.getPricesText = "Get prices";
$scope.$watch('squadText', function(newVal, oldVal){
if(newVal){
var multipliedValues = _.map(newVal.split(/[ ,]+/), function(el){
var elements = el.split(/x|\*/);
return elements.length > 1 ? (elements[0]+",").repeat(parseInt(elements[1])): el;
});
multipliedValues = multipliedValues.join()
$scope.squad = _.map(multipliedValues.replace(/[^\d]$/,'').split(/[ ,]+/), function(el){
return parseInt(el) || 0;
});
}
});
$scope.$watch('target', function(newVal, oldVal){
if(oldVal && $scope.bottom && $scope.top){
$scope.bottom = newVal - (oldVal - $scope.bottom);
$scope.top = newVal + ($scope.top - oldVal);
}
else{
$scope.bottom = newVal - 1;
$scope.top = newVal + 1;
}
});
$scope.$watchCollection('[bottom,top]', function(newVals, oldVals){
if(newVals){
$scope.range = _.range(newVals[0], newVals[1]+1);
}
});
$scope.getPrices = function(){
$scope.isGettingPrices = true;
$scope.getPricesText = "Loading...";
fetch('https://cors-anywhere.herokuapp.com/https://www.futbin.com/stc/cheapest')
.then((response) => {
return response.text().then(function(text) {
parser = new DOMParser();
doc = parser.parseFromString(text, "text/html");
var container = doc.querySelectorAll(".top-stc-players-box");
var prices = {};
for (var i = 0; i < container.length; i++) {
var rating = container[i].querySelector("span span").innerText;
var minPrices = container[i].querySelectorAll(".price-holder-row span");
var minPrice = minPrices[minPrices.length > 5 ? 5 : 0].innerText;
var multiplier = minPrice.includes('K') ? 1000 : minPrice.includes('M') ? 1000000 : 1;
prices[parseInt(rating)] = parseFloat(minPrice.replace('K', '').replace('M', '')) * multiplier;
}
$scope.prices = prices;
$scope.isGettingPrices = false;
$scope.getPricesText = "Get prices";
$scope.$apply();
})
});
}
$scope.calculate = function(){
var possible = _.range($scope.bottom, $scope.top + 1);
$scope.ratingRange = possible;
var openPositions = 11 - $scope.squad.length;
var combinations = [];
if(window.Worker){
$scope.results = [];
var myWorker = new Worker("worker.js");
myWorker.onmessage = function(e){
switch (e.data.code) {
case 'SQUAD':
var squad = _.countBy(e.data.squad);
if($scope.setPrices){
squad.price = getPrice($scope.prices, squad);
}
$scope.results.push(squad);
$scope.$apply();
break;
case 'DONE':
myWorker.terminate();
$scope.running = false;
$scope.$apply();
break;
default:
};
};
var params = {
possible: possible,
openPositions: openPositions,
squad: $scope.squad,
target: $scope.target
};
myWorker.postMessage(params);
$scope.running = true;
}
else{
cmb = Combinatorics.baseN(possible, openPositions);
while(a = cmb.next()){
// a is open position set
if(Math.floor(rating(_.concat(a, $scope.squad))) == $scope.target){
combinations.push(a.sort());
}
}
$scope.results = _.map(_.uniqBy(combinations, function(el){
return JSON.stringify(el);
}), function(el){
return _.countBy(el);
});
}
};
function getPrice(prices, squad){
return _(squad).reduce(function(prev, next, index){
return prev + next * prices[index];
}, 0);
}
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-89115163-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>