bel lavoro, in allegato potresti condividire il source (file cpp) ? grazie
Buonasera Martyn Manuk ,come richiesto posto il Codice (C++) cpp:
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <chrono>
#include <algorithm>
#include <iomanip>
using namespace std;
const int NUM_RUOTE = 11;
const int NUM_ESTRATTI = 5;
const int NUM_AMBI = 4005;
const long long NUM_COPPIE = 8018010LL;
const int SOGLIA = 100;
const int DIST_CALDI = 10;
struct Estrazione {
string data;
int numeri[NUM_RUOTE][NUM_ESTRATTI];
};
struct AmboNumerico {
int n1, n2;
};
struct RecordCoppia {
long long originale_pos;
string ambo1_str;
string ambo2_str;
int mx;
int att;
int diff;
bool sfaldato;
};
bool comparaCaldi(const RecordCoppia& a, const RecordCoppia& b) {
if (a.diff != b.diff) return a.diff < b.diff;
return a.mx > b.mx;
}
inline int getAmboIdx(int a, int b) {
if (a > b) swap(a, b);
return (a - 1) * 90 - a * (a - 1) / 2 + (b - a - 1);
}
string pulisci(string str) {
string out = "";
for (char c : str) {
if (c != '[' && c != ']' && c != '"' && c != '\'' && c != ';') {
out += c;
}
}
return out;
}
void aggiornaArchivioCopiaIncolla() {
cout << "\n=================================================================\n";
cout << " SISTEMA DI AGGIORNAMENTO AUTOMATICO DELL'ARCHIVIO\n";
cout << "=================================================================\n";
cout << "Istruzioni:\n1. Copia le nuove righe delle estrazioni.\n2. Click destro qui per INCOLLARE.\n3. Scrivi FINE e premi INVIO.\n-----------------------------------------------------------------\n\n";
vector<string> nuove_righe; string linea;
while (getline(cin, linea)) {
while(!linea.empty() && isspace(linea.back())) linea.pop_back();
while(!linea.empty() && isspace(linea.front())) linea.erase(linea.begin());
if (linea == "FINE" || linea == "fine" || linea == "Fine") break;
if (!linea.empty()) nuove_righe.push_back(linea);
}
ofstream file_out("estrazioni.csv", ios::app);
for (const auto& riga : nuove_righe) {
string r_f = riga;
replace(r_f.begin(), r_f.end(), '[', ' '); replace(r_f.begin(), r_f.end(), ']', ' ');
replace(r_f.begin(), r_f.end(), '"', ' '); replace(r_f.begin(), r_f.end(), '\'', ' ');
replace(r_f.begin(), r_f.end(), ';', ',');
r_f.erase(remove_if(r_f.begin(), r_f.end(), ::isspace), r_f.end());
if (!r_f.empty()) file_out << r_f << "\n";
}
file_out.close(); cout << "\n[SUCCESSO] Aggiornamento completato!\n";
}
void eseguiElaborazione() {
int id_inizio_scelto = 7440; // Impostato fisso sull'inizio della Ruota Nazionale
cout << "\n -> Elaborazione impostata sull'inizio della Ruota Nazionale (ID 10000)\n";
auto t_start = chrono::high_resolution_clock::now();
ifstream file("estrazioni.csv");
if (!file.is_open()) { cout << "[ERRORE] File 'estrazioni.csv' mancante!\n"; return; }
vector<Estrazione> archivio; string linea; int lineno = 0;
while (getline(file, linea)) {
lineno++; linea = pulisci(linea);
if (linea.empty() || linea.rfind("data", 0) == 0 || linea.rfind("//", 0) == 0 || linea.rfind("#", 0) == 0) continue;
stringstream ss(linea); string cella; vector<string> parti;
while (getline(ss, cella, ',')) parti.push_back(cella);
if (parti.size() < 2) continue;
int id_reale = lineno - 1; if (id_reale < id_inizio_scelto) continue;
Estrazione est; if (!parti.empty()) est.data = parti[0];
vector<int> valori;
for (size_t i = 1; i < parti.size(); ++i) { if (!parti
.empty()) { try { valori.push_back(stoi(parti)); } catch (...) {} } }
if (valori.size() < 55) continue;
int idx = 0;
for (int r = 0; r < 11; ++r) { for (int e = 0; e < 5; ++e) est.numeri[r][e] = valori[idx++]; }
archivio.push_back(est);
}
file.close(); int N = archivio.size(); if (N == 0) return;
cout << " -> Estrazioni caricate: " << N << "\n";
vector<unsigned short> rit_cor(NUM_COPPIE, 0), rit_max(NUM_COPPIE, 0);
vector<AmboNumerico> mappaAmbi(4005); vector<pair<int, int>> coppie(NUM_COPPIE);
int c_ambo = 0;
for (int i = 1; i <= 89; ++i) { for (int j = i + 1; j <= 90; ++j) { mappaAmbi[c_ambo].n1 = i; mappaAmbi[c_ambo].n2 = j; c_ambo++; } }
long long ci = 0;
for (int i = 0; i < 4005; ++i) { for (int j = i + 1; j < 4005; ++j) coppie[ci++] = {i, j}; }
cout << " -> Elaborazione parallela in corso... \n";
vector<bool> ambo_uscito(4005, false); vector<int> ultimi_usciti;
for (int idx_e = 0; idx_e < N; ++idx_e) {
fill(ambo_uscito.begin(), ambo_uscito.end(), false); if (idx_e == N - 1) ultimi_usciti.clear();
for (int r = 0; r < 11; ++r) {
for (int c1 = 0; c1 < 4; ++c1) {
for (int c2 = c1 + 1; c2 < 5; ++c2) {
int n1 = archivio[idx_e].numeri[r][c1], n2 = archivio[idx_e].numeri[r][c2];
if (n1 > 0 && n2 > 0) { int a_idx = getAmboIdx(n1, n2); ambo_uscito[a_idx] = true; if (idx_e == N - 1) ultimi_usciti.push_back(a_idx); }
}
}
}
for (long long c = 0; c < NUM_COPPIE; ++c) {
if (ambo_uscito[coppie[c].first] || ambo_uscito[coppie[c].second]) { if (rit_cor[c] > rit_max[c]) rit_max[c] = rit_cor[c]; rit_cor[c] = 0; }
else { rit_cor[c]++; }
}
}
for (long long c = 0; c < NUM_COPPIE; ++c) { if (rit_cor[c] > rit_max[c]) rit_max[c] = rit_cor[c]; }
vector<RecordCoppia> lista_generale, lista_caldi, lista_sfaldati; long long progressivo_pos = 0;
for (long long c = 0; c < NUM_COPPIE; ++c) {
if (rit_max[c] <= SOGLIA) {
progressivo_pos++; int idx1 = coppie[c].first, idx2 = coppie[c].second;
int mx = rit_max[c], att = rit_cor[c], diff = mx - att;
bool sfaldato = (find(ultimi_usciti.begin(), ultimi_usciti.end(), idx1) != ultimi_usciti.end()) || (find(ultimi_usciti.begin(), ultimi_usciti.end(), idx2) != ultimi_usciti.end());
stringstream s1, s2; s1 << setfill('0') << setw(2) << mappaAmbi[idx1].n1 << "-" << setw(2) << mappaAmbi[idx1].n2; s2 << setfill('0') << setw(2) << mappaAmbi[idx2].n1 << "-" << setw(2) << mappaAmbi[idx2].n2;
RecordCoppia rec = {progressivo_pos, s1.str(), s2.str(), mx, att, diff, sfaldato};
lista_generale.push_back(rec); if (sfaldato) lista_sfaldati.push_back(rec); if (diff <= DIST_CALDI && att > 0) lista_caldi.push_back(rec);
}
}
sort(lista_caldi.begin(), lista_caldi.end(), comparaCaldi);
ofstream f_gen("biambi_sotto79.txt"), f_sf("biambi_sfaldati.txt"), f_caldi("biambi_caldi.txt");
string intestazione = " Pos. Ambo 1 Ambo 2 Rit.Max Rit.Att Info\n---------------------------------------------------------------------------\n";
f_gen << intestazione; f_sf << intestazione; f_caldi << " Rank Ambo 1 Ambo 2 Rit.Max Rit.Att Segnale Visivo / Colpi Mancanti\n---------------------------------------------------------------------------\n";
for (const auto& rec : lista_generale) f_gen << setw(7) << rec.originale_pos << ". " << rec.ambo1_str << " " << rec.ambo2_str << " " << setw(3) << rec.mx << " " << setw(3) << rec.att << "\n";
for (const auto& rec : lista_sfaldati) f_sf << setw(7) << rec.originale_pos << ". " << rec.ambo1_str << " " << rec.ambo2_str << " " << setw(3) << rec.mx << " " << setw(3) << rec.att << "\n";
long long rank_caldi = 0;
for (const auto& rec : lista_caldi) {
rank_caldi++; f_caldi << setw(7) << rank_caldi << ". " << rec.ambo1_str << " " << rec.ambo2_str << " " << setw(3) << rec.mx << " " << setw(3) << rec.att << " ";
if (rec.diff == 0) f_caldi << "[CRITICO] !!! RECORD PAREGGIATO !!! (Mancano " << rec.diff << " colpi)";
else if (rec.diff >= 1 && rec.diff <= 4) f_caldi << "[ALTO] *** SURRISCALDATO *** (Mancano " << rec.diff << " colpi)";
else f_caldi << "[ZONA CALDA] (Mancano " << rec.diff << " colpi)";
f_caldi << "\n";
}
f_gen.close(); f_sf.close(); f_caldi.close();
// --- GENERATORE DI INTERFACCIA GRAFICA HTML ---
cout << " -> Generazione dell'Interfaccia Grafica a colori... \n";
ofstream html("Pannello_Grafico.html");
html << "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Pannello BiAmbi Caldi</title>"
<< "<style>body{font-family:'Segoe UI',sans-serif;background-color:#121212;color:#e0e0e0;margin:30px;}"
<< "h1{color:#1e88e5;text-align:center;margin-bottom:5px;}h3{text-align:center;color:#888;margin-bottom:30px;}"
<< ".search-box{display:block;width:300px;margin:0 auto 20px auto;padding:10px;font-size:16px;background:#222;color:#fff;border:1px solid #444;border-radius:5px;text-align:center;}"
<< "table{width:100%;max-width:900px;margin:0 auto;border-collapse:collapse;box-shadow:0 4px 8px rgba(0,0,0,0.5);}"
<< "th,td{padding:12px;text-align:center;border-bottom:1px solid #333;}th{background-color:#1e88e5;color:#fff;}"
<< "tr:hover{background-color:#252525;}.critico{background-color:#c62828 !important;color:#fff;font-weight:bold;}"
<< ".alto{background-color:#ef6c00 !important;color:#fff;}.zona{background-color:#2e7d32 !important;color:#fff;}</style></head><body>"
<< "<h1>PANNELLO VISIVO - BI-AMBI CALDI</h1><h3>Aggiornato al concorso corrente (Analisi dal 2005 - Ruota Nazionale)</h3>"
<< "<input type='text' id='search' class='search-box' placeholder='Filtra per numero (es. 08)...' onkeyup='filtraTabella()'>"
<< "<table id='tabellaLotto'><thead><tr><th>Rank</th><th>Ambo 1</th><th>Ambo 2</th><th>Rit.Max</th><th>Rit.Att</th><th>Stato / Colpi Mancanti</th></tr></thead><tbody>";
rank_caldi = 0;
for (const auto& rec : lista_caldi) {
rank_caldi++;
string classe_colore = (rec.diff == 0) ? "critico" : (rec.diff <= 4 ? "alto" : "zona");
string testo_stato = (rec.diff == 0) ? "CRITICO - Record Pareggiato!" : (rec.diff <= 4 ? "ALTO - Surriscaldato" : "ZONA CALDA");
html << "<tr><td>" << rank_caldi << "</td><td>" << rec.ambo1_str << "</td><td>" << rec.ambo2_str << "</td><td>"
<< rec.mx << "</td><td>" << rec.att << "</td><td><span class='" << classe_colore << "' style='padding:4px 10px; display:inline-block;'>" << testo_stato << " (Mancano " << rec.diff << " colpi)</span></td></tr>";
}
html << "</tbody></table>"
<< "<script>function filtraTabella(){var input=document.getElementById('search').value;var filter=input.toUpperCase();"
<< "var rows=document.getElementById('tabellaLotto').getElementsByTagName('tbody')[0].getElementsByTagName('tr');"
<< "for(var i=0;i<rows.length;i++){var cells=rows.getElementsByTagName('td');var match=false;"
<< "for(var j=1;j<3;j++){if(cells[j]){var txt=cells[j].textContent||cells[j].innerText;"
<< "if(txt.toUpperCase().indexOf(filter)>-1){match=true;break;}}}"
<< "if(match){rows.style.display='';}else{rows.style.display='none';}}}</script></body></html>";
html.close();
auto t_end = chrono::high_resolution_clock::now();
cout << "\n[SUCCESSO] Elaborazione e Pannello Grafico completati in " << fixed << setprecision(2) << chrono::duration<double>(t_end - t_start).count() << " secondi!\n";
}
int main() {
while (true) {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
cout << "=================================================================\n";
cout << " SOFTWARE STATISTICO: BI-AMBI CALDI\n";
cout << " COMPILAZIONE NATIVA C++ 2026\n";
cout << "=================================================================\n";
cout << " 1. AGGIORNA ARCHIVIO (Incolla direttamente le nuove estrazioni)\n";
cout << " 2. AVVIA ELABORAZIONE STATISTICA (Genera i Report e la GUI)\n";
cout << " 3. ESCI DAL PROGRAMMA\n";
cout << "=================================================================\n";
cout << " Seleziona un'opzione (1-3): ";
string scelta; getline(cin, scelta);
if (scelta == "1") {
aggiornaArchivioCopiaIncolla();
cout << "\nPremi INVIO per tornare al menu..."; cin.get();
} else if (scelta == "2") {
eseguiElaborazione();
cout << "\nPremi INVIO per tornare al menu..."; cin.get();
} else if (scelta == "3") {
break;
}
}
return 0;
}