-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-properties.js
More file actions
85 lines (75 loc) · 2.33 KB
/
Copy pathcheck-properties.js
File metadata and controls
85 lines (75 loc) · 2.33 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
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
#!/usr/bin/env node
import pkg from 'pg';
const { Pool } = pkg;
// Configuration de la base de données
const pool = new Pool({
host: 'localhost',
port: 5432,
database: 'housy_tunisia',
user: 'postgres',
password: '0000',
ssl: false
});
async function checkProperties() {
try {
console.log('📊 STATISTIQUES DE LA BASE DE DONNÉES HOUSY_TUNISIA');
console.log('=' .repeat(50));
// Compter les propriétés
const propertiesResult = await pool.query('SELECT COUNT(*) FROM real_estate_market');
console.log(`🏠 PROPRIÉTÉS TOTALES: ${propertiesResult.rows[0].count}`);
// Répartition par type
const typeResult = await pool.query(`
SELECT property_type, COUNT(*) as count
FROM real_estate_market
GROUP BY property_type
ORDER BY count DESC
`);
console.log('\n📊 Répartition par type:');
typeResult.rows.forEach(row => {
console.log(` - ${row.property_type}: ${row.count}`);
});
// Répartition par ville
const cityResult = await pool.query(`
SELECT city, COUNT(*) as count
FROM real_estate_market
GROUP BY city
ORDER BY count DESC
LIMIT 10
`);
console.log('\n🏘️ Top 10 villes:');
cityResult.rows.forEach(row => {
console.log(` - ${row.city}: ${row.count}`);
});
// Répartition par source
const sourceResult = await pool.query(`
SELECT source, COUNT(*) as count
FROM real_estate_market
GROUP BY source
ORDER BY count DESC
`);
console.log('\n🔗 Répartition par source:');
sourceResult.rows.forEach(row => {
console.log(` - ${row.source}: ${row.count}`);
});
// Prix moyen par type
const priceResult = await pool.query(`
SELECT property_type,
ROUND(AVG(price)) as prix_moyen,
MIN(price) as prix_min,
MAX(price) as prix_max
FROM real_estate_market
WHERE price IS NOT NULL
GROUP BY property_type
ORDER BY prix_moyen DESC
`);
console.log('\n💰 Prix par type (TND):');
priceResult.rows.forEach(row => {
console.log(` - ${row.property_type}: Moyen ${row.prix_moyen}, Min ${row.prix_min}, Max ${row.prix_max}`);
});
} catch (error) {
console.error('❌ Erreur:', error.message);
} finally {
await pool.end();
}
}
checkProperties();