예제 #1
0
 double LinearApproximation::Approximate() {
         S_LOG("Approximate");
         coeffScale = 0.0;
         coefShift = 0.0;
         if (values.empty() || values.size() == 1){
                 log(logxx::error) << "There should be at least 2 values" << logxx::endl;
                 return 0.0;
         } else {
                 double alpha(0.0), beta(0.0), gamma(0.0), phi(0.0), psi(0.0);
                 size_t N = values.size();
                 gamma = N;
                 for (size_t i = 0; i < N; ++i){
                         alpha += Sqr(keys[i]);
                         beta += keys[i];
                         phi += values[i] * keys[i];
                         psi += values[i];
                 }
                 double determinant = alpha * gamma - Sqr(beta);
                 
                 coeffScale = (gamma * phi - beta * psi) / determinant;
                 coefShift = (-beta * phi + alpha * psi) / determinant;
                 
                 return CalculateRelativeError();
         }
 }
예제 #2
0
S_API bool S_CALL SteamGameServer_Init()
{
	S_LOG();

	// TODO: implement game server stuff from the old project.

	return true;
}
예제 #3
0
bool DateHelper::Parse(const std::string & s) {
        S_LOG("Parse");
        if (std::sscanf(s.c_str(), "%2d.%2d.%4d", &day, &month, &year) != 3) {
                log(Log::error) << "Can't parse date {" << s << "}" << std::endl;
                return false;
        } else
                return true;
}
예제 #4
0
bool TestLinearApproximation::TestLinears(int tests) {
        S_LOG("TestLinear");
        log(logxx::notice) << "Testing approximation of linear functions" << logxx::endl;
        for(int i = 0; i < tests; ++i){
                double c = Random();
                if (!Test(c)){
                        log(logxx::error) << "Failed while testing y = " << c << logxx::endl;
                        return false;
                }
        }
        return true;
}
예제 #5
0
bool TestLinearApproximation::TestConstants(int tests) {
        S_LOG("TestConstants");
        log(logxx::notice) << "Testing approximation of constants" << logxx::endl;
        for(int i = 0; i < tests; ++i){
                double a = Random();
                double b = Random();
                if (!Test(a, b)){
                        log(logxx::error) << "Failed while testing y = " << a << " * x + " << b << logxx::endl;
                        return false;
                }
        }
        return true;
}
예제 #6
0
void PrintProgress(){
        S_LOG("PrintProgress");
        static time_t start = time(nullptr);
        static const time_t interval = 10;
        static int counter = 0;
        
        time_t now = time(nullptr);
        ++counter;
        if (now > start + interval){
                start = now;
                log(logxx::info) << counter << logxx::endl;
        }
}
예제 #7
0
bool Field::Load(std::ifstream& f, int shift){
	S_LOG("Load");
	auto current = std::ios_base::cur;
	if (f.good()){
		f.seekg(shift, current);
                log(logxx::debug) << "Current position: 0x" << std::hex << f.tellg() << std::dec << logxx::endl;
                uint32_t fieldLength(0);
                char optionalField[2];
                f.read(optionalField, 2);
                check_error(optionalField);
                if (
                        std::strncmp(optionalField, "PN", 2) == 0 ||
                        std::strncmp(optionalField, "LO", 2) == 0 ||
                        std::strncmp(optionalField, "DA", 2) == 0
                        ){
                        uint16_t shortFieldLength(0);
                        fread(shortFieldLength);
                        fieldLength = shortFieldLength;
                } else{
                        f.seekg(-2, std::ios_base::cur);
                        fread(fieldLength);
                }
                
                static const decltype(fieldLength) maxLength = 100;
                
                if (fieldLength == 0){
                        log(logxx::warning) << "Field length is zero, nothing to read!" << logxx::endl;
                        return false;
                } else if (fieldLength > maxLength){
                        log(logxx::warning) << "Too large field: " << fieldLength <<
                                "; maximum allowed is: " << maxLength << logxx::endl;
                        return false;
                }
		std::unique_ptr<char[]> cValue(new char[fieldLength]);
		f.read(cValue.get(), fieldLength);
		check_error(cValue);
		try {
			value.assign(cValue.get(), fieldLength);
			ProcessValue();
			return true;
		} catch (const std::exception& e){
			log(logxx::warning) << "Cought an exception: " << e.what() << logxx::endl;
			value.assign('%', fieldLength);
			return true;
		}
	} else {
		log(logxx::error) << "Can't read file" << logxx::endl;
		return false;
	}
}
예제 #8
0
int main(int argc, char **argv){
	S_LOG("main");
        logxx::GlobalLogLevel(logxx::warning);
        EncodingConverter converter;
        if (argc < 2){
                log(logxx::error) << "A path with dicom files should be specified" << logxx::endl;
                return 1;
        } else {
                std::string path(argv[1]);                
                if (path[path.length()-1] != '/')
                        path += '/';
                
                std::string csvFile = path + "out.csv";
                std::ofstream out(csvFile);
                if (out.good()){
                        Dir dir(path, true, ".dcm");
                        if (dir.Ok()) {
                                std::string fName;
                                while ((fName = dir.Read()).empty() == false) {
                                        log(logxx::debug) << "{" << fName << "}" << logxx::endl;
                                        Dicom dicom(path + fName);
                                        if (dicom.Parse(converter)){
                                                // cppcheck-suppress constStatement
                                                log(logxx::notice) << "{" << fName << "} Parsed" << logxx::endl;
                                                out << fName << "," << dicom << std::endl;

                                        } else {
                                                // cppcheck-suppress constStatement
                                                log(logxx::notice) << "{" << fName << "} Not parsed" << logxx::endl;
                                        }
                                        PrintProgress();
                                }
                                return 0;
                        } else {
                                log(logxx::error) << "Can't open path {" << path << "}" << logxx::endl;
                                return 1;
                        }
                } else {
                        log(logxx::error) << "Can't open file {" << csvFile <<  "} for writing"  << logxx::endl;
                        return 1;
                }
        }
}
예제 #9
0
bool TestLinearApproximation::Test(double a, double b) {
        S_LOG("Test linear function");
        approxx::LinearApproximation approximation;
        
        auto etalonFunction = [a, b](double x)->double{return a * x + b;};
        
        if (!Fill(approximation, etalonFunction)){
                log(logxx::error) << "Can't load data for linear function = " << a << " * x + " << b << logxx::endl;
                return false;
        } else {
                double error = approximation.Approximate();
                if (!Cmp(error, 0.0)){
                        log(logxx::error) << "Error should be 0.0, but it is " << error << logxx::endl;
                        return false;
                } else if (!Check(approximation, etalonFunction)){
                                log(logxx::error) << "Comparison for linear function = " << a << " * x + " << b << logxx::endl;
                                return false;
                } else
                        return true;
        }
}
예제 #10
0
S_API bool S_CALL SteamAPI_Init()
{
	if(GetFileAttributesA(".\\steam_api.ini") == INVALID_FILE_ATTRIBUTES)
	{
		MessageBoxA(0, 
			"The configuration file \'steam_api.ini\' could not be found in the current directory. " 
			"A new one will be automatically generated once you press OK.", 
			"Warning", MB_OK | MB_ICONWARNING);

		srand((uint32)time(NULL));

		CIniWriter ini(".\\steam_api.ini");
		ini.WriteString("Settings", "Nickname", "UnnamedPlayer");
		ini.WriteInteger("Settings", "SteamID", rand());
		ini.WriteBoolean("Miscellaneous", "EnableDebugConsole", false);
	}

	CIniReader ini(".\\steam_api.ini");
	g_nickname = ini.ReadString("Settings", "Nickname", "UnnamedPlayer");
	g_steamID = ini.ReadInteger("Settings", "SteamID", 0);
	g_consoleAlloc = ini.ReadBoolean("Miscellaneous", "EnableDebugConsole", false);
	
	if(g_consoleAlloc && !g_consoleAllocDone)
	{
		if(!AllocConsole())
		{
			MessageBoxA(0, "Could not allocate console.", "Error", MB_OK | MB_ICONERROR);
			TerminateProcess(GetCurrentProcess(), 0x0000DEAD);
			
			return false;
		}

		freopen("CON","w",stdout);
		g_consoleAllocDone = true;
	}

	S_LOG();

	return true;
}
예제 #11
0
bool TestLinearApproximation::Test(double constant) {
        S_LOG("Test constant");
        approxx::LinearApproximation approximation;
        
        auto etalonFunction = [constant](double)->double{return constant;};
        
        if (!Fill(approximation, etalonFunction)){
                log(logxx::error) << "Can't load data for constant = " << constant << logxx::endl;
                return false;
        } else {
                double error = approximation.Approximate();
                double val = approximation.Get(0.0);
                if (!Cmp(error, 0.0)){
                        log(logxx::error) << "Error should be 0.0, but it is " << error << logxx::endl;
                        return false;
                } else {
                        if (!Check(approximation, etalonFunction)){
                                log(logxx::error) << "Value should be " << constant << ", but it is " << val << logxx::endl;
                                return false;
                        }
                        return true;
                }
        }
}
예제 #12
0
S_API ISteamUser016* S_CALL SteamUser()
{
	S_LOG();
	return new CSteamUser016();
}
예제 #13
0
S_API bool S_CALL SteamAPI_Shutdown()
{
	S_LOG();

	return true;
}
예제 #14
0
S_API ISteamGameServer010* S_CALL SteamGameServer()
{
	S_LOG();
	return 0;
}
예제 #15
0
int CSteamApps004::GetDLCCount()
{
	S_LOG();
	return 0;
	return dlcList.size();
}
예제 #16
0
S_API ISteamFriends009* S_CALL SteamFriends()
{
	S_LOG();
	return new CSteamFriends009();	
}
예제 #17
0
S_API ISteamApps004* S_CALL SteamApps()
{
	S_LOG();
	return new CSteamApps004();
}
예제 #18
0
S_API void S_CALL SteamGameServer_RunCallbacks()
{
	S_LOG();
	CallbacksManager::RunCallbacks();
}
예제 #19
0
S_API ISteamMasterServerUpdater001* S_CALL SteamMasterServerUpdater()
{
	S_LOG();
	return 0;
}
예제 #20
0
S_API ISteamRemoteStorage004* S_CALL SteamRemoteStorage()
{
	S_LOG();
	return new CSteamRemoteStorage004();
}
예제 #21
0
S_API ISteamMatchmakingServers002* S_CALL SteamMatchmakingServers()
{
	S_LOG();
	return new CSteamMatchmakingServers002();
}
예제 #22
0
S_API ISteamMatchmaking008* S_CALL SteamMatchmaking()
{
	S_LOG();
	return new CSteamMatchmaking008();
}
예제 #23
0
S_API ISteamUtils005* S_CALL SteamUtils()
{
	S_LOG();
	return new CSteamUtils005();
}
예제 #24
0
S_API bool S_CALL SteamGameServer_Shutdown()
{
	S_LOG();
	return true;
}