Introduced big DB (~500 000 results) and multiple improvements

This commit is contained in:
Florian SYLVAIN
2021-10-29 15:11:09 +02:00
parent 4cfcf90ffc
commit 0f425bb06a
7 changed files with 71 additions and 28 deletions
+1
View File
@@ -1 +1,2 @@
/ProjetProgWeb/.env
/scripts/*.csv
+2 -7
View File
@@ -3,11 +3,6 @@
require_once("class/dump.php");
$author_name = $_GET['author'];
$these_array = dump::getTheseByAuthor($author_name);
$json = json_encode($these_array, JSON_PRETTY_PRINT);
echo '<pre>';
var_dump($json);
echo '</pre>';
$json = json_encode($these_array);
print_r($json);
+26
View File
@@ -0,0 +1,26 @@
function requestToApi(author) {
fetch(`api.php?author=${author}`)
.then(response => response.json())
.then(data => displayResults(data))
}
function displayResults(results) {
results.forEach(function(elem) {
let result = document.createElement('div')
result.classList.add('result-element')
let i = 0
elem.forEach(function(e) {
let child = document.createElement(i === 0 ? 'h1' : 'p')
child.innerText = e
result.appendChild(child)
i += 1
})
document.getElementById('results').appendChild(result)
})
}
+3 -1
View File
@@ -1,5 +1,7 @@
<?php
ini_set('max_execution_time', 0);
require_once("these.php");
require_once("conf.php");
@@ -22,7 +24,7 @@ class dump {
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->query("SELECT * FROM theses WHERE author = '$author';");
$stmt = $pdo->query("SELECT * FROM theses WHERE author LIKE '%$author%';");
$i = 0;
while ($obj = $stmt->fetchObject()) {
$theses_array[$i] = array();
+8 -16
View File
@@ -5,29 +5,21 @@
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="app.js"></script>
<link rel="stylesheet" href="stylesheet.css">
<title>Document</title>
</head>
<body>
<?php
include("navbar.php");
if (!isset($_POST['author'])) {
exit();
if (isset($_POST['author'])) {
if (strlen($_POST['author']) < 3) {
echo "<p class='error'>Veuillez entrer 3 caractères minimum.</p>";
} else {
echo "<script>requestToApi('" . $_POST['author'] . "')</script>";
}
}
require_once("class/dump.php");
$author_name = $_POST['author'];
$these_array = dump::getTheseByAuthor($author_name);
$json = json_encode($these_array, JSON_PRETTY_PRINT);
echo '<pre>';
var_dump($json);
echo '</pre>';
?>
<div id="results"></div>
</body>
</html>
+13 -3
View File
@@ -2,9 +2,14 @@
require_once("../class/these.php");
require_once("../class/dump.php");
require_once("../class/conf.php");
if (($handle = fopen("2021-09-15-theses.csv", "r")) !== FALSE) {
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->query("TRUNCATE `projet_prog_web`.`theses`");
if (($handle = fopen("dump_abes_thesesfr.csv", "r")) !== FALSE) {
$row = 1;
$new_these = these::emptyThese();
while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) {
@@ -14,9 +19,14 @@ if (($handle = fopen("dump_abes_thesesfr.csv", "r")) !== FALSE) {
$new_these->insertField($data[$c], $c);
}
$dump = new dump($new_these);
$dump->sendThese();
try {
$dump->sendThese();
} catch (Exception) {
echo "<br><br>Failed on (" . $row .") :<br>";
var_dump($new_these);
}
} $row++;
}
fclose($handle);
echo "CSV file imported into DB.";
echo "<br><br>CSV file imported into DB. (" . $row . " results)";
}
+18 -1
View File
@@ -64,10 +64,27 @@ body {
display: none;
}
pre {
#results {
font-family: sans-serif;
margin: 10px;
display: flex;
flex-direction: column;
gap: 15px;
overflow: scroll;
}
.result-element {
box-shadow: rgba(0, 0, 0, 0.10) 2px 2px 8px;
background-color: rgba(250, 250, 250, 0.5);
border-radius: 3px;
margin: 0 5px 5px 5px;
padding: 5px 10px 10px 10px;
}
.error {
color: red;
}
/* Small */
@media (min-width: 576px) {