forked from EPERLab/QGISrunOpenDSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAEBsFunctions.py
111 lines (88 loc) · 3.59 KB
/
AEBsFunctions.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
108
109
110
111
import numpy as np
"""
########################################################################
Función que descomenta la líneas que el programa pudo comentar anteriormente
y crea una lista ordenada de todos los dssname existentes.
Parámetros de entrada:
*file_path (str): dirección del archivo a ser analizado.
Parámetros de salida:
*dss_name_dict (dict): diccionario con la lista de dss de buses
"""
def uncomment_lines(file_path):
with open(file_path, "r+") as f:
lineList = f.readlines()
f.seek(0)
dss_name_dict = {}
for line in lineList:
if line[:2] == "!!": #aquí es donde se descomenta
line = line[2:]
f.write(line)
in_dssname = line.find("storage.")
if in_dssname == -1:
f.write(line)
continue
in_dssname += len("storage.")
fin_dssname = line.find(" ", in_dssname)
fin_plantelname = line.rfind("_",0, fin_dssname)
dssname = line[in_dssname:fin_dssname]
dssplantelname = line[in_dssname:fin_plantelname]
if "monitor" not in line:
if dssplantelname not in dss_name_dict:
dss_name_dict[dssplantelname] = [dssname]
else:
vector_names = dss_name_dict[dssplantelname]
vector_names.append(dssname)
dss_name_dict[dssplantelname] = vector_names
f.truncate()
return dss_name_dict
"""
########################################################################
Función
Parámetros de entrada:
*dss_name_dict (dict): diccionario con la lista de dss de buses
*file_path (str): dirección del archivo a ser analizado.
*percentaje_aebs (int): porcentaje de AEBs a ser analizados
Parámetros de salida:
No retorna nada
"""
def comment_lines(dss_name_dict, file_path, percentaje_aebs):
dss_name_dictnew = {}
if float(percentaje_aebs) > 1:
percentaje_aebs = float(percentaje_aebs)/100
#Se reacomoda el vector de nombres según el porcentaje seleccionado
for key in dss_name_dict:
dssname_vect = dss_name_dict[key]
longitud_vector = len(dssname_vect)
len_nueva = longitud_vector*percentaje_aebs
len_nueva = int(len_nueva)
vector_nuevo = dssname_vect
np.random.shuffle(vector_nuevo)
vector_nuevo = vector_nuevo[:len_nueva]
dss_name_dict[key] = vector_nuevo
with open(file_path, "r+") as f:
lineList = f.readlines()
f.seek(0)
for line in lineList:
if line[0] == "!" and line[1] != "!": #comentario del usuario
f.write(line)
continue
in_dssname = line.find("storage.")
if in_dssname == -1:
f.write(line)
continue
in_dssname += len("storage.")
fin_dssname = line.find(" ", in_dssname)
fin_plantelname = line.rfind("_",0, fin_dssname)
dssname = line[in_dssname:fin_dssname]
dssplantelname = line[in_dssname:fin_plantelname]
vector_dss = dss_name_dict[dssplantelname]
if dssname not in vector_dss:
line = "!!" + line
f.write(line)
f.truncate()
return 1
if __name__ == "__main__":
file_path = "CAR_StorageBuses.dss"
vector_dss = uncomment_lines(file_path)
print( vector_dss )
comment_lines( vector_dss, file_path, 1)