コード例 #1
0
ファイル: rpinode.cpp プロジェクト: lstopar/HomeDevelopment
TNodeJsRf24Radio* TNodeJsRf24Radio::NewFromArgs(const v8::FunctionCallbackInfo<v8::Value>& Args) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	PJsonVal ParamJson = TNodeJsUtil::GetArgJson(Args, 0);

	const int PinCE = ParamJson->GetObjInt("pinCE");
	const int PinCSN = ParamJson->GetObjInt("pinCSN");
	const uint16 MyId = (uint16) ParamJson->GetObjInt("id");
	const PJsonVal SensorJsonV = ParamJson->GetObjKey("sensors");

	const bool Verbose = ParamJson->GetObjBool("verbose", false);
	const PNotify Notify = Verbose ? TNotify::StdNotify : TNotify::NullNotify;

	Notify->OnNotify(TNotifyType::ntInfo, "Parsing configuration ...");

	TStrIntH SensorNmIdH;
	TStrIntH SensorIdNodeIdH;

	for (int SensorN = 0; SensorN < SensorJsonV->GetArrVals(); SensorN++) {
		const PJsonVal SensorJson = SensorJsonV->GetArrVal(SensorN);
		const TStr& SensorId = SensorJson->GetObjStr("id");
		SensorNmIdH.AddDat(SensorId, SensorJson->GetObjInt("internalId"));
		SensorIdNodeIdH.AddDat(SensorId, SensorJson->GetObjInt("nodeId"));
	}

	Notify->OnNotify(TNotifyType::ntInfo, "Calling cpp constructor ...");

	return new TNodeJsRf24Radio(MyId, PinCE, PinCSN, SensorNmIdH, SensorIdNodeIdH, Notify);
}
コード例 #2
0
ファイル: graphprocess.cpp プロジェクト: Bradeskojest/qminer
TGraphCascade::TGraphCascade(const PJsonVal& Params) {
    // build graph and node name-id maps
    PJsonVal Dag = Params->GetObjKey("dag");
    GenGraph(Dag);
    // read enabled (ignore the ones missing from the graph)
    PJsonVal EnabledNodeIdH = Params->GetObjKey("enabledNodes");
    ProcessEnabled(EnabledNodeIdH);
    PruneGraph();
    InitTimestamps();
    // read models
    PJsonVal NodeModels = Params->GetObjKey("nodeModels");
    ProcessModels(NodeModels);
    TimeUnit = Params->GetObjInt("timeUnit", 1000);
    Rnd.PutSeed(Params->GetObjInt("randSeed", 0));
}
コード例 #3
0
ファイル: signalproc.cpp プロジェクト: amrsobhy/qminer
TOnlineHistogram::TOnlineHistogram(const PJsonVal& ParamVal) {
	EAssertR(ParamVal->IsObjKey("lowerBound"), "TOnlineHistogram: lowerBound key missing!");
	EAssertR(ParamVal->IsObjKey("upperBound"), "TOnlineHistogram: upperBound key missing!");
	// bounded lowest point
	TFlt LBound = ParamVal->GetObjNum("lowerBound");
	// bounded highest point
	TFlt UBound = ParamVal->GetObjNum("upperBound");
	EAssertR(LBound < UBound, "TOnlineHistogram: Lower bound should be smaller than upper bound");
	// number of equal bins ? (not counting possibly infinite ones)
	TInt Bins = ParamVal->GetObjInt("bins", 5);
	EAssertR(Bins > 0, "TOnlineHistogram: Number of bins should be greater than 0");
	// include infinities in the bounds?
	TBool AddNegInf = ParamVal->GetObjBool("addNegInf", false);
	TBool AddPosInf = ParamVal->GetObjBool("addPosInf", false);
	
	MinCount = ParamVal->GetObjInt("initMinCount", 0);

	Init(LBound, UBound, Bins, AddNegInf, AddPosInf);
};
コード例 #4
0
ファイル: rpinode.cpp プロジェクト: lstopar/HomeDevelopment
void TNodeJsRf24Radio::set(const v8::FunctionCallbackInfo<v8::Value>& Args) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	TNodeJsRf24Radio* JsRadio = ObjectWrap::Unwrap<TNodeJsRf24Radio>(Args.Holder());

	if (Args.Length() == 0) { return; }

	const PJsonVal ArgVal = TNodeJsUtil::GetArgJson(Args, 0);
	bool Success = true;

	if (ArgVal->IsArr()) {
		THash<TInt, TIntPrV> NodeIdValIdValPrVH;

		for (int ArgN = 0; ArgN < ArgVal->GetArrVals(); ArgN++) {
			const PJsonVal& ValJson = ArgVal->GetArrVal(ArgN);

			const TStr& ValNm = ValJson->GetObjStr("sensorId");
			const int& Val = ValJson->GetObjInt("value");

			const TIntPr& NodeIdValIdPr = JsRadio->ValNmNodeIdValIdPrH.GetDat(ValNm);
			const uint16 NodeId = NodeIdValIdPr.Val1;
			const int ValId = NodeIdValIdPr.Val2;

			if (!NodeIdValIdValPrVH.IsKey(NodeId)) { NodeIdValIdValPrVH.AddDat(NodeId); }

			TIntPrV& ValIdValPrV = NodeIdValIdValPrVH.GetDat(NodeId);
			ValIdValPrV.Add(TIntPr(ValId, Val));
		}

		int KeyId = NodeIdValIdValPrVH.FFirstKeyId();
		while (NodeIdValIdValPrVH.FNextKeyId(KeyId)) {
			const uint16 NodeId = NodeIdValIdValPrVH.GetKey(KeyId);
			const TIntPrV& ValIdValPrV = NodeIdValIdValPrVH[KeyId];
			Success &= JsRadio->Radio.Set(NodeId, ValIdValPrV);
		}
	} else {
		const TStr& ValueNm = ArgVal->GetObjStr("sensorId");
		const int Val = ArgVal->GetObjInt("value");

		const TIntPr& NodeIdValIdPr = JsRadio->ValNmNodeIdValIdPrH.GetDat(ValueNm);
		const uint16 NodeId = (uint16) NodeIdValIdPr.Val1;
		const int ValId = NodeIdValIdPr.Val2;

		Success = JsRadio->Radio.Set(NodeId, ValId, Val);
	}

	Args.GetReturnValue().Set(v8::Boolean::New(Isolate, Success));
}
コード例 #5
0
ファイル: rpinode.cpp プロジェクト: lstopar/HomeDevelopment
TNodejsDHT11Sensor* TNodejsDHT11Sensor::NewFromArgs(const v8::FunctionCallbackInfo<v8::Value>& Args) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	PJsonVal ParamJson = TNodeJsUtil::GetArgJson(Args, 0);

	const int Pin = ParamJson->GetObjInt("pin");
	const TStr& TempId = ParamJson->GetObjStr("temperatureId");
	const TStr& HumId = ParamJson->GetObjStr("humidityId");
	const uint64 MxSampleTm = ParamJson->GetObjUInt64("timeout", 10000);
	const bool Verbose = ParamJson->GetObjBool("verbose", false);

	const PNotify Notify = Verbose ? TNotify::StdNotify : TNotify::NullNotify;

	return new TNodejsDHT11Sensor(new TDHT11Sensor(Pin, Notify), TempId, HumId, MxSampleTm, Notify);
}
コード例 #6
0
ファイル: signalproc.cpp プロジェクト: amrsobhy/qminer
TEma::TEma(const PJsonVal& ParamVal) : LastVal(TFlt::Mn), InitP(false) {
    // type
    TStr TypeStr = ParamVal->GetObjStr("emaType");
    if (TypeStr == "previous") { 
        Type = etPreviousPoint;
    } else if (TypeStr == "linear") {
        Type = etLinear;
    } else if (TypeStr == "next") {
        Type = etNextPoint;
    } else {
        throw TExcept::New("Unknown ema type " + TypeStr);
    }
    // rest
    TmInterval = ParamVal->GetObjNum("interval");
    InitMinMSecs = ParamVal->GetObjInt("initWindow", 0);
}
コード例 #7
0
ファイル: rpinode.cpp プロジェクト: lstopar/HomeDevelopment
TNodeJsYL40Adc* TNodeJsYL40Adc::NewFromArgs(const v8::FunctionCallbackInfo<v8::Value>& Args) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	PJsonVal ParamJson = TNodeJsUtil::GetArgJson(Args, 0);
	PJsonVal InputJsonV = ParamJson->GetObjKey("inputs");
	const bool Verbose = ParamJson->GetObjBool("verbose", false);

	TIntStrKdV InputNumNmKdV(InputJsonV->GetArrVals());
	for (int InputN = 0; InputN < InputJsonV->GetArrVals(); InputN++) {
		PJsonVal InputJson = InputJsonV->GetArrVal(InputN);
		InputNumNmKdV[InputN].Key = InputJson->GetObjInt("number");
		InputNumNmKdV[InputN].Dat = InputJson->GetObjStr("id");
	}

	const PNotify Notify = Verbose ? TNotify::StdNotify : TNotify::NullNotify;

	return new TNodeJsYL40Adc(new TYL40Adc(Notify), InputNumNmKdV, Notify);
}
コード例 #8
0
ファイル: folderbackup.cpp プロジェクト: Bradeskojest/qminer
//
// TBackupProfile
// 
TBackupProfile::TBackupProfile(const PJsonVal& SettingsJson, const TStr& Destination_, const TStr& ProfileName_)
{
    Destination = Destination_;
    if (Destination.Len() > 0 && (Destination.LastCh() != '\\' || Destination.LastCh() != '/'))
        Destination += "/";
    ProfileName = ProfileName_;
    if (!TDir::Exists(Destination))
        TDir::GenDir(Destination);
    
    VersionsToKeep = SettingsJson->GetObjInt("versionsToKeep", 1);
    PJsonVal FoldersJson = SettingsJson->GetObjKey("folders");
    EAssertR(FoldersJson->IsArr(), "Expected to get an array of folders");
    for (int N = 0; N < FoldersJson->GetArrVals(); N++) {
        PJsonVal FolderJson = FoldersJson->GetArrVal(N);
        TBackupFolderInfo FolderInfo;
        FolderInfo.Folder = FolderJson->GetObjStr("folder");
        if (FolderJson->IsObjKey("extensions"))
            FolderJson->GetObjStrV("extensions", FolderInfo.Extensions);
        if (FolderInfo.Extensions.IsIn("*"))
            FolderInfo.Extensions.Clr();
        FolderInfo.IncludeSubfolders = FolderJson->GetObjBool("includeSubfolders");
        if (FolderJson->IsObjKey("skipIfContaining"))
            FolderJson->GetObjStrV("skipIfContaining", FolderInfo.SkipIfContainingV);
        FolderV.Add(FolderInfo);
    }
    
    // load logs of the previous backups
    ProfileLogFile = Destination + ProfileName + "/backupInfo.json";
    if (TFile::Exists(ProfileLogFile)) {
        PJsonVal LogJson = TJsonVal::GetValFromStr(TStr::LoadTxt(ProfileLogFile));
        if (LogJson->IsArr()) {
            for (int N = 0; N < LogJson->GetArrVals(); N++) {
                PJsonVal Log = LogJson->GetArrVal(N);
                LogV.Add(TBackupLogInfo(Log));
            }
        }
    }
}
コード例 #9
0
ファイル: folderbackup.cpp プロジェクト: Bradeskojest/qminer
//
// TBackupLogInfo
//
TBackupLogInfo::TBackupLogInfo(const PJsonVal& Json)
{
    FolderName = Json->GetObjStr("folderName");
    SecsNeeded = Json->GetObjInt("secsNeeded");
    LogInfo = Json->GetObjStr("logInfo");
}
コード例 #10
0
PJsonVal TDecisionTree::TNode::ExplainLabel(const int& Label) const {
	if (IsLeaf()) {
		if (ClassHist[Label] <= ClassHist[1 - Label]) {
			return PJsonVal();
		} else {
			const double Prob = ClassHist[Label];

			PJsonVal Result = TJsonVal::NewArr();

			PJsonVal IntersectJson = TJsonVal::NewObj();
			IntersectJson->AddToObj("covered", int(NExamples*Prob));
			IntersectJson->AddToObj("purity", Prob);
			IntersectJson->AddToObj("terms", TJsonVal::NewArr());

			Result->AddToArr(IntersectJson);

			return Result;
		}
	}

	PJsonVal Result = TJsonVal::NewArr();

	if (HasLeft()) {
		PJsonVal LeftUnion = Left->ExplainLabel(Label);

		if (!LeftUnion.Empty()) {
			if (LeftUnion->GetArrVals() == 0) {
				LeftUnion->AddToArr(TJsonVal::NewArr());
			}

			for (int i = 0; i < LeftUnion->GetArrVals(); i++) {
				PJsonVal IntersectJson = LeftUnion->GetArrVal(i);
				PJsonVal TermsJson = IntersectJson->GetObjKey("terms");
				bool HadFtr = false;
				for (int TermN = 0; TermN < TermsJson->GetArrVals(); TermN++) {
					PJsonVal TermJson = TermsJson->GetArrVal(TermN);

					const int TermFtrN = TermJson->GetObjInt("ftrId");
					if (TermFtrN == CutFtrN) {
						HadFtr = true;
						if (TermJson->GetObjNum("le") == TFlt::PInf) {
							TermJson->AddToObj("le", CutFtrVal);
						}
					}
				}
				if (!HadFtr) {
					PJsonVal TermJson = TJsonVal::NewObj();
					TermJson->AddToObj("ftrId", CutFtrN);
					TermJson->AddToObj("le", CutFtrVal);
					TermJson->AddToObj("gt", TFlt::NInf);
					TermsJson->AddToArr(TermJson);
				}

				Result->AddToArr(IntersectJson);
			}
		}
	}
	if (HasRight()) {
		PJsonVal RightUnion = Right->ExplainLabel(Label);

		if (!RightUnion.Empty()) {
			if (RightUnion->GetArrVals() == 0) {
				RightUnion->AddToArr(TJsonVal::NewArr());
			}

			for (int i = 0; i < RightUnion->GetArrVals(); i++) {
				PJsonVal IntersectJson = RightUnion->GetArrVal(i);
				PJsonVal TermsJson = IntersectJson->GetObjKey("terms");

				bool HadFtr = false;
				for (int TermN = 0; TermN < TermsJson->GetArrVals(); TermN++) {
					PJsonVal TermJson = TermsJson->GetArrVal(TermN);

					const int TermFtrN = TermJson->GetObjInt("ftrId");
					if (TermFtrN == CutFtrN) {
						HadFtr = true;
						if (TermJson->GetObjNum("gt") == TFlt::NInf) {
							TermJson->AddToObj("gt", CutFtrVal);
						}
					}
				}
				if (!HadFtr) {
					PJsonVal TermJson = TJsonVal::NewObj();
					TermJson->AddToObj("ftrId", CutFtrN);
					TermJson->AddToObj("le", TFlt::PInf);
					TermJson->AddToObj("gt", CutFtrVal);
					TermsJson->AddToArr(TermJson);
				}

				Result->AddToArr(IntersectJson);
			}
		}
	}

	return Result->GetArrVals() > 0 ? Result : PJsonVal();
}
コード例 #11
0
ファイル: signalproc.cpp プロジェクト: amrsobhy/qminer
TChiSquare::TChiSquare(const PJsonVal& ParamVal): P(TFlt::PInf) {
	// P value is set to infinity by default (null hypothesis is not rejected)
	EAssertR(ParamVal->IsObjKey("degreesOfFreedom"), "TChiSquare: degreesOfFreedom key missing!");
	// degrees of freedom
	DegreesOfFreedom = ParamVal->GetObjInt("degreesOfFreedom");
}