Example #1
0
 def read(new_text):
     times_options = TimesOptions()
     for line in new_text.splitlines():
         try:
             SectionReader.set_text_line(times_options, line)
         except:
             print("TimesOptionsReader skipping input line: " + line)
     return times_options
Example #2
0
 def read(new_text):
     energy_options = EnergyOptions()
     for line in new_text.splitlines():
         try:
             line = SectionReader.set_comment_check_section(energy_options, line)
             fields = line.split()
             if len(fields) > 1:
                 if fields[0].upper() == "PUMP":
                     energy_options.pumps.append(PumpEnergyReader.read(line))
                 else:
                     SectionReader.set_text_line(energy_options, line)
         except:
             print("BackdropOptions skipping input line: " + line)
     return energy_options
Example #3
0
 def read(new_text):
     """Read this section from the text representation"""
     report_options = ReportOptions()
     lines = new_text.splitlines()
     for line in lines:
         line = SectionReader.set_comment_check_section(report_options, line)
         if line:
             (attr_name, attr_value) = line.split(None, 1)
             attr_name = attr_name.upper()
             if attr_name == "NODES":
                 report_options.nodes.extend(attr_value.split())
             elif attr_name == "LINKS":
                 report_options.links.extend(attr_value.split())
             elif attr_name == "STATUS":
                 report_options.setattr_keep_type("status", attr_value)
             elif attr_name == "FILE":
                 report_options.file = attr_value
             elif attr_name == "SUMMARY":
                 report_options.setattr_keep_type("summary", attr_value)
             elif attr_name == "PAGESIZE" or attr_name == "PAGE":
                 report_options.pagesize = attr_value
             elif attr_name == "ENERGY":
                 report_options.setattr_keep_type("energy", attr_value)
             else:
                 report_options.parameters.append(line)
     return report_options
Example #4
0
 def read(new_text, project):
     section_map = {"NODE": project.nodes_groups(),
                    "LINK": project.links_groups()}
     disposable_tags = Section()
     disposable_tags.SECTION_NAME = "[TAGS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_tags, line)
         fields = line.split()
         if len(fields) > 2:
             object_type_name = fields[0].upper()
             object_name = fields[1].upper()
             tag = ' '.join(fields[2:])
             sections = section_map[object_type_name]
             found = False
             for section in sections:
                 for candidate in section.values:
                     if candidate.name.upper() == object_name:
                         candidate.tag = tag
                         found = True
                         # print "Tagged: " + type(candidate).__name__ + ' ' + candidate.name + ' = ' + tag
                         break
                 if found:
                     break
             if not found:
                 print "Tag not applied: " + line
Example #5
0
 def read(new_text):
     status = Status()
     new_text = SectionReader.set_comment_check_section(status, new_text)
     fields = new_text.split()
     if len(fields) > 1:
         status.name = fields[0]
         status.status = fields[1]
     return status
Example #6
0
 def read(new_text):
     pump_energy = PumpEnergy()
     new_text = SectionReader.set_comment_check_section(pump_energy, new_text)
     fields = new_text.split()
     if len(fields) > 3:
         pump_energy.name = fields[1]
         pump_energy.PricePatternEfficiency = PumpEnergyType[fields[2].upper()]
         pump_energy.value = fields[3]
     return pump_energy
Example #7
0
 def read(new_text):
     """Read properties from text.
         Args:
             new_text (str): Text to parse into properties.
     """
     reactions = Reactions()
     # Replace "zero" (any capitalization) with numeral 0
     zero_pos = new_text.upper().find("ZERO")
     while zero_pos >= 0:
         new_text = new_text[:zero_pos] + '0' + new_text[zero_pos + len("ZERO"):]
         zero_pos = new_text.upper().find("ZERO", zero_pos)
     for line in new_text.splitlines():
         upper_line = line.upper().strip()
         if upper_line.startswith("BULK") or upper_line.startswith("WALL") or upper_line.startswith("TANK"):
             reactions.value.append(upper_line)
             #reactions.comment += '\n' + line  # TODO: parse into table of per pipe values
         else:
             SectionReader.set_text_line(reactions, line)
     return reactions
Example #8
0
    def read(new_text):
        label = Label()
        new_text = SectionReader.set_comment_check_section(label, new_text)
        fields = shlex.split(new_text.encode('utf8'))
        if len(fields) > 2:
            (label.x, label.y) = fields[0:2]
            label.name = fields[2].decode('UTF8')

            if len(fields) > 3:
                label.anchor_name = fields[3].decode('UTF8')  # name of an anchor node (optional)
        return label
Example #9
0
 def read(new_text):
     reservoir = Reservoir()
     new_text = SectionReader.set_comment_check_section(reservoir, new_text)
     fields = new_text.split()
     if len(fields) > 0:
         reservoir.name = fields[0]
     if len(fields) > 1:
         reservoir.total_head = fields[1]
     if len(fields) > 2:
         reservoir.head_pattern_name = fields[2]
     return reservoir
Example #10
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[STATUS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             link_name = fields[0]
             status = fields[1]
             for link in project.all_links():
                 if link.name == link_name:
                     link.setattr_keep_type("initial_status", status)
                     break
Example #11
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[EMITTERS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             node_name = fields[0]
             emitter_coefficient = fields[1]
             for node in project.junctions.value:
                 if node.name == node_name:
                     node.setattr_keep_type("emitter_coefficient", emitter_coefficient)
                     break
Example #12
0
 def read(new_text):
     junction = Junction()
     new_text = SectionReader.set_comment_check_section(junction, new_text)
     fields = new_text.split()
     if len(fields) > 0:
         junction.name = fields[0]
     if len(fields) > 1:
         junction.elevation = fields[1]
     if len(fields) > 2:
         junction.base_demand_flow = fields[2]
     if len(fields) > 3:
         junction.demand_pattern_name = fields[3]
     return junction
Example #13
0
 def read(new_text, project):
     all_nodes = project.all_nodes()
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[COORDINATES]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         coordinate = CoordinateReader.read(line)
         if coordinate:
             try:
                 node = all_nodes[coordinate.name]
                 node.x = coordinate.x
                 node.y = coordinate.y
             except:
                 print("Node not found in model for coordinate " + coordinate.name)
Example #14
0
 def read(new_text, project):
     links = project.all_links()
     if links:
         disposable_section = Section()
         disposable_section.SECTION_NAME = "[VERTICES]"
         for line in new_text.splitlines():
             line = SectionReader.set_comment_check_section(disposable_section, line)
             coordinate = CoordinateReader.read(line)
             if coordinate:
                 try:
                     link = links[coordinate.name]
                     link.vertices.append(coordinate)
                 except Exception:
                     print("Link not found in model for vertex " + coordinate.name)
Example #15
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[QUALITY]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None, 1)
         if len(fields) > 1:
             node_name = fields[0]
             initial_quality = fields[1]
             for nodes in (project.junctions.value, project.reservoirs.value, project.tanks.value):
                 for node in nodes:
                     if node.name == node_name:
                         node.setattr_keep_type("initial_quality", initial_quality)
                         break
Example #16
0
 def read(new_text):
     backdrop_options = BackdropOptions()
     for line in new_text.splitlines():
         try:
             line = SectionReader.set_comment_check_section(backdrop_options, line)
             fields = line.split()
             if len(fields) > 1:
                 if fields[0].lower() == "dimensions" and len(fields) > 4:
                     backdrop_options.dimensions = fields[1:5]
                 elif fields[0].lower() == "offset" and len(fields) > 2:
                     backdrop_options.offset = (fields[1], fields[2])
                 else:
                     backdrop_options.setattr_keep_type(ProjectBase.format_as_attribute_name(fields[0]), fields[1])
         except:
             print("BackdropOptions skipping input line: " + line)
     return backdrop_options
Example #17
0
 def read(new_text):
     pump = Pump()
     new_text = SectionReader.set_comment_check_section(pump, new_text)
     fields = new_text.split()
     if len(fields) > 2:
         pump.name, pump.inlet_node, pump.outlet_node = fields[0:3]
         for key_index in range(3, len(fields) - 1, 2):
             value_index = key_index + 1
             if fields[key_index].upper() == "HEAD":
                 pump.head_curve_name = fields[value_index]
             elif fields[key_index].upper() == "POWER":
                 pump.power = fields[value_index]
             elif fields[key_index].upper() == "PATTERN":
                 pump.pattern = fields[value_index]
             elif fields[key_index].upper() == "SPEED":
                 pump.speed = fields[value_index]
     return pump
Example #18
0
 def read(new_text):
     valve = Valve()
     new_text = SectionReader.set_comment_check_section(valve, new_text)
     fields = new_text.split()
     if len(fields) > 2:
         valve.name = fields[0]
         valve.inlet_node = fields[1]
         valve.outlet_node = fields[2]
         if len(fields) > 3:
             valve.diameter = fields[3]
         if len(fields) > 4:
             valve.type = ValveType[fields[4].upper()]
         if len(fields) > 5:
             valve.setting = fields[5]
         if len(fields) > 6:
             valve.minor_loss_coefficient = fields[6]
     return valve
Example #19
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[MIXING]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             node_name = fields[0]
             mixing_model = MixingModel[fields[1].upper().replace("2", "TWO_")]
             if len(fields) > 2:
                 mixing_fraction = fields[2]
             for tank in (project.tanks.value):
                 if tank.name == node_name:
                     tank.setattr_keep_type("mixing_model", mixing_model)
                     if len(fields) > 2:
                         tank.setattr_keep_type("mixing_fraction", mixing_fraction)
                 break
Example #20
0
 def read(new_text):
     """Read properties from text.
         Args:
             new_text (str): Text to parse into properties.
     """
     pipe = Pipe()
     new_text = SectionReader.set_comment_check_section(pipe, new_text)
     fields = new_text.split(None, 8)
     if len(fields) > 2:
         pipe.name, pipe.inlet_node, pipe.outlet_node = fields[0:3]
     if len(fields) > 6:
         pipe.length = fields[3]
         pipe.diameter = fields[4]
         pipe.roughness = fields[5]
         pipe.loss_coefficient = fields[6]
     if len(fields) > 7:
         pipe.initial_status = fields[7]
     return pipe
Example #21
0
 def read(new_text):
     tank = Tank()
     new_text = SectionReader.set_comment_check_section(tank, new_text)
     fields = new_text.split()
     if len(fields) > 0:
         tank.name = fields[0]
     if len(fields) > 1:
         tank.elevation = fields[1]
     if len(fields) > 2:
         tank.initial_level = fields[2]
     if len(fields) > 3:
         tank.minimum_level = fields[3]
     if len(fields) > 4:
         tank.maximum_level = fields[4]
     if len(fields) > 5:
         tank.diameter = fields[5]
     if len(fields) > 6:
         tank.minimum_volume = fields[6]
     if len(fields) > 7:
         tank.volume_curve = fields[7]
     return tank