forked from PierSaik/RTE-MSDS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EurostagState_v2.py
107 lines (91 loc) · 3.34 KB
/
EurostagState_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
# Copyright (c) 2016, Pierre Saikaly ([email protected])
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#===========================#
# created on 07 sept 2016
#===========================#
# Import Python dependencies :
# ----------------------------
import os
import sys
import time
# Script :
# --------
def CheckEurostagState(folder):
"""
Reads eurostagOutputFile and check if the situation at the beginning is stable
or unstable
Inputs :
- eurostagOutputFile : file.out containing the informations
Outputs :
- 0 -> Situation is stable
- 1 -> Situation is unstable
Used in :
- main
"""
etat = "ETAT D'EQUILIBRE A 0.10000D-02 VERIFIE POUR LES EQUATIONS MACHINE"
etat2 = "ETAT D'EQUILIBRE A 0.10000D-02 NON VERIFIE DANS LES EQUATIONS SUIVANTES"
eurostagOutputFile = os.path.join(folder,"sim_pre_fault.out")
# Checking Eurostag status :
# --------------------------
if etat in open(eurostagOutputFile, 'U').read():
# Eurostag returns stable
status = 0
else:
# Eurostag returns unstable :
# ---------------------------
equi_value = []
with open(eurostagOutputFile, 'U') as outfile:
lines = outfile.readlines()
for i, line in enumerate(lines):
if etat2 in line:
k = i+5
while (lines[k]!="1\n" and lines[k]!="\n"):
machine_name = lines[k].split()[0]
value_line = lines[k].split()[-2]
value_real = float(value_line.split("D")[0])*10**int(value_line.split("D")[1])
if (abs(value_real) > 0.01):
with open('ecart_groupe.csv','a') as egf:
egf.write(folder + ';' + machine_name + ';' + str(value_real) + '\n')
equi_value.append(abs(value_real))
k += 1
# Checking tolerance :
# --------------------
if( len(equi_value) > 0):
if (max(equi_value) < 0.01):
status = 0 # Stable state within tolerance
else:
status = 1 # Unstable state
return status
def main():
"""
Get list of eurostag simulation folders and check if thoses situations are
stable or not. The outputs are stored in eurostag_status.txt file
"""
# Creating output file :
# ----------------------
print "Beginning writing outputs for folders in directory..."
with open('eurostag_status.txt','w') as f:
f.write("# " + time.strftime("%d/%m/%y") + "\n")
with open('ecart_groupe.csv','w') as egf:
egf.write(time.strftime("%d/%m/%y") + "\n")
egf.write("Situations;groupe;valeur\n")
# Checking folders and writing output :
# -------------------------------------
with open('eurostag_status.txt','a') as f:
for folder in os.listdir('.'):
if folder.startswith('itesla_eurostag_stabilization_'):
f.write(folder + " " + str(CheckEurostagState(folder)) + '\n')
print "Done writing outputs in eurostag_status.txt"
print "Done analysis in ecart_groupe.csv"
if __name__=='__main__':
try:
with open('ecart_groupe.csv','w') as egf:
egf.write(time.strftime("%d/%m/%y") + "\n")
egf.write("Situations;groupe;valeur\n")
eurostag_folder = sys.argv[1] # version of program used
print eurostag_folder, ' ', CheckEurostagState(eurostag_folder)
except IndexError:
main()