Example #1
0
		TimePeriod span(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( isInvalid(tp1) || isInvalid(tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}

			return TimePeriod(std::min(tp1.begin(), tp2.begin()), std::max(tp1.end(), tp2.end()));
		}
Example #2
0
		TimePeriod intersection(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( !intersect(tp1, tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}

			return TimePeriod(std::max(tp1.begin(), tp2.begin()), std::min(tp1.end(), tp2.end()));
		}
Example #3
0
		TimePeriod merge(const TimePeriod& tp1, const TimePeriod& tp2)
		{
			if( isInvalid(tp1) || isInvalid(tp2) )
			{
				return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
			}
			else if( intersect(tp1, tp2) || (tp1.end() == tp2.begin()) || (tp1.begin() == tp2.begin()) )
			{
				return TimePeriod(std::min(tp1.begin(), tp2.begin()), std::max(tp1.end(), tp2.end()));
			}

			return TimePeriod(DateTime::getNADT(), DateTime::getNADT());
		}
Example #4
0
 static int select(int n, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const Nullable<TimePeriod>& timePeriod)
 {
     struct timeval  t;
     struct timeval* tPtr;
     
     if (timePeriod.isValid())
     {
         if (timePeriod.get() > Seconds(0)) {
             t = timePeriod.get().toTimeval();
         } else {
             t = TimePeriod(Seconds(0)).toTimeval();
         }
         tPtr = &t;
     } else {
         tPtr = NULL;
     }
     return ::select(n, readfds, writefds, exceptfds, tPtr);
 }
template <> ProfilVariable makeIV(const std::string& s, const float& a, const float& b) {
  ProfilVariable pv;
  pv.setString(s);
  pv.setValidRange(TimePeriod(a,b));
  return pv;
}
 void setValidRange(const TimePeriod& t) { validRange=TimePeriod(t.getStart(), t.getEnd()); }
Example #7
0
bool Contest::setupPrizes(void) {

#ifdef DEBUG
  stringstream debug;
#endif

	PrizeNames.push_back("Nothing");
  PrizeNames.push_back("Ringtones");
	PrizeNames.push_back("Obsolete");
	PrizeNames.push_back("Philips MP3 player");
	PrizeNames.push_back("Philips Home Cinema");
	PrizeNames.push_back("Peugeot 206 CC");

	size_t ind = 0;
	TimePeriod tp;
	giftDetails p;
	stringstream index;
	while (ind < EOD.size() -1) {
		tp = TimePeriod(EOD[ind], EOD[ind+1]);
		index << EOD[ind].toString(true) << ":" << giftDetails::ID_MINUTEPRIZES;
		p = giftDetails(giftDetails::ID_MINUTEPRIZES, PrizeNames[giftDetails::ID_MINUTEPRIZES], tp, MINUTEPRIZES, MINUTEPRIZES);
		Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
		debug << index.str() << ": ";
		debug << p.insertString() << endl;
	  logMsg(debug.str());
	  debug.str("");
#endif

/*    index.str("");
		index << current.toString(true) << ":" << giftDetails::ID_HOURLYPRIZES;
		p = giftDetails(giftDetails::ID_HOURLYPRIZES, PrizeNames[giftDetails::ID_HOURLYPRIZES], tp, HOURLYPRIZES, HOURLYPRIZES);
		Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
		debug << index.str() << ": ";
		debug << p.insertString() << endl;
	  logMsg(debug.str());
	  debug.str("");
#endif*/

    index.str("");
		index << EOD[ind].toString(true) << ":" << giftDetails::ID_DAILYPRIZES;
		p = giftDetails(giftDetails::ID_DAILYPRIZES, PrizeNames[giftDetails::ID_DAILYPRIZES], tp, DAILYPRIZES, DAILYPRIZES);
		Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
		debug << index.str() << ": ";
		debug << p.insertString() << endl;
	  logMsg(debug.str());
	  debug.str("");
#endif
		ind++;
	  index.str("");
	}

	ind = 0;
 	while (ind < EOW.size()-1) {
		tp = TimePeriod(EOW[ind], EOW[ind+1]);
		index << EOW[ind].toString(true) << ":" << giftDetails::ID_WEEKLYPRIZES;
		p = giftDetails(giftDetails::ID_WEEKLYPRIZES, PrizeNames[giftDetails::ID_WEEKLYPRIZES], tp, WEEKLYPRIZES, WEEKLYPRIZES);
		Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
		debug << index.str() << ": ";
		debug << p.insertString() << endl;
	  logMsg(debug.str());
	  debug.str("");
#endif
		ind++;
	  index.str("");
	}
  
	tp = TimePeriod(EOW[ind], EOC);
 	index << EOW[ind].toString(true) << ":" << giftDetails::ID_WEEKLYPRIZES;
 	p = giftDetails(giftDetails::ID_WEEKLYPRIZES, PrizeNames[giftDetails::ID_WEEKLYPRIZES], tp, WEEKLYPRIZES, WEEKLYPRIZES);
 	Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
  debug << index.str() << ": ";
  debug << p.insertString() << endl;
  logMsg(debug.str());
  debug.str("");
#endif
 	ind++;
  index.str("");

	ind = 0;
 	while (ind < EOM.size() -1) {
		tp = TimePeriod(EOM[ind], EOM[ind+1]);
		index << EOM[ind].toString(true) << ":" << giftDetails::ID_MONTHLYPRIZES;
		p = giftDetails(giftDetails::ID_MONTHLYPRIZES, PrizeNames[giftDetails::ID_MONTHLYPRIZES], tp, MONTHLYPRIZES, MONTHLYPRIZES);
		Prizes.insertObject(index.str(), p);
#ifdef EXTRADEBUG
		debug << index.str() << ": ";
		debug << p.insertString() << endl;
	  logMsg(debug.str());
	  debug.str("");
#endif
		ind++;
	  index.str("");
	}

#ifdef DEBUG
	debug.str("");
	string colname = "qty_rem";
	string iname = "gid";
	stringstream val;
  for (u_int i = giftDetails::ID_MINUTEPRIZES; i <= giftDetails::ID_MONTHLYPRIZES; i++) {
    val.str("");
    val << i;
   	debug << dec << "There are " << Prizes.sumColumn(val.str(), iname, colname)
	  			<< " " << PrizeNames[i] << " available" << endl;
  }
  logMsg(debug.str());
#endif

	return true;
}
Example #8
0
int Contest::handle_timeout(const ACE_Time_Value &tv,
																			const void *argument) {

	ACE_Guard<ACE_Thread_Mutex> guard(mutex_); {
    // Disable Transactions as we're about to write data to the DB
    if (dbconnection)
  	  dbconnection->disableTransactions();

		TimePeriod tp;
    int arg = (int)(argument);

#ifdef DEBUG
    stringstream debug;
    debug.str("");
#endif

		if (arg == ID_SOC) {
			logMsg("Contest::handle_timeout(): Start of Contest timer\n");
      init();
  	}
		
	 	if (arg == ID_EOC) {
 			logMsg("Contest::handle_timeout(): End of Contest timer\n");
 			preparetoShutdown();
	 	}

 		if ((arg == ID_EOD) || (arg == ID_EOW) || (arg == ID_EOM)) {
			logMsg("Contest::handle_timeout(): End of day timer\n");
			tp = TimePeriod(EOD[current_day], EOD[current_day+1]);
      current_day++;
 		}

	 	if (arg == ID_EOW) {
 			logMsg("Contest::handle_timeout(): End of week timer\n");
     	tp = TimePeriod(EOW[current_week], EOW[current_week+1]);
			current_week++;
 		}

	 	if (arg == ID_EOM) {
 			logMsg("Contest::handle_timeout(): End of month timer\n");
     	tp = TimePeriod(EOM[current_month], EOM[current_month+1]);
			current_month++;
		}

		if (arg != ID_SOC) {
			tp = TimePeriod(SOC, tp.getEndTS());
      if (tp.getEndTS().nextDay() >= time(0)) {
#ifdef EXTRADEBUG
        debug.str("");
        debug << "Contest::handle_timeout(): tp.getEndTS().nextDay() = " << tp.getEndTS().nextDay()
              << ", time(0) = " << time(0) << endl;
		    logMsg(debug.str());
#endif
      }
      dbconnection->changeLogFilename();
		}

    if (current_day < EOD.size()) {
			TimeStamp ts(EOD[current_day]);	
			// Create Day Object (the constructor writes to the DB)
#ifdef DEBUG
      debug.str("");
      debug << "Transactions enabled: " << boolalpha
            << dbconnection->transactionsEnabled() << endl;
      logMsg(debug.str());
#endif
			Day *newday = new Day(this, ts);
		  ContestDays.push_back(*newday);
#ifdef DEBUG
      debug.str("");
      debug << "Contest::handle_timeout(): ContestDays.size() = " << ContestDays.size() << endl;
      debug << "Waiting for today's traffic..." << endl;
		  logMsg(debug.str());
#endif 
  		delete newday;
    }
    // Enable Transactions again
    if (dbconnection)
      dbconnection->enableTransactions();
	}

  return 0;
}
Example #9
0
void ReqLogin::ChooseMode()
{
  TheResearchCalendar::Instance()->Clear();

  GameMode gm = AMJU_MODE_NO_GAME;
  bool doCogTests = false;

  PXml research = m_xml.getChildNode(5);
  if (SafeStrCmp(research.getName(), "research"))
  {
    // Schedule - for calendar
    PXml p = research.getChildNode(4);
    if (SafeStrCmp(p.getName(), "dates"))
    {
      Time today(Time::Now());
      today.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS));

      // Bunch of dates - add to TheResearchCal
      int numDates = p.nChildNode();
      for (int i = 0; i < numDates; i++)
      {
        PXml date = p.getChildNode(i);
        if (SafeStrCmp(date.getName(), "date"))
        {
          if (SafeStrCmp(date.getChildNode(0).getName(), "timestamp") &&
              SafeStrCmp(date.getChildNode(1).getName(), "cogtest") &&
              SafeStrCmp(date.getChildNode(2).getName(), "play"))
          {
            std::string dateStr = date.getChildNode(0).getText();
            bool cogtest = SafeStrCmp(date.getChildNode(1).getText(), "1"); 
            bool play = SafeStrCmp(date.getChildNode(2).getText(), "1"); 

            Time t(dateStr);
            t.RoundDown(TimePeriod(ONE_DAY_IN_SECONDS));
            if (t == today)
            {
              // Cog tests already done today ?
              Results results = TheCogTestResults::Instance()->GetResultsForDate(Time::Now());
              if (results.empty())
              {
                doCogTests = cogtest;
              }
              else
              {
                doCogTests = false;
                std::cout << "Test results for today are here already.\n";
              }

              if (play)
              { 
                gm = AMJU_MODE_MULTI;
              }
              if (doCogTests && !play)
              {
                // Create dummy target for heart count, etc
                CreateDummyLocalPlayer();
              }
            }
            TheResearchCalendar::Instance()->AddResearchDate(ResearchDate(Time(dateStr), cogtest, play));   
          }
          else
          {
            std::cout << "Login: unexpected format for session dates.\n";
            Assert(0);
          }
        }
      }
    }
    else
    {
      std::cout << "Login: found research element but no schedule.\n";
    }
  }
  else
  {
    std::cout << "No research element in login.pl response?!?\n";
    Assert(0);
  }

  // Now we can look up today on the calendar to get game mode flags.

  ResetLocalPlayerFuelCount();

  SetGameMode(gm); // TODO handle edit mode - send extra flag to login.pl ??

  SetDoCogTests(doCogTests); // mode, in GameMode

  TheGSCalendar::Instance()->SetPrevState(TheGSToday::Instance());
  TheGSThanks::Instance()->SetPrevState(TheGSToday::Instance());
  TheGame::Instance()->SetCurrentState(TheGSThanks::Instance());
  TheGSMain::Instance()->ResetHud();
}