Giter Club home page Giter Club logo

Comments (5)

dbhart avatar dbhart commented on July 23, 2024 1

Okay - so, for the _read_control_line, it has to formatted like in the CONTROLS section, so that's why the first way didn't work, because this is a rule. So, the _EpanetRule class can be used as:

>>> control_objects = wntr.epanet.io._EpanetRule.parse_rules_lines(["RULE 1 IF TANK 1 LEVEL ABOVE 19.1 THEN PUMP 335 STATUS IS CLOSED AND PIPE 330 STATUS IS OPEN"], flow_units=wntr.epanet.util.FlowUnits.GPM)
>>> # Note that each rule should be it's own string -- no newlines -- within a list; so you can parse more than one rule at a time
>>> control_objects
[<wntr.epanet.io._EpanetRule at 0x7fbb10f61970>]
>>> for ctrl in control_objects:
...     new_control = ctrl.generate_control(wn)
...     wn.add_control(new_control.name, new_control)
>>> print(new_control)
<Control: '1', <ValueCondition: 1, level, >, 5.821680000000001>, [<ControlAction: 335, status, CLOSED>, <ControlAction: 330, status, OPEN>], [], priority=0>
>>> print([c for c in wn.controls()][-1])
('1', <Control: '1', <ValueCondition: 1, level, >, 5.821680000000001>, [<ControlAction: 335, status, CLOSED>, <ControlAction: 330, status, OPEN>], [], priority=0>)

So, I'm hoping that if you follow the above it works for you!
I realize this is a bit of work, but this is basically the internal guts of the I/O reader pulled out a bit.

from wntr.

kaklise avatar kaklise commented on July 23, 2024

There is a function that reads lines of control strings, it's used by read_inpfile. The function is private (underscore), but you can call it directly, see _read_control_line in wntr/epanet/io.py.

The to_dict and from_dict methods should read and write controls as well.

from wntr.

alemanuel995 avatar alemanuel995 commented on July 23, 2024

If I try to make the same thig for the rules, it returns me an error. Is there another method to create rules from a string input? I type this in epanet and creates a rule inside the inp:

Rule 1
IF TANK 1 LEVEL ABOVE 19.1
THEN PUMP 335 STATUS IS CLOSED
AND PIPE 330 STATUS IS OPEN

Is there a way to add a rule to a water network by typing the text above? I've tried to make the same thing as for the controls with "_read_control_line" which works fine and adds the control to the water network, but if I do the same thing passing the rule text, returns an error like this:

venv\lib\site-packages\wntr\network\base.py", line 597, in getitem
return self._data[key]
KeyError: 'TANK'

This is the way I'm trying to call it:

control_object = wntr.epanet.io._read_control_line(line="IF TANK 1 LEVEL ABOVE 19.1 THEN PUMP 335 STATUS "
"IS CLOSED AND PIPE 330 STATUS IS OPEN", wn=wn,
flow_units="GPM",
control_name="3")

Thank you!

from wntr.

kaklise avatar kaklise commented on July 23, 2024

Rules are parsed using the _EpanetRule class, see wntr.epanet.io._EpanetRule.parse_rules_lines.

from wntr.

alemanuel995 avatar alemanuel995 commented on July 23, 2024

Yes. It works for me. Thank you for the support!

from wntr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.