MStatus exampleCameraSetViewCmd::doEditFlags()
//
//	Description:
//		Handle edits for flags added by this class.
//		If the flag is unknown, return MS::kSuccess and the parent class
//		will attempt to process the flag. Returning MS::kUnknownParameter
//		will cause the parent class to process the flag.
//
{
	MPx3dModelView *user3dModelView = modelView();
	if (NULL == user3dModelView) {
		MGlobal::displayError("NULL == user3dModelView!");
		return MS::kFailure;
	}

	//	This is now safe to do, since the above test passed.
	//
	exampleCameraSetView *dView = (exampleCameraSetView *)user3dModelView;

	MArgParser argData = parser();
	if (argData.isFlagSet(kTestMultiPackInitFlag)) {
		return initTests(*dView);
	} else if (argData.isFlagSet(kTestMultiPackResultsFlag)) {
		return testResults(*dView);
	} else if (argData.isFlagSet(kTestMultiPackClearFlag)) {
		return clearResults(*dView);
	}

	return MS::kUnknownParameter;
}
Exemplo n.º 2
0
static int test_blink(TestState *state)
{
    TestState state2;
    int phase = 0;
    int count = 4;

    initState(&state2, "  Subtest", state);

    while (--count >= 0) {
        if (startTest(&state2, "SET:pin-gpio13")) {
            if (serialRequest(&state2, "SET:pin-gpio13,%d", phase))
                checkSerialResponse(&state2, "=S,0");
        }
        if (startTest(&state2, "SET:pin-gpio15")) {
            if (serialRequest(&state2, "SET:pin-gpio15,%d", !phase))
                checkSerialResponse(&state2, "=S,0");
        }
        phase = !phase;
        msleep(500);
    }
    if (startTest(&state2, "SET:pin-gpio13")) {
        if (serialRequest(&state2, "SET:pin-gpio13,0"))
            checkSerialResponse(&state2, "=S,0");
    }
    if (startTest(&state2, "SET:pin-gpio15")) {
        if (serialRequest(&state2, "SET:pin-gpio15,0"))
            checkSerialResponse(&state2, "=S,0");
    }

    testResults(&state2);

    return state2.testPassed;
}
Exemplo n.º 3
0
TestResults ModelTester::Test(const std::string slideDir, const std::string outputDir) {
	std::vector<std::string> slideNames;
	std::vector<Slide> slides;
	SlideLoader::loadSlides(slideDir, slides, slideNames);

	cv::Mat totalPredictions;
	cv::Mat totalGroundTruth;
	for (int i = 0; i < slides.size(); ++i) {
		Slide slide = slides[i];
		cv::Mat predictions = Test(slide, outputDir + "/" + slideNames[i] + "_predictions.yaml");
		cv::Mat groundTruth = slide.getGroundTruth();
		std::string groundTruthLoc = outputDir + "/" + slideNames[i] + "_groundTruth.bmp";
		cv::imwrite(groundTruthLoc, renderHeatMap(slide.getTissueTiles(), groundTruth));
		std::string heatMapLoc = outputDir + "/" + slideNames[i] + "_heatMap.bmp";
		cv::imwrite(heatMapLoc, renderHeatMap(slide.getTissueTiles(), predictions));
		totalPredictions.push_back(predictions);
		totalGroundTruth.push_back(groundTruth);
	}

	TestResults testResults(totalPredictions, totalGroundTruth);
	cv::imwrite(outputDir + "/ROC.bmp", testResults.plotROC(1000));
	return testResults;
}
Exemplo n.º 4
0
int flcrd_quiz(Account & acct)
{
    cout << "Beginning Flashcard Quiz." << endl;

    chr::system_clock::time_point timeStart;
    boost::chrono::duration<float> timeDiff;
    bool isWrong = true, disableHintMsg = false;
    vector<Flashcard> cards;
    string response, prompt;
    SmartPicker * picker;
    Hint myhint("  ", acct.getVerbose());

    /* Choose flashcard set, then input */
    cards[0].input(cards,listDicts());

    {
        int index = 1;
        cout << "Pick how you're quizzed:\n"
             << "   1. LeastPicked\n"
             << "   2. Adaptive\n"
             << "   3. LeastCorrect\n" 
             << "   4. Walk Through\n"
             << endl;
        index = ltest::readint<usInt>(">> ");

        switch (index)
        {
            case 1:
                cout << "You picked LeastPicked" << endl;
                picker = new LeastPicked;
                break;
            case 2:
                cout << "You picked Adaptive" << endl;
                picker = new Adaptive(cards.size());
                break;
            case 3:
                cout << "You picked LeastCorrect" << endl;
                picker = new LeastCorrect;
                break;
            case 4:
                cout << "You picked WalkThrough" << endl;
                picker = new WalkThrough;
                break;
            default:
                cout << "Your choice isn't valid, so you're getting LeastPicked" << endl;
                picker = new LeastPicked;
                break;
        }
    }

    do
    {
        picker->getNextIndex(cards);

        // could we conditionally set this instead?
        myhint.setKey(cards[picker->getCurrentIndex()].getWord('B',ltest::randIndex(cards[picker->getCurrentIndex()].size('B'))));
        string sideAword = cards[picker->getCurrentIndex()].getWord('A',ltest::randIndex(cards[picker->getCurrentIndex()].size('A')));

        usInt numOfTries = 0;

        prompt = sideAword;

        while (isWrong)
        {
            numOfTries++;
            timeStart = chr::system_clock::now();
            response = ltest::readstring(prompt + ": ");
            timeDiff = chr::system_clock::now() - timeStart;

            /* options processing */
            if ( response[0] == '-' ) /* if hint */
            {
                if ( response[1] == 's' ) break; /* skip word */
                else                             /* deal with response */
                    cout << myhint.handle(response, disableHintMsg);
            }
            else if ( response == "exit" )
            {
                exitToMain = true;
                break;
            }
            else /* no hint, check response */
            {
/* TODO: if noun, and beginning with el or la (or los or las), and user
 *  gets the article correct, do not require them to keep typing that...
 */
                isWrong = ltest::isInvalidAnswer(response,cards[picker->getCurrentIndex()].getSideB());
                if (isWrong)
                {
                    if (acct.getVerbose())
                    {
                        cout << "You are " \
                             << wordCompare::lcsPercent(cards[picker->getCurrentIndex()].getWord('B',0),response) \
                             << "%% correct.\n" \
                             << wordCompare::correctness(response,cards[picker->getCurrentIndex()].getWord('B',0)) << endl;
                    }

                    if ( (numOfTries % 5) == 0 && !disableHintMsg)
                    {
                        cout << myhint.help(sideAword.size())
                             << '\n';
                        prompt = sideAword;
                    }
                    else
                        prompt = ltest::printWhitespace(sideAword.size()-1);
                }
                else if (acct.getVerbose()) cout << "Right!" << endl;
            }
        }
        /* finish this card */
        cards[picker->getCurrentIndex()].recordPerformance(numOfTries,isWrong,timeDiff.count());
        isWrong = true;
//        cout << response << " has " << ltest::isAccented(response) << " accents" << endl;
    } while (!exitToMain);

    testResults(cards,acct.getVerbose());

    delete picker;

    return 0;
}
Exemplo n.º 5
0
static int test_001(TestState *state)
{
    TestState state2;
    int listener1, listener2, connection1, count, result;
    char response[1024];

    initState(&state2, "  Subtest", state);

    if (startTest(&state2, "LISTEN")) {
        if (serialRequest(&state2, "LISTEN:HTTP,/robot*"))
            checkSerialResponse(&state2, "=S,^i", &listener1);
    }

    beginGroup(&state2);

    if (startTest(&state2, "PATH of a listener")) {
        if (!skipTest(&state2) && serialRequest(&state2, "PATH:%d", listener1))
            checkSerialResponse(&state2, "=S,/robot*");
    }

    if (startTest(&state2, "Send request to WX module")) {
        if (!skipTest(&state2)) {
            if (sendRequest(&state->moduleAddr, "POST", "/robot?gto=f", "") >= 0)
                passTest(&state2, "");
            else
                failTest(&state2, "");
        }
    }

    beginGroup(&state2);

    if (startTest(&state2, "POLL for incoming POST request")) {
        if (!skipTest(&state2)) {
            do {
                if (!serialRequest(&state2, "POLL"))
                    break;
            } while (!waitAndCheckSerialResponse(&state2, "=N,0,0", "=P,^i,^i", &connection1, &listener2));
        }
    }

    beginGroup(&state2);

    if (startTest(&state2, "listener handle returned by POLL")) {
        if (listener1 == listener2)
            passTest(&state2, "");
        else
            failTest(&state2, ": got %d", listener2);
    }

    if (startTest(&state2, "PATH of a connection")) {
        if (!skipTest(&state2) && serialRequest(&state2, "PATH:%d", connection1))
            checkSerialResponse(&state2, "=S,/robot");
    }

    if (startTest(&state2, "ARG")) {
        if (!skipTest(&state2) && serialRequest(&state2, "ARG:%d,gto", connection1))
            checkSerialResponse(&state2, "=S,f");
    }

    if (startTest(&state2, "REPLY")) {
        if (!skipTest(&state2) && serialRequest(&state2, "REPLY:%d,200", connection1))
            checkSerialResponse(&state2, "=S,^i", &count);
    }

    if (startTest(&state2, "POLL for send complete")) {
        if (!skipTest(&state2)) {
            do {
                if (!serialRequest(&state2, "POLL"))
                    break;
            } while (!waitAndCheckSerialResponse(&state2, "=N,0,0", "=S,^i,0", &count, &listener2));
        }
    }

    if (startTest(&state2, "Receive response from WX")) {
        if (!skipTest(&state2)) {
            if (receiveResponse((uint8_t *)response, sizeof(response), &result) >= 0)
                passTest(&state2, "");
            else
                failTest(&state2, "");
        }
    }

    if (startTest(&state2, "CLOSE")) {
        if (!skipTest(&state2) && serialRequest(&state2, "CLOSE:%d", listener1))
            checkSerialResponse(&state2, "=S,0");
    }

    testResults(&state2);

    return state2.testPassed;
}
Exemplo n.º 6
0
void run_tests(TestState *parent, int selectedTest)
{
    TestState state;

    initState(&state, "Test", parent);
    state.selectedTest = selectedTest;

    if (startTest(&state, "the empty command")) {
        if (serialRequest(&state, ""))
            checkSerialResponse(&state, "=S,0");
    }

    if (startTest(&state, "an invalid command")) {
        if (serialRequest(&state, "FOO"))
            checkSerialResponse(&state, "=E,1");
    }

#ifdef DO_BLINK_TEST
    if (startTest(&state, "Blink LEDs on GPIO13 and GPIO15")) {
        if (test_blink(&state))
            passTest(&state, "");
        else
            failTest(&state, "");
    }
#endif

    if (state.ssid) {
        if (startTest(&state, "switch to STA+AP mode")) {
            if (serialRequest(&state, "SET:wifi-mode,3"))
                checkSerialResponse(&state, "=S,0");
        }
        if (startTest(&state, "JOIN")) {
            if (serialRequest(&state, "JOIN:%s,%s", state.ssid, state.passwd))
                checkSerialResponse(&state, "=S,0");
            if (state.testPassed)
                msleep(10000); // wait for WX to disconnect. It has a .5 second delay
        }
        beginGroup(&state);
        if (startTest(&state, "CHECK:station-ipaddr")) {
            if (!skipTest(&state)) {
                char ipaddr[32];
                do {
                    if (!serialRequest(&state, "CHECK:station-ipaddr"))
                        break;
                } while (!waitAndCheckSerialResponse(&state, "=S,0.0.0.0", "=S,^s", ipaddr, sizeof(ipaddr)));
                if (state.testPassed) {
                    infoTest(&state, "got '%s'", ipaddr);
                    if (GetInternetAddress(ipaddr, 80, &state.moduleAddr) != 0)
                        infoTest(&state, "error: failed to parse IP address '%s'", ipaddr);
                }
            }
        }
    }

    if (startTest(&state, "simple transaction")) {
        if (test_001(&state))
            passTest(&state, "");
        else
            failTest(&state, "");
    }

    testResults(&state);
}
Exemplo n.º 7
0
  ModelGenerationSeriesResult testSeries(std::string p_ontPath, std::vector<std::string>* p_requiredModelElements,
                                         int p_count, bool warmUp, bool global, bool verbose, int maxHopCount = 3,
                                         int maxStepCount = 10,
                                         std::function<void(supplementary::ClingWrapper *asp)> lambda = nullptr, int models = 1)
  {
    ModelGenerationSeriesResult result;
    result.numberTotal = p_count;
    result.numberSuccessful = 0;
    std::vector<ModelGenerationResult> testResults(p_count + 1);
    std::chrono::time_point<std::chrono::system_clock> start, end;

    result.totalTimeVar = 0;
    result.ontologyReadTimeVar = 0;
    result.ontologyReasonerTimeVar = 0;
    result.ontologyToASPTimeVar = 0;
    result.aspGroundingTimeVar = 0;
    result.aspSolvingTimeVar = 0;

    VarianceOnline totalTimeVar, ontologyReadTimeVar, ontologyReasonerTimeVar, ontologyToASPTimeVar,
                   aspGroundingTimeVar, aspSolvingTimeVar, aspSatTimeVar, aspUnsatTimeVar, aspModelCountVar,
                   aspAtomCountVar, aspBodiesCountVar, aspAuxAtomCountVar;

    if (warmUp)
    {
      ice::OntologyInterface::callJniGc();

      std::cout << "Starting warm up " << std::flush;
      for (int i = 1; i < 101; ++i)
      {
        std::string ontology;

        if (this->testRepresentations)
        {
          ontology = p_ontPath + "0.owl";
        }
        else
        {
          ontology = p_ontPath;
        }

        this->test(ontology, p_requiredModelElements, true, global, false, maxHopCount, maxStepCount);

        if (i % 10 == 0)
        {
          std::cout << ".";
          std::cout << std::flush;
        }
      }
      std::cout << " done." << std::endl;
    }

    for (int m = 0; m < models; ++m)
    {
      for (int i = 0; i < p_count; ++i)
      {
        std::cout << "Starting run " << (i + 1) << " ... ";
        start = std::chrono::system_clock::now();

        std::string ontology;

        if (this->testRepresentations)
        {
          ontology = p_ontPath + std::to_string(m) + ".owl";
        }
        else
        {
          ontology = p_ontPath;
        }

        auto r = this->test(ontology, p_requiredModelElements, false, global, verbose, maxHopCount, maxStepCount, lambda);

        if (r.successful)
          ++result.numberSuccessful;

        testResults.push_back(r);

        totalTimeVar.add(r.totalTime);
        ontologyReadTimeVar.add(r.ontologyReadTime);
        ontologyReasonerTimeVar.add(r.ontologyReasonerTime);
        ontologyToASPTimeVar.add(r.ontologyToASPTime);
        aspGroundingTimeVar.add(r.aspGroundingTime);
        aspSolvingTimeVar.add(r.aspSolvingTime);
        aspSatTimeVar.add(r.aspSatTime);
        aspUnsatTimeVar.add(r.aspUnsatTime);
        aspModelCountVar.add(r.aspModelCount);
        aspAtomCountVar.add(r.aspAtomCount);
        aspBodiesCountVar.add(r.aspBodiesCount);
        aspAuxAtomCountVar.add(r.aspAuxAtomCount);

        if (i == 0 && m == 0)
        {
          result.best = r;
          result.worst = r;
          result.avg = r;
        }
        else
        {
          result.avg.totalTime += r.totalTime;
          result.avg.ontologyReadTime += r.ontologyReadTime;
          result.avg.ontologyReasonerTime += r.ontologyReasonerTime;
          result.avg.ontologyToASPTime += r.ontologyToASPTime;
          result.avg.aspGroundingTime += r.aspGroundingTime;
          result.avg.aspSolvingTime += r.aspSolvingTime;
          result.avg.aspSatTime += r.aspSatTime;
          result.avg.aspUnsatTime += r.aspUnsatTime;
          result.avg.aspModelCount += r.aspModelCount;
          result.avg.aspAtomCount += r.aspAtomCount;
          result.avg.aspBodiesCount += r.aspBodiesCount;
          result.avg.aspAuxAtomCount += r.aspAuxAtomCount;

          if (r.totalTime < result.best.totalTime)
            result.best.totalTime = r.totalTime;
          else if (r.totalTime > result.worst.totalTime)
            result.worst.totalTime = r.totalTime;

          if (r.ontologyReadTime < result.best.ontologyReadTime)
            result.best.ontologyReadTime = r.ontologyReadTime;
          else if (r.ontologyReadTime > result.worst.ontologyReadTime)
            result.worst.ontologyReadTime = r.ontologyReadTime;

          if (r.ontologyReasonerTime < result.best.ontologyReasonerTime)
            result.best.ontologyReasonerTime = r.ontologyReasonerTime;
          else if (r.ontologyReasonerTime > result.worst.ontologyReasonerTime)
            result.worst.ontologyReasonerTime = r.ontologyReasonerTime;

          if (r.ontologyToASPTime < result.best.ontologyToASPTime)
            result.best.ontologyToASPTime = r.ontologyToASPTime;
          else if (r.ontologyToASPTime > result.worst.ontologyToASPTime)
            result.worst.ontologyToASPTime = r.ontologyToASPTime;

          if (r.aspGroundingTime < result.best.aspGroundingTime)
            result.best.aspGroundingTime = r.aspGroundingTime;
          else if (r.aspGroundingTime > result.worst.aspGroundingTime)
            result.worst.aspGroundingTime = r.aspGroundingTime;

          if (r.aspSolvingTime < result.best.aspSolvingTime)
            result.best.aspSolvingTime = r.aspSolvingTime;
          else if (r.aspSolvingTime > result.worst.aspSolvingTime)
            result.worst.aspSolvingTime = r.aspSolvingTime;

          if (r.aspSatTime < result.best.aspSatTime)
            result.best.aspSatTime = r.aspSatTime;
          else if (r.aspSatTime > result.worst.aspSatTime)
            result.worst.aspSatTime = r.aspSatTime;

          if (r.aspUnsatTime < result.best.aspUnsatTime)
            result.best.aspUnsatTime = r.aspUnsatTime;
          else if (r.aspUnsatTime > result.worst.aspUnsatTime)
            result.worst.aspUnsatTime = r.aspUnsatTime;

          if (r.aspModelCount < result.best.aspModelCount)
            result.best.aspModelCount = r.aspModelCount;
          else if (r.aspModelCount > result.worst.aspModelCount)
            result.worst.aspModelCount = r.aspModelCount;

          if (r.aspAtomCount < result.best.aspAtomCount)
            result.best.aspAtomCount = r.aspAtomCount;
          else if (r.aspAtomCount > result.worst.aspAtomCount)
            result.worst.aspAtomCount = r.aspAtomCount;

          if (r.aspBodiesCount < result.best.aspBodiesCount)
            result.best.aspBodiesCount = r.aspBodiesCount;
          else if (r.aspBodiesCount > result.worst.aspBodiesCount)
            result.worst.aspBodiesCount = r.aspBodiesCount;

          if (r.aspAuxAtomCount < result.best.aspAuxAtomCount)
            result.best.aspAuxAtomCount = r.aspAuxAtomCount;
          else if (r.aspAuxAtomCount > result.worst.aspAuxAtomCount)
            result.worst.aspAuxAtomCount = r.aspAuxAtomCount;
        }

        end = std::chrono::system_clock::now();
        std::cout << "finished " << (r.successful ? "successful" : "unsuccessful") << " after: "
            << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms, processing time: "
            << r.totalTime << " ms" << std::endl;
      }
    }

    result.totalTimeVar = totalTimeVar.getVariance();
    result.ontologyReadTimeVar = ontologyReadTimeVar.getVariance();
    result.ontologyReasonerTimeVar = ontologyReasonerTimeVar.getVariance();
    result.ontologyToASPTimeVar = ontologyToASPTimeVar.getVariance();
    result.aspGroundingTimeVar = aspGroundingTimeVar.getVariance();
    result.aspSolvingTimeVar = aspSolvingTimeVar.getVariance();
    result.aspSatTimeVar = aspSatTimeVar.getVariance();
    result.aspUnsatTimeVar = aspUnsatTimeVar.getVariance();
    result.aspModelCountVar = aspModelCountVar.getVariance();
    result.aspAtomCountVar = aspAtomCountVar.getVariance();
    result.aspBodiesCountVar = aspBodiesCountVar.getVariance();
    result.aspAuxAtomCountVar = aspAuxAtomCountVar.getVariance();

    int runCount = models * p_count;

    result.avg.totalTime /= runCount;
    result.avg.ontologyReadTime /= runCount;
    result.avg.ontologyReasonerTime /= runCount;
    result.avg.ontologyToASPTime /= runCount;
    result.avg.aspGroundingTime /= runCount;
    result.avg.aspSolvingTime /= runCount;
    result.avg.aspSatTime /= runCount;
    result.avg.aspUnsatTime /= runCount;
    result.avg.aspModelCount /= runCount;
    result.avg.aspAtomCount /= runCount;
    result.avg.aspBodiesCount /= runCount;
    result.avg.aspAuxAtomCount /= runCount;

    return result;
  }