-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattlenetscrape.php
69 lines (58 loc) · 1.98 KB
/
battlenetscrape.php
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
<?php
//Get Data from BattleNet
class exampleClass{
public $wholeAH = array();
function getWholeAH() {
$key = 'zs54fyqy2mycxjd2pv9rmev2db6x8k59';
$server = 'malganis';
$fetch_url = "https://us.api.battle.net/wow/auction/data/{$server}?locale=en_US&apikey={$key}";
//Create JSON object and parse it into a php associated array if possible
$responseJson = file_get_contents($fetch_url);
$responseObj = json_decode($responseJson);
$db_url = $responseObj->files[0]->url;
printf("Connected To: %s\n", $db_url);
return $db_url;
}
function parseAH($itemID){
$responseJson = file_get_contents($wholeAH);
$responseObj = json_decode($responseJson);
$auctions = $responseObj->auctions;
$filteredAuctions = array();
foreach ($auctions as $auction){
if ($auction->item == $itemID) {
array_push($filteredAuctions,$auction);
}
}
return $filteredAuctions;
}
function calcStats($itemID){
$filteredAuctions = exampleClass::parseAH($itemID);
$allPrices = array();
$marketVolume = 0;
foreach ($filteredAuctions as $auction){
$marketVolume += $auction->quantity;
$price = $auction->buyout / $auction->quantity / 10000;
array_push($allPrices,$price);
}
$allPrices = exampleClass::removeOutliers($allPrices);
$meanPrice = array_sum($allPrices) / count($allPrices);
$stdDev = stats_standard_deviation($allPrices);
$minPrice = min($allPrices);
printf("\n");
printf("OUTLIERS REMOVED:\n");
printf("\nMinimum Price: %.2f\nMean Price: %.2f\nStandard Deviation: %.2f\n", $minPrice, $meanPrice, $stdDev);
}
function removeOutliers($unfiltered){
$stdDev = stats_standard_deviation($unfiltered);
$meanPrice = array_sum($unfiltered) / count($unfiltered);
$filtered = array();
foreach ($unfiltered as $price){
if ($price < $meanPrice + $stdDev*2){
array_push($filtered, $price);
}
}
return $filtered;
}
}
$A = new exampleClass();
$A::calcStats(124125);