Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adding support to compare results with csv-files
- Adding python-script to convert the Buildings reference files to csv-files git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17763 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Converts the buildings .txt format to equidistant csv-files | ||
|
||
import os | ||
import sys | ||
from optparse import OptionParser | ||
|
||
def convertDir(indir,outdir): | ||
for fil in os.listdir(indir): | ||
with open(indir+"/"+fil) as f: | ||
v = {} | ||
for line in f.readlines(): | ||
line = line.strip().split('=') | ||
if line[1][0] == '[': | ||
l = [str(float(s)) for s in line[1].strip('[]').split(',')] | ||
if len(l)==2: | ||
diff = float(l[1])-float(l[0]) | ||
l = [str(float(l[0])+x*diff) for x in range(101)] | ||
if len(l)<>101: | ||
raise Exception("Assumed buildings result format has exactly 101 data points") | ||
v[line[0]] = l | ||
keys = v.keys() | ||
keys.remove('time') | ||
keys.sort() | ||
keys = ['time'] + keys | ||
values = [v[key] for key in keys] | ||
# Transpose | ||
rows = map(list, zip(*values)) | ||
o = open(outdir+"/"+fil[0:-4]+'.csv', 'w') | ||
o.write(','.join(keys) + '\n') | ||
for row in rows: | ||
o.write(','.join(row) + '\n') | ||
|
||
def main(): | ||
parser = OptionParser() | ||
parser.add_option("--input-dir", help="Directory containing .txt reference files in the Buildings package format", type="string", dest="input_dir", default=os.path.abspath('.')) | ||
parser.add_option("--output-dir", help="Directory to generate csv-files in", type="string", dest="output_dir", default=os.path.abspath('.')) | ||
(options, args) = parser.parse_args() | ||
if len(args)<>0: | ||
parser.error('This program does not take positional arguments') | ||
convertDir(options.input_dir,options.output_dir) | ||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters