Esempio n. 1
0
File: typer.c Progetto: mmr/b1n
void
printSentence( char *string, int error_possibility )
{
    int i = 0;
    char aux  = 0;
    int tmp; 

    if(error_possibility == 0)
    {
        error_possibility = 100;
    }

    srandom((unsigned int) ((long) time((time_t *) 0) ^ getpid()));

    /* coloca em verde e imprime _ intermitente */
    clearScreen();
    printTerminal( TERM_CHAR, TERM_COLOR, TEXT_COLOR );
    while( string[i] != '\0' )
    {
        /* BackSpace pra apagar o _ intermitente */
        printChar( '\b' );

        /* Vendo se Errou */
        tmp = 0;
        tmp = random();
        if( tmp %  error_possibility == 0 )
        {
            /*
                Se Errou, pegar um char randomico entre 'a' (97) e 'z' 122
                122 - 97 = 25
            */

            aux = (((int)random()%25)+97);

            /*
                Se a tecla pega, miseravelmente, foi a esperada, nao fazer nada.
                Se nao for, imprimir a errada, esperar um pouco e apagar a errada (\b)
            */
            if(aux != string[i])
            {
                printChar( aux );
                usleep(((int)random() % DELAY_ERROR));
                printChar( '\b' );
            }
        }
        usleep(random() % DELAY_RIGHT);
        printChar( string[i] );
        printTerminal( TERM_CHAR, TERM_COLOR, TEXT_COLOR );
        i++;
    }
    usleep( DELAY_FINAL );
    printTerminal(' ', "0", "0");
    clearScreen();
}
Esempio n. 2
0
void printGeneral(parseTree curNode, FILE* fp)
{
    if(curNode->tk->sym < nNonTerminals)
        printNonTerminal(curNode, fp);
    else if(curNode->tk->sym == NUM || curNode->tk->sym == RNUM )
        printNumber(curNode, fp);
    else
        printTerminal(curNode, fp);
}
Esempio n. 3
0
void ViNoiseBatcher::process()
{
	QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process()));

	qint64 time;

	ViNoiseCreator creator;
	creator.createNoise(mCurrentObject->buffer(ViAudio::Target), mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::CustomMask), mCurrentObject->buffer(ViAudio::Custom));
	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::CustomMask);

	ViClassificationErrorCollection errors;

	//do
	//{
		mCurrentObject->clearBuffer(ViAudio::Noise);

		for(int i = 0; i < mParamsStart.size(); ++i) mDetector->setParameter(mParamsNames[i], mParamsCurrent[i]);

		if(mDetector->validParameters())
		{
			mTime.restart();
			mDetector->detect(mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::Noise));
			time = mTime.elapsed();

			errors = mDetector->error(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), mThreshold);

			// Write
		/*	QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
			mCurrentObject->encode(ViAudio::Noise);
			return;*/

			/*calculateThreshold(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), bestThreshold, bestErrors, bestMatthews, maxNoise);
			if(bestMatthews > maxMatthews) maxMatthews = bestMatthews;
			clearProgress();*/

			// Write
			/*mDetector->mask(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::NoiseMask), 0.15, 8);
			QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
			mCurrentObject->encode(ViAudio::NoiseMask);
			return;*/
		}
		else
		{
			time = 0;
		}

		++mDoneParamIterations;
		printFileData(errors, time);
		printTerminal(errors, time);
	//}
	//while(nextParam());

	nextFile();
}
Esempio n. 4
0
void swapTTY(int num)
{
	if(currentTTY!=num)
	{
		memcpy(auxv, VID_DIR, 160*24);
		memcpy(VID_DIR, terminals[num].video, 160*24);
		memcpy(terminals[num].video, auxv, 160*24);
		terminals[currentTTY].video=terminals[num].video;
		terminals[num].video=VID_DIR;
		currentTTY=num;
		update_cursor(&terminals[currentTTY]);
		printTerminal();
	}
}
Esempio n. 5
0
void SystemLog_Printf(BOOL hasPrompt, BYTE tagTrace, const char * format, ...){

    char buffer[SYSTEM_LOG_PRINT_MAX_BUFFER_SIZE];
    va_list argptr;

    if(!(tagTrace & systemLogTrace))
        return;
    
    va_start(argptr, format);
    vsprintf(buffer, format, argptr);
    va_end(argptr);

    printTerminal(buffer, hasPrompt);
}
Esempio n. 6
0
void printBar()
{
	char* vidmem=VID_DIR;
	int i=80*24*2;
	while(i < (80*25*2))
	{
		vidmem[i]=' ';
		i++;
		vidmem[i]=BLACK_TXT;
		i++;
	};
	printScancode();
	printTerminal();
	printTime();
}
Esempio n. 7
0
void ViStatistician::process()
{
	QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process()));

	ViAudioReadData data(mCurrentObject->buffer(ViAudio::Target));
	data.setSampleCount(mWindowSize);
	qreal value = 0;
	qint64 count = 0;

	qreal top = 0, bottom1 = 0, bottom2 = 0;
	qreal valuePos = 0, valueNeg = 0;
	int countPos = 0, countNeg = 0;

	while(data.hasData())
	{
		data.read();
		ViSampleChunk &samples1 = data.splitSamples(0);
		ViSampleChunk &samples2 = data.splitSamples(1);

		if(mMode == Mean)
		{
			value += mean(samples1);
			value += mean(samples2);
			count += 2;
		}
		else if(mMode == StandardDeviation)
		{
			value += standardDeviation(samples1);
			value +standardDeviation(samples2);
			count += 2;
		}
		else if(mMode == Pearson)
		{
			qreal theTopA = 0, theBottom1A = 0, theBottom2A = 0;
			qreal theTopB = 0, theBottom1B = 0, theBottom2B = 0;

			qreal value1 = pearson(samples1, theTopA, theBottom1A, theBottom2A);
			qreal value2 = pearson(samples2, theTopB, theBottom1B, theBottom2B);
			/*if(value1 != 0)
			{
				top += theTopA;
				bottom1 += theBottom1A;
				bottom2 += theBottom2A;
			}
			if(value2 != 0)
			{
				top += theTopB;
				bottom1 += theBottom1B;
				bottom2 += theBottom2B;
			}*/
			if(value1 > 0)
			{
				valuePos += value1;
				++countPos;
			}
			else if(value1 < 0)
			{
				valueNeg += value1;
				++countNeg;
			}
			if(value2 > 0)
			{
				valuePos += value2;
				++countPos;
			}
			else if(value2 < 0)
			{
				valueNeg += value2;
				++countNeg;
			}
		}
	}

	if(mMode == Pearson)
	{
		/*value = top / (qSqrt(bottom1) * qSqrt(bottom2));
		mValue += value;
		mCount += 1;

		printFileData(value);
		printTerminal(value);*/


		mValuePos += valuePos;
		mCountPos += countPos;
		mValueNeg += valueNeg;
		mCountNeg += countNeg;

		valuePos /= countPos;
		valueNeg /= countNeg;

		printFileDataPearson(valuePos, valueNeg);
		printTerminalPearson(valuePos, valueNeg);
	}
	else
	{
		mValue += value;
		mCount += count;
		value /= count;
		printFileData(value);
		printTerminal(value);
	}

	nextFile();
}
Esempio n. 8
0
void ViBenchMarker3::process2()
{
	int time = mTime.elapsed();
	QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2()));

	/*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
	mCurrentObject->encode(ViAudio::Noise);
	return;*/

	qreal maxMAT = 0;
	qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0;
	qint64 i, lengthIndex, offset1 = 0, offset2 = 0;
	int noChange = 0;

	ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise));
	ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask));
	ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom));
	corrupted.setSampleCount(WINDOW_SIZE);
	realMask.setSampleCount(WINDOW_SIZE);
	length.setSampleCount(WINDOW_SIZE);

	ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2);

	while(corrupted.hasData() && realMask.hasData())
	{
		corrupted.read();
		ViSampleChunk &corrupted1 = corrupted.splitSamples(0);
		ViSampleChunk &corrupted2 = corrupted.splitSamples(1);

		realMask.read();
		ViSampleChunk &realMask1 = realMask.splitSamples(0);
		ViSampleChunk &realMask2 = realMask.splitSamples(1);

		length.read();
		ViSampleChunk &length1 = length.splitSamples(0);
		ViSampleChunk &length2 = length.splitSamples(1);

		for(i = 0; i < corrupted1.size(); ++i)
		{
			(*nData1)[i + offset1] = corrupted1[i];
			(*nRealMask1)[i + offset1] = realMask1[i];
			(*nLength1)[i + offset1] = length1[i];
		}
		offset1 += corrupted1.size();
		for(i = 0; i < corrupted2.size(); ++i)
		{
			(*nData2)[i + offset2] = corrupted2[i];
			(*nRealMask2)[i + offset2] = realMask2[i];
			(*nLength2)[i + offset2] = length2[i];
		}
		offset2 += corrupted2.size();
	}

	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::Noise);
	mCurrentObject->clearBuffer(ViAudio::NoiseMask);

	ViNoise noise1(nData1, nMask1, mCurrentThreshold);
	ViNoise noise2(nData2, nMask2, mCurrentThreshold);

	QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount());
	QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount());
	lengthTP.fill(0);
	lengthFN.fill(0);
	QVector<qreal> maxLengthTP, maxLengthFN;

	for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL)
	{
		noise1.setThreshold(mCurrentThreshold);
		noise1.generateMask(ViNoise::NOISE_TYPE);
		noise2.setThreshold(mCurrentThreshold);
		noise2.generateMask(ViNoise::NOISE_TYPE);

		qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0;

		for(i = 0; i < nRealMask1->size(); ++i)
		{
			if((*nRealMask1)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1;
				if((*nMask1)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask1)[i] == 0)
			{
				if((*nMask1)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		for(i = 0; i < nRealMask2->size(); ++i)
		{
			if((*nRealMask2)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1;
				if((*nMask2)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask2)[i] == 0)
			{
				if((*nMask2)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives);
		if(math > maxMAT)
		{
			maxMAT = math;
			maxTP = truePositives;
			maxTN = trueNegatives;
			maxFP = falsePositives;
			maxFN = falseNegatives;
			maxLengthTP = lengthTP;
			maxLengthFN = lengthFN;
			noChange = 0;
		}
		++noChange;
		if(noChange > NO_CHANGE) break;
	}

	delete nRealMask1;
	delete nRealMask2;
	delete nLength1;
	delete nLength2;

	++mDoneParamIterations;
	if(maxMAT > mBestMatthews) mBestMatthews = maxMAT;
	printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN);
	printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews);

	if(nextParam()) process1(false);
	else nextFile();
}