iTwin.js
Published in

iTwin.js

A Methodology to Build a Versatile iModel.js Application

By Zachary Zhu

Introduction

  1. What inspired me to create this methodology
  2. Potential problems with the current system
  3. Use a tree data structure to illustrate the power of this methodology
  4. Build a data-driven and interactive system from the ground up
  5. Further discussion
  6. Notes

Stretching the idea of Digital Twin

Problems of working solely with iModel(s)

Problems of representing external data

Key Terms

  • EC instance ID to Matching Key
  • Matching Key to EC instance ID
  • Matching Key to Data Object

The Fundamentals

Relationships:

Messaging:

  1. Propagation: A signal can be propagated from any tree node to its descendants and trigger them to call an inherited function until the bottom of the tree is reached. For example, if all three of our Data Objects need to call different API endpoints to update their data and the data of an entire building need to be updated, a way to implement this is by creating a generic update function that is inherited by all Data Objects classes, and override it with a specific implementation in these Data Object classes. Then, one can create another propagating function (also inherited by all Data Object) that not only calls the update function of the Data Object but its direct children, which then call the propagating function on their children… Eventually, the entire subtree including the starting node would update itself entirely. By calling an update function on a BuildingDataObject, all of the FloorDataObjects and RoomDataObjects would be consequently updated from their data source. Note that an update function is only an example. My implementation of the example above. Various other interesting functions could be implemented such as a delete function that truncates the whole subtree.
  2. Aggregation: The member functions of tree nodes can be used to gather information from its descendants as well. For example, if a BuildingDataObject calls “getDailyPower()”, this function would automatically and recursively get all the DailyPower value from its children, FloorDataObject, average them, and store as its DailyPower value; each FloorDataObject would then do the same thing to its children, RoomDataObject(s), which in this case are the leaf nodes so we will stop here. Each floor’s DailyPower is calculated from their rooms’ DailyPower and each building’s DailyPower is calculated from the resulted DailyPower of their floors’ DailyPower. My implementation of this example.
  3. Implicit Optimization: With the power of propagation in a tree, implementing a Data Object member function that implicitly uses optimization algorithms can abstract away some of the complexity in our program. For example, if the goal is to maximize the number of meetings scheduled in a building or on a floor, the scheduler can greedily pick the room, with the least number of seats, that can hold all the meeting attendees. This greedy algorithm maximizes the number of meetings scheduled with two conditions: 1. meetings are scheduled in a First-in-First-out order and 2. the starting and ending time of a meeting are unknown. When a BuildingDataObject calls this function to schedule a meeting, it would implicitly use the greedy algorithm to optimally schedule a meeting in a building, while FloorDataObject would instead optimally schedule a meeting on a floor. My implementation of this example.

Controlled Data

Free Data

Handling UI / Canvas Event

Further Discussion

Notes

  1. Using Mapper is one approach to integrate external data. If one can control the iModel contents, another way to map data is to assign the primary key values of external data objects to be the values of FederationGuid for your chosen EC instances. It’s capable of handling both Controlled Data and Free Data. FederationGuid acts as a secondary identifier for EC instances. FederationGuid is superior to an ad-hoc property based mapping key like BuildingNumber since it is globally unique while BuildingNumber could be used in many contexts.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store