Logo Search packages:      
Sourcecode: pcalendar version File versions  Download package

void net::sf::linuxorg::pcal::engine::Engine::recalculate (  ) [inline, private]

This function is called each time the statistics needs to be recalculated

Definition at line 1198 of file Engine.java.

References avgLength, dateDiff(), dateTypes, and periodsCount.

Referenced by importFromFile(), loadFromFile(), and setEnginePreferences().

      {
            // at this point we have the sorted starting dates list
            periodsCount = 0;
            avgLength = 0;
            minLength = 0;
            maxLength = 0;
            int sumLength = 0;
            recordedOvulations = 0;
            minOvulationDayNum = 0;
            maxOvulationDayNum = 0;
            calMethodAccuracy = 3;
            if(startDates.size()<2) {
                  // there are no even a single period
                  return;
            }

            Date prevdate = null;

            // we need to calculate the average, min and max period length
            for(Date pstart: startDates)
            {
                  if(prevdate == null) { 
                        prevdate = pstart;
                        continue;
                  }
                  int pDateType = dateTypes.get(pstart);
                  int prevDateType = dateTypes.get(prevdate); 

                  if(pDateType == PCAL_TYPE_OVULATION) {
                        if(prevDateType == PCAL_TYPE_MENS) {
                              int ovulDayNumber = dateDiff(prevdate, pstart);
                              if(ovulDayNumber < enginePreferences.regularMaxLength) {
                                    if(ovulDayNumber > maxOvulationDayNum) maxOvulationDayNum = ovulDayNumber;
                                    if((ovulDayNumber < minOvulationDayNum)||
                                                (minOvulationDayNum == 0)) minOvulationDayNum = ovulDayNumber;
                                    recordedOvulations++;
                              }
                        }
                        // keep prev date the same jump to the next date
                        continue;
                  }

                  // skip the non-menstruation neighbor records
                  if((pDateType != PCAL_TYPE_MENS)||
                              (prevDateType != PCAL_TYPE_MENS)) {
                        prevdate = pstart;
                        continue;
                  }
                  // pstart and pend points to starting and ending date of the period
                  int p_length = dateDiff(prevdate, pstart);

                  if((p_length < enginePreferences.regularMinLength) ||
                              (p_length > enginePreferences.regularMaxLength)) {
                        // bad period should not be taken into account

                  } else {
                        periodsCount++;
                        if(p_length>maxLength) maxLength = p_length;
                        if((p_length<minLength) || minLength == 0) minLength = p_length;
                        sumLength+=p_length;        
                  }
                  prevdate = pstart;
            }
            if(periodsCount>0) avgLength = Math.round(sumLength/periodsCount);

            // calendar method accuracy depends on the medium period length,
            // the difference between the longest and the shortest periodsCount
            // and the number of the recorded periods
            // 0 - high, 1 - moderate, 2 - low
            // for the high accuracy the conditions are almost unreal
            if((periodsCount>RELIABLE_PERIODS_COUNT) &&
                        (avgLength>RELIABLE_MIN_AVG_LENGTH) &&
                        (avgLength<RELIABLE_MAX_AVG_LENGTH) &&
                        ((maxLength - minLength)<RELIABLE_LENGTH_DIFF) &&
                        (recordedOvulations > 12))
                  calMethodAccuracy = 0;
            else
                  if((periodsCount<RELIABLE_PERIODS_COUNT) ||
                              ((maxLength - minLength)>UNRELIABLE_LENGTH_DIFF) ||
                              ((avgLength<UNRELIABLE_MIN_AVG_LENGTH) &&
                                          (avgLength>UNRELIABLE_MAX_AVG_LENGTH))) 
                        calMethodAccuracy = 2;
                  else 
                        calMethodAccuracy = 1;
      }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index