Join (at least) 2 Property History Infotables by Timestamp
Hi,
So I have a mashup which selects a number of properties for a thing. It then loops through each of these properties and Queries the property history. The goal is to take each history infotable and add it to an overall history table with all of the properties and timestamps. The following tables may give more of an idea:
table1 - overall table (starts without any values)
| timestamp | Property1 |
table2 - property1 history table
| timestamp | Property1 |
| 1 | x |
| 2 | y |
So after the first iteration table1 will look the same as table2. For the second iteration/property the overall table should become:
| timestamp | Property1 | Property2 |
| 1 | x | |
| 2 | y |
Table3 - property2 history table
| timestamp | Property2 |
| 1 | z |
| 3 | x |
After joining the overall table to the second property table, it should become:
| timestamp | Property1 | Property2 |
| 1 | x | z |
| 2 | y | - |
| 3 | - | x |
The method for this should work for any number of properties. I tried using a full join then a distinct but the tables just returned empty after the join.
Here is essentially what I have currently (doesn't work). Note that there may be a completely different method to reaching that final overall table.
var params = {
infoTableName : "InfoTable",
dataShapeName : "Reports_OverallHistory_datashape"
};
//CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Reports_OverallHistory_datashape)
var allHistory = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var length = joinedPropertiesTable.rows.length;
for (var i = 0; i < length; i++){
var property = joinedPropertiesTable.rows[i];
var params = {
name: property.name /* STRING */
};
// result: INFOTABLE dataShape: PropertyDefinition
var singlePropTable = Things[asset].GetPropertyDefinition(params);
var params = {
oldestFirst: oldestFirst /* BOOLEAN */,
maxItems: maxHis /* NUMBER */,
endDate: endDate /* DATETIME */,
propertyNames: singlePropTable /* INFOTABLE */,
query: undefined /* QUERY */,
startDate: startDate /* DATETIME */
};
//Get Property History for selected assets
// result: INFOTABLE
var singlePropertyHistory = Things[asset].QueryNamedPropertyHistory(params);
var newField = new Object();
newField.name = property.name;
newField.baseType = singlePropTable.baseType;
allHistory.AddField(newField);
var params = {
columns2: "*" /* STRING */,
columns1: "*" /* STRING */,
joinType: "FULL" /* STRING */,
t1: allHistory /* INFOTABLE */,
t2: singlePropertyHistory /* INFOTABLE */,
joinColumns1: "timestamp" /* STRING */,
joinColumns2: "timestamp" /* STRING */
};
// result: INFOTABLE
allHistory = Resources["InfoTableFunctions"].Intersect(params);
}
var result = allHistory;
The reason I don't simply query property history with multiple properties all at once, is because I want the exact timestamps for each property and not the value at a time which wasn't logged for one property but was the other.

