use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method generateSensorValueUnit.
private List<ValueUnit> generateSensorValueUnit(Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap, long starttime, int duration, Map<String, String> locationAndIdMap, String metricName) {
List<ValueUnit> valueunits = new ArrayList<>();
for (Map.Entry<String, String> locationInfoAndId : locationAndIdMap.entrySet()) {
String formula = locationInfoAndId.getValue();
String location = locationInfoAndId.getKey();
String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
for (String assetId : ids) {
List<RealTimeData> realtimeDatas = null;
if (!assetIdAndRealtimeDataMap.containsKey(assetId)) {
realtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetId, starttime, duration);
assetIdAndRealtimeDataMap.put(assetId, realtimeDatas);
}
realtimeDatas = assetIdAndRealtimeDataMap.get(assetId);
if (realtimeDatas == null || realtimeDatas.isEmpty()) {
continue;
}
RealTimeData realTimeData = findLatestData(realtimeDatas);
for (ValueUnit value : realTimeData.getValues()) {
if (value.getKey().equals(metricNameMap.get(metricName))) {
if (location.indexOf(FlowgateConstant.SEPARATOR) > -1) {
location = location.replace(FlowgateConstant.SEPARATOR, FlowgateConstant.UNDERLINE);
}
value.setExtraidentifier(location);
valueunits.add(value);
}
}
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method generateOtherMetricData.
private List<MetricData> generateOtherMetricData(List<ValueUnit> valueUnits) {
List<MetricData> result = new ArrayList<>();
if (valueUnits == null || valueUnits.isEmpty()) {
return result;
}
MetricData data;
for (ValueUnit value : valueUnits) {
data = new MetricData();
data.setTimeStamp(value.getTime());
data.setValueNum(value.getValueNum());
data.setValue(value.getValue());
data.setMetricName(value.getKey());
String unit = databaseUnitAndOutputUnitMap.get(value.getUnit());
if (unit == null) {
unit = value.getUnit();
}
data.setUnit(unit);
result.add(data);
}
return result;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method translateToMetricDataForOtherAsset.
private List<MetricData> translateToMetricDataForOtherAsset(Map<String, List<ValueUnit>> assetAndValueUnitsMap, Asset asset) {
List<MetricData> metricDatas = new ArrayList<MetricData>();
Map<String, Map<String, String>> displayNameAndFormulasMap = getMetricDispalyNameAndFormulaMap(asset);
if (displayNameAndFormulasMap.isEmpty() || !displayNameAndFormulasMap.containsKey(DISPLAYNAMEANDFORMULANAMEMAPKEY)) {
return metricDatas;
}
// The displayNameAndFormulaKeyMap use to find a method to translate the valueUnit to MetricData
Map<String, String> displayNameAndFormulaKeyMap = displayNameAndFormulasMap.get(DISPLAYNAMEANDFORMULANAMEMAPKEY);
displayNameAndFormulasMap.remove(DISPLAYNAMEANDFORMULANAMEMAPKEY);
CompareValueUnitByTime comparator = new CompareValueUnitByTime();
for (Map.Entry<String, Map<String, String>> entry : displayNameAndFormulasMap.entrySet()) {
String displayName = entry.getKey();
Map<String, String> formulaMap = entry.getValue();
for (Map.Entry<String, String> formulaEntry : formulaMap.entrySet()) {
String valueUnitName = formulaEntry.getKey();
String formula = formulaEntry.getValue();
String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
Map<String, List<ValueUnit>> idAndValues = new HashMap<>();
for (String id : ids) {
List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
for (ValueUnit valueUnit : assetAndValueUnitsMap.get(id)) {
if (!valueUnitName.equals(valueUnit.getKey())) {
continue;
}
valueUnits.add(valueUnit);
}
if (valueUnits.isEmpty()) {
continue;
}
Collections.sort(valueUnits, comparator);
idAndValues.put(id, valueUnits);
}
if (idAndValues.isEmpty()) {
continue;
}
Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
String formulaKey = displayNameAndFormulaKeyMap.get(displayName);
if (TranslateFunctionService.defaultFormulaKeyAndFunction.containsKey(formulaKey)) {
function = TranslateFunctionService.defaultFormulaKeyAndFunction.get(formulaKey);
}
metricDatas.addAll(convertValueUnitToMetricData(displayName, function, formula, idAndValues));
}
}
return metricDatas;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method getValueUnits.
private List<ValueUnit> getValueUnits(List<RealTimeData> realtimeDatas, List<String> metricsName) {
List<ValueUnit> valueunits = new ArrayList<>();
if (realtimeDatas == null || realtimeDatas.isEmpty()) {
return valueunits;
}
RealTimeData realTimeData = findLatestData(realtimeDatas);
for (ValueUnit value : realTimeData.getValues()) {
if (metricsName.contains(value.getKey())) {
valueunits.add(value);
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method convertValueUnitToMetricData.
/**
* Sample of TranslateContext
* {
* DisplayName:"Temperature|%S",
* Formulas:"23551d6dacf2432c8a3edbc6bbc922cd + 123456",
* valueData:[{id,valueUnit}]
* }
* One displayName may correspond to one or multiple values
* When the API of get-latest-data use the method, One MetricName correspond one value
* When the API of get-duration-data use the method, One MetricName correspond multiple values
* @param displayName
* @param formula
* @param idAndValues
* @return
*/
private List<MetricData> convertValueUnitToMetricData(String displayName, Function<TranslateContext, MetricData> function, String formula, Map<String, List<ValueUnit>> idAndValues) {
List<ValueUnit> valueUnits = idAndValues.get(idAndValues.keySet().iterator().next());
Map<String, ValueUnit> idAndValueUnitMap = null;
// Assuming the collection length is the same
List<MetricData> metricDatas = new ArrayList<MetricData>();
for (int i = 0; i < valueUnits.size(); i++) {
// Sample data: <id1, valueUnit1>,<id2, valueUnit1>
idAndValueUnitMap = new HashMap<String, ValueUnit>();
TranslateContext translateContext = new TranslateContext();
for (Map.Entry<String, List<ValueUnit>> valuesEntry : idAndValues.entrySet()) {
String id = valuesEntry.getKey();
ValueUnit value = valuesEntry.getValue().get(i);
idAndValueUnitMap.put(id, value);
}
translateContext.setDisplayName(displayName);
translateContext.setFormula(formula);
translateContext.setValueUnits(idAndValueUnitMap);
MetricData metricData = function.apply(translateContext);
if (metricData != null) {
metricDatas.add(metricData);
}
}
return metricDatas;
}
Aggregations