From 8bf09ee6840f6fa38d3ab8964f23beb922590194 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Mon, 17 Jun 2013 14:58:50 +0200 Subject: [PATCH] Adding editable UserPostAnalysis templates and improving observers ones --- bin/AdaoCatalogGenerator.py | 34 ++++++++++++++++--- src/daEficas/generator_adao.py | 7 ++++ .../daYacsSchemaCreator/infos_daComposant.py | 4 +-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index d5425df..a619ec0 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -71,6 +71,18 @@ def F_${data_name}(statut) : return FACT(statut = statut, FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="OBSOLETE : conservé pour compatibilité avec la version 6.5, sera supprimé dans le futur", ang="OBSOLETE: keeped for compatibility with the 6.5 version, will be removed in the future"), ), + TEMPLATE_DATA = BLOC (condition = " FROM in ( 'Template', ) ", + Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "AnalysisPrinter", into=("AnalysisPrinter", "AnalysisSaver", "AnalysisPrinterAndSaver")), + AnalysisPrinter = BLOC (condition = " Template == 'AnalysisPrinter' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa" ), + ), + AnalysisSaver = BLOC (condition = " Template == 'AnalysisSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ), + ), + AnalysisPrinterAndSaver = BLOC (condition = " Template == 'AnalysisPrinterAndSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ), + ), + ), ) """ @@ -110,8 +122,8 @@ observers_choice = """ ${var_name} = BLOC (condition=" '${var_name}' in set(SELECTION) ", ${var_name}_data = FACT(statut = "o", Scheduler = SIMP(statut = "f", typ = "TXM"), - Info = SIMP(statut = "f", typ = "TXM", defaut = "${var_name}"), - NodeType = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "", into=("String", "Script", "Template")), + Info = SIMP(statut = "o", typ = "TXM", defaut = "${var_name}"), + NodeType = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "Template", into=("String", "Script", "Template")), PythonScript = BLOC (condition = " NodeType == 'String' ", Value = SIMP(statut = "o", typ = "TXM") ), @@ -119,18 +131,30 @@ observers_choice = """ Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())) ), ObserverTemplate = BLOC (condition = " NodeType == 'Template' ", - Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "", into=("ValuePrinter", "ValueSeriePrinter", "ValueGnuPlotter", "ValueSerieGnuPlotter")), + Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "ValuePrinter", into=("ValuePrinter", "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", "ValueSerieGnuPlotter")), ValuePrinter = BLOC (condition = " Template == 'ValuePrinter' ", ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[-1]" ), ), ValueSeriePrinter = BLOC (condition = " Template == 'ValueSeriePrinter' ", ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[:]" ), ), + ValueSaver = BLOC (condition = " Template == 'ValueSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ), + ), + ValueSerieSaver = BLOC (condition = " Template == 'ValueSerieSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ), + ), + ValuePrinterAndSaver = BLOC (condition = " Template == 'ValuePrinterAndSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nprint info,v\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ), + ), + ValueSeriePrinterAndSaver = BLOC (condition = " Template == 'ValueSeriePrinterAndSaver' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nprint info,v\\nglobal istep\\ntry:\\n istep += 1\\nexcept:\\n istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ), + ), ValueGnuPlotter = BLOC (condition = " Template == 'ValueGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal nfig,gp\\ntry:\\n nfig += 1\\n gp('set style data lines')\\nexcept:\\n nfig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"'+str(info)+' (Figure %i)\\"'%nfig)\\ngp.plot( Gnuplot.Data( var[-1], with_='lines lw 2' ) )" ), + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n ifig += 1\\n gp('set style data lines')\\nexcept:\\n ifig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[-1], with_='lines lw 2' ) )" ), ), ValueSerieGnuPlotter = BLOC (condition = " Template == 'ValueSerieGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal nfig,gp\\ntry:\\n nfig += 1\\n gp('set style data lines')\\nexcept:\\n nfig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"'+str(info)+' (Figure %i)\\"'%nfig)\\ngp.plot( Gnuplot.Data( var[:], with_='lines lw 2' ) )" ), + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n ifig += 1\\n gp('set style data lines')\\nexcept:\\n ifig = 0\\n gp = Gnuplot.Gnuplot(persist=1)\\n gp('set style data lines')\\ngp('set title \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[:], with_='lines lw 2' ) )" ), ), ), ), diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index d1bcd29..3ce44bd 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -277,6 +277,13 @@ class AdaoGenerator(PythonGenerator): self.text_da += "Analysis_config['From'] = 'Script'\n" self.text_da += "Analysis_config['Data'] = '" + data + "'\n" self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n" + elif from_type == "Template": + tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"] + data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl] + self.text_da += "Analysis_config = {}\n" + self.text_da += "Analysis_config['From'] = 'String'\n" + self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n" + self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n" else: raise Exception('From Type unknown', from_type) diff --git a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py index c520708..8b6d787 100644 --- a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py +++ b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py @@ -208,9 +208,9 @@ StoredAssimData = ["Vector", "VectorSerie", "Matrix", "ScalarSparseMatrix", "Dia # Assimilation optional nodes OptDict = {} -OptDict["UserPostAnalysis"] = ["String", "Script"] +OptDict["UserPostAnalysis"] = ["String", "Script", "Template"] OptDefaultDict = {} -OptDefaultDict["UserPostAnalysis"] = "Script" +OptDefaultDict["UserPostAnalysis"] = "Template" # Observers ObserversList = [ -- 2.39.2