From 4663347b4e223a1a565c1b99d13623c3e71e946a Mon Sep 17 00:00:00 2001 From: Mark Driver <mdd31@alumni.cam.ac.uk> Date: Mon, 17 Feb 2020 22:46:52 +0000 Subject: [PATCH] doc updates. --- phasecalculator/classes/outputinformation.py | 97 ++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/phasecalculator/classes/outputinformation.py b/phasecalculator/classes/outputinformation.py index c66313f..c78f7a8 100755 --- a/phasecalculator/classes/outputinformation.py +++ b/phasecalculator/classes/outputinformation.py @@ -32,6 +32,25 @@ LOGGER.setLevel(logging.WARN) class OutputInformation(object): """Class representation of output information.""" def __init__(self, fgip_output, similarity_output, similarity_output_type, vle_output): + """Initialise OutputInformation. + + Parameters + ---------- + fgip_output : bool + FGIP output result. + similarity_output : bool + Similarity output result. + similarity_output_type : str + Output type, see schema for restriction. + vle_output : bool + VLE output result. + + Returns + ------- + OutputInformation + Initialise new OutputInformation. + + """ self.fgip_output = fgip_output self.similarity_output = similarity_output self.similarity_output_type = similarity_output_type @@ -58,17 +77,58 @@ class OutputInformation(object): return False @classmethod def parse_xml(cls, output_xml): + """Parse XML representation. + + Parameters + ---------- + output_xml : etree.Element + OutputInformation element representation. + + Returns + ------- + OutputInformation + New class instance. + + """ fgip_output = OutputInformation.parse_fgip_output(output_xml) similarity_output, similarity_output_type = OutputInformation.parse_similarity_output(output_xml) vle_output = OutputInformation.parse_vle_output(output_xml) return OutputInformation(fgip_output, similarity_output, similarity_output_type, vle_output) @classmethod def parse_fgip_output(cls, output_xml): + """Parse FGIP output information from from output information element. + + Parameters + ---------- + output_xml : etree.Element + OutputInformation element representation. + + Returns + ------- + bool + FGIP output result. + + """ xpath_expression = "phasecalc:FGIPOutput/text()" fgip_output = output_xml.xpath(xpath_expression, namespaces=PHASE_CALC_NAMESPACE_DICT)[0] return True if fgip_output == "true" else False @classmethod def parse_similarity_output(cls, output_xml): + """Parse similarity output information from output information element. + + Parameters + ---------- + output_xml : etree.Element + OutputInformation element representation. + + Returns + ------- + similarity_output : bool + Similarity output result. + similarity_output_type : str + Output type, see schema for restriction. + + """ xpath_expression = "phasecalc:SimilarityOutput/text()" similarity_output = output_xml.xpath(xpath_expression, namespaces=PHASE_CALC_NAMESPACE_DICT)[0] if similarity_output: @@ -80,6 +140,19 @@ class OutputInformation(object): return similarity_output, similarity_output_type @classmethod def parse_vle_output(cls, output_xml): + """Parse VLE from output information element. + + Parameters + ---------- + output_xml : etree.Element + OutputInformation element representation. + + Returns + ------- + bool + VLE output option. + + """ xpath_expression = "phasecalc:FGIPOutput/text()" vle_output = output_xml.xpath(xpath_expression, namespaces=PHASE_CALC_NAMESPACE_DICT)[0] return True if vle_output == "true" else False @@ -98,16 +171,40 @@ class OutputInformation(object): out_element.append(self.write_vle_output()) return out_element def write_fgip_output(self): + """Write FGIP output XML Element. + + Returns + ------- + fgip_element : etree.Element + FGIP element representation. + + """ fgip_element = etree.Element(PHASE_CALCULATOR + "FGIPOutput", nsmap=PHASE_CALC_NAMESPACE_DICT) fgip_element.text = str(self.fgip_output).lower() return fgip_element def write_similarity_output(self): + """Write Similarity output XML Element. + + Returns + ------- + sim_element : etree.Element + Similarity element representation. + + """ sim_element = etree.Element(PHASE_CALCULATOR + "SimilarityOutput", nsmap=PHASE_CALC_NAMESPACE_DICT) sim_element.text = str(self.similarity_output).lower() if self.similarity_output_type is not None: sim_element.set(PHASE_CALCULATOR + "outputType", self.similarity_output_type) return sim_element def write_vle_output(self): + """Write VLE output XML Element. + + Returns + ------- + vle_element : etree.Element + VLE element representation. + + """ vle_element = etree.Element(PHASE_CALCULATOR + "VLEOutput", nsmap=PHASE_CALC_NAMESPACE_DICT) vle_element.text = str(self.vle_output).lower() return vle_element \ No newline at end of file -- GitLab