-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Vitens/development
Development
- Loading branch information
Showing
16 changed files
with
1,619 additions
and
914 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ install: | |
- activate test-environment | ||
|
||
test_script: | ||
- python setup.py install | ||
- nosetests -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from network import Network | ||
from link import Link, Pipe, Pump, Valve | ||
from node import Node, Junction, Reservoir, Tank | ||
from objectcollection import ObjectCollection | ||
from .network import Network | ||
from .link import Link, Pipe, Pump, Valve | ||
from .node import Node, Junction, Reservoir, Tank | ||
from .objectcollection import ObjectCollection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,90 @@ | ||
import pandas as pd | ||
import warnings | ||
import weakref | ||
|
||
|
||
def lazy_property(fn): | ||
'''Decorator that makes a property lazy-evaluated. | ||
''' | ||
attr_name = fn.__name__ | ||
|
||
@property | ||
def _lazy_property(self): | ||
if attr_name not in self._values.keys(): | ||
self._values[attr_name] = fn(self) | ||
return self._values[attr_name] | ||
return _lazy_property | ||
|
||
class BaseObject(object): | ||
|
||
static_properties = {} | ||
properties = {} | ||
|
||
def __init__(self, index): | ||
def __init__(self, uid, network): | ||
|
||
# the object index | ||
self.index = index | ||
# the object id | ||
self.uid = self.get_uid(index) | ||
# dictionary of static values | ||
self._static_values = {} | ||
self.uid = uid | ||
# weak reference to the network | ||
self.network = weakref.ref(network) | ||
# cache of values | ||
self._values = {} | ||
# dictionary of calculation results, only gets | ||
# filled during solve() method | ||
self.results = {} | ||
# list of times | ||
self.times = [] | ||
# index caching | ||
self._index = None | ||
|
||
def get_uid(self, index): | ||
def get_index(self, uid): | ||
raise NotImplementedError | ||
|
||
def set_object_value(self, index, code, value): | ||
def set_object_value(self, code, value): | ||
raise NotImplementedError | ||
|
||
def get_object_value(self, index, code): | ||
def get_object_value(self, code): | ||
raise NotImplementedError | ||
|
||
def reset(self): | ||
self._static_values = {} | ||
self._values = {} | ||
self.results = {} | ||
self.times = [] | ||
|
||
def __str__(self): | ||
return "<epynet."+self.__class__.__name__ + " with id '" + self.uid + "'>" | ||
|
||
def __getattr__(self, name): | ||
|
||
if name in self.static_properties.keys(): | ||
return self.get_static_property(self.static_properties[name]) | ||
return self.get_property(self.static_properties[name]) | ||
|
||
elif name in self.properties.keys(): | ||
if not self.network().solved: | ||
warnings.warn("requesting dynamic properties from an unsolved network") | ||
if self.results == {}: | ||
return self.get_property(self.properties[name]) | ||
else: | ||
return pd.Series(self.results[name], index=self.times) | ||
else: | ||
raise AttributeError('Nonexistant Attribute',name) | ||
raise AttributeError('Nonexistant Attribute', name) | ||
|
||
def __setattr__(self, name, value): | ||
if name in self.properties.keys(): | ||
raise AttributeError("Illegal Assignment to Computed Value") | ||
|
||
if name in self.static_properties.keys(): | ||
self.set_static_property(self.static_properties[name],value) | ||
self.set_static_property(self.static_properties[name], value) | ||
else: | ||
super(BaseObject, self).__setattr__(name, value) | ||
|
||
def set_static_property(self, code, value): | ||
self._static_values[code] = value | ||
self.set_object_value(self.index, code, value) | ||
# set network as unsolved | ||
self.network().solved = False | ||
self._values[code] = value | ||
self.set_object_value(code, value) | ||
|
||
def get_property(self, code): | ||
return self.get_object_value(self.index, code) | ||
if code not in self._values.keys(): | ||
self._values[code] = self.get_object_value(code) | ||
return self._values[code] | ||
|
||
def get_static_property(self, code): | ||
if code not in self._static_values.keys(): | ||
self._static_values[code] = self.get_property(code) | ||
return self._static_values[code] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from . import epanet2 | ||
import weakref | ||
|
||
class Curve(object): | ||
|
||
def __init__(self, uid, network): | ||
self.uid = uid | ||
self.network = weakref.ref(network) | ||
|
||
def __str__(self): | ||
return "<epynet."+self.__class__.__name__ + " with id '" + self.uid + "'>" | ||
|
||
@property | ||
def index(self): | ||
return self.network().ep.ENgetcurveindex(self.uid) | ||
|
||
@property | ||
def values(self): | ||
return self.network().ep.ENgetcurve(self.index) | ||
|
||
@values.setter | ||
def values(self, value): | ||
self.network().ep.ENsetcurve(self.index, value) |
Oops, something went wrong.