示例#1
0
void Game::printTimeLeft(void) const
{
	struct timeval rem, total;
	total.tv_sec = 360;
	total.tv_usec = 0;

	timeRemaining(Player::Player1, &rem);
	std::cout << rem.tv_sec / 60  << ":" << rem.tv_sec % 60 << " - ";
	timeRemaining(Player::Player2, &rem);
	std::cout << rem.tv_sec / 60 << ":" << rem.tv_sec % 60 << std::endl;
	std::cout << std::endl;
}
示例#2
0
void RenderCanvas::OnTimerUpdate( wxTimerEvent& event )
{
   if(timer == NULL)
      return;
   
   //percent
   float completed = (float)pixelsRendered / (float)pixelsToRender;
      
   wxString progressString = wxString::Format(wxT("Rendering...%d%%"),
                                             (int)(completed*100));
   wxGetApp().SetStatusText( progressString , 0);
   
   //time elapsed
   long interval = timer->Time();
   
   wxTimeSpan timeElapsed(0, 0, 0, interval);
   
   //time remaining
   float remaining = 1.0f - completed;
   long msecRemain = (long)
                       (((double)interval / (completed*100)) * 100 * remaining);
   
   wxTimeSpan timeRemaining(0, 0, 0, msecRemain);
   
   wxString timeRemainString = timeRemaining.Format(wxT(" / ETA: %H:%M:%S"));
   wxString timeString = timeElapsed.Format(wxT("Elapsed Time: %H:%M:%S"));
   
   //only display ETA if something has been completed
   if(msecRemain >= 0)
      wxGetApp().SetStatusText( timeString + timeRemainString, 1);
   else
      wxGetApp().SetStatusText( timeString, 1);
}
unsigned Aggregate::displayChunks() const {
    fancyprint(activeChunks() << "/" << totalChunks(),NOTIFY);

    int j = m_chunk.size();
    for(auto i=0;i<m_chunk.size();i++){
        uintmax_t lower = std::atoi(m_chunk[i]->file()->filename().c_str());
        uintmax_t down= m_chunk[i]->txn()->range().lb()+m_chunk[i]->txn()->bytesDone();
        uintmax_t higher = m_chunk[i]->txn()->range().ub();
        std::string myColor;

        if(m_chunk[i]->txn()->isComplete())
            myColor = SUCCESS;
        else if(m_chunk[i]->txn()->hasFailed())
            myColor = ERROR;
        else if(m_chunk[i]->txn()->isDownloading())
            myColor = WARNING;
        else
            myColor = NOTIFY;

        fancyprint(lower << ":" << down << ":"<< higher<< " ",myColor);
    }

    std::cout << progressbar(progress(),COLOR(0,CC::WHITE,CC::PURPLE),COLOR(0,CC::PURPLE,CC::WHITE));
    print( " " << round(progress(),2) << "%\t"
            << formatTime(timeRemaining()) << "\t"
            << formatByte(speed()) << "ps\t");

    return j+1;
}
void REIXSXESScanController::onScanProgressCheck() {

	int secondsElapsed = startTime_.secsTo(QDateTime::currentDateTime());

	if(secondsElapsed > config_->maximumDurationSeconds()) {
		onScanFinished();
		return;
	}

	int totalCounts = int(REIXSBeamline::bl()->mcpDetector()->totalCounts());

	// Check if total counts is reached.
	// problem: What if this occurs before the detector is done clearing itself? could be spurious?  To solve this problem simply, just make sure we collect at least 5 seconds regardless of the total counts.
	if(secondsElapsed > 5 && totalCounts > config_->maximumTotalCounts()) {
		onScanFinished();
		return;
	}

	double timeProgress = double(secondsElapsed) / config_->maximumDurationSeconds();
	double countsProgress = double(totalCounts) / config_->maximumTotalCounts();

	// emit based on whichever looks more promising to happen first...
	if(countsProgress > timeProgress) {	// more likely to hit max counts first
		emit progress(totalCounts, config_->maximumTotalCounts());
		double timeLeft = (config_->maximumTotalCounts()-totalCounts) * (double(secondsElapsed)/totalCounts);
		emit timeRemaining(timeLeft);
	}
	else {
		emit progress(secondsElapsed, config_->maximumDurationSeconds());
		emit timeRemaining(config_->maximumDurationSeconds() - secondsElapsed);
	}


	// every 5 seconds, save the raw data to disk.
	/// \todo Make this a define adjustable
	if(secondsElapsed % 5 == 0) {
		saveRawData();
	}
}
示例#5
0
void ServerAllocation::print(std::ostream& os) const
{
    os << "ServerAllocation["
       << "\r\tTuple=" << _tuple << "\r\tUsername="******"\n\tBandwidth Limit=" << bandwidthLimit()
       << "\n\tBandwidth Used=" << bandwidthUsed()
       << "\n\tBandwidth Remaining=" << bandwidthRemaining()
       << "\n\tBase Time Remaining=" << IAllocation::timeRemaining()
       << "\n\tTime Remaining=" << timeRemaining()
       << "\n\tMax Time Remaining=" << maxTimeRemaining()
       << "\n\tDeletable=" << IAllocation::deleted()
       << "\n\tExpired=" << expired() << "]" << endl;
}
示例#6
0
int Spark_Prepare_For_Firmware_Update(FileTransfer::Descriptor& file, uint32_t flags, void* reserved)
{
    if (file.store==FileTransfer::Store::FIRMWARE)
    {
        // address is relative to the OTA region. Normally will be 0.
        file.file_address = HAL_OTA_FlashAddress() + file.chunk_address;

        // chunk_size 0 indicates defaults.
        if (file.chunk_size==0) {
            file.chunk_size = HAL_OTA_ChunkSize();
            file.file_length = HAL_OTA_FlashLength();
        }
    }
    int result = 0;
    if (flags & 1) {
        // only check address
    }
    else {
        uint32_t start = HAL_Timer_Milliseconds();
        system_set_flag(SYSTEM_FLAG_OTA_UPDATE_PENDING, 1, nullptr);

        volatile bool flag = false;
        system_notify_event(firmware_update_pending, 0, nullptr, set_flag, (void*)&flag);

        System.waitCondition([&flag]{return flag;}, timeRemaining(start, 30000));

        system_set_flag(SYSTEM_FLAG_OTA_UPDATE_PENDING, 0, nullptr);
        	if (System.updatesEnabled())		// application event is handled asynchronously
        {
            RGB.control(true);
            RGB.color(RGB_COLOR_MAGENTA);
            SPARK_FLASH_UPDATE = 1;
            TimingFlashUpdateTimeout = 0;
            system_notify_event(firmware_update, firmware_update_begin, &file);
            HAL_FLASH_Begin(file.file_address, file.file_length, NULL);
        }
        else
        {
            result = 1;     // updates disabled
        }
    }
    return result;
}
示例#7
0
bool Game::movePlayer(Player::Who who, bool subtract_time)
{
	struct timeval tv_start, tv_end, tv_elapsed, tv_rem;
	std::string *str;
	Move mv;

	timeRemaining(who, &tv_rem);

	// Print board
	str = m_board->toString();
	std::cout << *str << "\n";
	delete str;

	// Perform move
	gettimeofday(&tv_start, 0);
	mv = m_players[ndxFromPlayer(who)]->move(m_board, &tv_rem, 0);

	std::cout << (char)('A'+mv.from().x()) << 6 - mv.from().y() << '-';
	std::cout << (char)('A'+mv.to().x()) << 6 - mv.to().y() << std::endl;

	if(!mv.isValid())
		return false;

	m_board->move(mv);

	gettimeofday(&tv_end, 0);

	// Update players time
	if(subtract_time)
	{
		timersub(&tv_end, &tv_start, &tv_elapsed);
		timeradd(&m_expiredTime[ndxFromPlayer(who)], &tv_elapsed, &m_expiredTime[ndxFromPlayer(who)]);
	}

	printTimeLeft();

	return mv.isValid();
}
示例#8
0
bool IAllocation::expired() const
{
    return timeRemaining() == 0
        || bandwidthRemaining() == 0;
}
示例#9
0
文件: rf.cpp 项目: afrozm/projects
int _tmain(int argc, _TCHAR* argv[])
{
	if (argc < 3) {
		_tprintf(_T("Usage: rf <source file/disk path> <desnitantion folder/file>\nFor disk use \\\\.\\H: as source path"));
		return -1;
	}
	HANDLE hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE) {
		UINT64 currentDone(0), totalSize(0);
		LARGE_INTEGER fileSize = {0};
		GetFileSizeEx(hFile, &fileSize);
		totalSize = fileSize.QuadPart;
		if (totalSize == 0) { // Disk Path
			ULARGE_INTEGER li = {0};
			GetDiskFreeSpaceEx(argv[1]+4, NULL, &li, NULL);
			totalSize = li.QuadPart;
		}
		Progress progress;
		progress.SetTask(totalSize);
		ConsoleProgress cp;
		Path dstPath(argv[2]);
		auto updateWSTime = ProcessUtil::GetTickCount(); // Update Writing speed time
		lprintf(_T("\nTime Elapsed: "));
		CountTimer timeElapsed;
		lprintf(_T("\t\t\t\tTime Remaining: "));
		CountTimer timeRemaining(true);
		if (dstPath.IsDir()) {
            CRecoverManager recoverManger;
            recoverManger.SetInputFileHandle(hFile);
            recoverManger.SetSavePath(dstPath);
            recoverManger.SetTotal(totalSize);
            recoverManger.Initialize();
            recoverManger.BeginRecover();
			while (recoverManger.ProcessRecover()) {
                currentDone = recoverManger.GetCurrentDone();
				if (progress.UpdateProgress(currentDone))
					cp.ShowPercentage(progress.GetCurrentPercentageDone());
				auto curTime = ProcessUtil::GetTickCount();
				if (curTime - updateWSTime >= 5000) { // 5 secs passed
					timeRemaining.SetTimeDuration((timeElapsed.GetTimeDuration() * totalSize) / currentDone);
					updateWSTime = curTime;
				}
				timeElapsed.PrintTimeDuration();
				timeRemaining.PrintTimeDuration();
			}
            if (progress.UpdateProgress(currentDone))
                cp.ShowPercentage(progress.GetCurrentPercentageDone());
            recoverManger.EndRecover();
            progress.UpdateProgress(totalSize);
            cp.ShowPercentage(progress.GetCurrentPercentageDone());
        }
		else {
			CFileMapping fileDstMap;
			CFileMapping fileSrcMap;
			//fileSrcMap.GetFileMapping(hFile);
			fileSrcMap.SetFileHandle(hFile);
			//HANDLE hDestFile = CreateFile(argv[2], GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
			//if (hDestFile != INVALID_HANDLE_VALUE) {
			//	fileDstMap.SetFileHandle(hDestFile);
			if (fileDstMap.GetFileMapping(argv[2], totalSize) != NULL) {
				std::vector<char> buffer;
				buffer.resize(1024*1024);
				size_t size = buffer.size();
				char *buf = &buffer[0];
				while (currentDone < totalSize) {
					DWORD nBytesRead(fileSrcMap.Read(buf, (UINT)size));
					if (nBytesRead > 0) {
						fileDstMap.Write(buf, nBytesRead);
						currentDone += nBytesRead;
						if (progress.UpdateProgress(currentDone))
							cp.ShowPercentage(progress.GetCurrentPercentageDone());
						auto curTime = ProcessUtil::GetTickCount();
						if (curTime - updateWSTime >= 5000) { // 5 secs passed
							double p = progress.GetCurrentPercentageDone();
							if (p < 0.01)
								p = 0.01;
							timeRemaining.SetTimeDuration(__int64((timeElapsed.GetTimeDuration() * (100-p)) / p));
							updateWSTime = curTime;
						}
						timeElapsed.PrintTimeDuration();
						timeRemaining.PrintTimeDuration();
					}
					else break;
				}
				//CloseHandle(hDestFile);
			}
			else _tprintf(_T("Cannot open file: '%s'\nError: %d"), argv[2], GetLastError());
		}
		CloseHandle(hFile);
	}
    else {
        bool bError(true);
        if (GetLastError() == ERROR_ACCESS_DENIED)
            bError = !ProcessUtil::RunApplication(argc, (LPCTSTR*)argv, RAF_ADMIN);
        if (bError)
            _tprintf(_T("Cannot open file: '%s'\nError: %d"), argv[1], GetLastError());
    }
	return 0;
}
示例#10
0
time_t ProgressBar::endTime() {
  time_t currentTime;
  time(&currentTime);
  time_t estEndTime = currentTime + timeRemaining();
  return estEndTime;
}