Back to index

fet  5.18.0
activitiesroomsstatisticsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           activitiesroomsstatisticform.cpp  -  description
00003                              -------------------
00004     begin                : October 6, 2011
00005     copyright            : (C) 2011 by Lalescu Liviu
00006     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "activitiesroomsstatisticsform.h"
00019 
00020 #include "timetable_defs.h"
00021 #include "timetable.h"
00022 
00023 #include "fet.h"
00024 
00025 #include <QString>
00026 #include <QStringList>
00027 
00028 #include <QSet>
00029 #include <QList>
00030 #include <QStringList>
00031 
00032 ActivitiesRoomsStatisticsForm::ActivitiesRoomsStatisticsForm(QWidget* parent): QDialog(parent)
00033 {
00034        setupUi(this);
00035        
00036        closeButton->setDefault(true);
00037 
00038        connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00039        
00040        centerWidgetOnScreen(this);
00041        restoreFETDialogGeometry(this);
00042 
00043        possiblyPlainTextEdit->setReadOnly(true);
00044        certainlyPlainTextEdit->setReadOnly(true);
00045        
00046        QSet<int> activitiesWith100;
00047        QSet<int> activitiesWithUnder100;
00048        
00049        foreach(Activity* act, gt.rules.activitiesList){
00050               if(!act->active)
00051                      continue;
00052        
00053               QSet<QString> currentActivityTagsSet=act->activityTagsNames.toSet();
00054        
00055               foreach(SpaceConstraint* genericConstraint, gt.rules.spaceConstraintsList){
00056                      if(genericConstraint->type==CONSTRAINT_STUDENTS_SET_HOME_ROOM){
00057                             ConstraintStudentsSetHomeRoom* ctr=(ConstraintStudentsSetHomeRoom*)genericConstraint;
00058                             
00059                             if(act->studentsNames.count()==1){
00060                                    if(act->studentsNames.at(0)==ctr->studentsName){
00061                                           if(ctr->weightPercentage==100.0){
00062                                                  if(!activitiesWith100.contains(act->id)){
00063                                                         activitiesWith100.insert(act->id);
00064                                                  }
00065                                           }
00066                                           else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00067                                                  if(!activitiesWithUnder100.contains(act->id)){
00068                                                         activitiesWithUnder100.insert(act->id);
00069                                                  }
00070                                           }
00071                                    }
00072                             }
00073                      }
00074 
00075                      else if(genericConstraint->type==CONSTRAINT_STUDENTS_SET_HOME_ROOMS){
00076                             ConstraintStudentsSetHomeRooms* ctr=(ConstraintStudentsSetHomeRooms*)genericConstraint;
00077                             
00078                             if(act->studentsNames.count()==1){
00079                                    if(act->studentsNames.at(0)==ctr->studentsName){
00080                                           if(ctr->weightPercentage==100.0){
00081                                                  if(!activitiesWith100.contains(act->id)){
00082                                                         activitiesWith100.insert(act->id);
00083                                                  }
00084                                           }
00085                                           else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00086                                                  if(!activitiesWithUnder100.contains(act->id)){
00087                                                         activitiesWithUnder100.insert(act->id);
00088                                                  }
00089                                           }
00090                                    }
00091                             }
00092                      }
00093 
00094                      else if(genericConstraint->type==CONSTRAINT_TEACHER_HOME_ROOM){
00095                             ConstraintTeacherHomeRoom* ctr=(ConstraintTeacherHomeRoom*)genericConstraint;
00096                             
00097                             if(act->teachersNames.count()==1){
00098                                    if(act->teachersNames.at(0)==ctr->teacherName){
00099                                           if(ctr->weightPercentage==100.0){
00100                                                  if(!activitiesWith100.contains(act->id)){
00101                                                         activitiesWith100.insert(act->id);
00102                                                  }
00103                                           }
00104                                           else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00105                                                  if(!activitiesWithUnder100.contains(act->id)){
00106                                                         activitiesWithUnder100.insert(act->id);
00107                                                  }
00108                                           }
00109                                    }
00110                             }
00111                      }
00112 
00113                      else if(genericConstraint->type==CONSTRAINT_TEACHER_HOME_ROOMS){
00114                             ConstraintTeacherHomeRooms* ctr=(ConstraintTeacherHomeRooms*)genericConstraint;
00115                             
00116                             if(act->teachersNames.count()==1){
00117                                    if(act->teachersNames.at(0)==ctr->teacherName){
00118                                           if(ctr->weightPercentage==100.0){
00119                                                  if(!activitiesWith100.contains(act->id)){
00120                                                         activitiesWith100.insert(act->id);
00121                                                  }
00122                                           }
00123                                           else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00124                                                  if(!activitiesWithUnder100.contains(act->id)){
00125                                                         activitiesWithUnder100.insert(act->id);
00126                                                  }
00127                                           }
00128                                    }
00129                             }
00130                      }
00131 
00132                      else if(genericConstraint->type==CONSTRAINT_SUBJECT_PREFERRED_ROOM){
00133                             ConstraintSubjectPreferredRoom* ctr=(ConstraintSubjectPreferredRoom*)genericConstraint;
00134                             
00135                             if(act->subjectName==ctr->subjectName){
00136                                    if(ctr->weightPercentage==100.0){
00137                                           if(!activitiesWith100.contains(act->id)){
00138                                                  activitiesWith100.insert(act->id);
00139                                           }
00140                                    }
00141                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00142                                           if(!activitiesWithUnder100.contains(act->id)){
00143                                                  activitiesWithUnder100.insert(act->id);
00144                                           }
00145                                    }
00146                             }
00147                      }
00148 
00149                      else if(genericConstraint->type==CONSTRAINT_SUBJECT_PREFERRED_ROOMS){
00150                             ConstraintSubjectPreferredRooms* ctr=(ConstraintSubjectPreferredRooms*)genericConstraint;
00151                             
00152                             if(act->subjectName==ctr->subjectName){
00153                                    if(ctr->weightPercentage==100.0){
00154                                           if(!activitiesWith100.contains(act->id)){
00155                                                  activitiesWith100.insert(act->id);
00156                                           }
00157                                    }
00158                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00159                                           if(!activitiesWithUnder100.contains(act->id)){
00160                                                  activitiesWithUnder100.insert(act->id);
00161                                           }
00162                                    }
00163                             }
00164                      }
00165 
00166                      else if(genericConstraint->type==CONSTRAINT_SUBJECT_ACTIVITY_TAG_PREFERRED_ROOM){
00167                             ConstraintSubjectActivityTagPreferredRoom* ctr=(ConstraintSubjectActivityTagPreferredRoom*)genericConstraint;
00168                             
00169                             if(act->subjectName==ctr->subjectName && currentActivityTagsSet.contains(ctr->activityTagName)){
00170                                    if(ctr->weightPercentage==100.0){
00171                                           if(!activitiesWith100.contains(act->id)){
00172                                                  activitiesWith100.insert(act->id);
00173                                           }
00174                                    }
00175                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00176                                           if(!activitiesWithUnder100.contains(act->id)){
00177                                                  activitiesWithUnder100.insert(act->id);
00178                                           }
00179                                    }
00180                             }
00181                      }
00182 
00183                      else if(genericConstraint->type==CONSTRAINT_SUBJECT_ACTIVITY_TAG_PREFERRED_ROOMS){
00184                             ConstraintSubjectActivityTagPreferredRooms* ctr=(ConstraintSubjectActivityTagPreferredRooms*)genericConstraint;
00185                             
00186                             if(act->subjectName==ctr->subjectName && currentActivityTagsSet.contains(ctr->activityTagName)){
00187                                    if(ctr->weightPercentage==100.0){
00188                                           if(!activitiesWith100.contains(act->id)){
00189                                                  activitiesWith100.insert(act->id);
00190                                           }
00191                                    }
00192                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00193                                           if(!activitiesWithUnder100.contains(act->id)){
00194                                                  activitiesWithUnder100.insert(act->id);
00195                                           }
00196                                    }
00197                             }
00198                      }
00199 
00200                      else if(genericConstraint->type==CONSTRAINT_ACTIVITY_TAG_PREFERRED_ROOM){
00201                             ConstraintActivityTagPreferredRoom* ctr=(ConstraintActivityTagPreferredRoom*)genericConstraint;
00202                             
00203                             if(currentActivityTagsSet.contains(ctr->activityTagName)){
00204                                    if(ctr->weightPercentage==100.0){
00205                                           if(!activitiesWith100.contains(act->id)){
00206                                                  activitiesWith100.insert(act->id);
00207                                           }
00208                                    }
00209                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00210                                           if(!activitiesWithUnder100.contains(act->id)){
00211                                                  activitiesWithUnder100.insert(act->id);
00212                                           }
00213                                    }
00214                             }
00215                      }
00216 
00217                      else if(genericConstraint->type==CONSTRAINT_ACTIVITY_TAG_PREFERRED_ROOMS){
00218                             ConstraintActivityTagPreferredRooms* ctr=(ConstraintActivityTagPreferredRooms*)genericConstraint;
00219                             
00220                             if(currentActivityTagsSet.contains(ctr->activityTagName)){
00221                                    if(ctr->weightPercentage==100.0){
00222                                           if(!activitiesWith100.contains(act->id)){
00223                                                  activitiesWith100.insert(act->id);
00224                                           }
00225                                    }
00226                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00227                                           if(!activitiesWithUnder100.contains(act->id)){
00228                                                  activitiesWithUnder100.insert(act->id);
00229                                           }
00230                                    }
00231                             }
00232                      }
00233 
00234                      else if(genericConstraint->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
00235                             ConstraintActivityPreferredRoom* ctr=(ConstraintActivityPreferredRoom*)genericConstraint;
00236                             
00237                             if(act->id==ctr->activityId){
00238                                    if(ctr->weightPercentage==100.0){
00239                                           if(!activitiesWith100.contains(act->id)){
00240                                                  activitiesWith100.insert(act->id);
00241                                           }
00242                                    }
00243                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00244                                           if(!activitiesWithUnder100.contains(act->id)){
00245                                                  activitiesWithUnder100.insert(act->id);
00246                                           }
00247                                    }
00248                             }
00249                      }
00250 
00251                      else if(genericConstraint->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOMS){
00252                             ConstraintActivityPreferredRooms* ctr=(ConstraintActivityPreferredRooms*)genericConstraint;
00253                             
00254                             if(act->id==ctr->activityId){
00255                                    if(ctr->weightPercentage==100.0){
00256                                           if(!activitiesWith100.contains(act->id)){
00257                                                  activitiesWith100.insert(act->id);
00258                                           }
00259                                    }
00260                                    else if(ctr->weightPercentage>=0.0 && ctr->weightPercentage<100.0){
00261                                           if(!activitiesWithUnder100.contains(act->id)){
00262                                                  activitiesWithUnder100.insert(act->id);
00263                                           }
00264                                    }
00265                             }
00266                      }
00267               }
00268        }
00269        
00270        activitiesWithUnder100.subtract(activitiesWith100);
00271        
00272        QList<int> certainlyWithUnspecifiedRoom;
00273        QList<int> possiblyWithUnspecifiedRoom;
00274        
00275        foreach(Activity* act, gt.rules.activitiesList){
00276               if(!act->active)
00277                      continue;
00278 
00279               if(!activitiesWith100.contains(act->id)){
00280                      if(activitiesWithUnder100.contains(act->id)){
00281                             possiblyWithUnspecifiedRoom.append(act->id);
00282                      }
00283                      else{
00284                             certainlyWithUnspecifiedRoom.append(act->id);
00285                      }
00286               }
00287        }
00288        
00289        QString strPossiblyWithoutRoom;
00290        if(possiblyWithUnspecifiedRoom.count()>0){
00291               strPossiblyWithoutRoom=tr("You have %1 activities which might end up in an unspecified room"
00292                " (not considering those which will certainly end up in an unspecified room). They are listed below:",
00293                "Instructions for translators: take care, it is 'might', so it is only a possibility.")
00294                .arg(possiblyWithUnspecifiedRoom.count());
00295               strPossiblyWithoutRoom+=QString("\n\n");
00296               
00297               for(int i=0; i<possiblyWithUnspecifiedRoom.count(); i++){
00298                      int id=possiblyWithUnspecifiedRoom.at(i);
00299                      strPossiblyWithoutRoom+=tr("No: %1, Id: %2 (%3)", "%1 is the current number, %2 is the activity id, %3 is the detailed activity description")
00300                       .arg(i+1).arg(id).arg(getActivityDetailedDescription(gt.rules, id));
00301                      strPossiblyWithoutRoom+=QString("\n");
00302               }
00303        }
00304        else{
00305               strPossiblyWithoutRoom=tr("You do not have activities which might end up in an unspecified room"
00306               " (not considering those which will certainly end up in an unspecified room).",
00307                "Instructions for translators: take care, it is 'might', so it is only a possibility.");
00308               strPossiblyWithoutRoom+=QString("\n");
00309        }
00310 
00311        QString strCertainlyWithoutRoom;
00312        if(certainlyWithUnspecifiedRoom.count()>0){
00313               strCertainlyWithoutRoom=tr("You have %1 activities which will certainly end up in an unspecified room. They are listed below:",
00314                "Instructions for translators: take care, it is 'certainly'.")
00315                .arg(certainlyWithUnspecifiedRoom.count());
00316               strCertainlyWithoutRoom+=QString("\n\n");
00317               
00318               for(int i=0; i<certainlyWithUnspecifiedRoom.count(); i++){
00319                      int id=certainlyWithUnspecifiedRoom.at(i);
00320                      strCertainlyWithoutRoom+=tr("No: %1, Id: %2 (%3)", "%1 is the current number, %2 is the activity id, %3 is the detailed activity description")
00321                       .arg(i+1).arg(id).arg(getActivityDetailedDescription(gt.rules, id));
00322                      strCertainlyWithoutRoom+=QString("\n");
00323               }
00324        }
00325        else{
00326               strCertainlyWithoutRoom=tr("You do not have activities which will certainly end up in an unspecified room.",
00327                "Instructions for translators: take care, it is 'certainly'.");
00328               strCertainlyWithoutRoom+=QString("\n");
00329        }
00330        
00331        possiblyPlainTextEdit->setPlainText(strPossiblyWithoutRoom);
00332        certainlyPlainTextEdit->setPlainText(strCertainlyWithoutRoom);
00333 }
00334 
00335 ActivitiesRoomsStatisticsForm::~ActivitiesRoomsStatisticsForm()
00336 {
00337        saveFETDialogGeometry(this);
00338 }