text: from traits.api import HasTraits, Instance, DelegatesTo, Float, Range, Property
  from traitsui.api import View, Item, Group, VGroup
  
  from reservoir import Reservoir
  
  class ReservoirState(HasTraits):
      """Keeps track of the reservoir state given the initial storage.
  
      For the simplicity of the example, the release is considered in
      hm3/timestep and not in m3/s.
      """
      reservoir = Instance(Reservoir, ())
      name = DelegatesTo('reservoir')
      max_storage = DelegatesTo('reservoir')
      max_release = DelegatesTo('reservoir')
      min_release = Float
  
      # state attributes
      storage = Property(depends_on='inflows, release')
  
      # control attributes
      inflows =  Float(desc='Inflows [hm3]')
      release = Range(low='min_release', high='max_release')
      spillage = Property(
              desc='Spillage [hm3]', depends_on=['storage', 'inflows', 'release']
          )
  
      ### Traits view
      traits_view = View(
          Group(
              VGroup(Item('name'), Item('storage'), Item('spillage'),
                  label = 'State', style = 'readonly'
              ),
              VGroup(Item('inflows'), Item('release'), label='Control'),
          )
      )
  
      ### Private traits.
      _storage = Float
  
      ### Traits property implementation.
      def _get_storage(self):
          new_storage = self._storage - self.release + self.inflows
          return min(new_storage, self.max_storage)
  
      def _set_storage(self, storage_value):
          self._storage = storage_value
  
      def _get_spillage(self):
          new_storage = self._storage - self.release  + self.inflows
          overflow = new_storage - self.max_storage
          return max(overflow, 0)
  
      def print_state(self):
          print('Storage\tRelease\tInflows\tSpillage')
          str_format = '\t'.join(['{:7.2f}'for i in range(4)])
          print(str_format.format(self.storage, self.release, self.inflows,
                  self.spillage))
          print('-' * 79)
  
  if __name__ == '__main__':
      projectA = Reservoir(
          name = 'Project A',
          max_storage = 30,
          max_release = 5,
          hydraulic_head = 60,
          efficiency = 0.8
      )
  
      state = ReservoirState(reservoir=projectA, storage=25)
      state.release = 4
      state.inflows = 0
  
      state.print_state()
      state.configure_traits()
  