コード例 #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
ファイル: stemming.cpp プロジェクト: Zala/qminer
PStemmer TStemmer::ParseJson(const PJsonVal& StemmerVal, const bool& RealWordP) {
    if (StemmerVal->IsBool()) {
        return TStemmer::New(StemmerVal->GetBool() ? stmtPorter : stmtNone, RealWordP);
    } else if (StemmerVal->IsObj()) {
        TStr StemmerType = StemmerVal->GetObjStr("type", "none");
        const bool RealWordP = StemmerVal->GetObjBool("realWord", RealWordP);
        return TStemmer::New((StemmerType == "porter") ? stmtPorter : stmtNone, RealWordP);
    }
    throw TExcept::New("Unknown stemmer definiton " + StemmerVal->SaveStr());
}
コード例 #3
0
ファイル: tokenizer.cpp プロジェクト: Austindeadhead/qminer
PTokenizer THtml::New(const PJsonVal& ParamVal) {
    // get stopwords
    PSwSet SwSet = ParamVal->IsObjKey("stopwords") ? 
        TSwSet::ParseJson(ParamVal->GetObjKey("stopwords")) :
        TSwSet::New(swstNone);   
    // get stemmer
    PStemmer Stemmer = ParamVal->IsObjKey("stemmer") ? 
        TStemmer::ParseJson(ParamVal->GetObjKey("stemmer"), false) :
        TStemmer::New(stmtNone, false);
    const bool ToUcP = ParamVal->GetObjBool("uppercase", true);
    return new THtml(SwSet, Stemmer, ToUcP);
}
コード例 #4
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);
}
コード例 #5
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);
}
コード例 #6
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);
};
コード例 #7
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));
            }
        }
    }
}