campoleone-operations.mjsβ’5.66 kB
// Script per operazioni specifiche su istanza Campoleone attiva
// Usa l'istanza persistente giΓ avviata per analisi rapide
import { ProjectInstanceManager } from './build/project-instance-manager.js';
console.log("β‘ OPERAZIONI SU ISTANZA CAMPOLEONE ATTIVA");
console.log("=" .repeat(45));
const projectManager = ProjectInstanceManager.getInstance();
// Operazione 1: Statistiche di rete rapide
async function networkQuickStats() {
console.log("\nπ 1. STATISTICHE RETE RAPIDE");
const start = Date.now();
try {
const result = await projectManager.executeProjectAnalysis('campoleone', `
result = {
'nodes': visum.Net.Nodes.Count,
'links': visum.Net.Links.Count,
'zones': visum.Net.Zones.Count,
'analysis_type': 'quick_stats'
}
`, "Quick Network Stats");
const time = Date.now() - start;
console.log(`β
Completato in ${time}ms`);
console.log(`π Nodi: ${result.result.nodes}, Link: ${result.result.links}, Zone: ${result.result.zones}`);
} catch (error) {
console.error("β Errore:", error.message);
}
}
// Operazione 2: Analisi domanda di trasporto
async function demandAnalysis() {
console.log("\nπ 2. ANALISI DOMANDA TRASPORTO");
const start = Date.now();
try {
const result = await projectManager.executeProjectAnalysis('campoleone', `
# Analisi domanda di trasporto
zones = visum.Net.Zones
demand_data = []
for zone in zones:
zone_data = {
'zone_no': zone.GetAttribute('No'),
'demand_origin': zone.GetAttribute('DemOrig') if hasattr(zone, 'GetAttribute') else 0,
'demand_dest': zone.GetAttribute('DemDest') if hasattr(zone, 'GetAttribute') else 0
}
demand_data.append(zone_data)
if len(demand_data) >= 10: # Limitiamo a 10 zone per test rapido
break
total_zones = zones.Count
result = {
'total_zones': total_zones,
'sample_zones': len(demand_data),
'zone_data': demand_data[:5], # Prime 5 zone
'analysis_type': 'demand_analysis'
}
`, "Transport Demand Analysis");
const time = Date.now() - start;
console.log(`β
Completato in ${time}ms`);
console.log(`π― Zone totali: ${result.result.total_zones}`);
console.log(`π Zone campione analizzate: ${result.result.sample_zones}`);
} catch (error) {
console.error("β Errore:", error.message);
}
}
// Operazione 3: Analisi collegamenti piΓΉ lunghi
async function longestLinksAnalysis() {
console.log("\nπ€οΈ 3. ANALISI COLLEGAMENTI PIΓ LUNGHI");
const start = Date.now();
try {
const result = await projectManager.executeProjectAnalysis('campoleone', `
# Trova i collegamenti piΓΉ lunghi
links = visum.Net.Links
link_lengths = []
# Raccogli lunghezze di tutti i link (limitiamo per performance)
count = 0
for link in links:
if count >= 1000: # Limitiamo a 1000 link per test rapido
break
try:
length = link.GetAttribute('Length')
from_node = link.GetAttribute('FromNodeNo')
to_node = link.GetAttribute('ToNodeNo')
link_lengths.append({
'from_node': from_node,
'to_node': to_node,
'length': length
})
count += 1
except:
continue
# Ordina per lunghezza
link_lengths.sort(key=lambda x: x['length'], reverse=True)
result = {
'total_links_analyzed': len(link_lengths),
'total_links_in_network': links.Count,
'longest_links': link_lengths[:5], # Top 5 collegamenti piΓΉ lunghi
'shortest_links': link_lengths[-5:], # Top 5 collegamenti piΓΉ corti
'average_length': sum(l['length'] for l in link_lengths) / len(link_lengths) if link_lengths else 0,
'analysis_type': 'longest_links'
}
`, "Longest Links Analysis");
const time = Date.now() - start;
console.log(`β
Completato in ${time}ms`);
console.log(`π Link analizzati: ${result.result.total_links_analyzed}/${result.result.total_links_in_network}`);
console.log(`π Lunghezza media: ${result.result.average_length.toFixed(2)}m`);
if (result.result.longest_links.length > 0) {
const longest = result.result.longest_links[0];
console.log(`π₯ Link piΓΉ lungo: ${longest.from_node} β ${longest.to_node} (${longest.length.toFixed(2)}m)`);
}
} catch (error) {
console.error("β Errore:", error.message);
}
}
// Operazione 4: Health check rapido
async function quickHealthCheck() {
console.log("\nπ 4. HEALTH CHECK ISTANZA");
try {
const health = await projectManager.checkProjectHealth('campoleone');
if (health.success) {
const uptime = Math.floor((health.health.uptime || 0) / 1000);
console.log(`β
Istanza Salutare`);
console.log(`β° Uptime: ${uptime}s`);
console.log(`β‘ Response time: ${health.health.response_time_ms}ms`);
console.log(`πΎ Memoria: ${health.health.memory_mb}MB`);
} else {
console.log(`β Health check fallito: ${health.error}`);
}
} catch (error) {
console.error("β Errore health check:", error.message);
}
}
// Esegui tutte le operazioni in sequenza
async function executeAllOperations() {
console.log("π Inizio operazioni su istanza Campoleone...\n");
const totalStart = Date.now();
await networkQuickStats();
await demandAnalysis();
await longestLinksAnalysis();
await quickHealthCheck();
const totalTime = Date.now() - totalStart;
console.log("\n" + "=" .repeat(45));
console.log(`π― TUTTE LE OPERAZIONI COMPLETATE in ${totalTime}ms`);
console.log("π Istanza rimane attiva per altre operazioni...");
}
// Esegui script
executeAllOperations().catch(console.error);