12 #include "calculator/util/ElectricityReduction.h" 13 #include "calculator/util/NaturalGasReduction.h" 14 #include "calculator/util/CompressedAirReduction.h" 15 #include "calculator/util/CompressedAirLeakSurvey.h" 16 #include "calculator/util/CompressedAirPressureReduction.h" 17 #include "calculator/util/WaterReduction.h" 18 #include "calculator/util/insulation/pipes/InsulatedPipeInput.h" 19 #include "calculator/util/insulation/pipes/InsulatedPipeCalculator.h" 20 #include "calculator/util/insulation/pipes/InsulatedPipeOutput.h" 21 #include "calculator/util/insulation/tanks/InsulatedTankInput.h" 22 #include "calculator/util/insulation/tanks/InsulatedTankCalculator.h" 23 #include "calculator/util/insulation/tanks/InsulatedTankOutput.h" 25 #include "ssmt/SaturatedProperties.h" 26 #include "ssmt/SteamSystemModelerTool.h" 27 #include "calculator/util/SteamReduction.h" 28 #include "calculator/util/Conversion.h" 47 double GetDouble(std::string
const &key, Local<Object> obj)
49 v8::Isolate *isolate = v8::Isolate::GetCurrent();
50 v8::Local<v8::Context> context = isolate->GetCurrentContext();
51 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
52 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
53 if (rObj->IsUndefined())
55 ThrowTypeError(std::string(
"GetDouble method in calculator.h: " + key +
" not present in object").c_str());
57 return Nan::To<double>(rObj).FromJust();
60 std::vector<double> GetVector(std::string
const &key, Local<Object> obj)
62 v8::Isolate *isolate = v8::Isolate::GetCurrent();
63 v8::Local<v8::Context> context = isolate->GetCurrentContext();
64 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
65 Local<Value> arrayTmp = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
66 if (arrayTmp->IsUndefined())
68 ThrowTypeError(std::string(
"GetVector method in calculator.h: " + key +
" not present in object").c_str());
70 Local<Array> jsArray = v8::Local<v8::Array>::Cast(arrayTmp);
71 std::vector<double> array;
72 for (
unsigned int i = 0; i < jsArray->Length(); i++)
74 v8::Local<v8::Value> jsElement = jsArray->Get(context, i).ToLocalChecked();
75 double val = Nan::To<double>(jsElement).FromJust();
82 T GetEnumVal(std::string
const &key, Local<Object> obj)
84 v8::Isolate *isolate = v8::Isolate::GetCurrent();
85 v8::Local<v8::Context> context = isolate->GetCurrentContext();
86 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
87 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
88 if (rObj->IsUndefined())
90 ThrowTypeError(std::string(
"GetEnumVal method in calculator.h: Enum value " + key +
" not present in object").c_str());
92 return static_cast<T
>(Nan::To<double>(rObj).FromJust());
95 bool GetBool(std::string
const &key, Local<Object> obj)
97 v8::Isolate *isolate = v8::Isolate::GetCurrent();
98 v8::Local<v8::Context> context = isolate->GetCurrentContext();
99 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
100 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
101 if (rObj->IsUndefined())
103 ThrowTypeError(std::string(
"GetBool method in calculator.h: Boolean value " + key +
" not present in object").c_str());
105 return Nan::To<bool>(rObj).FromJust();
108 std::string GetStr(std::string
const &key, Local<Object> obj)
110 v8::Isolate *isolate = v8::Isolate::GetCurrent();
111 v8::Local<v8::Context> context = isolate->GetCurrentContext();
112 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
113 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
114 if (rObj->IsUndefined())
116 ThrowTypeError(std::string(
"GetStr method in calculator.h: String " + key +
" not present in object").c_str());
118 v8::String::Utf8Value s(isolate, rObj);
119 return std::string(*s);
123 bool isDefined(Local<Object> obj, std::string
const &key)
125 v8::Isolate *isolate = v8::Isolate::GetCurrent();
126 v8::Local<v8::Context> context = isolate->GetCurrentContext();
127 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
128 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
129 return !rObj->IsUndefined();
133 inline void SetR(
const std::string &key,
double val)
135 Nan::Set(r, Nan::New<String>(key).ToLocalChecked(), Nan::New<Number>(val));
142 v8::Isolate *isolate = v8::Isolate::GetCurrent();
143 v8::Local<v8::Context> context = isolate->GetCurrentContext();
144 Local<String> getName = Nan::New<String>(
"multimeterData").ToLocalChecked();
145 Local<Object> multimeterDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
146 if (multimeterDataV8->IsUndefined())
148 ThrowTypeError(std::string(
"ElectricityReduction: getMultimeterData method in calculator.h: multimeterData not present in object").c_str());
150 int numberOfPhases =
static_cast<int>(GetDouble(
"numberOfPhases", multimeterDataV8));
151 double supplyVoltage = GetDouble(
"supplyVoltage", multimeterDataV8);
152 double averageCurrent = GetDouble(
"averageCurrent", multimeterDataV8);
153 double powerFactor = GetDouble(
"powerFactor", multimeterDataV8);
163 v8::Isolate *isolate = v8::Isolate::GetCurrent();
164 v8::Local<v8::Context> context = isolate->GetCurrentContext();
165 Local<String> getName = Nan::New<String>(
"nameplateData").ToLocalChecked();
166 Local<Object> nameplateDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
167 if (nameplateDataV8->IsUndefined())
169 ThrowTypeError(std::string(
"ElectricityReduction: getNameplateData method in calculator.h: nameplateData not present in object").c_str());
171 double ratedMotorPower = GetDouble(
"ratedMotorPower", nameplateDataV8);
172 bool variableSpeedMotor = GetBool(
"variableSpeedMotor", nameplateDataV8);
173 double operationalFrequency = GetDouble(
"operationalFrequency", nameplateDataV8);
174 double lineFrequency = GetDouble(
"lineFrequency", nameplateDataV8);
175 double motorAndDriveEfficiency = GetDouble(
"motorAndDriveEfficiency", nameplateDataV8);
176 double loadFactor = GetDouble(
"loadFactor", nameplateDataV8);
180 operationalFrequency,
182 motorAndDriveEfficiency,
188 v8::Isolate *isolate = v8::Isolate::GetCurrent();
189 v8::Local<v8::Context> context = isolate->GetCurrentContext();
190 Local<String> getName = Nan::New<String>(
"powerMeterData").ToLocalChecked();
191 Local<Object> powerMeterDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
192 if (powerMeterDataV8->IsUndefined())
194 ThrowTypeError(std::string(
"ElectricityReduction: getPowerMeterData method in calculator.h: powerMeterData not present in object").c_str());
196 double power = GetDouble(
"power", powerMeterDataV8);
202 v8::Isolate *isolate = v8::Isolate::GetCurrent();
203 v8::Local<v8::Context> context = isolate->GetCurrentContext();
204 Local<String> getName = Nan::New<String>(
"otherMethodData").ToLocalChecked();
205 Local<Object> otherMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
206 if (otherMethodDataV8->IsUndefined())
208 ThrowTypeError(std::string(
"ElectricityReduction: getOtherMethodData method in calculator.h: otherMethodData not present in object").c_str());
210 double energy = GetDouble(
"energy", otherMethodDataV8);
216 int operatingHours =
static_cast<int>(GetDouble(
"operatingHours", obj));
217 double electricityCost = GetDouble(
"electricityCost", obj);
218 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
223 int units =
static_cast<int>(GetDouble(
"units", obj));
235 std::vector<ElectricityReductionInput> getElectricityReductionInputVec()
237 v8::Isolate *isolate = v8::Isolate::GetCurrent();
238 v8::Local<v8::Context> context = isolate->GetCurrentContext();
239 Local<String> getName = Nan::New<String>(
"electricityReductionInputVec").ToLocalChecked();
240 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
241 if (arrayTmp->IsUndefined())
243 ThrowTypeError(std::string(
"ElectricityReduction: getElectricityReductionInputVector method in calculator.h: electricityReductionInputVec not present in object").c_str());
245 Local<Array> electricityReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
246 std::vector<ElectricityReductionInput> inputVec;
247 for (std::size_t i = 0; i < electricityReductionInputArray->Length(); i++)
249 inputVec.emplace_back(constructElectricityReductionInput(Nan::To<Object>(electricityReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
254 NAN_METHOD(electricityReduction)
256 inp = Nan::To<Object>(info[0]).ToLocalChecked();
257 r = Nan::New<Object>();
260 std::vector<ElectricityReductionInput> inputVec = getElectricityReductionInputVec();
262 SetR(
"energyUse", rv.energyUse);
263 SetR(
"energyCost", rv.energyCost);
264 SetR(
"power", rv.power);
266 catch (std::runtime_error
const &e)
268 std::string
const what = e.what();
269 ThrowError(std::string(
"std::runtime_error thrown in electricityReduction - calculator.h: " + what).c_str());
271 info.GetReturnValue().Set(r);
279 v8::Isolate *isolate = v8::Isolate::GetCurrent();
280 v8::Local<v8::Context> context = isolate->GetCurrentContext();
281 Local<String> getName = Nan::New<String>(
"flowMeterMethodData").ToLocalChecked();
282 Local<Object> flowMeterMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
283 if (flowMeterMethodDataV8->IsUndefined())
285 ThrowTypeError(std::string(
"NaturalGasReduction: getFlowMeterMethodData method in calculator.h: flowMeterMethodData not present in object").c_str());
287 double flowRate = GetDouble(
"flowRate", flowMeterMethodDataV8);
293 v8::Isolate *isolate = v8::Isolate::GetCurrent();
294 v8::Local<v8::Context> context = isolate->GetCurrentContext();
295 Local<String> getName = Nan::New<String>(
"airMassFlowMeasuredData").ToLocalChecked();
296 Local<Object> airMassFlowMeasuredDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
297 if (airMassFlowMeasuredDataV8->IsUndefined())
299 ThrowTypeError(std::string(
"NaturalGasReduction: getAirMassFlowMeasuredData method in calculator.h: airMassFlowMeasuredData not present in object").c_str());
301 double areaOfDuct = GetDouble(
"areaOfDuct", airMassFlowMeasuredDataV8);
302 double airVelocity = GetDouble(
"airVelocity", airMassFlowMeasuredDataV8);
310 v8::Isolate *isolate = v8::Isolate::GetCurrent();
311 v8::Local<v8::Context> context = isolate->GetCurrentContext();
312 Local<String> getName = Nan::New<String>(
"airMassFlowNameplateData").ToLocalChecked();
313 Local<Object> airMassFlowNameplateDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
314 if (airMassFlowNameplateDataV8->IsUndefined())
316 ThrowTypeError(std::string(
"NaturalGasReduction: getAirMassFlowNameplateData method in calculator.h: airMassFlowNameplateData not present in object").c_str());
318 double airFlow = GetDouble(
"airFlow", airMassFlowNameplateDataV8);
325 v8::Isolate *isolate = v8::Isolate::GetCurrent();
326 v8::Local<v8::Context> context = isolate->GetCurrentContext();
327 Local<String> getName = Nan::New<String>(
"airMassFlowData").ToLocalChecked();
328 Local<Object> airMassFlowDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
329 if (airMassFlowDataV8->IsUndefined())
331 ThrowTypeError(std::string(
"NaturalGasReduction: getAirMassFlowData method in calculator.h: airMassFlowData not present in object").c_str());
333 bool isNameplate = GetBool(
"isNameplate", airMassFlowDataV8);
336 double inletTemperature = GetDouble(
"inletTemperature", airMassFlowDataV8);
337 double outletTemperature = GetDouble(
"outletTemperature", airMassFlowDataV8);
338 double systemEfficiency =
Conversion(GetDouble(
"systemEfficiency", airMassFlowDataV8)).percentToFraction();
350 v8::Isolate *isolate = v8::Isolate::GetCurrent();
351 v8::Local<v8::Context> context = isolate->GetCurrentContext();
352 Local<String> getName = Nan::New<String>(
"waterMassFlowData").ToLocalChecked();
353 Local<Object> waterMassFlowDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
354 if (waterMassFlowDataV8->IsUndefined())
356 ThrowTypeError(std::string(
"NaturalGasReduction: getWaterMassFlowData method in calculator.h: waterMassFlowData not present in object").c_str());
358 double waterFlow = GetDouble(
"waterFlow", waterMassFlowDataV8);
359 double inletTemperature = GetDouble(
"inletTemperature", waterMassFlowDataV8);
360 double outletTemperature = GetDouble(
"outletTemperature", waterMassFlowDataV8);
361 double systemEfficiency =
Conversion(GetDouble(
"systemEfficiency", waterMassFlowDataV8)).percentToFraction();
371 v8::Isolate *isolate = v8::Isolate::GetCurrent();
372 v8::Local<v8::Context> context = isolate->GetCurrentContext();
373 Local<String> getName = Nan::New<String>(
"otherMethodData").ToLocalChecked();
374 Local<Object> otherMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
375 if (otherMethodDataV8->IsUndefined())
377 ThrowTypeError(std::string(
"NaturalGasReduction: naturalGasGetOtherMethodData method in calculator.h: otherMethodData not present in object").c_str());
379 double consumption = GetDouble(
"consumption", otherMethodDataV8);
386 int operatingHours =
static_cast<int>(GetDouble(
"operatingHours", obj));
387 double fuelCost = GetDouble(
"fuelCost", obj);
388 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
393 int units =
static_cast<int>(GetDouble(
"units", obj));
405 std::vector<NaturalGasReductionInput> getNaturalGasReductionInputVec()
407 v8::Isolate *isolate = v8::Isolate::GetCurrent();
408 v8::Local<v8::Context> context = isolate->GetCurrentContext();
409 Local<String> getName = Nan::New<String>(
"naturalGasReductionInputVec").ToLocalChecked();
410 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
411 if (arrayTmp->IsUndefined())
413 ThrowTypeError(std::string(
"NaturalGasReduction: getNaturalGasReductionInputVector method in calculator.h: naturalGasReductionInputVec not present in object").c_str());
415 Local<Array> naturalGasReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
416 std::vector<NaturalGasReductionInput> inputVec;
417 for (std::size_t i = 0; i < naturalGasReductionInputArray->Length(); i++)
419 inputVec.emplace_back(constructNaturalGasReductionInput(Nan::To<Object>(naturalGasReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
424 NAN_METHOD(naturalGasReduction)
426 inp = Nan::To<Object>(info[0]).ToLocalChecked();
427 r = Nan::New<Object>();
430 std::vector<NaturalGasReductionInput> inputVec = getNaturalGasReductionInputVec();
432 SetR(
"energyUse", rv.energyUse);
433 SetR(
"energyCost", rv.energyCost);
434 SetR(
"heatFlow", rv.heatFlow);
435 SetR(
"totalFlow", rv.totalFlow);
437 catch (std::runtime_error
const &e)
439 std::string
const what = e.what();
440 ThrowError(std::string(
"std::runtime_error thrown in naturalGasReduction - calculator.h: " + what).c_str());
442 info.GetReturnValue().Set(r);
450 v8::Isolate *isolate = v8::Isolate::GetCurrent();
451 v8::Local<v8::Context> context = isolate->GetCurrentContext();
452 Local<String> getName = Nan::New<String>(
"flowMeterMethodData").ToLocalChecked();
453 Local<Object> flowMeterMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
454 if (flowMeterMethodDataV8->IsUndefined())
456 ThrowTypeError(std::string(
"CompressedAirReduction: getCompressedAirFlowMeterMethodData method in calculator.h: flowMeterMethodData not present in object").c_str());
458 double meterReading = GetDouble(
"meterReading", flowMeterMethodDataV8);
459 return {meterReading};
464 v8::Isolate *isolate = v8::Isolate::GetCurrent();
465 v8::Local<v8::Context> context = isolate->GetCurrentContext();
466 Local<String> getName = Nan::New<String>(
"bagMethodData").ToLocalChecked();
467 Local<Object> bagMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
468 if (bagMethodDataV8->IsUndefined())
470 ThrowTypeError(std::string(
"CompressedAirReduction: getBagMethodData method in calculator.h: bagMethodData not present in object").c_str());
472 double height = GetDouble(
"height", bagMethodDataV8);
473 double diameter = GetDouble(
"diameter", bagMethodDataV8);
474 double fillTime = GetDouble(
"fillTime", bagMethodDataV8);
483 v8::Isolate *isolate = v8::Isolate::GetCurrent();
484 v8::Local<v8::Context> context = isolate->GetCurrentContext();
485 Local<String> getName = Nan::New<String>(
"pressureMethodData").ToLocalChecked();
486 Local<Object> pressureMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
487 if (pressureMethodDataV8->IsUndefined())
489 ThrowTypeError(std::string(
"CompressedAirReduction: getPressureMethodData method in calculator.h: pressureMethodData not present in object").c_str());
491 int nozzleType =
static_cast<int>(GetDouble(
"nozzleType", pressureMethodDataV8));
492 int numberOfNozzles =
static_cast<int>(GetDouble(
"numberOfNozzles", pressureMethodDataV8));
493 double supplyPressure = GetDouble(
"supplyPressure", pressureMethodDataV8);
502 v8::Isolate *isolate = v8::Isolate::GetCurrent();
503 v8::Local<v8::Context> context = isolate->GetCurrentContext();
504 Local<String> getName = Nan::New<String>(
"otherMethodData").ToLocalChecked();
505 Local<Object> otherMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
506 if (otherMethodDataV8->IsUndefined())
508 ThrowTypeError(std::string(
"CompressedAirReduction: getCompressedAirOtherMethodData method in calculator.h: otherMethodData not present in object").c_str());
510 double consumption = GetDouble(
"consumption", otherMethodDataV8);
511 return {consumption};
516 v8::Isolate *isolate = v8::Isolate::GetCurrent();
517 v8::Local<v8::Context> context = isolate->GetCurrentContext();
518 Local<String> getName = Nan::New<String>(
"compressorElectricityData").ToLocalChecked();
519 Local<Object> compressorElectricityDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
520 if (compressorElectricityDataV8->IsUndefined())
522 ThrowTypeError(std::string(
"CompressedAirReduction: getCompressorElectricityData method in calculator.h: compressorElectricityData not present in object").c_str());
524 double compressorControlAdjustment;
527 compressorControlAdjustment =
Conversion(GetDouble(
"compressorControlAdjustment", compressorElectricityDataV8)).percentToFraction();
531 compressorControlAdjustment = GetDouble(
"compressorControlAdjustment", compressorElectricityDataV8);
533 double compressorSpecificPower = GetDouble(
"compressorSpecificPower", compressorElectricityDataV8);
535 compressorControlAdjustment,
536 compressorSpecificPower};
541 int hoursPerYear =
static_cast<int>(GetDouble(
"hoursPerYear", obj));
542 int utilityType =
static_cast<int>(GetDouble(
"utilityType", obj));
543 double utilityCost = GetDouble(
"utilityCost", obj);
544 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
550 int units =
static_cast<int>(GetDouble(
"units", obj));
564 std::vector<CompressedAirReductionInput> getCompressedAirReductionInputVec()
566 v8::Isolate *isolate = v8::Isolate::GetCurrent();
567 v8::Local<v8::Context> context = isolate->GetCurrentContext();
568 Local<String> getName = Nan::New<String>(
"compressedAirReductionInputVec").ToLocalChecked();
569 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
570 if (arrayTmp->IsUndefined())
572 ThrowTypeError(std::string(
"CompressedAirReduction: getCompressedAirReductionInputVec method in calculator.h: compressedAirReductionInputVec not present in object").c_str());
574 Local<Array> compressedAirReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
575 std::vector<CompressedAirReductionInput> inputVec;
576 for (std::size_t i = 0; i < compressedAirReductionInputArray->Length(); i++)
578 inputVec.emplace_back(constructCompressedAirReductionInput(Nan::To<Object>(compressedAirReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
583 NAN_METHOD(compressedAirReduction)
585 inp = Nan::To<Object>(info[0]).ToLocalChecked();
586 r = Nan::New<Object>();
589 std::vector<CompressedAirReductionInput> inputVec = getCompressedAirReductionInputVec();
591 SetR(
"energyUse", rv.energyUse);
592 SetR(
"energyCost", rv.energyCost);
593 SetR(
"flowRate", rv.flowRate);
594 SetR(
"singleNozzleFlowRate", rv.singleNozzleFlowRate);
595 SetR(
"consumption", rv.consumption);
597 catch (std::runtime_error
const &e)
599 std::string
const what = e.what();
600 ThrowError(std::string(
"std::runtime_error thrown in compressedAirReduction - calculator.h: " + what).c_str());
602 info.GetReturnValue().Set(r);
611 v8::Isolate *isolate = v8::Isolate::GetCurrent();
612 v8::Local<v8::Context> context = isolate->GetCurrentContext();
613 Local<String> getName = Nan::New<String>(
"estimateMethodData").ToLocalChecked();
614 Local<Object> estimateMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
615 if (estimateMethodDataV8->IsUndefined())
617 ThrowTypeError(std::string(
"CompressedAirReduction: getEstimateMethodData method in calculator.h: estimateMethodData not present in object").c_str());
619 double leakRateEstimate = GetDouble(
"leakRateEstimate", estimateMethodDataV8);
626 v8::Isolate *isolate = v8::Isolate::GetCurrent();
627 v8::Local<v8::Context> context = isolate->GetCurrentContext();
628 Local<String> getName = Nan::New<String>(
"decibelsMethodData").ToLocalChecked();
629 Local<Object> decibelsMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
630 if (decibelsMethodDataV8->IsUndefined())
632 ThrowTypeError(std::string(
"CompressedAirReduction: getDecibelsMethodData method in calculator.h: decibelsMethodData not present in object").c_str());
634 double linePressure = GetDouble(
"linePressure", decibelsMethodDataV8);
635 double decibels = GetDouble(
"decibels", decibelsMethodDataV8);
636 double decibelRatingA = GetDouble(
"decibelRatingA", decibelsMethodDataV8);
637 double pressureA = GetDouble(
"pressureA", decibelsMethodDataV8);
638 double firstFlowA = GetDouble(
"firstFlowA", decibelsMethodDataV8);
639 double secondFlowA = GetDouble(
"secondFlowA", decibelsMethodDataV8);
640 double decibelRatingB = GetDouble(
"decibelRatingB", decibelsMethodDataV8);
641 double pressureB = GetDouble(
"pressureB", decibelsMethodDataV8);
642 double firstFlowB = GetDouble(
"firstFlowB", decibelsMethodDataV8);
643 double secondFlowB = GetDouble(
"secondFlowB", decibelsMethodDataV8);
659 v8::Isolate *isolate = v8::Isolate::GetCurrent();
660 v8::Local<v8::Context> context = isolate->GetCurrentContext();
661 Local<String> getName = Nan::New<String>(
"orificeMethodData").ToLocalChecked();
662 Local<Object> orificeMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
663 if (orificeMethodDataV8->IsUndefined())
665 ThrowTypeError(std::string(
"CompressedAirReduction: getOrificeMethodData method in calculator.h: orificeMethodData not present in object").c_str());
667 double airTemp = GetDouble(
"compressorAirTemp", orificeMethodDataV8);
668 double atmPressure = GetDouble(
"atmosphericPressure", orificeMethodDataV8);
669 double dischargeCoef = GetDouble(
"dischargeCoefficient", orificeMethodDataV8);
670 double diameter = GetDouble(
"orificeDiameter", orificeMethodDataV8);
671 double supplyPressure = GetDouble(
"supplyPressure", orificeMethodDataV8);
672 int numOrifices =
static_cast<int>(GetDouble(
"numberOfOrifices", orificeMethodDataV8));
684 int hoursPerYear =
static_cast<int>(GetDouble(
"hoursPerYear", obj));
685 int utilityType =
static_cast<int>(GetDouble(
"utilityType", obj));
686 double utilityCost = GetDouble(
"utilityCost", obj);
687 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
693 int units =
static_cast<int>(GetDouble(
"units", obj));
707 std::vector<CompressedAirLeakSurveyInput> getCompressedAirLeakSurveyInputVec()
709 v8::Isolate *isolate = v8::Isolate::GetCurrent();
710 v8::Local<v8::Context> context = isolate->GetCurrentContext();
711 Local<String> getName = Nan::New<String>(
"compressedAirLeakSurveyInputVec").ToLocalChecked();
712 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
713 if (arrayTmp->IsUndefined())
715 ThrowTypeError(std::string(
"CompressedAirLeakSurvey: getCompressedAirLeakSurveyInputVec method in calculator.h: compressedAirLeakSurveyInputVec not present in object").c_str());
717 Local<Array> compressedAirLeakSurveyInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
718 std::vector<CompressedAirLeakSurveyInput> inputVec;
719 for (std::size_t i = 0; i < compressedAirLeakSurveyInputArray->Length(); i++)
721 inputVec.emplace_back(constructCompressedAirLeakSurveyInput(Nan::To<Object>(compressedAirLeakSurveyInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
726 NAN_METHOD(compressedAirLeakSurvey)
728 inp = Nan::To<Object>(info[0]).ToLocalChecked();
729 r = Nan::New<Object>();
732 std::vector<CompressedAirLeakSurveyInput> inputVec = getCompressedAirLeakSurveyInputVec();
734 SetR(
"annualTotalElectricity", rv.annualTotalElectricity);
735 SetR(
"annualTotalElectricityCost", rv.annualTotalElectricityCost);
736 SetR(
"totalFlowRate", rv.totalFlowRate);
737 SetR(
"annualTotalFlowRate", rv.annualTotalFlowRate);
739 catch (std::runtime_error
const &e)
741 std::string
const what = e.what();
742 ThrowError(std::string(
"std::runtime_error thrown in compressedAirLeakSurvey - calculator.h: " + what).c_str());
744 info.GetReturnValue().Set(r);
753 v8::Isolate *isolate = v8::Isolate::GetCurrent();
754 v8::Local<v8::Context> context = isolate->GetCurrentContext();
755 Local<String> getName = Nan::New<String>(
"meteredFlowMethodData").ToLocalChecked();
756 Local<Object> meteredFlowMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
757 if (meteredFlowMethodDataV8->IsUndefined())
759 ThrowTypeError(std::string(
"WaterReduction: getMeteredFlowMethodData method in calculator.h: meteredFlowMethodData not present in object").c_str());
761 double meterReading = GetDouble(
"meterReading", meteredFlowMethodDataV8);
762 return {meterReading};
767 v8::Isolate *isolate = v8::Isolate::GetCurrent();
768 v8::Local<v8::Context> context = isolate->GetCurrentContext();
769 Local<String> getName = Nan::New<String>(
"volumeMeterMethodData").ToLocalChecked();
770 Local<Object> volumeMeterMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
771 if (volumeMeterMethodDataV8->IsUndefined())
773 ThrowTypeError(std::string(
"WaterReduction: getVolumeMeterMethodData method in calculator.h: volumeMeterMethodData not present in object").c_str());
775 double finalMeterReading = GetDouble(
"finalMeterReading", volumeMeterMethodDataV8);
776 double initialMeterReading = GetDouble(
"initialMeterReading", volumeMeterMethodDataV8);
777 double elapsedTime = GetDouble(
"elapsedTime", volumeMeterMethodDataV8);
786 v8::Isolate *isolate = v8::Isolate::GetCurrent();
787 v8::Local<v8::Context> context = isolate->GetCurrentContext();
788 Local<String> getName = Nan::New<String>(
"bucketMethodData").ToLocalChecked();
789 Local<Object> bucketMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
790 if (bucketMethodDataV8->IsUndefined())
792 ThrowTypeError(std::string(
"WaterReduction: getBucketMethodData method in calculator.h: bucketMethodData not present in object").c_str());
794 double bucketVolume = GetDouble(
"bucketVolume", bucketMethodDataV8);
795 double bucketFillTime = GetDouble(
"bucketFillTime", bucketMethodDataV8);
803 v8::Isolate *isolate = v8::Isolate::GetCurrent();
804 v8::Local<v8::Context> context = isolate->GetCurrentContext();
805 Local<String> getName = Nan::New<String>(
"otherMethodData").ToLocalChecked();
806 Local<Object> otherMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
807 if (otherMethodDataV8->IsUndefined())
809 ThrowTypeError(std::string(
"WaterReduction: getWaterOtherMethodData method in calculator.h: otherMethodData not present in object").c_str());
811 double consumption = GetDouble(
"consumption", otherMethodDataV8);
818 int hoursPerYear =
static_cast<int>(GetDouble(
"hoursPerYear", obj));
819 double waterCost = GetDouble(
"waterCost", obj);
820 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
829 meteredFlowMethodData,
830 volumeMeterMethodData,
835 std::vector<WaterReductionInput> getWaterReductionInputVec()
837 v8::Isolate *isolate = v8::Isolate::GetCurrent();
838 v8::Local<v8::Context> context = isolate->GetCurrentContext();
839 Local<String> getName = Nan::New<String>(
"waterReductionInputVec").ToLocalChecked();
840 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
841 if (arrayTmp->IsUndefined())
843 ThrowTypeError(std::string(
"WaterReduction: getWaterReductionInputVec method in calculator.h: waterReductionInputVec not present in object").c_str());
845 Local<Array> waterReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
846 std::vector<WaterReductionInput> inputVec;
847 for (std::size_t i = 0; i < waterReductionInputArray->Length(); i++)
849 inputVec.emplace_back(constructWaterReductionInput(Nan::To<Object>(waterReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
854 NAN_METHOD(waterReduction)
856 inp = Nan::To<Object>(info[0]).ToLocalChecked();
857 r = Nan::New<Object>();
860 std::vector<WaterReductionInput> inputVec = getWaterReductionInputVec();
862 SetR(
"waterUse", rv.waterUse);
863 SetR(
"waterCost", rv.waterCost);
865 catch (std::runtime_error
const &e)
867 std::string
const what = e.what();
868 ThrowError(std::string(
"std::runtime_error thrown in waterReduction - calculator.h: " + what).c_str());
870 info.GetReturnValue().Set(r);
878 bool isBaseline = GetBool(
"isBaseline", obj);
879 int hoursPerYear =
static_cast<int>(GetDouble(
"hoursPerYear", obj));
880 double electricityCost = GetDouble(
"electricityCost", obj);
881 double compressorPower = GetDouble(
"compressorPower", obj);
882 double pressure = GetDouble(
"pressure", obj);
883 double proposedPressure = GetDouble(
"proposedPressure", obj);
893 std::vector<CompressedAirPressureReductionInput> getCompressedAirPressureReductionInputVec()
895 v8::Isolate *isolate = v8::Isolate::GetCurrent();
896 v8::Local<v8::Context> context = isolate->GetCurrentContext();
897 Local<String> getName = Nan::New<String>(
"compressedAirPressureReductionInputVec").ToLocalChecked();
898 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
899 if (arrayTmp->IsUndefined())
901 ThrowTypeError(std::string(
"CompressedAirPressureReduction: getCompressedAirPressureReductionInputVec method in calculator.h: compressedAirPressureReductionInputVec not present in object").c_str());
903 Local<Array> compressedAirPressureReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
904 std::vector<CompressedAirPressureReductionInput> inputVec;
905 for (std::size_t i = 0; i < compressedAirPressureReductionInputArray->Length(); i++)
907 inputVec.emplace_back(constructCompressedAirPressureReductionInput(Nan::To<Object>(compressedAirPressureReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
912 NAN_METHOD(compressedAirPressureReduction)
914 inp = Nan::To<Object>(info[0]).ToLocalChecked();
915 r = Nan::New<Object>();
918 std::vector<CompressedAirPressureReductionInput> inputVec = getCompressedAirPressureReductionInputVec();
920 SetR(
"energyUse", rv.energyUse);
921 SetR(
"energyCost", rv.energyCost);
923 catch (std::runtime_error
const &e)
925 std::string
const what = e.what();
926 ThrowError(std::string(
"std::runtime_error thrown in compressedAirPressureReduction - calculator.h: " + what).c_str());
928 info.GetReturnValue().Set(r);
933 NAN_METHOD(pipeInsulationReduction)
935 inp = Nan::To<Object>(info[0]).ToLocalChecked();
936 r = Nan::New<Object>();
938 int operatingHours =
static_cast<int>(GetDouble(
"operatingHours", inp));
939 double pipeLength = GetDouble(
"pipeLength", inp);
940 double pipeDiameter = GetDouble(
"pipeDiameter", inp);
941 double pipeThickness = GetDouble(
"pipeThickness", inp);
942 double pipeTemperature = GetDouble(
"pipeTemperature", inp);
943 double ambientTemperature = GetDouble(
"ambientTemperature", inp);
944 double windVelocity = GetDouble(
"windVelocity", inp);
945 double systemEfficiency =
Conversion(GetDouble(
"systemEfficiency", inp)).percentToFraction();
946 double insulationThickness = GetDouble(
"insulationThickness", inp);
947 double pipeEmissivity = GetDouble(
"pipeEmissivity", inp);
948 double jacketEmissivity = GetDouble(
"jacketEmissivity", inp);
949 std::vector<double> pipeMaterialCoefficients = GetVector(
"pipeMaterialCoefficients", inp);
950 std::vector<double> insulationMaterialCoefficients = GetVector(
"insulationMaterialCoefficients", inp);
964 pipeMaterialCoefficients,
965 insulationMaterialCoefficients);
969 SetR(
"heatLength", output.getHeatLength());
970 SetR(
"annualHeatLoss", output.getAnnualHeatLoss());
971 info.GetReturnValue().Set(r);
976 NAN_METHOD(tankInsulationReduction)
978 inp = Nan::To<Object>(info[0]).ToLocalChecked();
979 r = Nan::New<Object>();
981 int operatingHours =
static_cast<int>(GetDouble(
"operatingHours", inp));
982 double tankHeight = GetDouble(
"tankHeight", inp);
983 double tankDiameter = GetDouble(
"tankDiameter", inp);
984 double tankThickness = GetDouble(
"tankThickness", inp);
985 double tankEmissivity = GetDouble(
"tankEmissivity", inp);
986 double tankConductivity = GetDouble(
"tankConductivity", inp);
987 double tankTemperature = GetDouble(
"tankTemperature", inp);
988 double ambientTemperature = GetDouble(
"ambientTemperature", inp);
989 double systemEfficiency =
Conversion(GetDouble(
"systemEfficiency", inp)).percentToFraction();
990 double insulationThickness = GetDouble(
"insulationThickness", inp);
991 double insulationConductivity = GetDouble(
"insulationConductivity", inp);
992 double jacketEmissivity = GetDouble(
"jacketEmissivity", inp);
1004 insulationThickness,
1005 insulationConductivity,
1010 SetR(
"heatLoss", output.getHeatLoss());
1011 SetR(
"annualHeatLoss", output.getAnnualHeatLoss());
1012 info.GetReturnValue().Set(r);
1019 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1020 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1021 Local<String> getName = Nan::New<String>(
"flowMeterMethodData").ToLocalChecked();
1022 Local<Object> flowMeterMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1023 if (flowMeterMethodDataV8->IsUndefined())
1025 ThrowTypeError(std::string(
"SteamReduction: getSteamFlowMeterMethodData method in calculator.h: flowMeterMethodData not present in object").c_str());
1027 double flowRate = GetDouble(
"flowRate", flowMeterMethodDataV8);
1033 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1034 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1035 Local<String> getName = Nan::New<String>(
"massFlowMeasuredData").ToLocalChecked();
1036 Local<Object> massFlowMeasuredDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1037 if (massFlowMeasuredDataV8->IsUndefined())
1039 ThrowTypeError(std::string(
"SteamReduction: getSteamMassFlowMeasuredData method in calculator.h: massFlowMeasuredData not present in object").c_str());
1041 double areaOfDuct = GetDouble(
"areaOfDuct", massFlowMeasuredDataV8);
1042 double airVelocity = GetDouble(
"airVelocity", massFlowMeasuredDataV8);
1050 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1051 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1052 Local<String> getName = Nan::New<String>(
"massFlowNameplateData").ToLocalChecked();
1053 Local<Object> massFlowNameplateDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1054 if (massFlowNameplateDataV8->IsUndefined())
1056 ThrowTypeError(std::string(
"SteamReduction: getSteamMassFlowNameplateData method in calculator.h: massFlowNameplateData not present in object").c_str());
1058 double flowRate = GetDouble(
"flowRate", massFlowNameplateDataV8);
1064 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1065 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1066 Local<String> getName = Nan::New<String>(
"airMassFlowMethodData").ToLocalChecked();
1067 Local<Object> massFlowMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1068 if (massFlowMethodDataV8->IsUndefined())
1070 ThrowTypeError(std::string(
"SteamReduction: getSteamAirMassFlowMethodData method in calculator.h: airMassFlowMethodData not present in object").c_str());
1072 bool isNameplate = GetBool(
"isNameplate", massFlowMethodDataV8);
1075 double inletTemperature = GetDouble(
"inletTemperature", massFlowMethodDataV8);
1076 double outletTemperature = GetDouble(
"outletTemperature", massFlowMethodDataV8);
1087 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1088 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1089 Local<String> getName = Nan::New<String>(
"waterMassFlowMethodData").ToLocalChecked();
1090 Local<Object> massFlowMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1091 if (massFlowMethodDataV8->IsUndefined())
1093 ThrowTypeError(std::string(
"SteamReduction: getSteamWaterMassFlowMethodData method in calculator.h: waterMassFlowMethodData not present in object").c_str());
1095 bool isNameplate = GetBool(
"isNameplate", massFlowMethodDataV8);
1098 double inletTemperature = GetDouble(
"inletTemperature", massFlowMethodDataV8);
1099 double outletTemperature = GetDouble(
"outletTemperature", massFlowMethodDataV8);
1110 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1111 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1112 Local<String> getName = Nan::New<String>(
"otherMethodData").ToLocalChecked();
1113 Local<Object> otherMethodDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
1114 if (otherMethodDataV8->IsUndefined())
1116 ThrowTypeError(std::string(
"SteamReduction: getSteamOtherMethodData method in calculator.h: otherMethodData not present in object").c_str());
1118 double consumption = GetDouble(
"consumption", otherMethodDataV8);
1119 return {consumption};
1124 int hoursPerYear =
static_cast<int>(GetDouble(
"hoursPerYear", obj));
1125 int utilityType =
static_cast<int>(GetDouble(
"utilityType", obj));
1126 double utilityCost = GetDouble(
"utilityCost", obj);
1127 int measurementMethod =
static_cast<int>(GetDouble(
"measurementMethod", obj));
1128 double systemEfficiency =
Conversion(GetDouble(
"systemEfficiency", obj)).percentToFraction();
1129 double pressure = GetDouble(
"pressure", obj);
1134 int units =
static_cast<int>(GetDouble(
"units", obj));
1142 steamFlowMeterMethodData,
1143 steamAirMassFlowMethodData,
1144 steamWaterMassFlowMethodData,
1149 std::vector<SteamReductionInput> getSteamReductionInputVec()
1151 v8::Isolate *isolate = v8::Isolate::GetCurrent();
1152 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1153 Local<String> getName = Nan::New<String>(
"steamReductionInputVec").ToLocalChecked();
1154 Local<Value> arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
1155 if (arrayTmp->IsUndefined())
1157 ThrowTypeError(std::string(
"SteamReduction: getSteamReductionInputVec method in calculator.h: steamReductionInputVec not present in object").c_str());
1159 Local<Array> steamReductionInputArray = v8::Local<v8::Array>::Cast(arrayTmp);
1160 std::vector<SteamReductionInput> inputVec;
1161 for (std::size_t i = 0; i < steamReductionInputArray->Length(); i++)
1163 inputVec.emplace_back(constructSteamReductionInput(Nan::To<Object>(steamReductionInputArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
1168 NAN_METHOD(steamReduction)
1170 inp = Nan::To<Object>(info[0]).ToLocalChecked();
1171 r = Nan::New<Object>();
1174 std::vector<SteamReductionInput> inputVec = getSteamReductionInputVec();
1176 SetR(
"steamUse", rv.steamUse);
1177 SetR(
"energyUse", rv.energyUse);
1178 SetR(
"energyCost", rv.energyCost);
1180 catch (std::runtime_error
const &e)
1182 std::string
const what = e.what();
1183 ThrowError(std::string(
"std::runtime_error thrown in steamReduction - calculator.h: " + what).c_str());
1185 info.GetReturnValue().Set(r);