function drawCircles($image) { $max = 12; $min = 2; $gap = $max - $min; $total = getTotalElements(); $result = getCoords(); foreach ($result as $row) { drawCircle($image, $row['x'], $row['y'], $min + $gap * ($row['total'] / $total)); } }
public function siren($siren) { require_once APPLICATION_PATH . DS . '..' . '/public/vendeur/lib/simple_html_dom.php'; set_time_limit(0); $key = 'siren.' . $siren; $cached = redis()->get($key); if (empty($cached)) { $html = dwn("http://www.societe.com/cgi-bin/fiche?rncs={$siren}&mode=prt"); redis()->set($key, $html); } else { $html = $cached; } $html = utf8_encode($html); $infos = []; $html = str_get_html($html); $table = $html->find('table[id=rensjur]', 0); if (is_object($table)) { $trs = $table->find('tr'); foreach ($trs as $tr) { $tds = $tr->find('td'); $first = true; foreach ($tds as $td) { if ($first) { $attribute = Inflector::urlize($td->innertext, '_'); } else { $value = $td->innertext; } $first = false; } $attribute = str_replace(['denomination', 'description_de_l_activite_de_l_entreprise', 'siret_siege', 'tranche_d_effectif'], ['raison_sociale', 'activite', 'siret', 'effectif'], $attribute); if ($attribute == 'activite') { continue; } $infos[$attribute] = $value; } } $table = $html->find('table[id=rensjurcomplete]', 0); if (is_object($table)) { $trs = $table->find('tr'); foreach ($trs as $tr) { $tds = $tr->find('td'); $first = true; foreach ($tds as $td) { if ($first) { $attribute = Inflector::urlize($td->innertext, '_'); } else { $value = $td->innertext; } $first = false; } $attribute = str_replace(['denomination', 'description_de_l_activite_du_siege', 'description_de_l_activite_de_l_entreprise', 'siret_siege', 'tranche_d_effectif', 'code_ape_naf_de_l_entreprise', 'code_ape_naf_du_siege', 'n_dossier'], ['raison_sociale', 'activite_siege', 'activite_entreprise', 'siret', 'effectif', 'naf_entrprise', 'naf_siege', 'numero_dossier'], $attribute); $infos[$attribute] = $value; } if (isset($infos['adresse_rcs'])) { $infos['adresse'] = $infos['adresse_rcs']; } if (isset($infos['adresse_insee'])) { $infos['adresse'] = $infos['adresse_insee']; } if (isset($infos['complement_nom_adressage'])) { $infos['nom_commercial'] = $infos['complement_nom_adressage']; unset($infos['complement_nom_adressage']); } $infos['code_postal'] = $infos['code_postal']; $infos['department_code'] = substr($infos['code_postal'], 0, 2); $department = Model::Department()->where(['code', '=', (string) $infos['department_code']])->first(true); if ($department) { $infos['department_id'] = $department->id; $infos['department'] = $department->name; $region = $department->region(true); if ($region) { $infos['region_id'] = $region->id; $infos['region'] = $region->name; } } if (isset($infos['adresse'])) { $coords = getCoords($infos['adresse'] . ' ' . $infos['code_postal'] . ' ' . $infos['ville']); $lat = isAke($coords, 'lat', false); $lng = isAke($coords, 'lng', false); if (false !== $lat) { $infos['lat'] = $lat; } if (false !== $lng) { $infos['lng'] = $lng; } $infos['coords'] = $coords; } } unset($infos['adresse_rcs'], $infos['nom_adressage'], $infos['adresse_insee']); return $infos; }
</li> <?php } ?> </ol> </marquee> </div> <div class="stat"> <p><strong>Top 5 Blocked Countries:</strong></p> <ol> <?php $top_countries = topXCountries(5); foreach ($top_countries as $country => $count) { $iso_details = getCoords($country); ?> <li><img src="images/flags/<?php echo $country; ?> .png" alt="<?php echo $iso_details["name"]; ?> " title="<?php echo $iso_details["name"]; ?> " /> <?php echo $iso_details["name"] . " (" . $count . ")"; ?> </li>
/** * [getLines description] * @param [type] $buffer [description] * @return [type] [description] */ function getLines($buffer) { $lines = new SplFixedArray($buffer->count()); for ($buffer->rewind(); $buffer->valid(); $buffer->next()) { $lines[$buffer->key()] = getCoords($buffer->current()); } return $lines; }
deletePersonne($_GET); break; case "updatepersonne": updatePersonne($_GET); break; case "getpersonne": getPersonne(); break; case "auth": auth($_GET); break; case "document": getDoc(); break; case "coords": getCoords($_GET["idDoc"]); break; default: break; } function createScore($data) { global $conn; $sql = "INSERT INTO scores (id_doc, id_perso, distance, maj)\n\tVALUES (" . $data["id_doc"] . ", " . $data["id_perso"] . ", " . $data["distance"] . ",NOW())"; //echo $sql; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } }
$surp = $_POST['surprise']; $sad = $_POST['sadness']; $dis = $_POST['disgust']; $anger = $_POST['anger']; $ant = $_POST['anticipation']; // Check connection if ($sql->connect_error) { die("Connection failed: " . $sql->connect_error); } $query = "UPDATE artisan SET joy = joy + {$joy},trust = trust + {$trust},fear = fear \r\n+ {$fear}, surprise= surprise + {$surp},sadness = sadness + {$sad},disgust = disgust + {$dis},anger = anger \r\n+ {$anger},anticipation=anticipation + {$ant}, count = count + 1 WHERE title ='{$title}'"; mysqli_query($sql, $query); $query2 = "SELECT count,joy,trust,fear,surprise,sadness,disgust,anger,anticipation,x,y,rgb FROM artisan WHERE title='{$title}'"; $result = mysqli_query($sql, $query2); $row = mysqli_fetch_assoc($result); $count = $row['count']; unset($row['count']); foreach ($row as $k => $v) { if (is_numeric($v) && $k != "x" && $k != "y" && $k != "rgb") { $row[$k] = round($v / $count, 2); } } $coords = getCoords($row); $good = json_decode($coords, true); $x = $good['x']; $y = $good['y']; $query3 = "UPDATE artisan SET x ={$x}, y={$y} WHERE title ='{$title}'"; mysqli_query($sql, $query3); $row['x'] = $x; $row['y'] = $y; echo json_encode($row); mysqli_close($sql);
function collectCoordinates() { $organisms = getAllUpdates(); for ($a = 0; $a < count($organisms); $a++) { $larr = explode(",", $organisms[$a]['LATITUDE']); $lorr = explode(",", $organisms[$a]['LONGITUDE']); array_shift($larr); array_shift($lorr); $coords[$a] = getCoords($larr, $lorr); } return $coords; }
//please note, the php object returned from openCage class differs by country //the following function works for USA addresses function getCoords($query, $zip, $mykey) { $geocoder = new OpenCage\Geocoder($mykey); $result = $geocoder->geocode($query); $empty[0] = ""; if (empty($result['results'][0])) { array_push($empty, $result); } else { $jsst = '{"lat":' . ($latlng['lat'] = $result['results'][0]['geometry']['lat']); $jsst .= ', "long":' . ($latlng['lng'] = $result['results'][0]['geometry']['lng']); $jsst .= ', "zip":' . $zip . '}, '; } if (empty($latlng['lat'])) { return; } else { return $jsst; } } $work[1251] = [' 480 NORTH WOLF ROAD NORTHLAKE IL 60164', '60164 ']; $work[1252] = [' 48d0 NORTH WOLF ROAD NORTHLAKE IL 60164', '60164 ']; header('Content-type: text/html; charset=utf-8'); print_r("["); foreach ($work as &$value) { print_r(getCoords($value[0], $value[1], $key)); flush(); } print_r("{}]"); //my ugly way of dealing with trailing comma, since PHP has no nice way to get last index. //{"lat": 38.7603106, "long": -121.2946768, "zip" : "95678"},
$fname = $sql->real_escape_string($_POST['fname']); $lname = $sql->real_escape_string($_POST['lname']); $title = $sql->real_escape_string($_POST['title']); $joy = $_POST['joy']; $trust = $_POST['trust']; $fear = $_POST['fear']; $surp = $_POST['surprise']; $sad = $_POST['sadness']; $dis = $_POST['disgust']; $anger = $_POST['anger']; $ant = $_POST['anticipation']; $rgb = $_POST['rgb']; $avg = $_POST['avg']; $rat = $_POST['ratio']; $pal = $_POST['palette']; $coords = getCoords($_POST); // Call to xycoord.php returns x and y coordinates $good = json_decode($coords, true); //(central emotion) of artwork $x = $good['x']; $y = $good['y']; if ($sql->connect_error) { die("Connection failed: " . $sql->connect_error); } $query = "INSERT INTO artisan (firstname, lastname, title,joy,trust,\r\n\t\t\t\tfear,surprise,sadness,disgust,anger,anticipation,rgb,x,y,ratio,palette,imgpath,rgbavg)\r\n\t\t\t\tVALUES ('{$fname}', '{$lname}', '{$title}','{$joy}','{$trust}','{$fear}','{$surp}',\r\n\t\t\t\t'{$sad}','{$dis}','{$anger}','{$ant}','{$rgb}','{$x}','{$y}','{$rat}','{$pal}','{$targetPath}','{$avg}')"; mysqli_query($sql, $query); mysqli_close($sql); echo json_encode(array("rgb" => $rgb, "title" => $title, "imgpath" => $targetPath, "x" => $x, "y" => $y, "ratio" => $rat, "palette" => $pal, "avg" => $avg)); } } } else {
/** * Draws a canvas of the result if we're debugging * @param array $circle The circle description * @param array $lines The lines used to describe it * @param string $id The ID to use for the canvas * @return null */ function drawResult($circle, $lines, $id) { global $debug; if ($debug) { $arc = implode("\n", array_map(function ($a) { return " " . $a; }, explode("\n", generateGcodeArc($circle, $lines)))); $height = 500; $width = 500; $scale = 2; echo createCanvas($id, $height, $width); $canvasPoints = array(); foreach ($lines as $line) { $canvasPoints[] = array('X' => $line['X'] * $scale, 'Y' => $line['Y'] * $scale); } // echo "<pre>";var_dump($canvasPoints);echo "</pre>"; echo drawCanvasPoints($id, $canvasPoints); $line = 0; echo writeOnCanvas($id, "Number of nodes: " . $lines->count(), 5, $height - $line++ * 15); $ccenter = $circle['center']; echo pointOnCanvas($id, $ccenter['X'] * $scale, $ccenter['Y'] * $scale); echo writeOnCanvas($id, sprintf("%.1f, %.1f", $ccenter['X'], $ccenter['Y']), $ccenter['X'] * $scale, $ccenter['Y'] * $scale, 10, '#FF0000', 'true'); // echo circleOnCanvas($id, $ccenter['X']*$scale, $ccenter['Y']*$scale, $circle['radius']*$scale, '#00FF00'); // echo circleOnCanvas($id, $ccenter['X']*$scale, $ccenter['Y']*$scale, ($circle['radius']+max($circle['errors']))*2, '#FF0000'); // echo circleOnCanvas($id, $ccenter['X']*$scale, $ccenter['Y']*$scale, ($circle['radius']-max($circle['errors']))*2, '#0000FF'); $arcCoords = getCoords($arc); $endAngle = angleBetween(array('X' => $ccenter['X'] * $scale, 'Y' => $ccenter['Y'] * $scale), array('X' => $canvasPoints[0]['X'], 'Y' => $canvasPoints[0]['Y'])); $startAngle = angleBetween(array('X' => $ccenter['X'] * $scale, 'Y' => $ccenter['Y'] * $scale), array('X' => $canvasPoints[count($canvasPoints) - 1]['X'], 'Y' => $canvasPoints[count($canvasPoints) - 1]['Y'])); echo arcOnCanvas($id, $ccenter['X'] * $scale, $ccenter['Y'] * $scale, $circle['radius'] * $scale, $startAngle, $endAngle, '#FF0000'); $arc = "GCODE:\n" . $arc . "\n---------------"; $line += substr_count($arc, "\n") - 1; echo writeOnCanvas($id, $arc, 5, $height - $line * 15); // $pc = print_r($circle,true); // $line += substr_count($pc, "\n")-1; // echo writeOnCanvas($id, '$circle = '.$pc, 5, $height-($line*9.1), 8); } }