From 34b5a57f9e1809dc3282143df1e9e39116a819dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Mon, 14 Sep 2020 11:29:13 +0200 Subject: [PATCH] Add the ADC25generator python tool --- tools/ADC25generator.py | 105 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 tools/ADC25generator.py diff --git a/tools/ADC25generator.py b/tools/ADC25generator.py new file mode 100755 index 00000000..aa39e45c --- /dev/null +++ b/tools/ADC25generator.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +import os +import re +import sys +import copy +from statistics import mean +from math import nan,isnan +from pathlib import Path +from collections import defaultdict,OrderedDict +from lib.data import dataFileBase,DataType,method,state,excitationValue +import argparse +parser = argparse.ArgumentParser() +parser.add_argument('--debug', action='store_true', help='Debug mode') +parser.add_argument("--sets",nargs="*") +parser.add_argument("--articles",nargs="*") +args=parser.parse_args() +scriptpath=Path(sys.argv[0]).resolve() +datadir=scriptpath.parents[1]/"static"/"data" +articles=None +if args.articles is not None or args.sets is not None: + articles=set() + if args.articles is not None: + for article in args.articles: + articles.add(article) + if args.sets is not None: + import yaml + pubindex=datadir/"publis"/"index.yaml" + with pubindex.open("r") as pubindexstream: + pubindexdata = yaml.load(pubindexstream,Loader=yaml.loader.FullLoader) + pubsetsdata=pubindexdata["sets"] + for myset in args.sets: + if myset in pubsetsdata: + artset=pubsetsdata[myset] + for article in artset: + articles.add(article) +outputdir=datadir/"test" if args.debug else datadir +ADC23re=re.compile(r"ADC\(([23])\)") +def getValue(ADC2,ADC3,parametername): + vals = [getattr(x,parametername) for x in [ADC2,ADC3]] + isObject=hasattr(vals[0], '__dict__') + if isObject: + if vars(vals[0]) == vars(vals[1]): + return copy.deepcopy(vals[0]) + else: + if vals[0] == vals[1]: + return vals[0] + d=OrderedDict() + for i in range(2): + key=f"ADC({i+2})" + if isObject: + d[key]=copy.deepcopy(vals[i]) + else: + d[key]=vals[i] + index=-1 + while len(vals)0: + exADC3=exADC3s[0] + value=mean([(float(x.value)) for x in [exADC2,exADC3]]) + value= "_" if isnan(value) else "{0:.2f}".format(value) + T1 = "_" + f = "_" + isUnsafe = exADC2.isUnsafe or exADC3.isUnsafe + Type=getValue(exADC2,exADC3,"type") + exADC25=excitationValue(copy.deepcopy(exADC2.initial),copy.deepcopy(exADC2.final),value,Type,T1,isUnsafe,f) + ADC25File.excitations.append(exADC25) + ADC25File.toFile(outputdir) + + except ValueError as ex: + pass \ No newline at end of file