// ####################################################################### // ### generator.cc ### // ### Testdaten-Generator ### // ### von ### // ### Thomas Dreibholz, dreibh@iem.uni-due.de ### // ### Harald Schwarz, schwarzh@cs.uni-bonn.de ### // ### (c) 10.Juli 2000 ### // ####################################################################### #include #include #include #include #include #include // ======================================================================= // Type definitions = // ======================================================================= struct list_t { char** value; int no_of_elements; }; // ======================================================================= // Global variables = // ======================================================================= list_t* list_names_male; list_t* list_names_female; list_t* list_names_family; list_t* list_names_towns; list_t* list_names_street; list_t* list_names_str_typ; // ======================================================================= // Global constants = // ======================================================================= const int MAX_ELEMENTS = 500; const int MIN_STUD_ID = 20000000; const int MAX_STUD_ID = 50000000; const int MIN_PERS_ID = 98765431; const int MAX_PERS_ID = 98765460; const int SEX_QUOTA = 20; const int BIRTH_START = 1970; const int BIRTH_VAR = 11; const int ABI_AGE = 18; const int IMMAT_VAR = 6; const int YEAR_NOW = 2000; const int SEM_LIMIT = 6; const int MAX_QUALIES = 17; const int Q_HZB = 0; const int Q_INF_1 = 1; const int Q_INF_2 = 2; const int Q_INF_3 = 3; const int Q_INF_4 = 4; const int Q_INF_PS = 5; const int Q_INF_PP = 6; const int Q_M_IR_1 = 7; const int Q_M_IR_2 = 8; const int Q_M_LA_1 = 9; const int Q_M_LA_2 = 10; const int Q_V_DIPL = 11; const int Q_INF_SA = 12; const int Q_INF_SB = 13; const int Q_INF_PC = 14; const int Q_M_PMWR = 15; const int Q_DIPLOM = 16; const int MAX_DP_EXAMS = 11; const int DP_VD_DIPLOM = 0; const int DP_VD_INF_A = 1; const int DP_VD_INF_B = 2; const int DP_VD_MATHE = 3; const int DP_VD_NF = 4; const int DP_HD_INF_A = 5; const int DP_HD_INF_B = 6; const int DP_HD_INF_C = 7; const int DP_HD_NF = 8; const int DP_HD_ARBEIT = 9; const int DP_HD_DIPLOM = 10; const int NO = 1; const int YES = 0; const int NOT_PASSED = 1; const int YES_PASSED = 0; const int MAX_VD_TRY = 3; const int MAX_HD_TRY = 3; const int MAX_DIPL_TRY = 2; const int WIN_SEM = 0; const int SOM_SEM = 1; // ======================================================================= // Subroutines = // ======================================================================= int odd(int num) { return (num % 2); } int even(int num) { return (num % 2); } //------------------------------------------------------------------------ // Zufallszahlengenerator mit Startwert von Systemzeit initialisieren void Randomize() { ifstream is("/dev/urandom",ios::in | ios::binary); if(is.good()) { unsigned int zahl; char a,b,c,d; is >> a >> b >> c >> d; zahl = ((unsigned int)a << 24) + ((unsigned int)b << 16) + ((unsigned int)c << 8) + d; srand(zahl); } else { time_t zeit; time(&zeit); srand(zeit); } } // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Read Strings from file into list list_t* load_list(const char* name, const int number) { // Initialize list list_t* list = new list_t; list->value = new char*[number]; list->no_of_elements = 0; for(int i = 0; i < number; i++) list->value[i] = NULL; // Read strings from file into list ifstream is(name); if(is.good()) { char s[256]; while(!is.eof() && (list->no_of_elements < number)) { is.getline(s,sizeof(s)); if(s[0] != 0x00) { list->value[list->no_of_elements++] = strdup(s); } } } else { cerr << "Datei nicht gefunden: " << name << endl; exit(1); } if(list->no_of_elements < 1) { cerr << "Datei ist leer: " << name << endl; exit(1); } return(list); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Get random element from the list char* rand_element(const list_t* list) { const int i = random() % list->no_of_elements; return(list->value[i]); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Get a random integer in the range [0...number] int rand_int(int number) { return( random() % number ); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Load all list used by this program void load_all_lists(void) { list_names_male = load_list("Names_male.lst", MAX_ELEMENTS); list_names_female = load_list("Names_female.lst", MAX_ELEMENTS); list_names_family = load_list("Names_family.lst", MAX_ELEMENTS); list_names_towns = load_list("Names_towns.lst", MAX_ELEMENTS); list_names_street = load_list("Names_street.lst", MAX_ELEMENTS); list_names_str_typ = load_list("Names_str_typ.lst", MAX_ELEMENTS); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // PG-SQL Command void begin_transaction() { cout << "BEGIN TRANSACTION;" << endl; cout << "SET DATESTYLE = GERMAN;" << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // PG-SQL Command void commit_work() { cout << "COMMIT WORK;" << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_intro() { cout << "INSERT INTO uni_qualifikate "; cout << endl; cout << "(stud_id, qal_typ, pers_id, datum, titel, bemerkung) "; cout << "VALUES ( "; cout << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Write qualies separator void w_q_s() { cout << ","; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_stud_id(int stud_id) { cout << "'" << stud_id << "'"; w_q_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_typ(int q_typ) { char* Q_TYPTXT[MAX_QUALIES]; Q_TYPTXT[ Q_HZB ] = "HZB"; Q_TYPTXT[ Q_INF_1 ] = "IF-I"; Q_TYPTXT[ Q_INF_2 ] = "IF-II"; Q_TYPTXT[ Q_INF_3 ] = "IF-III"; Q_TYPTXT[ Q_INF_4 ] = "IF-IV"; Q_TYPTXT[ Q_INF_PS ] = "IF-PS"; Q_TYPTXT[ Q_INF_PP ] = "IF-PP"; Q_TYPTXT[ Q_M_IR_1 ] = "M-IR-I"; Q_TYPTXT[ Q_M_IR_2 ] = "M-IR-II"; Q_TYPTXT[ Q_M_LA_1 ] = "M-LA-I"; Q_TYPTXT[ Q_M_LA_2 ] = "M-LA-II"; Q_TYPTXT[ Q_V_DIPL ] = "VDIPL"; Q_TYPTXT[ Q_INF_SA ] = "IF-SA"; Q_TYPTXT[ Q_INF_SB ] = "IF-SB"; Q_TYPTXT[ Q_INF_PC ] = "IF-PC"; Q_TYPTXT[ Q_M_PMWR ] = "M-PM"; Q_TYPTXT[ Q_DIPLOM ] = "DIPLOM"; cout << "'" << Q_TYPTXT[q_typ] << "'"; w_q_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_title(int q_typ) { char* Q_TITLE[MAX_QUALIES]; Q_TITLE[ Q_HZB ] = "Abitur-Zeugnis"; Q_TITLE[ Q_INF_1 ] = "Informatik I"; Q_TITLE[ Q_INF_2 ] = "Informatik II"; Q_TITLE[ Q_INF_3 ] = "Informatik III"; Q_TITLE[ Q_INF_4 ] = "Informatik IV"; Q_TITLE[ Q_INF_PS ] = "Informatik Proseminar"; Q_TITLE[ Q_INF_PP ] = "Informatik Prog-Praktikum"; Q_TITLE[ Q_M_IR_1 ] = "Infinitesimalrechnung I"; Q_TITLE[ Q_M_IR_2 ] = "Infinitesimalrechnung II"; Q_TITLE[ Q_M_LA_1 ] = "Lineare Algebra I"; Q_TITLE[ Q_M_LA_2 ] = "Lineare Algebra II"; Q_TITLE[ Q_V_DIPL ] = "Vordiplom-Zeugnis"; Q_TITLE[ Q_INF_SA ] = "Informatik Hauptseminar A"; Q_TITLE[ Q_INF_SB ] = "Informatik Hauptseminar B"; Q_TITLE[ Q_INF_PC ] = "Informatik Praktikum C"; Q_TITLE[ Q_M_PMWR ] = "Praktische Mathematik"; Q_TITLE[ Q_DIPLOM ] = "Diplom Informatik"; cout << "'" << Q_TITLE[q_typ] << "'"; w_q_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_pers_id(int faculty) { int dummy = faculty; dummy++; int num_of_pers = MAX_PERS_ID - MIN_PERS_ID; int pers_id = MIN_PERS_ID + rand_int(num_of_pers); cout << "'" << pers_id << "'"; w_q_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_date(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM ) { cout << "'28.2."; cout << sem_year + 1; cout << "'"; w_q_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'30.7."; cout << sem_year; cout << "'"; w_q_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_date_late(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM ) { cout << "'31.3."; cout << sem_year + 1; cout << "'"; w_q_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'30.9."; cout << sem_year; cout << "'"; w_q_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_comment() { cout << "'ohne Bewertung'"; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_qualies_closing() { // cout << endl; cout << " );"; cout << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int qualies_test(int q_typ, int stud_level, int stud_id, int sem_year, int sem_typ) { int Q_LEVEL[ MAX_QUALIES ]; Q_LEVEL[ Q_HZB ] = 100; Q_LEVEL[ Q_INF_1 ] = 60; Q_LEVEL[ Q_INF_2 ] = 60; Q_LEVEL[ Q_INF_3 ] = 60; Q_LEVEL[ Q_INF_4 ] = 50; Q_LEVEL[ Q_INF_PS ] = 60; Q_LEVEL[ Q_INF_PP ] = 60; Q_LEVEL[ Q_M_IR_1 ] = 50; Q_LEVEL[ Q_M_IR_2 ] = 50; Q_LEVEL[ Q_M_LA_1 ] = 50; Q_LEVEL[ Q_M_LA_2 ] = 40; Q_LEVEL[ Q_V_DIPL ] = 100; Q_LEVEL[ Q_INF_SA ] = 50; Q_LEVEL[ Q_INF_SB ] = 50; Q_LEVEL[ Q_INF_PC ] = 50; Q_LEVEL[ Q_M_PMWR ] = 40; Q_LEVEL[ Q_DIPLOM ] = 100; int level = 100 - stud_level; if ( rand_int(level) <= Q_LEVEL[ q_typ ] ) { write_qualies_intro(); write_qualies_stud_id(stud_id); write_qualies_typ(q_typ); write_qualies_pers_id(q_typ); if ( (q_typ == Q_V_DIPL) || (q_typ == Q_DIPLOM) ) { write_qualies_date_late(sem_year, sem_typ); } else { write_qualies_date(sem_year, sem_typ); } write_qualies_title(q_typ); write_qualies_comment(); write_qualies_closing(); return( YES_PASSED ); } else return ( NOT_PASSED ); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Write exams separator void w_e_s() { cout << ","; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_date(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM) { cout << "'15.3."; cout << sem_year + 1; cout << "'"; w_e_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'15.9."; cout << sem_year; cout << "'"; w_e_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int generate_exams_result(int stud_level, int sem_year, int sem_typ) { const int MAX_RESULT = 99 - stud_level; const int LEVEL_1 = 5; const int LEVEL_1_M = 10; const int LEVEL_2_P = 15; const int LEVEL_2 = 25; const int LEVEL_2_M = 40; const int LEVEL_3_P = 50; const int LEVEL_3 = 60; const int LEVEL_3_M = 70; const int LEVEL_4_P = 75; const int LEVEL_4 = 80; int result = rand_int(MAX_RESULT); if (result <= LEVEL_1) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "1.0"; } else if ( result > LEVEL_1 && result <= LEVEL_1_M ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "1.3"; } else if ( result > LEVEL_1_M && result <= LEVEL_2_P ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "1.7"; } else if ( result > LEVEL_2_P && result <= LEVEL_2 ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "2.0"; } else if ( result > LEVEL_2 && result <= LEVEL_2_M ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "2.3"; } else if ( result > LEVEL_2_M && result <= LEVEL_3_P ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "2.7"; } else if ( result > LEVEL_3_P && result <= LEVEL_3 ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "3.0"; } else if ( result > LEVEL_3 && result <= LEVEL_3_M ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "3.3"; } else if ( result > LEVEL_3_M && result <= LEVEL_4_P ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "3.7"; } else if ( result > LEVEL_4_P && result <= LEVEL_4 ) { cout << "'B',"; write_exams_date(sem_year, sem_typ); cout << "4.0"; } else if (result > LEVEL_4) { cout << "'NB',"; write_exams_date(sem_year, sem_typ); cout << "5.0"; } w_e_s(); if (result <= LEVEL_4) { return( 0 ); } else { return( 1 ); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_intro() { cout << "INSERT INTO uni_pruefungen "; cout << endl; cout << "(stud_id, typ_id, versuch, zaehler, anmelde_datum,"; cout << " gew_pruefer_id, pruefer_id, beisitz_id,"; cout << " status_id, datum, note, bemerkung"; // cout << ", thema"; cout << " )"; cout << " VALUES ("; cout << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_stud_id(int stud_id) { cout << "'" << stud_id << "'"; w_e_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_typ(int exam_typ) { char* E_TYPTXT[MAX_DP_EXAMS]; E_TYPTXT[ DP_VD_DIPLOM ] = "VD-DIPLOM"; E_TYPTXT[ DP_VD_INF_A ] = "VD-I/II"; E_TYPTXT[ DP_VD_INF_B ] = "VD-III/IV"; E_TYPTXT[ DP_VD_MATHE ] = "VD-MATH"; E_TYPTXT[ DP_VD_NF ] = "VD-NF"; E_TYPTXT[ DP_HD_INF_A ] = "HD-A"; E_TYPTXT[ DP_HD_INF_B ] = "HD-B"; E_TYPTXT[ DP_HD_INF_C ] = "HD-C"; E_TYPTXT[ DP_HD_NF ] = "HD-NF"; E_TYPTXT[ DP_HD_ARBEIT ] = "HD-ARBEIT"; E_TYPTXT[ DP_HD_DIPLOM ] = "HD-DIPLOM"; cout << "'" << E_TYPTXT[exam_typ] << "'"; w_e_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_counter(int counter, int subcounter) { cout << counter; w_e_s(); cout << subcounter; w_e_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_entry_date(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM) { cout << "'1.3."; cout << sem_year + 1; cout << "'"; w_e_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'1.8."; cout << sem_year; cout << "'"; w_e_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_pers_id(int stud_id) { cout << "'" << stud_id << "'"; w_e_s(); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_comment(int stud_level) { cout << "'"; cout << "LEVEL: " << stud_level; cout << "'"; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_closing() { // cout << endl; cout << " );"; cout << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int dp_exams_test(int exam_typ, int stud_level, int stud_id, int sem_year, int sem_typ, int counter) { int gew_pruefer_id = MIN_PERS_ID + rand_int( MAX_PERS_ID - MIN_PERS_ID - 1 ); int pruefer_id = gew_pruefer_id; int beisitz_id = pruefer_id + 1; int subcounter = 1; write_exams_intro(); write_exams_stud_id(stud_id); write_exams_typ(exam_typ); write_exams_counter(counter, subcounter); write_exams_entry_date(sem_year, sem_typ); write_exams_pers_id( gew_pruefer_id ); write_exams_pers_id( pruefer_id ); write_exams_pers_id( beisitz_id ); int result = generate_exams_result( stud_level, sem_year, sem_typ ); write_exams_comment(stud_level); write_exams_closing(); if ( result == 0 ) { return( 0 ); } else { counter++; return ( counter ); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_thesis_intro() { cout << "INSERT INTO uni_diplarbeit "; cout << endl; cout << "(stud_id, versuch, zaehler, anmelde_datum,"; cout << " gew_pruefer_id, thema,"; cout << " ausgabe_datum, abgabe_datum, abgabe_limit,"; cout << " pruefer1_id, pruefer2_id,"; cout << " status_id, note, bemerkung"; cout << " )"; cout << " VALUES ("; cout << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_thesis_entry_date(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM) { cout << "'1.10."; cout << sem_year; cout << "'"; w_e_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'1.4."; cout << sem_year; cout << "'"; w_e_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_thesis_dates(int sem_year, int sem_typ) { if ( sem_typ == WIN_SEM) { cout << "'1.10."; cout << sem_year; cout << "'"; w_e_s(); cout << "'28.3."; cout << sem_year + 1; cout << "'"; w_e_s(); cout << "'30.3."; cout << sem_year + 1; cout << "'"; w_e_s(); } else if ( sem_typ == SOM_SEM ) { cout << "'1.4."; cout << sem_year; cout << "'"; w_e_s(); cout << "'28.9."; cout << sem_year; cout << "'"; w_e_s(); cout << "'30.9."; cout << sem_year; cout << "'"; w_e_s(); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- void write_exams_thesis_theme() // Just one theme for all students!!! :-( { cout << "'Implementation eines Diplomthemengenerators',"; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int generate_exams_thesis_result(int stud_level) { const int MAX_RESULT = 99 - stud_level; const int LEVEL_1 = 5; const int LEVEL_1_M = 10; const int LEVEL_2_P = 15; const int LEVEL_2 = 25; const int LEVEL_2_M = 40; const int LEVEL_3_P = 50; const int LEVEL_3 = 60; const int LEVEL_3_M = 70; const int LEVEL_4_P = 75; const int LEVEL_4 = 80; int result = rand_int(MAX_RESULT); if (result <= LEVEL_1) { cout << "'B',"; cout << "1.0"; } else if ( result > LEVEL_1 && result <= LEVEL_1_M ) { cout << "'B',"; cout << "1.3"; } else if ( result > LEVEL_1_M && result <= LEVEL_2_P ) { cout << "'B',"; cout << "1.7"; } else if ( result > LEVEL_2_P && result <= LEVEL_2 ) { cout << "'B',"; cout << "2.0"; } else if ( result > LEVEL_2 && result <= LEVEL_2_M ) { cout << "'B',"; cout << "2.3"; } else if ( result > LEVEL_2_M && result <= LEVEL_3_P ) { cout << "'B',"; cout << "2.7"; } else if ( result > LEVEL_3_P && result <= LEVEL_3 ) { cout << "'B',"; cout << "3.0"; } else if ( result > LEVEL_3 && result <= LEVEL_3_M ) { cout << "'B',"; cout << "3.3"; } else if ( result > LEVEL_3_M && result <= LEVEL_4_P ) { cout << "'B',"; cout << "3.7"; } else if ( result > LEVEL_4_P && result <= LEVEL_4 ) { cout << "'B',"; cout << "4.0"; } else if (result > LEVEL_4) { cout << "'NB',"; cout << "5.0"; } w_e_s(); if (result <= LEVEL_4) { return( 0 ); } else { return( 1 ); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int dp_exams_thesis(int exam_typ, int stud_level, int stud_id, int sem_year, int sem_typ, int counter) { int gew_pruefer_id = MIN_PERS_ID + rand_int( MAX_PERS_ID - MIN_PERS_ID - 1 ); int pruefer1_id = gew_pruefer_id; int pruefer2_id = pruefer1_id + 2; int subcounter = 1; write_exams_thesis_intro(); write_exams_stud_id(stud_id); write_exams_counter(counter, subcounter); write_exams_thesis_entry_date(sem_year, sem_typ); write_exams_pers_id(gew_pruefer_id); write_exams_thesis_theme(); write_exams_thesis_dates(sem_year, sem_typ); write_exams_pers_id(pruefer1_id); write_exams_pers_id(pruefer2_id); int result = generate_exams_thesis_result( stud_level); write_exams_comment(stud_level); write_exams_closing(); if ( result == 0 ) { return( 0 ); } else { counter++; return ( counter ); } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Delete all data in the default interval void delete_student_data() { cout << "DELETE FROM pers_studenten " << endl; cout << " where ( (stud_id >= '" << MIN_STUD_ID; cout << "') AND (stud_id < '" << MAX_STUD_ID; cout << "') );" << endl; cout << "DELETE FROM pers_adressen " << endl; cout << " where ( (id >= '" << MIN_STUD_ID; cout << "') AND (id < '" << MAX_STUD_ID; cout << "') );" << endl; cout << "DELETE FROM uni_studium " << endl; cout << " where ( (stud_id >= '" << MIN_STUD_ID; cout << "') AND (stud_id < '" << MAX_STUD_ID; cout << "') );" << endl; cout << "DELETE FROM uni_qualifikate " << endl; cout << " where ( (stud_id >= '" << MIN_STUD_ID; cout << "') AND (stud_id < '" << MAX_STUD_ID; cout << "') );" << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Delete all data in the default interval void delete_student_data(int min_id, int max_id) { cout << "DELETE FROM pers_studenten " << endl; cout << " where ( (stud_id >= '" << min_id; cout << "') AND (stud_id < '" << max_id; cout << "') );" << endl; cout << "DELETE FROM pers_adressen " << endl; cout << " where ( (id >= '" << min_id; cout << "') AND (id < '" << max_id; cout << "') );" << endl; cout << "DELETE FROM uni_studium " << endl; cout << " where ( (stud_id >= '" << min_id; cout << "') AND (stud_id < '" << max_id; cout << "') );" << endl; cout << "DELETE FROM uni_qualifikate " << endl; cout << " where ( (stud_id >= '" << min_id; cout << "') AND (stud_id < '" << max_id; cout << "') );" << endl; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- int generate_personal_data(int stud_id) { int birth_year; int birth_month; int birth_day; int immat_year; const int MAX_NEFA = 7; char* nebenfach[ MAX_NEFA ]; nebenfach[ 0 ] = "Physik"; nebenfach[ 1 ] = "Chemie"; nebenfach[ 2 ] = "Biologie"; nebenfach[ 3 ] = "Mathematik"; nebenfach[ 4 ] = "BWL"; nebenfach[ 5 ] = "Psychologie"; nebenfach[ 6 ] = "Kommunikationsf. und Phonetik"; // Write SQL-Statement cout << "INSERT INTO pers_studenten "; cout << endl; cout << "(stud_id, name, vorname, m_w,"; cout << " geb_datum, geb_ort, immat_datum, nebenfach)"; cout << endl; cout << "VALUES ("; cout << endl; // Write student data cout << stud_id << ","; // Generate family name cout << "'" << rand_element(list_names_family) << "'" << ","; // Generate sex and first name if( rand_int( SEX_QUOTA ) != 1) cout << "'" << rand_element(list_names_male) << "', 'm', "; else cout << "'" << rand_element(list_names_female) << "', 'w',"; // Generate the birth date birth_year = BIRTH_START + rand_int(BIRTH_VAR); birth_month = rand_int(12) + 1; if ( ( birth_month == 1 ) || ( birth_month == 3 ) || ( birth_month == 5 ) || ( birth_month == 7 ) || ( birth_month == 8 ) || ( birth_month == 10 ) || ( birth_month == 12 ) ) { birth_day = rand_int(30) + 1; } else if ( ( birth_month == 4 ) || ( birth_month == 6 ) || ( birth_month == 9 ) || ( birth_month == 11 ) ) { birth_day = rand_int(29) + 1; } else { birth_day = rand_int(27) + 1; } cout << "'" << birth_day << "." << birth_month << "." << birth_year << "',"; // Generate the place of birth cout << "'" << rand_element( list_names_towns ) << "',"; // Generate the immatrikulation date: immat_year = birth_year + ABI_AGE + rand_int(IMMAT_VAR); if (immat_year >= YEAR_NOW) immat_year = YEAR_NOW - 1; cout << "'1.10." << immat_year << "',"; cout << "'" << nebenfach[ rand_int( MAX_NEFA) ] << "'"; cout << ");" << endl; // Generate the student's address: cout << "INSERT INTO pers_adressen "; cout << "(id, zaehler, adr_typ, sonstiges, raum, "; cout << " strasse, land, plz, ort, telefon1, telefon2, fax, email)"; cout << endl; cout << "VALUES ("; // Give out student identity cout << "'" << stud_id << "',"; // Give out zaehler and typ: cout << "1,'Ladung',"; // Give out sonstiges and raum: cout << "NULL,NULL,"; // Generate street and house number: cout << "'" << rand_element( list_names_street ) << rand_element( list_names_str_typ ) << " " << ( rand_int(100) + 1 ) << "',"; // Give out land: cout << "'D',"; // Give out plz: cout << "12345,"; // Generate ort: cout << "'" << rand_element( list_names_towns ) << "',"; // Generate telephone numbers: cout << "'" << (random() % 100000) << "',"; cout << "'" << (random() % 100000) << "',"; // Generate fax number: cout << "'" << (random() % 100000) << "',"; // Generate the email address: cout << "'stud_"; cout << stud_id - MIN_STUD_ID; cout << "@cs.uni-bonn.de'"; cout << ");" << endl; // Generate "Hochschul-Zugangsberechtigung" write_qualies_intro(); cout << "'" << stud_id << "','HZB',NULL,"; cout << "'15.5."; cout << immat_year - rand_int(IMMAT_VAR); cout << "','Abitur-Zeugnis','' );"; cout << endl; return( immat_year ); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Generate data about semester for this student void generate_student_semester(int stud_id, int immat_year) { int qualies[MAX_QUALIES]; int dp_exams[MAX_DP_EXAMS]; int time_to_go = NO; int stud_is_ex = NO; int stud_level = rand_int(30); for ( int i = 0; i < MAX_QUALIES; i++) { qualies[i] = NOT_PASSED; } for ( int i = 0; i < MAX_DP_EXAMS; i++) { dp_exams[i] = NOT_PASSED; } for (int year = immat_year, semester = 1; year < YEAR_NOW; year++, semester++ ) { for(int sem_typ = WIN_SEM; sem_typ <= SOM_SEM; sem_typ++) { if ( (time_to_go == YES) && (stud_is_ex == NO) ) { cout << "UPDATE pers_studenten " << endl; cout << "SET exmat_datum = "; // VERY DIRTY CODE !!! // DAS time_to_go Flag stammt noch aus dem vorhergehenden // Semester. Wird jetzt rueckdatiert. if ( sem_typ == WIN_SEM ) { cout << "'30.9."; cout << year << "' "; } else { cout << "'31.3."; cout << year + 1 << "' "; } cout << "WHERE stud_id = '" << stud_id << "';" << endl; cout << "/* TIME TO GO */" << endl; stud_is_ex = YES; } else if ((time_to_go == YES) && (stud_is_ex == YES )) { cout << "/* IST SCHON EXMATRIKULIERT */" << endl; } else { int sem_year = year + sem_typ; int sem_count = semester + sem_typ; cout << "INSERT INTO uni_studium "; cout << endl; cout << "( stud_id, semester, studien_typ) VALUES ("; cout << endl; cout << "'" << stud_id <<"',"; if (sem_typ == 0) { cout << "'WS" << sem_year << "/" << sem_year+1 << "',"; } else if (sem_typ == 1) { cout << "'SS" << sem_year << "',"; } cout << "'Voll'"; cout << ");" << endl; // STUDENT hat keine Lust mehr if ( rand_int(100) >= 97 ) { time_to_go = YES; cout << "/* ABRUCH: Keine Lust mehr */" << endl; } // INFO-I Schein if ( qualies[Q_INF_1] == NOT_PASSED && sem_count >= 1 && sem_typ == WIN_SEM ) { qualies[Q_INF_1] = qualies_test(Q_INF_1, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_INF_1] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFO-1 Schein */" << endl; } // INFO-II Schein if ( qualies[Q_INF_2] == NOT_PASSED && sem_count >= 2 && sem_typ == SOM_SEM ) { qualies[Q_INF_2] = qualies_test(Q_INF_2, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_INF_2] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFO-2 Schein */" << endl; } // INFO-III Schein if ( qualies[Q_INF_3] == NOT_PASSED && sem_count >= 3 && sem_typ == WIN_SEM ) { qualies[Q_INF_3] = qualies_test(Q_INF_3, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_INF_3] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFO-3 Schein */" << endl; } // INFO-IV Schein if ( qualies[Q_INF_4] == NOT_PASSED && sem_count >= 4 && sem_typ == SOM_SEM ) { qualies[Q_INF_4] = qualies_test(Q_INF_4, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_INF_4] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFO-4 Schein */" << endl; } // INFO Proseminar-Schein if ( qualies[Q_INF_PS] == NOT_PASSED && sem_count >= 4 ) { qualies[Q_INF_PS] = qualies_test(Q_INF_PS, stud_level, stud_id, sem_year, sem_typ); } // INFO Programmier-Praktikum-Schein if ( qualies[Q_INF_PP] == NOT_PASSED && sem_count >= 4 ) { qualies[Q_INF_PP] = qualies_test(Q_INF_PP, stud_level, stud_id, sem_year, sem_typ); } // MATHE Infini-I-Schein if ( qualies[Q_M_IR_1] == NOT_PASSED && sem_count >= 1 && sem_typ == WIN_SEM ) { qualies[Q_M_IR_1] = qualies_test(Q_M_IR_1, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_M_IR_1] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFINI-1 Schein */" << endl; } // MATHE Infini-II-Schein if ( qualies[Q_M_IR_2] == NOT_PASSED && sem_count >= 2 && sem_typ == SOM_SEM ) { qualies[Q_M_IR_2] = qualies_test(Q_M_IR_2, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_M_IR_2] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein INFINI-2 Schein */" << endl; } // MATHE LA-I-Schein if ( qualies[Q_M_LA_1] == NOT_PASSED && sem_count >= 1 && sem_typ == WIN_SEM ) { qualies[Q_M_LA_1] = qualies_test(Q_M_LA_1, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_M_LA_1] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein LA-1 Schein */" << endl; } // MATHE LA-II-Schein if ( qualies[Q_M_LA_2] == NOT_PASSED && sem_count >= 2 && sem_typ == SOM_SEM ) { qualies[Q_M_LA_2] = qualies_test(Q_M_LA_2, stud_level, stud_id, sem_year, sem_typ); } if ( qualies[Q_M_LA_2] == NOT_PASSED && sem_count > SEM_LIMIT ) { time_to_go = YES; cout << "/* ABBRUCH: kein LA-II Schein */" << endl; } // INFO I-II VD-Pruefung if ( sem_count >= 3 && time_to_go == NO && qualies[Q_INF_1] == YES_PASSED && qualies[Q_INF_2] == YES_PASSED && dp_exams[DP_VD_INF_A] != YES_PASSED && dp_exams[DP_VD_INF_A] <= MAX_VD_TRY ) { int counter = dp_exams[DP_VD_INF_A]; dp_exams[DP_VD_INF_A] = dp_exams_test( DP_VD_INF_A, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_VD_INF_A] > MAX_VD_TRY ) { time_to_go = YES; } } // INFO III-IV VD-Pruefung if ( sem_count >= 4 && time_to_go == NO && qualies[Q_INF_3] == YES_PASSED && qualies[Q_INF_4] == YES_PASSED && qualies[Q_INF_PS] == YES_PASSED && qualies[Q_INF_PP] == YES_PASSED && dp_exams[DP_VD_INF_B] != YES_PASSED && dp_exams[DP_VD_INF_B] <= MAX_VD_TRY ) { int counter = dp_exams[DP_VD_INF_B]; dp_exams[DP_VD_INF_B] = dp_exams_test( DP_VD_INF_B, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_VD_INF_B] > MAX_VD_TRY ) { time_to_go = YES; } } // MATHE VD-Pruefung if ( sem_count >= 3 && time_to_go == NO && ( ( qualies[Q_M_IR_1] == YES_PASSED && qualies[Q_M_IR_2] == YES_PASSED && qualies[Q_M_LA_1] == YES_PASSED ) || ( qualies[Q_M_IR_1] == YES_PASSED && qualies[Q_M_IR_2] == YES_PASSED && qualies[Q_M_LA_2] == YES_PASSED ) || ( qualies[Q_M_IR_2] == YES_PASSED && qualies[Q_M_LA_1] == YES_PASSED && qualies[Q_M_LA_2] == YES_PASSED ) ) && dp_exams[DP_VD_MATHE] != YES_PASSED && dp_exams[DP_VD_MATHE] <= MAX_VD_TRY ) { int counter = dp_exams[DP_VD_MATHE]; dp_exams[DP_VD_MATHE] = dp_exams_test( DP_VD_MATHE, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_VD_MATHE] > MAX_VD_TRY ) { time_to_go = YES; } } // Nebenfach VD-Pruefung if ( sem_count >= 4 && time_to_go == NO && dp_exams[DP_VD_NF] != YES_PASSED && dp_exams[DP_VD_NF] <= MAX_VD_TRY ) { int counter = dp_exams[DP_VD_NF]; dp_exams[DP_VD_NF] = dp_exams_test( DP_VD_NF, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_VD_NF] > MAX_VD_TRY ) { time_to_go = YES; } } // Vordiplom erreicht? if ( dp_exams[DP_VD_DIPLOM] != YES_PASSED && dp_exams[DP_VD_INF_A] == YES_PASSED && dp_exams[DP_VD_INF_B] == YES_PASSED && dp_exams[DP_VD_MATHE] == YES_PASSED && dp_exams[DP_VD_NF] == YES_PASSED ) { dp_exams[DP_VD_DIPLOM] = YES_PASSED; qualies[Q_V_DIPL] = qualies_test(Q_V_DIPL, stud_level, stud_id, sem_year, sem_typ); } /* qualies[Q_V_DIPL] = YES_PASSED; cout << "INSERT INTO uni_qualifikate "; cout << "(stud_id, qal_typ, pers_id, datum, titel, bemerkung)"; cout << endl; cout << "VALUES ('"; cout << stud_id << "','VDIPL',NULL,"; cout << "'30.3."; cout << sem_year; cout << "','Vordiplom-Zeugnis','');"; cout << endl; } */ // HD Seminar A Schein if ( qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_SA] == NOT_PASSED ) { qualies[Q_INF_SA] = qualies_test(Q_INF_SA, stud_level, stud_id, sem_year, sem_typ); } // HD Seminar B Schein if ( qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_SB] == NOT_PASSED ) { qualies[Q_INF_SB] = qualies_test(Q_INF_SB, stud_level, stud_id, sem_year, sem_typ); } // HD Praktikum C Schein if ( qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_PC] == NOT_PASSED ) { qualies[Q_INF_PC] = qualies_test(Q_INF_PC, stud_level, stud_id, sem_year, sem_typ); } // HD Mathe (PraMa, WR) Schein if ( qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_M_PMWR] == NOT_PASSED ) { qualies[Q_M_PMWR] = qualies_test(Q_M_PMWR, stud_level, stud_id, sem_year, sem_typ); } // HD Pruefung A if ( sem_count >= 6 && time_to_go == NO && qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_SA] == YES_PASSED && qualies[Q_M_PMWR] == YES_PASSED && dp_exams[DP_HD_INF_A] != YES_PASSED && dp_exams[DP_HD_INF_A] <= MAX_HD_TRY ) { int counter = dp_exams[DP_HD_INF_A]; dp_exams[DP_HD_INF_A] = dp_exams_test( DP_HD_INF_A, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_HD_INF_A] > MAX_HD_TRY ) { time_to_go = YES; } } // HD Pruefung B if ( sem_count >= 7 && time_to_go == NO && qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_SB] == YES_PASSED && dp_exams[DP_HD_INF_B] != YES_PASSED && dp_exams[DP_HD_INF_B] <= MAX_HD_TRY ) { int counter = dp_exams[DP_HD_INF_B]; dp_exams[DP_HD_INF_B] = dp_exams_test( DP_HD_INF_B, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_HD_INF_B] > MAX_HD_TRY ) { time_to_go = YES; } } // HD Pruefung C if ( sem_count >= 8 && time_to_go == NO && qualies[Q_V_DIPL] == YES_PASSED && qualies[Q_INF_PC] == YES_PASSED && qualies[Q_M_PMWR] == YES_PASSED && dp_exams[DP_HD_INF_C] != YES_PASSED && dp_exams[DP_HD_INF_C] <= MAX_HD_TRY ) { int counter = dp_exams[DP_HD_INF_C]; dp_exams[DP_HD_INF_C] = dp_exams_test( DP_HD_INF_C, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_HD_INF_C] > MAX_HD_TRY ) { time_to_go = YES; } } // HD Pruefung Nebenfach if ( sem_count >= 7 && time_to_go == NO && qualies[Q_V_DIPL] == YES_PASSED && dp_exams[DP_HD_NF] != YES_PASSED && dp_exams[DP_HD_NF] <= MAX_HD_TRY ) { int counter = dp_exams[DP_HD_NF]; dp_exams[DP_HD_NF] = dp_exams_test( DP_HD_NF, stud_level, stud_id, sem_year, sem_typ, counter); if ( dp_exams[DP_HD_NF] > MAX_HD_TRY ) { time_to_go = YES; } } // HD Diplom Arbeit if ( sem_count >= 8 && time_to_go == NO && dp_exams[DP_HD_INF_A] == YES_PASSED && dp_exams[DP_HD_INF_B] == YES_PASSED && dp_exams[DP_HD_ARBEIT] != YES_PASSED && dp_exams[DP_HD_ARBEIT] <= MAX_DIPL_TRY ) { int counter = dp_exams[DP_HD_ARBEIT]; dp_exams[DP_HD_ARBEIT] = dp_exams_thesis( DP_HD_ARBEIT, stud_level, stud_id, sem_year, sem_typ, counter); if ( (dp_exams[DP_HD_ARBEIT] > MAX_HD_TRY ) ) { time_to_go = YES; } } // Diplom erreicht? if ( dp_exams[DP_HD_DIPLOM] != YES_PASSED && dp_exams[DP_HD_INF_A] == YES_PASSED && dp_exams[DP_HD_INF_B] == YES_PASSED && dp_exams[DP_HD_INF_C] == YES_PASSED && dp_exams[DP_HD_NF] == YES_PASSED && dp_exams[DP_HD_ARBEIT] == YES_PASSED ) { dp_exams[DP_HD_DIPLOM] = YES_PASSED; qualies[Q_DIPLOM] = qualies_test(Q_DIPLOM, stud_level, stud_id, sem_year, sem_typ); time_to_go = YES; } } } } } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Generate all data for this student void generate_student(int stud_id) { int immat_year; immat_year = generate_personal_data(stud_id); generate_student_semester(stud_id, immat_year); } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Clean up the database void vacuum_database() { cout << "VACUUM ANALYZE pers_studenten;" << endl; cout << "VACUUM ANALYZE pers_adressen;" << endl; cout << "VACUUM ANALYZE uni_studium;" << endl; cout << "VACUUM ANALYZE uni_qualifikate;" << endl; } //---------------------------------------------------------------------- // ======================================================================= // Main program = // ======================================================================= int main(int argc, char* argv[]) { int no_of_students = 1; int start_number = 0; int min_id; int max_id; // Check command line arguments if ( argc == 3 ) { no_of_students = atol(argv[1]); if(no_of_students < 1) no_of_students = 1; start_number = atol(argv[2]); if(start_number < 0) start_number = 0; } else if ( argc == 2 ) { no_of_students = atol(argv[1]); if(no_of_students < 1) no_of_students = 1; start_number = 0; } else if (argc < 2) { cerr << "Aufruf: " << argv[0] << " [Anzahl]" << endl; cerr << "oder" << endl; cerr << "Aufruf: " << argv[0] << " [Anzahl Namen] [Startnummer]" << endl; return(1); } // Calculate the range in which students get generated min_id = MIN_STUD_ID + start_number; max_id = min_id + no_of_students; if (max_id > MAX_STUD_ID) { cerr << "Zuviele Studenten gewaehlt!" << endl; exit(1); } // Prepare program values load_all_lists(); Randomize(); // Remove old entries from the database begin_transaction(); if ( start_number == 0 ) { delete_student_data(); } else { delete_student_data(min_id, max_id); } commit_work(); // Generate students begin_transaction(); for (int i = min_id; i < max_id; i++) { generate_student( i ); } commit_work(); // Clean up the database vacuum_database(); }