LogReader::LogReader(QObject *parent) : QObject(parent) { if (!isRunning("mongod.exe")){ qDebug() << "MongoDB Server is not running!"; exit(0); } connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); connect(this, SIGNAL(dataReceived(QString)), &sHandle, SLOT(checkString(QString))); connect(&sHandle, SIGNAL(codeChanged(CodeType)), &json, SLOT(inputCode(CodeType))); connect(&sHandle, SIGNAL(codeChanged(CodeType)), &db, SLOT(inputCode(CodeType))); connect(&sHandle, SIGNAL(dataValidated(QRegularExpressionMatch)), &json, SLOT(inputData(QRegularExpressionMatch))); connect(&json, SIGNAL(jsonCreated(QJsonObject)), &db, SLOT(receiveData(QJsonObject))); connect(this, SIGNAL(readToWrite()), &db, SLOT(openMongoConn())); connect(this, SIGNAL(writenDone()), &db, SLOT(closeMongoConn())); directory.setPath("Z:/Log"); fileList << "/Pvqvscmw.log" << "/Pvqvscmw1.log" << "/Pvqvscmw2.log" << "/Pvqvscmw3.log" << "/Pvqvscmw4.log" << "/Pvqvscmw5.log" << "/Pvqvscmw6.log" << "/Pvqvscmw7.log" << "/Pvqvscmw8.log" << "/Pvqvscmw9.log"; // directory.setPath("C:/Temp/Data"); // fileList << "/Pvqvscmw.log"; // directory.setPath("C:/Temp/Data"); // fileList << "/Log (1).log" << "/Log (2).log" // << "/Log (3).log" << "/Log (4).log" // << "/Log (5).log" << "/Log (6).log" // << "/Log (7).log" << "/Log (8).log" // << "/Log (9).log" << "/Log (10).log" // << "/Log (11).log" << "/Log (12).log" // << "/Log (13).log" << "/Log (14).log" // << "/Log (15).log" << "/Log (16).log" // << "/Log (17).log" << "/Log (18).log" // << "/Log (19).log" << "/Log (20).log" // << "/Log (21).log" << "/Log (22).log" // << "/Log (23).log" << "/Log (24).log" // << "/Log (25).log" << "/Log (26).log" // << "/Log (27).log" << "/Log (28).log" // << "/Log (29).log" << "/Log (30).log" // << "/Log (31).log" << "/Log (32).log" // << "/Log (33).log" << "/Log (34).log" // << "/Log (35).log" << "/Log (36).log" // << "/Log (37).log" << "/Log (38).log" // << "/Log (39).log" << "/Log (40).log" // << "/Log (41).log" << "/Log (42).log"; // Força a leitura no arquivo na inicialização. readFile(0); watcher.addPath(directory.absolutePath()+fileList.at(0)); }
/*************************************************************************** ** expand ** ** Purpose: To uncompress the data contained in the input buffer and store ** the result in the output buffer. The fileLength parameter says how ** many bytes to uncompress. The compression itself is a form of LZW that ** adjusts the number of bits that it represents its codes in as it fills ** up the available codes. Two codes have special meaning: ** ** code 256 = start over ** code 257 = end of data ***************************************************************************/ void lzwExpand(uint8 *in, uint8 *out, int32 len) { int32 c, lzwnext, lzwnew, lzwold; uint8 *s, *end; initLZW(); setBits(START_BITS); // Starts at 9-bits lzwnext = 257; // Next available code to define end = (uint8 *)(out + (uint32)len); lzwold = inputCode(&in); // Read in the first code c = lzwold; lzwnew = inputCode(&in); while ((out < end) && (lzwnew != 0x101)) { if (lzwnew == 0x100) { // Code to "start over" lzwnext = 258; setBits(START_BITS); lzwold = inputCode(&in); c = lzwold; *out++ = (char)c; lzwnew = inputCode(&in); } else { if (lzwnew >= lzwnext) { // Handles special LZW scenario *decodeStack = c; s = decodeString(decodeStack + 1, lzwold); } else s = decodeString(decodeStack, lzwnew); // Reverse order of decoded string and // store in out buffer c = *s; while (s >= decodeStack) *out++ = *s--; if (lzwnext > MAX_CODE) setBits(BITS + 1); prefixCode[lzwnext] = lzwold; appendCharacter[lzwnext] = c; lzwnext++; lzwold = lzwnew; lzwnew = inputCode(&in); } } closeLZW(); }
LexicalAnalizer::LexicalAnalizer(string fileName) { ifstream inputCode(fileName); if (inputCode.is_open()) { string tmp; while (getline(inputCode, tmp)) code.push_back(tmp); inputCode.close(); bool flag = false; for (int i = 0; i < code.size(); ++i) { int j = 0; while (j < code[i].length()) if (!quoteCheck(code[i][j])) { code[i][j] = toupper(code[i][j]); ++j; } else { ++j; while (j < code[i].length() && !quoteCheck(code[i][j])) ++j; } } GenerateLexemVector(); AnalizeLexems(); //OutputTokens(fileName); } else { cout << "Sorry, but file don't exist :C"; exit(1); } }
int main () { //int XOR[4][3] = {{0,0,0,},{0,1,1,},{1,0,1,},{1,1,0,}}; // XOR data clock_t t; // auxiliary variable for compute running time float sec; // auxiliary variable for compute seconds double error1,error2; int sumData = 0, tPoints = 0; char trash[50000]; // -------------------- srand(time(NULL)); // seed for random numbers initWeights(-0.1,0.1); // initialize weights FILE * trainingSet = fopen("trainingData.txt","r"); FILE * con1 = fopen("con1.txt","w"); FILE * con2 = fopen("con2.txt","w"); while (fgets (trash, 50000 , trainingSet) != NULL) tPoints++; t = clock(); // start timer //printf("\nEpoch: Output Des.out. (Error)\n"); // -------------------- //printf("--------------------------------\n"); // -------------------- int epoch; // -------------------- for (epoch = 0; epoch <= epochs; epoch++) { // for every error1 = 0, error2 = 0; rewind(trainingSet); for (int p = 0; p < tPoints; p++) { // for every pattern for (int img = 1; img <= IN; img++) { fscanf(trainingSet,"%lf",&y(img)); y(img) = inputCode(y(img)); } fscanf(trainingSet,"%lf %lf",&dv(0),&dv(1)); dv(0) = outputCode(dv(0)); dv(1) = outputCode(dv(1)); // -------------------- forwardRun(); // train backwardRun(); // train weightsUpdate(); // train double J1=fabs(dv(0) - y(FO)); // compute the error double J2=fabs(dv(1) - y(LO)); // compute the error error1 += J1; error2 += J2; sumData++; // -------------------- if (epoch % 100==0) { // every 20000 ep. print error if (p == 0 && epoch != 0) { printf("\n"); printf("\n%f %f\n",error1,error2); } // -------------------- // -------------------- //forwardRun(); // runs network //if (p % 20 == 0) printf("%5d: %f %f (%.6f) ::: %f %f (%.6f)\n",epoch,y(FO),dv(0),J1,y(LO),dv(1),J2); } } fprintf(con1,"%f ",error1 / tPoints); fprintf(con2,"%f ",error2 / tPoints); if ((error1 / tPoints < 0.005) && (error2 / tPoints < 0.005)) { printf("%5d: %f %f\n", epoch, error1 / sumData, error2 / sumData); break; } } fprintf(con1,"\n%d ",epoch); fprintf(con2,"\n%d ",epoch); fclose(con1); fclose(con2); fclose(trainingSet); t = clock() - t; // stop timer sec = ((float)t)/CLOCKS_PER_SEC; // conversion to seconds //printf("--------------------------------\n%.3f sec\n\n",sec); weightsToFileHelper(); //printf("%.3f ",sec); printf("%d",tPoints); return 0; }