-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetPokeData.php
More file actions
55 lines (52 loc) · 2.69 KB
/
getPokeData.php
File metadata and controls
55 lines (52 loc) · 2.69 KB
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
<?php
$name = urlencode($_GET['name']);
$request = urlencode($_GET['request']);
$latMax = $_GET['latMax'];
$latMin = $_GET['latMin'];
$lngMax = $_GET['lngMax'];
$lngMin = $_GET['lngMin'];
$filePath = "Spawns.sqlite";
$currentURL = "http".( ($_SERVER["HTTPS"] == "on")?'s':'' )."://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/";
#echo $name;
if (isset($_GET['name'])){
echo file_get_contents($currentURL."sqlite_geojson.php?geotable=vw_Pokemon_Encounters_By_Location_Example&fields=lat,lng,count(*)as%22count%22¶meters=name%3D%22".$name."%22&groupby=SpawnID&filePath=".urlencode($filePath));
}else{
$dir = 'sqlite:'.$filePath;
$dbh = new PDO($dir) or die("cannot open database");
if($request=="total"){
$query = "SELECT count(*) FROM vw_Pokemon_Encounters_By_Location_Example";
foreach ($dbh->query($query) as $row) {
echo $row[0];
}
}
if($request=="spawnLocations"){
$result = file_get_contents($currentURL."sqlite_geojson.php?geotable=vw_Pokemon_Encounters_By_Location_Example&fields=SpawnID,count(*)as%22count%22,lat,lng,group_concat(name,%22,%22)as%22pokes%22&groupby=SpawnID&filePath=".urlencode($filePath));
$resultArr = json_decode($result, TRUE);
$resultArrFormatted = $resultArr;
$resultArrFormatted['features'] = []; //clear the old features
//print_r(array_count_values($resultArr));
foreach($resultArr['features'] as $feature) {
$pokeArray = array_count_values(str_getcsv($feature['properties']['pokes'],",")); //count of poke names
arsort($pokeArray); //sort by count
$feature['properties']['pokes'] = $pokeArray;
array_push($resultArrFormatted['features'], $feature); //add new formatted feature
}
echo json_encode($resultArrFormatted); //return formatted results
}
if($request=="spawnLocationsBounds"){
$parameters = "lat<".$latMax." and lat>".$latMin." and lng<".$lngMax." and lng>".$lngMin;
$result = file_get_contents($currentURL."sqlite_geojson.php?geotable=vw_Pokemon_Encounters_By_Location_Example&fields=SpawnID,count(*)as%22count%22,lat,lng,group_concat(name,%22,%22)as%22pokes%22&groupby=SpawnID&filePath=".urlencode($filePath)."¶meters=".urlencode($parameters));
$resultArr = json_decode($result, TRUE);
$resultArrFormatted = $resultArr;
$resultArrFormatted['features'] = []; //clear the old features
//print_r(array_count_values($resultArr));
foreach($resultArr['features'] as $feature) {
$pokeArray = array_count_values(str_getcsv($feature['properties']['pokes'],",")); //count of poke names
arsort($pokeArray); //sort by count
$feature['properties']['pokes'] = $pokeArray;
array_push($resultArrFormatted['features'], $feature); //add new formatted feature
}
echo json_encode($resultArrFormatted); //return formatted results
}
}
?>