--- /dev/null
+def fill_matrice(dataframe, component_label, component, contingency_label, contingency, value_label, nb_cases):
+
+ import pandas as pd
+
+ """
+ On range ces listes par ordre alphabetique
+ """
+ component.sort()
+ contingency.sort()
+
+ """
+ On vient creer le squelette de notre matrice, on la remplit de 0
+ """
+ output_excel = pd.DataFrame(index = component, columns = contingency)
+ output_excel = output_excel.fillna(0)
+
+
+ """
+ On vient ranger nos lignes et colonnes par ordre alphabetique, de la meme maniere que les listes component et contingency
+ """
+ output_excel.sort_index(axis = 1, ascending = True, inplace =True)
+ output_excel.sort_index(axis = 0, ascending = True, inplace = True)
+
+ if value_label != 'Number of Violations':
+
+ for i in range(len(component)):
+
+ for j in range(len(contingency)):
+
+ """
+ Cette commande permet de venir selectionner la valeur du componentsant X impacte par la contingence Y
+ """
+ valeur = dataframe[(dataframe[component_label] == component[i]) & (dataframe[contingency_label] == contingency[j])][value_label]
+
+
+ """
+ Cette commande permet de venir remplir notre matrice avec les valeurs recuperees dans la DataFrame d origine
+ """
+ try:
+ output_excel.loc[component[i], contingency[j]] = float(valeur)
+ except:
+ pass
+
+ else:
+
+ for i in range(len(component)):
+
+ for j in range(len(contingency)):
+
+ """
+ Cette commande permet de venir selectionner la valeur du componentsant X impacte par la contingence Y
+ """
+ nb_viol = dataframe[(dataframe[component_label] == component[i]) & (dataframe[contingency_label] == contingency[j])][value_label]
+ valeur = nb_viol/nb_cases
+
+ """
+ Cette commande permet de venir remplir notre matrice avec les valeurs recuperees dans la DataFrame d origine
+ """
+ try:
+ output_excel.loc[component[i], contingency[j]] = float(int(valeur*100))/100
+ except:
+ pass
+
+ return output_excel
\ No newline at end of file
--- /dev/null
+
+"""
+On importe nos modules et on renseigne les chemins vers les fichiers d'entrée et de sortie
+"""
+import os
+import xlrd
+import pandas as pd
+import win32com.client as win32
+
+from Matrice import fill_matrice
+from TreatOutputs.dicoN1_process import Dico as dico
+
+
+input_path = dico['CONTINGENCY_PROCESSING']['XLS_file']
+filename = dico['CONTINGENCY_SELECTION']['case_name']
+output_path = os.path.join(dico['CASE_SELECTION']['PSEN_results_folder'],filename + '.xlsx')
+
+wb = xlrd.open_workbook(input_path)
+sheets = wb.sheet_names()
+
+"""
+Cette commande va permettre d ouvrir le fichier resultat dans lequel on va enregistrer differents onglets
+Uniquement a la fin de toutes les ecritures, nous viendrons le sauvegarder
+"""
+writer = pd.ExcelWriter(output_path, engine='xlsxwriter')
+
+"""
+On importe le fichier excel et on cree une DataFrame pour chaque Onglet/Sheet du fichier
+On recupere egalement les noms des Onglets/Sheets afin de pouvoir adapter les intitules des composants et des valeurs
+
+Voltage ==> 'Bus' ; 'Max Voltage'
+Flows ==> 'Branch' ; 'Max Violation'
+"""
+input_excel = pd.ExcelFile(input_path)
+
+sheet_names_all = {}
+
+for name in sheets:
+
+ if 'Voltage' in name:
+ max_sheet = filename + ' Max' + name[len(filename):]
+ min_sheet = filename + ' Min' + name[len(filename):]
+ occu_sheet = filename + ' Occurence' + name[len(filename):]
+
+ sheet_names_all[name]=[max_sheet, min_sheet, occu_sheet]
+
+
+ elif 'Flows' in name:
+ max_sheet = filename + ' Max' + name[len(filename):]
+ occu_sheet = filename + ' Occurence' + name[len(filename):]
+
+ sheet_names_all[name]=[max_sheet, occu_sheet]
+
+# nomColonne = "'" + 'Component_List_For_'+ str(name) + "'"
+# nomColonne = nomColonne.replace('_ ',' _')
+#
+# nomLigne = "'" + 'Contingency_List_For_'+ str(name) +"'"
+# nomLigne = nomLigne.replace('_ ',' _')
+#
+# Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
+# Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
+
+
+for sheet_keys in sheet_names_all.keys():
+
+ """
+ On cree une DataFrame pour l'onglet/sheet actuel
+ Selon le nom de l onglet/sheet, on precise l intitule de la valeur que l on va recuperer
+ On cree des listes repertoriant les noms des composants et contingences en faisant appel aux elements selectionnes par l utilisateur
+ Ces elements sont stockes dans dicoN1_process
+ """
+
+ df = input_excel.parse(sheet_keys)
+
+ """
+ On compte le nombre de cas simules
+ """
+ nb_cases = 0
+
+ for col in df.columns:
+ if 'Case' in col:
+ nb_cases+=1
+
+ conting_label = 'Contingency'
+
+ """
+ Soit on observe des tensions (Voltage) et dans ce cas la, trois grandeurs vont nous interesser (Max/Min/Occurence)
+ Soit on observe des flux (Flows) et dans ce cas la, deux grandeurs vont nous interesser (Max/Occurence)
+ """
+ if 'Voltage' in sheet_keys:
+
+ compo_label = 'Bus'
+ ite = 0
+
+ for sheet in sheet_names_all[sheet_keys]:
+
+ """
+ On vient recuperer differentes valeurs en fonction de l onglet dans lequel on se trouve (Max/Min/Occurence)
+ """
+ if 'Max' in sheet:
+ value_label = 'Max Voltage'
+ elif 'Min' in sheet:
+ value_label = 'Min Voltage'
+ elif 'Occurence' in sheet:
+ value_label = 'Number of Violations'
+
+
+ for k in dico['CONTINGENCY_PROCESSING'].keys():
+
+ if 'Voltage' in k and 'Component' in k:
+ compo = dico['CONTINGENCY_PROCESSING'][k]
+ elif 'Voltage' in k and 'Contingency' in k:
+ conting = dico['CONTINGENCY_PROCESSING'][k]
+
+ """
+ On fait appel a la fonction fill_matrice afin de creer notre matrice croisee dynamique
+ """
+ output_excel = fill_matrice(df, compo_label, compo, conting_label, conting, value_label, nb_cases)
+
+ """
+ On importe notre matrice au format excel
+ """
+ output_excel.to_excel(writer, sheet_name = sheet_names_all[sheet_keys][ite])
+ ite += 1
+
+ elif 'Flows' in sheet_keys:
+
+ compo_label = 'Branch'
+ ite = 0
+
+ for sheet in sheet_names_all[sheet_keys]:
+
+ """
+ On vient recuperer differentes valeurs en fonction de l onglet dans lequel on se trouve (Max/Occurence)
+ """
+
+ if 'Max' in sheet:
+ value_label = 'Max Violation'
+ elif 'Occurence' in sheet:
+ value_label = 'Number of Violations'
+
+
+ for k in dico['CONTINGENCY_PROCESSING'].keys():
+
+ if 'Flows' in k and 'Component' in k:
+ compo = dico['CONTINGENCY_PROCESSING'][k]
+ elif 'Flows' in k and 'Contingency' in k:
+ conting = dico['CONTINGENCY_PROCESSING'][k]
+
+ """
+ On fait appel a la fonction fill_matrice afin de creer notre matrice croisee dynamique
+ """
+ output_excel = fill_matrice(df, compo_label, compo, conting_label, conting, value_label, nb_cases)
+
+ """
+ On importe notre matrice au format excel
+ """
+ output_excel.to_excel(writer, sheet_name = sheet_names_all[sheet_keys][ite])
+ ite += 1
+
+ else:
+ break
+
+
+writer.save()
+
+"""
+Ajustez la taille des colonnes et lignes automatiquement
+"""
+
+excel = win32.gencache.EnsureDispatch('Excel.Application')
+wb = excel.Workbooks.Open(output_path)
+
+autofit_sheet_names = []
+
+for k in sheet_names_all.keys():
+ for v in sheet_names_all[k]:
+ autofit_sheet_names.append(v)
+
+for sheet_to_autofit in autofit_sheet_names:
+ ws = wb.Worksheets(sheet_to_autofit)
+ ws.Columns.AutoFit()
+
+wb.Save()
+excel.Application.Quit()
print('je suis dans processor')
UpdateProcessorOptions(dico)
- indexes = {}
- toGather = {}
- data = {}
- totalData = {}
-
- if Options.csvFileName.endswith('xls'):
- # Step 1 : get the indexes of each columns to process
- wb = xlrd.open_workbook(Options.csvFileName)
- sheets = wb.sheet_names()
- # Now get data from the selected columns. data and TotalData are filled in gatherxlsData and are accessible here
- gatherXlsData(wb, sheets, data, totalData)
- elif Options.csvFileName.endswith('csv'):
-
- ACCCresultsfolder = os.path.dirname(Options.csvFileName) #os.path.join(Options.FolderList[0], "ACCCresults")
- sheets =[]
- for file in os.listdir(ACCCresultsfolder):
- if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) :
- name = str(file[0:-4])
- nomCle = "'"+'Component_List_For_'+str(name)+"'"
- nomCle = nomCle.replace('_ ',' _')
- if nomCle in dico['CONTINGENCY_PROCESSING'].keys():
- sheets.append(file[0:-4])
- gatherCsvData(sheets, data, totalData)
- # Now we process the gathered data depending on the required calculus
- processedData = {}
+ wb = xlrd.open_workbook(Options.csvFileName)
+ sheets = wb.sheet_names()
+ input_path = dico['CONTINGENCY_PROCESSING']['XLS_file']
+ filename = dico['CONTINGENCY_SELECTION']['case_name']
+ output_path = os.path.join(dico['CASE_SELECTION']['PSEN_results_folder'],filename + '.xlsx')
+
+ """
+ Cette commande va permettre d ouvrir le fichier resultat dans lequel on va enregistrer differents onglets
+ Uniquement a la fin de toutes les ecritures, nous viendrons le sauvegarder
+ """
+ writer = pd.ExcelWriter(output_path, engine='xlsxwriter')
+
+ """
+ On importe le fichier excel et on cree une DataFrame pour chaque Onglet/Sheet du fichier
+ On recupere egalement les noms des Onglets/Sheets afin de pouvoir adapter les intitules des composants et des valeurs
+
+ Voltage ==> 'Bus' ; 'Max Voltage'
+ Flows ==> 'Branch' ; 'Max Violation'
+ """
+ input_excel = pd.ExcelFile(input_path)
+
+ sheet_names_all = {}
+
for name in sheets:
-
- try:
-
- nomColonne = 'Component_List_For_'+str(name)
- nomColonne = nomColonne.replace('_ ',' _')
+ if 'Voltage' in name:
+ max_sheet = filename + ' Max' + name[len(filename):]
+ min_sheet = filename + ' Min' + name[len(filename):]
+ occu_sheet = filename + ' Occurence' + name[len(filename):]
+
+ sheet_names_all[name]=[max_sheet, min_sheet, occu_sheet]
+
+
+ elif 'Flows' in name:
+ max_sheet = filename + ' Max' + name[len(filename):]
+ occu_sheet = filename + ' Occurence' + name[len(filename):]
+
+ sheet_names_all[name]=[max_sheet, occu_sheet]
+
+ nomColonne = "'" + 'Component_List_For_'+ str(name) + "'"
+ nomColonne = nomColonne.replace('_ ',' _')
+
+ nomLigne = "'" + 'Contingency_List_For_'+ str(name) +"'"
+ nomLigne = nomLigne.replace('_ ',' _')
+
+ Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
+ Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
+
+
+ for sheet_keys in sheet_names_all.keys():
+
+ """
+ On cree une DataFrame pour l'onglet/sheet actuel
+ Selon le nom de l onglet/sheet, on precise l intitule de la valeur que l on va recuperer
+ On cree des listes repertoriant les noms des composants et contingences en faisant appel aux elements selectionnes par l utilisateur
+ Ces elements sont stockes dans dicoN1_process
+ """
+
+ df = input_excel.parse(sheet_keys)
+
+ """
+ On compte le nombre de cas simules
+ """
+ nb_cases = 0
+
+ for col in df.columns:
+ if 'Case' in col:
+ nb_cases+=1
+
+ conting_label = 'Contingency'
+
+ """
+ Soit on observe des tensions (Voltage) et dans ce cas la, trois grandeurs vont nous interesser (Max/Min/Occurence)
+ Soit on observe des flux (Flows) et dans ce cas la, deux grandeurs vont nous interesser (Max/Occurence)
+ """
+ if 'Voltage' in sheet_keys:
- nomLigne = 'Contingency_List_For_'+str(name)
- nomLigne = nomLigne.replace('_ ',' _')
+ compo_label = 'Bus'
+ ite = 0
+
+ for sheet in sheet_names_all[sheet_keys]:
+
+ """
+ On vient recuperer differentes valeurs en fonction de l onglet dans lequel on se trouve (Max/Min/Occurence)
+ """
+ if 'Max' in sheet:
+ value_label = 'Max Voltage'
+ elif 'Min' in sheet:
+ value_label = 'Min Voltage'
+ elif 'Occurence' in sheet:
+ value_label = 'Number of Violations'
+
+ for k in dico['CONTINGENCY_PROCESSING'].keys():
+
+ if 'Voltage' in k and 'Component' in k:
+ compo = dico['CONTINGENCY_PROCESSING'][k]
+ elif 'Voltage' in k and 'Contingency' in k:
+ conting = dico['CONTINGENCY_PROCESSING'][k]
+
+ """
+ On fait appel a la fonction fill_matrice afin de creer notre matrice croisee dynamique
+ """
+ output_excel = fill_matrice(df, compo_label, compo, conting_label, conting, value_label, nb_cases)
+
+ """
+ On importe notre matrice au format excel
+ """
+ output_excel.to_excel(writer, sheet_name = sheet_names_all[sheet_keys][ite])
+ ite += 1
+
+ elif 'Flows' in sheet_keys:
+
+ compo_label = 'Branch'
+ ite = 0
+
+ for sheet in sheet_names_all[sheet_keys]:
+
+ """
+ On vient recuperer differentes valeurs en fonction de l onglet dans lequel on se trouve (Max/Occurence)
+ """
+
+ if 'Max' in sheet:
+ value_label = 'Max Violation'
+ elif 'Occurence' in sheet:
+ value_label = 'Number of Violations'
+
+
+ for k in dico['CONTINGENCY_PROCESSING'].keys():
+
+ if 'Flows' in k and 'Component' in k:
+ compo = dico['CONTINGENCY_PROCESSING'][k]
+ elif 'Flows' in k and 'Contingency' in k:
+ conting = dico['CONTINGENCY_PROCESSING'][k]
+
+ """
+ On fait appel a la fonction fill_matrice afin de creer notre matrice croisee dynamique
+ """
+ output_excel = fill_matrice(df, compo_label, compo, conting_label, conting, value_label, nb_cases)
+
+ """
+ On importe notre matrice au format excel
+ """
+ output_excel.to_excel(writer, sheet_name = sheet_names_all[sheet_keys][ite])
+ ite += 1
+
+ else:
+ break
+
+ writer.save()
+ """
+ Ajustez la taille des colonnes et lignes automatiquement
+ """
- if nomColonne not in dico['CONTINGENCY_PROCESSING'].keys():
- continue
-
- Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
- Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
+ excel = win32.gencache.EnsureDispatch('Excel.Application')
+ wb = excel.Workbooks.Open(output_path)
- print('apres select')
- processedData[name] = [[]]
-
- processedData[name] = Compute.createDoubleArray(totalData[name], processedData[name], name)
-
- xlsToOutput(processedData[name])
+ autofit_sheet_names = []
-
- except KeyError:
- print("error dans ecriture acc results")
- pass
+ for k in sheet_names_all.keys():
+ for v in sheet_names_all[k]:
+ autofit_sheet_names.append(v)
+
+ for sheet_to_autofit in autofit_sheet_names:
+ ws = wb.Worksheets(sheet_to_autofit)
+ ws.Columns.AutoFit()
+
+ wb.Save()
+ excel.Application.Quit()
h.close()
- # except: #python 3
- # for name in sheets:
- # ACCCresultsfolder = os.path.dirname(Options.csvFileName)
- # ACCCresultsfile = os.path.join(ACCCresultsfolder,name + '.csv')
- # h = open(ACCCresultsfile,"r", newline='')
- # crd = csv.reader(h,delimiter=";")
-
- # data[name] = []
- # totalData[name] = []
-
- # for i, row in enumerate(crd):
- # totalData[name].append([])
- # data[name].append([])
-
- # for j in range(len(row)):
- ##Store data anyway in totalData
- # if i == 0:
- # totalData[name][i] = [j]
- # try:
- # totalData[name][i].append(float(row[j]))
- # except:
- # totalData[name][i].append(row[j])
- # try:
- # if j == 0:
- # try:
- # if row[0] in Options.selectedDoubleRow[name] and row[1] in Options.selectedDoubleCol[name]:
- # pass
- # else:
- # break
- # except:
- # break
- # if i == 0:
- # data[name][i] = [j]
- # data[name][i].append(float(row[j]))
- # except:
- # data[name][i].append('N/A')
- # h.close()
+
def isData(row):
for item in row:
newWb.save(name)
print('Processing over. The file has been saved under ' + name + '.')
+
+def fill_matrice(dataframe, component_label, component, contingency_label, contingency, value_label, nb_cases):
+
+ import pandas as pd
+
+ """
+ On range ces listes par ordre alphabetique
+ """
+ component.sort()
+ contingency.sort()
+
+ """
+ On vient creer le squelette de notre matrice, on la remplit de 0
+ """
+ output_excel = pd.DataFrame(index = component, columns = contingency)
+ output_excel = output_excel.fillna(0)
+
+
+ """
+ On vient ranger nos lignes et colonnes par ordre alphabetique, de la meme maniere que les listes component et contingency
+ """
+ output_excel.sort_index(axis = 1, ascending = True, inplace =True)
+ output_excel.sort_index(axis = 0, ascending = True, inplace = True)
+
+ if value_label != 'Number of Violations':
+
+ for i in range(len(component)):
+
+ for j in range(len(contingency)):
+
+ """
+ Cette commande permet de venir selectionner la valeur du componentsant X impacte par la contingence Y
+ """
+ valeur = dataframe[(dataframe[component_label] == component[i]) & (dataframe[contingency_label] == contingency[j])][value_label]
+
+
+ """
+ Cette commande permet de venir remplir notre matrice avec les valeurs recuperees dans la DataFrame d origine
+ """
+ try:
+ output_excel.loc[component[i], contingency[j]] = float(valeur)
+ except:
+ pass
+
+ else:
+
+ for i in range(len(component)):
+
+ for j in range(len(contingency)):
+
+ """
+ Cette commande permet de venir selectionner la valeur du componentsant X impacte par la contingence Y
+ """
+ nb_viol = dataframe[(dataframe[component_label] == component[i]) & (dataframe[contingency_label] == contingency[j])][value_label]
+ valeur = nb_viol/nb_cases
+
+ """
+ Cette commande permet de venir remplir notre matrice avec les valeurs recuperees dans la DataFrame d origine
+ """
+ try:
+ output_excel.loc[component[i], contingency[j]] = float(int(valeur*100))/100
+ except:
+ pass
+
+ return output_excel
if __name__ == '__main__':
- from dicoProcessor import dico
+ from dicoN1_process import Dico as dico
- processXLS(dico)
+ processXLS(dico)
\ No newline at end of file
+++ /dev/null
-import xlrd # XLS read
-import xlwt # XLS write
-import csv
-import pdb
-
-import Options
-import Compute
-#from Run import *
-import pickle
-from UpdateOptions import UpdateProcessorOptions
-#from itertools import izip_longest # Reverse the double array
-#from future.moves.itertools import zip_longest
-import itertools
-import os
-import xlsxwriter
-
-import os
-import pandas as pd
-import win32com.client as win32
-
-
-def getXLSinfo(filename):
- wb = xlrd.open_workbook(filename)
- sheets = wb.sheet_names()
- ret = {}
- for name in sheets:
- sheet = wb.sheet_by_name(name)
- ret[name] = [[],[]]
- for i in range(0, sheet.nrows):
- data = str(sheet.cell_value(i, 0))
- if data not in ret[name][0]:
- ret[name][0].append(data)
- data = str(sheet.cell_value(i, 1))
- if data not in ret[name][1]:
- ret[name][1].append(data)
- return ret
-
-def getCSVinfo(csvfilename):
- foldername = os.path.dirname(csvfilename)
- sheets =[]
- for file in os.listdir(foldername):
- if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) and 'processed_' not in file.lower():
- sheets.append(file[0:-4])
- ret = {}
- for name in sheets:
- ACCCresultsfile = os.path.join(foldername, name + '.csv')
- try: #python 2 compatible
- h = open(ACCCresultsfile,"rb")
- crd = csv.reader(h,delimiter=";")
- ret[name] = [[],[]]
- for i, row in enumerate(crd):
- if len(row)>2:
- data = str(row[0])
- if data not in ret[name][0]:
- ret[name][0].append(data)
- data = str(row[1])
- if data not in ret[name][1]:
- ret[name][1].append(data)
- h.close()
- except: #python 3 compatible
- h = open(ACCCresultsfile,"r",newline='')
- crd = csv.reader(h,delimiter=";")
- ret[name] = [[],[]]
- for i, row in enumerate(crd):
- if len(row)>2:
- data = str(row[0])
- if data not in ret[name][0]:
- ret[name][0].append(data)
- data = str(row[1])
- if data not in ret[name][1]:
- ret[name][1].append(data)
- h.close()
- return ret
-
-def processXLS(dico):
- print('je suis dans processor')
-
-
- # """
- # On renseigne les chemins vers les fichiers d'entrée et de sortie
- # """
-
- # input_path = dico['CONTINGENCY_PROCESSING']['XLS_file']
-
- # filename = dico['CONTINGENCY_SELECTION']['case_name'] + '.xlsx'
- # output_path = os.path.join(dico['CASE_SELECTION']['PSEN_results_folder'],filename)
-
-
- # """
- # Cette commande va permettre d'ouvrir le fichier résultat dans lequel on va enregistrer différents onglets
- # Uniquement à la fin de totues les écritures, nous viendrons le sauvegarder
- # """
- # writer = pd.ExcelWriter(output_path, engine='xlsxwriter')
-
-
-
- # """
- # On importe le fichier excel et on crée une DataFrame pour chaque Onglet/Sheet du fichier
- # On récupère également les noms des Onglets/Sheets afin de pouvoir adapter les intitulés des composants et des valeurs
-
- # Voltage ==> 'Bus' ; 'Max Voltage'
- # Flows ==> 'Branch' ; 'Max Violation'
- # """
- # input_excel = pd.ExcelFile(input_path)
-
- # sheet_names_all = dico['CONTINGENCY_PROCESSING']['TabList']
-
-
- # for sheet in sheet_names_all:
-
-
- # """
- # On crée une DataFrame pour l'onglet/sheet actuel
- # Selon le nom de l'onglet/sheet, on précise l'intitulé de la valeur que l'on va récupérer
-
-
- # On crée des listes répertoriant les noms des composants et contingingences en faisant appel aux éléments sélectionnés par l'utilisateur
- # Ces éléments sont stockes dans dicoN1_process
-
- # """
-
- # df = input_excel.parse(sheet)
-
- # conting_label = 'Contingency'
-
- # if 'Voltage' in sheet:
-
- # compo_label = 'Bus'
- # value_label = 'Max Voltage'
-
- # for k in dico['CONTINGENCY_PROCESSING'].keys():
-
- # if 'Voltage' in k and 'Component' in k:
- # compo = dico['CONTINGENCY_PROCESSING'][k]
-
- # elif 'Voltage' in k and 'Contingency' in k:
- # conting = dico['CONTINGENCY_PROCESSING'][k]
-
-
- # elif 'Flows' in sheet:
-
- # compo_label = 'Branch'
- # value_label = 'Max Violation'
-
- # for k in dico['CONTINGENCY_PROCESSING'].keys():
-
- # if 'Flows' in k and 'Component' in k:
- # compo = dico['CONTINGENCY_PROCESSING'][k]
-
- # elif 'Flows' in k and 'Contingency' in k:
- # conting = dico['CONTINGENCY_PROCESSING'][k]
-
-
- # """
- # On range ces listes par ordre alphabétique
- # """
- # compo.sort()
- # conting.sort()
-
- # """
- # On vient créer le squelette de notre matrice, on la remplit de 0
- # """
- # output_excel = pd.DataFrame(index = compo, columns = conting)
- # output_excel = output_excel.fillna(0)
-
-
- # """
- # On vient ranger nos lignes et colonnes par ordre alphabétique, de la même manière que les listes compo et conting
- # """
- # output_excel.sort_index(axis = 1, ascending = True, inplace =True)
- # output_excel.sort_index(axis = 0, ascending = True, inplace = True)
-
-
- # for i in range(len(compo)):
-
- # for j in range(len(conting)):
- # """
- # Cette commande permet de venir selectionner la valeur du composant X impacté par la contingence Y
-
- # """
- # valeur = df[(df[compo_label] == compo[i]) & (df[conting_label] == conting[j])][value_label]
-
-
- # """
- # Cette commande permet de venir remplir notre matrice avec les valeurs récupérés dans la DataFrame d'origine
- # """
- # try:
- # output_excel.loc[compo[i], conting[j]] = float(valeur)
- # except:
- # pass
-
-
- # """
- # On importe notre matrice au format excel
- # """
- # output_excel.to_excel(writer, sheet_name = sheet)
-
- # writer.save()
-
- # """
- # Ajustez la taille des colonnes et lignes automatiquement
- # """
-
- # excel = win32.gencache.EnsureDispatch('Excel.Application')
- # wb = excel.Workbooks.Open(output_path)
-
- # for sheet_to_autofit in sheet_names_all:
- # ws = wb.Worksheets(sheet_to_autofit)
- # ws.Columns.AutoFit()
-
- # wb.Save()
- # excel.Application.Quit()
-
-
-def processXLS_out(dico):
-
- UpdateProcessorOptions(dico)
- indexes = {}
- toGather = {}
- data = {}
- totalData = {}
- # pdb.set_trace()
-
- if Options.csvFileName.endswith('xls'):
- # Step 1 : get the indexes of each columns to process
- wb = xlrd.open_workbook(Options.csvFileName)
- sheets = wb.sheet_names()
- # Now get data from the selected columns. data and TotalData are filled in gatherxlsData and are accessible here
- gatherXlsData(wb, sheets, data, totalData)
- elif Options.csvFileName.endswith('csv'):
-
- ACCCresultsfolder = os.path.dirname(Options.csvFileName) #os.path.join(Options.FolderList[0], "ACCCresults")
- sheets =[]
- for file in os.listdir(ACCCresultsfolder):
- if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) :
- # print(file[0:-4])
- name = str(file[0:-4])
- nomCle = "'"+'Component_List_For_'+str(name)+"'"
- nomCle = nomCle.replace('_ ',' _')
- if nomCle in dico['CONTINGENCY_PROCESSING'].keys():
- sheets.append(file[0:-4])
-
- gatherCsvData(sheets, data, totalData)
-
- # Now we process the gathered data depending on the required calculus
- processedData = {}
-
- for name in sheets:
-
- try:
-
- nomColonne = "'"+'Component_List_For_'+str(name)+"'"
- nomColonne = nomColonne.replace('_ ',' _')
-
- nomLigne = "'"+'Contingency_List_For_'+str(name)+"'"
- nomLigne = nomLigne.replace('_ ',' _')
-
-
- if nomColonne not in dico['CONTINGENCY_PROCESSING'].keys():
- continue
-
- Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
- Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
-
- processedData[name] = [[]]
-
- processedData[name] = Compute.createDoubleArray(totalData[name], processedData[name], name)
-
- except KeyError:
- print("error dans ecriture acc results")
- pass
-
- xlsToOutput(processedData)
-
-def gatherXlsData(wb, sheets, data, totalData):
- for name in sheets:
- sheet = wb.sheet_by_name(name)
- data[name] = []
- totalData[name] = []
-
- for i in range(0, sheet.nrows):
- totalData[name].append([])
- data[name].append([])
- for j in range(0, sheet.ncols):
- # Store data anyway in totalData
- if i == 0:
- totalData[name][i] = [j]
- try:
- totalData[name][i].append(float(sheet.cell_value(i, j)))
- except:
- totalData[name][i].append(sheet.cell_value(i, j))
- try:
- if j == 0:
- try:
- if sheet.cell_value(i, 0) in Options.selectedDoubleRow[name] and sheet.cell_value(i, 1) in Options.selectedDoubleCol[name]:
- pass
- else:
- break
- except:
- break
- if i == 0:
- data[name][i] = [j]
- data[name][i].append(float(sheet.cell_value(i, j)))
- except:
- data[name][i].append('N/A')
-
-def gatherCsvData(sheets, data, totalData):
- # try: #python 2
- for name in sheets:
- ACCCresultsfolder = os.path.dirname(Options.csvFileName)
- ACCCresultsfile = os.path.join(ACCCresultsfolder,name + '.csv')
- h = open(ACCCresultsfile,"rb")
- crd = csv.reader(h,delimiter=";")
-
- data[name] = []
- totalData[name] = []
-
- for i, row in enumerate(crd):
-
- totalData[name].append([])
- data[name].append([])
-
- for j in range(len(row)):
- # Store data anyway in totalData
- if i == 0:
- totalData[name][i] = [j]
- continue
- try:
- totalData[name][i].append(float(row[j]))
- except:
- totalData[name][i].append(row[j])
-
-
-
- h.close()
-
-
-def isData(row):
- for item in row:
- try:
- v = float(item)
- if v > 0:
- return True
- except:
- try:
- v = float(item['mean'])
- if v >= 0: #used to be > 0 but want to keep zero cases!!
- return True
- except:
- pass
- return False
-
-
-def xlsToOutput(data):
- ACCCresultsfolder = os.path.dirname(Options.csvFileName)
- filename = os.path.join(ACCCresultsfolder,"ACCCresults_processed.xlsx")
- workbook = xlsxwriter.Workbook(filename)
- worksheet = workbook.add_worksheet()
- row = 0
-
- for colonne in data:
- col=0
- for cellule in colonne:
- worksheet.write(col, row, cellule)
- col = col+1
- row = row+1
- workbook.close()
-
-
-def xlsToCsv(indexes, data): #if too much data to be written to xls file, output a csv
- for name in data:
- if Options.csvFileName.endswith('.csv'):
- ACCCresultsfolder = os.path.dirname(Options.csvFileName)
- newSheet = os.path.join(ACCCresultsfolder,"Processed_" + name +'.csv')
- totalsSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Total.csv')
- if 'voltage' in name.lower() and 'loadshed' not in name.lower():
- zerosSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Zeros.csv')
- recapSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Recap.csv')
- elif Options.csvFileName.endswith('.xls') or Options.csvFileName.endswith('.xlsx'):
- newSheet = Options.csvFileName[:-4] + '_processed_' + name + '.csv'
- totalsSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Total.csv'
- if 'voltage' in name.lower() and 'loadshed' not in name.lower():
- zerosSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Zeros.csv'
- recapSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Recap.csv'
- with open(newSheet, 'wb') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['mean'])
- except:
- print(item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print('A file has been saved under ' + newSheet + '.')
-
- with open(totalsSheet, 'wb') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['badcase'])
- except:
- print(item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print ('A file has been saved under ' + totalsSheet + '.')
-
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- with open(zerosSheet, 'wb') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['zerocase'])
- except:
- print (item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print( 'A file has been saved under ' + zerosSheet + '.')
-
- with open(recapSheet, 'wb') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']))
- else:
- newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) )
- except:
- print (item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print( 'A file has been saved under ' + recapSheet + '.')
-
- print( 'Processing over.')
-
-def xlsToCsvPython3(indexes, data): #if too much data to be written to xls file, output a csv
- for name in data:
- if Options.csvFileName.endswith('.csv'):
- ACCCresultsfolder = os.path.dirname(Options.csvFileName)
- newSheet = os.path.join(ACCCresultsfolder,"Processed_" + name +'.csv')
- totalsSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Total.csv')
- if 'voltage' in name.lower() and 'loadshed' not in name.lower():
- zerosSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Zeros.csv')
- recapSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Recap.csv')
- elif Options.csvFileName.endswith('.xls') or Options.csvFileName.endswith('.xlsx'):
- newSheet = Options.csvFileName[:-4] + '_processed_' + name + '.csv'
- totalsSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Total.csv'
- if 'voltage' in name.lower() and 'loadshed' not in name.lower():
- zerosSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Zeros.csv'
- recapSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Recap.csv'
- with open(newSheet, 'w', newline='') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['mean'])
- except:
- print(item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print('A file has been saved under ' + newSheet + '.')
-
- with open(totalsSheet, 'w', newline='') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- #print( row)
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['badcase'])
- except:
- print( item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print ('A file has been saved under ' + totalsSheet + '.')
-
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- with open(zerosSheet, 'w', newline='') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- newRow.append(item['zerocase'])
- except:
- print (item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print( 'A file has been saved under ' + zerosSheet + '.')
-
- with open(recapSheet, 'w', newline='') as csvfile:
- writer = csv.writer(csvfile, delimiter = ';')
- flatData = []
- # Flatten data to remove all dict items
- for row in data[name]:
- newRow = []
- for item in row:
- if type(item) == dict:
- try:
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']))
- else:
- newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) )
- except:
- print (item)
- else:
- newRow.append(item)
- flatData.append(newRow)
- for row in flatData:
- writer.writerow(row)
- print( 'A file has been saved under ' + recapSheet + '.')
-
- print( 'Processing over.')
-
-def xlsToXls(indexes, data):
-
- print('xlsToXls')
-
- palette = []
- newWb = xlwt.Workbook(style_compression = 2)
- color = 8
- for name in data:
- # print( name)
- newSheet = newWb.add_sheet(name)
- totalsSheet = newWb.add_sheet(name + '_Total')
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet = newWb.add_sheet(name + '_Zeros')
- recapSheet = newWb.add_sheet(name + '_Recap')
- i = 0
- j = 0
- for row in data[name]:
-
- n = 0
- for item in row:
-
- try:
- newSheet.write(i, n, item)
- totalsSheet.write(i, n, item)
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet.write(i, n, item)
- recapSheet.write(i, n, item)
- except:
- # item is not a cell, it's a dict -> display color
- try:
- if item['color'] == 0x55FF55:
- newSheet.write(i, n, item['mean'])
- totalsSheet.write(i, n, item['badcase'])
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet.write(i, n, item['zerocase'])
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']) )
- else:
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) )
- else:
- if item['color'] in palette:
- style = xlwt.easyxf('pattern: pattern solid, fore_colour custom' + str(item['color']))
- newSheet.write(i, n, item['mean'], style)
- totalsSheet.write(i, n, item['badcase'], style)
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet.write(i, n, item['zerocase'], style)
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']), style)
- else:
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']), style)
- else:
- R = item['color'] / 65536
- G = item['color'] / 256 - R * 256
- B = 0x55
-
- palette.append(item['color'])
- xlwt.add_palette_colour('custom' + str(item['color']), color)
- if R>-0.01 and R<256.01 and G>-0.01 and G<256.01 and B>-0.01 and B<256.01:
- newWb.set_colour_RGB(color, R, G, B)
- style = xlwt.easyxf('pattern: pattern solid, fore_colour custom' + str(item['color']))
- newSheet.write(i, n, item['mean'], style)
- totalsSheet.write(i, n, item['badcase'], style)
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet.write(i, n, item['zerocase'], style)
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']), style)
- else:
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']), style)
- color += 1
- else:
- newSheet.write(i, n, item['mean'])
- totalsSheet.write(i, n, item['badcase'])
- if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
- zerosSheet.write(i, n, item['zerocase'])
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']) )
- else:
- recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) )
-
- except Exception as e:
- print(e)
- n += 1
- continue
- n += 1
- i += 1
- if Options.outFileName == '':
- if Options.ACCcsv:
- name = os.path.join(os.path.dirname(Options.csvFileName),'ACCCresults_processed.xls')
- name = name.replace("/","\\")
- else:
- name = Options.csvFileName[:-4] + '_processed.xls'
- name = name.replace("/","\\")
- else:
- name = Options.outFileName
-
- newWb.save(name)
- print('Processing over. The file has been saved under ' + name + '.')
-
-if __name__ == '__main__':
-
- from dicodicoN1_process import Dico as dico
-
- processXLS(dico)
--- /dev/null
+import xlrd # XLS read
+import xlwt # XLS write
+import csv
+import pdb
+
+import Options
+import Compute
+#from Run import *
+import pickle
+from UpdateOptions import UpdateProcessorOptions
+#from itertools import izip_longest # Reverse the double array
+#from future.moves.itertools import zip_longest
+import itertools
+import os
+import xlsxwriter
+
+import os
+import pandas as pd
+import win32com.client as win32
+
+def getXLSinfo(filename):
+ wb = xlrd.open_workbook(filename)
+ sheets = wb.sheet_names()
+ ret = {}
+ for name in sheets:
+ sheet = wb.sheet_by_name(name)
+ ret[name] = [[],[]]
+ for i in range(0, sheet.nrows):
+ data = str(sheet.cell_value(i, 0))
+ if data not in ret[name][0]:
+ ret[name][0].append(data)
+ data = str(sheet.cell_value(i, 1))
+ if data not in ret[name][1]:
+ ret[name][1].append(data)
+ return ret
+
+def getCSVinfo(csvfilename):
+ foldername = os.path.dirname(csvfilename)
+ sheets =[]
+ for file in os.listdir(foldername):
+ if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) and 'processed_' not in file.lower():
+ sheets.append(file[0:-4])
+ ret = {}
+ for name in sheets:
+ ACCCresultsfile = os.path.join(foldername, name + '.csv')
+ try: #python 2 compatible
+ h = open(ACCCresultsfile,"rb")
+ crd = csv.reader(h,delimiter=";")
+ ret[name] = [[],[]]
+ for i, row in enumerate(crd):
+ if len(row)>2:
+ data = str(row[0])
+ if data not in ret[name][0]:
+ ret[name][0].append(data)
+ data = str(row[1])
+ if data not in ret[name][1]:
+ ret[name][1].append(data)
+ h.close()
+ except: #python 3 compatible
+ h = open(ACCCresultsfile,"r",newline='')
+ crd = csv.reader(h,delimiter=";")
+ ret[name] = [[],[]]
+ for i, row in enumerate(crd):
+ if len(row)>2:
+ data = str(row[0])
+ if data not in ret[name][0]:
+ ret[name][0].append(data)
+ data = str(row[1])
+ if data not in ret[name][1]:
+ ret[name][1].append(data)
+ h.close()
+ return ret
+
+def processXLS(dico):
+ print('je suis dans processor')
+
+ UpdateProcessorOptions(dico)
+ indexes = {}
+ toGather = {}
+ data = {}
+ totalData = {}
+
+ if Options.csvFileName.endswith('xls'):
+ # Step 1 : get the indexes of each columns to process
+ wb = xlrd.open_workbook(Options.csvFileName)
+ sheets = wb.sheet_names()
+ # Now get data from the selected columns. data and TotalData are filled in gatherxlsData and are accessible here
+ gatherXlsData(wb, sheets, data, totalData)
+ # elif Options.csvFileName.endswith('csv'):
+
+ # ACCCresultsfolder = os.path.dirname(Options.csvFileName) #os.path.join(Options.FolderList[0], "ACCCresults")
+ # sheets =[]
+ # for file in os.listdir(ACCCresultsfolder):
+ # if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) :
+ # name = str(file[0:-4])
+ # nomCle = "'"+'Component_List_For_'+str(name)+"'"
+ # nomCle = nomCle.replace('_ ',' _')
+ # if nomCle in dico['CONTINGENCY_PROCESSING'].keys():
+ # sheets.append(file[0:-4])
+ # gatherCsvData(sheets, data, totalData)
+
+ # Now we process the gathered data depending on the required calculus
+ # processedData = {}
+
+ # for name in sheets:
+
+ # try:
+
+ # nomColonne = 'Component_List_For_'+str(name)
+ # nomColonne = nomColonne.replace('_ ',' _')
+
+ # nomLigne = 'Contingency_List_For_'+str(name)
+ # nomLigne = nomLigne.replace('_ ',' _')
+
+ # if nomColonne not in dico['CONTINGENCY_PROCESSING'].keys():
+ # continue
+
+ # Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
+ # Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
+
+ # print('options')
+ # print(type(Options.selectedDoubleCol[str(name)]))
+
+ # print('apres select')
+ # processedData[name] = [[]]
+
+ # processedData[name] = Compute.createDoubleArray(totalData[name], processedData[name], name)
+
+ # xlsToOutput(processedData[name])
+
+
+ # except KeyError:
+ # print("error dans ecriture acc results")
+ # pass
+
+
+
+def processXLS_out(dico):
+
+ UpdateProcessorOptions(dico)
+ indexes = {}
+ toGather = {}
+ data = {}
+ totalData = {}
+ # pdb.set_trace()
+
+ if Options.csvFileName.endswith('xls'):
+ # Step 1 : get the indexes of each columns to process
+ wb = xlrd.open_workbook(Options.csvFileName)
+ sheets = wb.sheet_names()
+ # Now get data from the selected columns. data and TotalData are filled in gatherxlsData and are accessible here
+ gatherXlsData(wb, sheets, data, totalData)
+ elif Options.csvFileName.endswith('csv'):
+
+ ACCCresultsfolder = os.path.dirname(Options.csvFileName) #os.path.join(Options.FolderList[0], "ACCCresults")
+ sheets =[]
+ for file in os.listdir(ACCCresultsfolder):
+ if file.endswith('.csv') and (' Voltage ' in file or ' FlowsDif ' in file or ' Flows ' in file or ' LoadShed ' in file) :
+ # print(file[0:-4])
+ name = str(file[0:-4])
+ nomCle = "'"+'Component_List_For_'+str(name)+"'"
+ nomCle = nomCle.replace('_ ',' _')
+ if nomCle in dico['CONTINGENCY_PROCESSING'].keys():
+ sheets.append(file[0:-4])
+
+ gatherCsvData(sheets, data, totalData)
+
+ # Now we process the gathered data depending on the required calculus
+ processedData = {}
+
+ for name in sheets:
+
+ try:
+
+ nomColonne = "'"+'Component_List_For_'+str(name)+"'"
+ nomColonne = nomColonne.replace('_ ',' _')
+
+ nomLigne = "'"+'Contingency_List_For_'+str(name)+"'"
+ nomLigne = nomLigne.replace('_ ',' _')
+
+
+ if nomColonne not in dico['CONTINGENCY_PROCESSING'].keys():
+ continue
+
+ Options.selectedDoubleCol[str(name)] = dico['CONTINGENCY_PROCESSING'][nomColonne]
+ Options.selectedDoubleRow[str(name)] = dico['CONTINGENCY_PROCESSING'][nomLigne]
+
+ processedData[name] = [[]]
+
+ processedData[name] = Compute.createDoubleArray(totalData[name], processedData[name], name)
+
+ except KeyError:
+ print("error dans ecriture acc results")
+ pass
+
+ xlsToOutput(processedData)
+
+def gatherXlsData(wb, sheets, data, totalData):
+ for name in sheets:
+ sheet = wb.sheet_by_name(name)
+ data[name] = []
+ totalData[name] = []
+
+ for i in range(0, sheet.nrows):
+ totalData[name].append([])
+ data[name].append([])
+ for j in range(0, sheet.ncols):
+ # Store data anyway in totalData
+ if i == 0:
+ totalData[name][i] = [j]
+ try:
+ totalData[name][i].append(float(sheet.cell_value(i, j)))
+ except:
+ totalData[name][i].append(sheet.cell_value(i, j))
+ try:
+ if j == 0:
+ try:
+ if sheet.cell_value(i, 0) in Options.selectedDoubleRow[name] and sheet.cell_value(i, 1) in Options.selectedDoubleCol[name]:
+ pass
+ else:
+ break
+ except:
+ break
+ if i == 0:
+ data[name][i] = [j]
+ data[name][i].append(float(sheet.cell_value(i, j)))
+ except:
+ data[name][i].append('N/A')
+
+def gatherCsvData(sheets, data, totalData):
+ # try: #python 2
+ for name in sheets:
+ ACCCresultsfolder = os.path.dirname(Options.csvFileName)
+ ACCCresultsfile = os.path.join(ACCCresultsfolder,name + '.csv')
+ h = open(ACCCresultsfile,"rb")
+ crd = csv.reader(h,delimiter=";")
+
+ data[name] = []
+ totalData[name] = []
+
+ for i, row in enumerate(crd):
+
+ totalData[name].append([])
+ data[name].append([])
+
+ for j in range(len(row)):
+ # Store data anyway in totalData
+ if i == 0:
+ totalData[name][i] = [j]
+ continue
+ try:
+ totalData[name][i].append(float(row[j]))
+ except:
+ totalData[name][i].append(row[j])
+
+
+
+ h.close()
+ # except: #python 3
+ # for name in sheets:
+ # ACCCresultsfolder = os.path.dirname(Options.csvFileName)
+ # ACCCresultsfile = os.path.join(ACCCresultsfolder,name + '.csv')
+ # h = open(ACCCresultsfile,"r", newline='')
+ # crd = csv.reader(h,delimiter=";")
+
+ # data[name] = []
+ # totalData[name] = []
+
+ # for i, row in enumerate(crd):
+ # totalData[name].append([])
+ # data[name].append([])
+
+ # for j in range(len(row)):
+ ##Store data anyway in totalData
+ # if i == 0:
+ # totalData[name][i] = [j]
+ # try:
+ # totalData[name][i].append(float(row[j]))
+ # except:
+ # totalData[name][i].append(row[j])
+ # try:
+ # if j == 0:
+ # try:
+ # if row[0] in Options.selectedDoubleRow[name] and row[1] in Options.selectedDoubleCol[name]:
+ # pass
+ # else:
+ # break
+ # except:
+ # break
+ # if i == 0:
+ # data[name][i] = [j]
+ # data[name][i].append(float(row[j]))
+ # except:
+ # data[name][i].append('N/A')
+ # h.close()
+
+def isData(row):
+ for item in row:
+ try:
+ v = float(item)
+ if v > 0:
+ return True
+ except:
+ try:
+ v = float(item['mean'])
+ if v >= 0: #used to be > 0 but want to keep zero cases!!
+ return True
+ except:
+ pass
+ return False
+
+
+def xlsToOutput(data):
+ ACCCresultsfolder = os.path.dirname(Options.csvFileName)
+ filename = os.path.join(ACCCresultsfolder,"ACCCresults_processed.xlsx")
+ workbook = xlsxwriter.Workbook(filename)
+ worksheet = workbook.add_worksheet()
+ row = 0
+
+ for colonne in data:
+ col=0
+ for cellule in colonne:
+ worksheet.write(col, row, cellule)
+ col = col+1
+ row = row+1
+ workbook.close()
+
+
+def xlsToCsv(indexes, data): #if too much data to be written to xls file, output a csv
+ for name in data:
+ if Options.csvFileName.endswith('.csv'):
+ ACCCresultsfolder = os.path.dirname(Options.csvFileName)
+ newSheet = os.path.join(ACCCresultsfolder,"Processed_" + name +'.csv')
+ totalsSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Total.csv')
+ if 'voltage' in name.lower() and 'loadshed' not in name.lower():
+ zerosSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Zeros.csv')
+ recapSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Recap.csv')
+ elif Options.csvFileName.endswith('.xls') or Options.csvFileName.endswith('.xlsx'):
+ newSheet = Options.csvFileName[:-4] + '_processed_' + name + '.csv'
+ totalsSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Total.csv'
+ if 'voltage' in name.lower() and 'loadshed' not in name.lower():
+ zerosSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Zeros.csv'
+ recapSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Recap.csv'
+ with open(newSheet, 'wb') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['mean'])
+ except:
+ print(item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print('A file has been saved under ' + newSheet + '.')
+
+ with open(totalsSheet, 'wb') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['badcase'])
+ except:
+ print(item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print ('A file has been saved under ' + totalsSheet + '.')
+
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ with open(zerosSheet, 'wb') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['zerocase'])
+ except:
+ print (item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print( 'A file has been saved under ' + zerosSheet + '.')
+
+ with open(recapSheet, 'wb') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']))
+ else:
+ newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) )
+ except:
+ print (item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print( 'A file has been saved under ' + recapSheet + '.')
+
+ print( 'Processing over.')
+
+def xlsToCsvPython3(indexes, data): #if too much data to be written to xls file, output a csv
+ for name in data:
+ if Options.csvFileName.endswith('.csv'):
+ ACCCresultsfolder = os.path.dirname(Options.csvFileName)
+ newSheet = os.path.join(ACCCresultsfolder,"Processed_" + name +'.csv')
+ totalsSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Total.csv')
+ if 'voltage' in name.lower() and 'loadshed' not in name.lower():
+ zerosSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Zeros.csv')
+ recapSheet = os.path.join(ACCCresultsfolder,"Processed_" + name + '_Recap.csv')
+ elif Options.csvFileName.endswith('.xls') or Options.csvFileName.endswith('.xlsx'):
+ newSheet = Options.csvFileName[:-4] + '_processed_' + name + '.csv'
+ totalsSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Total.csv'
+ if 'voltage' in name.lower() and 'loadshed' not in name.lower():
+ zerosSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Zeros.csv'
+ recapSheet = Options.csvFileName[:-4] + '_processed_' + name + '_Recap.csv'
+ with open(newSheet, 'w', newline='') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['mean'])
+ except:
+ print(item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print('A file has been saved under ' + newSheet + '.')
+
+ with open(totalsSheet, 'w', newline='') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ #print( row)
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['badcase'])
+ except:
+ print( item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print ('A file has been saved under ' + totalsSheet + '.')
+
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ with open(zerosSheet, 'w', newline='') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ newRow.append(item['zerocase'])
+ except:
+ print (item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print( 'A file has been saved under ' + zerosSheet + '.')
+
+ with open(recapSheet, 'w', newline='') as csvfile:
+ writer = csv.writer(csvfile, delimiter = ';')
+ flatData = []
+ # Flatten data to remove all dict items
+ for row in data[name]:
+ newRow = []
+ for item in row:
+ if type(item) == dict:
+ try:
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']))
+ else:
+ newRow.append(str(item['mean']) + ' / ' + str(item['badcase']) )
+ except:
+ print (item)
+ else:
+ newRow.append(item)
+ flatData.append(newRow)
+ for row in flatData:
+ writer.writerow(row)
+ print( 'A file has been saved under ' + recapSheet + '.')
+
+ print( 'Processing over.')
+
+def xlsToXls(indexes, data):
+
+ print('xlsToXls')
+
+ palette = []
+ newWb = xlwt.Workbook(style_compression = 2)
+ color = 8
+ for name in data:
+ # print( name)
+ newSheet = newWb.add_sheet(name)
+ totalsSheet = newWb.add_sheet(name + '_Total')
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet = newWb.add_sheet(name + '_Zeros')
+ recapSheet = newWb.add_sheet(name + '_Recap')
+ i = 0
+ j = 0
+ for row in data[name]:
+
+ n = 0
+ for item in row:
+
+ try:
+ newSheet.write(i, n, item)
+ totalsSheet.write(i, n, item)
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet.write(i, n, item)
+ recapSheet.write(i, n, item)
+ except:
+ # item is not a cell, it's a dict -> display color
+ try:
+ if item['color'] == 0x55FF55:
+ newSheet.write(i, n, item['mean'])
+ totalsSheet.write(i, n, item['badcase'])
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet.write(i, n, item['zerocase'])
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']) )
+ else:
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) )
+ else:
+ if item['color'] in palette:
+ style = xlwt.easyxf('pattern: pattern solid, fore_colour custom' + str(item['color']))
+ newSheet.write(i, n, item['mean'], style)
+ totalsSheet.write(i, n, item['badcase'], style)
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet.write(i, n, item['zerocase'], style)
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']), style)
+ else:
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']), style)
+ else:
+ R = item['color'] / 65536
+ G = item['color'] / 256 - R * 256
+ B = 0x55
+
+ palette.append(item['color'])
+ xlwt.add_palette_colour('custom' + str(item['color']), color)
+ if R>-0.01 and R<256.01 and G>-0.01 and G<256.01 and B>-0.01 and B<256.01:
+ newWb.set_colour_RGB(color, R, G, B)
+ style = xlwt.easyxf('pattern: pattern solid, fore_colour custom' + str(item['color']))
+ newSheet.write(i, n, item['mean'], style)
+ totalsSheet.write(i, n, item['badcase'], style)
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet.write(i, n, item['zerocase'], style)
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']), style)
+ else:
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']), style)
+ color += 1
+ else:
+ newSheet.write(i, n, item['mean'])
+ totalsSheet.write(i, n, item['badcase'])
+ if ' voltage ' in name.lower() and ' loadshed ' not in name.lower() and ' flows ' not in name.lower():
+ zerosSheet.write(i, n, item['zerocase'])
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) + ' / ' + str(item['zerocase']) )
+ else:
+ recapSheet.write(i, n, str(item['mean']) + ' / ' + str(item['badcase']) )
+
+ except Exception as e:
+ print(e)
+ n += 1
+ continue
+ n += 1
+ i += 1
+ if Options.outFileName == '':
+ if Options.ACCcsv:
+ name = os.path.join(os.path.dirname(Options.csvFileName),'ACCCresults_processed.xls')
+ name = name.replace("/","\\")
+ else:
+ name = Options.csvFileName[:-4] + '_processed.xls'
+ name = name.replace("/","\\")
+ else:
+ name = Options.outFileName
+
+ newWb.save(name)
+ print('Processing over. The file has been saved under ' + name + '.')
+
+if __name__ == '__main__':
+
+ from dicoN1_process import Dico as dico
+
+ processXLS(dico)
\ No newline at end of file
+++ /dev/null
-# -*- coding: utf-8 -*-
-"""
-On importe nos modules et on renseigne les chemins vers les fichiers d'entrée et de sortie
-"""
-import os
-import pandas as pd
-import win32com.client as win32
-from dicoN1_process import Dico as dico
-
-input_path = dico['CONTINGENCY_PROCESSING']['XLS_file']
-
-filename = dico['CONTINGENCY_SELECTION']['case_name'] + '.xlsx'
-output_path = os.path.join(dico['CASE_SELECTION']['PSEN_results_folder'],filename)
-
-
-"""
-Cette commande va permettre d'ouvrir le fichier résultat dans lequel on va enregistrer différents onglets
-Uniquement à la fin de totues les écritures, nous viendrons le sauvegarder
-"""
-writer = pd.ExcelWriter(output_path, engine='xlsxwriter')
-
-
-
-"""
-On importe le fichier excel et on crée une DataFrame pour chaque Onglet/Sheet du fichier
-On récupère également les noms des Onglets/Sheets afin de pouvoir adapter les intitulés des composants et des valeurs
-
-Voltage ==> 'Bus' ; 'Max Voltage'
-Flows ==> 'Branch' ; 'Max Violation'
-"""
-input_excel = pd.ExcelFile(input_path)
-
-sheet_names_all = dico['CONTINGENCY_PROCESSING']['TabList']
-
-
-for sheet in sheet_names_all:
-
-
- """
- On crée une DataFrame pour l'onglet/sheet actuel
- Selon le nom de l'onglet/sheet, on précise l'intitulé de la valeur que l'on va récupérer
-
-
- On crée des listes répertoriant les noms des composants et contingingences en faisant appel aux éléments sélectionnés par l'utilisateur
- Ces éléments sont stockes dans dicoN1_process
-
- """
-
- df = input_excel.parse(sheet)
-
- conting_label = 'Contingency'
-
- if 'Voltage' in sheet:
-
- compo_label = 'Bus'
- value_label = 'Max Voltage'
-
- for k in dico['CONTINGENCY_PROCESSING'].keys():
-
- if 'Voltage' in k and 'Component' in k:
- compo = dico['CONTINGENCY_PROCESSING'][k]
-
- elif 'Voltage' in k and 'Contingency' in k:
- conting = dico['CONTINGENCY_PROCESSING'][k]
-
-
- elif 'Flows' in sheet:
-
- compo_label = 'Branch'
- value_label = 'Max Violation'
-
- for k in dico['CONTINGENCY_PROCESSING'].keys():
-
- if 'Flows' in k and 'Component' in k:
- compo = dico['CONTINGENCY_PROCESSING'][k]
-
- elif 'Flows' in k and 'Contingency' in k:
- conting = dico['CONTINGENCY_PROCESSING'][k]
-
-
- """
- On range ces listes par ordre alphabétique
- """
- compo.sort()
- conting.sort()
-
- """
- On vient créer le squelette de notre matrice, on la remplit de 0
- """
- output_excel = pd.DataFrame(index = compo, columns = conting)
- output_excel = output_excel.fillna(0)
-
-
- """
- On vient ranger nos lignes et colonnes par ordre alphabétique, de la même manière que les listes compo et conting
- """
- output_excel.sort_index(axis = 1, ascending = True, inplace =True)
- output_excel.sort_index(axis = 0, ascending = True, inplace = True)
-
-
- for i in range(len(compo)):
-
- for j in range(len(conting)):
- """
- Cette commande permet de venir selectionner la valeur du composant X impacté par la contingence Y
-
- """
- valeur = df[(df[compo_label] == compo[i]) & (df[conting_label] == conting[j])][value_label]
-
-
- """
- Cette commande permet de venir remplir notre matrice avec les valeurs récupérés dans la DataFrame d'origine
- """
- try:
- output_excel.loc[compo[i], conting[j]] = float(valeur)
- except:
- pass
-
-
- """
- On importe notre matrice au format excel
- """
- output_excel.to_excel(writer, sheet_name = sheet)
-
-writer.save()
-
-"""
-Ajustez la taille des colonnes et lignes automatiquement
-"""
-
-excel = win32.gencache.EnsureDispatch('Excel.Application')
-wb = excel.Workbooks.Open(output_path)
-
-for sheet_to_autofit in sheet_names_all:
- ws = wb.Worksheets(sheet_to_autofit)
- ws.Columns.AutoFit()
-
-wb.Save()
-excel.Application.Quit()
\ No newline at end of file
except:
flow_idx += 1
sheet.write(flow_idx, 1, "Contingency")
- sheet.write(flow_idx, 2, "Nb. Violations")
+ sheet.write(flow_idx, 2, "Number of Violations")
sheet.write(flow_idx, 3, "Max Violation")
sheet.write(flow_idx, 4, "Rate (MVA)")
sheet_num = 0
def writeFlowsLines(book, outputExcel, case, SavFileList, ContList, LineList, Flows, BranchesDico, FlowMax, Ops):
rows = []
- row = ["Branch", "Contingency", "Nb. Violations", "Max Violation", "Rate (MVA)"]
+ row = ["Branch", "Contingency", "Number of Violations", "Max Violation", "Rate (MVA)"]
FlowsWriter = book[0]
VoltagesWriter = book[1]
-Dico ={'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/simulationDClog_complete_07h31m35.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'N_PROCESSING_OPTIONS': {'Output_bus_values': False, 'Output_transformer_values': False, 'Output_lines_values': True}}
\ No newline at end of file
+Dico ={'CONTINGENCY_SELECTION': {'TripLines': True, 'csv_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/Test.csv', 'SelectionMethod': 'CaseSelectionFromFile', 'case_name': 'testuno', 'TripTransfos': False, 'TripGenerators': True}, 'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/simulationDClog_complete_07h31m35.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'CONTINGENCY_OPTIONS': {'ActiveLimits': True, 'Vmin': 0.95, 'FlowLimitTransformers': 100, 'AdjustTaps': False, 'VarLimits': True, 'FlowLimitLines': 100, 'FlatStart': False, 'AdjustShunts': False, 'Vmax': 1.05, 'output_file_format': 'xls', 'DispatchMode': 'ReferenceMachine'}}
\ No newline at end of file
-Dico ={'CONTINGENCY_PROCESSING': {'XLS_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/ACCCresults.xls', "'Contingency_List_For_testuno Flows 0'": ['CERVIONE_GHISONACCIA'], "'Component_List_For_testuno Flows 0'": ['Aspretto_Aspretto_Vazzio_Vazzio_ASPRETTO_VAZZIO__LI'], 'TabList': ['testuno Voltage 0', 'testuno Flows 0'], "'Component_List_For_testuno Voltage 0'": ['Corsica_Corsica'], "'Contingency_List_For_testuno Voltage 0'": ['CASTIRLA_CORSICA']}, 'CONTINGENCY_SELECTION': {'TripLines': True, 'csv_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/Test.csv', 'SelectionMethod': 'CaseSelectionFromFile', 'case_name': 'testuno', 'TripTransfos': False, 'TripGenerators': True}, 'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/simulationDClog_complete_07h31m35.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'CONTINGENCY_OPTIONS': {'ActiveLimits': True, 'Vmin': 0.95, 'FlowLimitTransformers': 100, 'AdjustTaps': False, 'VarLimits': True, 'FlowLimitLines': 100, 'FlatStart': False, 'AdjustShunts': False, 'Vmax': 1.05, 'output_file_format': 'xls', 'DispatchMode': 'ReferenceMachine'}}
\ No newline at end of file
+Dico ={'CONTINGENCY_PROCESSING': {'XLS_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/ACCCresults.xls', "'Contingency_List_For_testuno Flows 0'": ['FURIANI_LUCCIANA1'], "'Component_List_For_testuno Flows 0'": ['Aspretto_Aspretto_Vazzio_Vazzio_ASPRETTO_VAZZIO__LI'], 'TabList': ['testuno Voltage 0', 'testuno Flows 0'], "'Component_List_For_testuno Voltage 0'": ['Corte_Corte'], "'Contingency_List_For_testuno Voltage 0'": ['CORTE_MOROSAGLIA']}, 'CONTINGENCY_SELECTION': {'TripLines': True, 'csv_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/Test.csv', 'SelectionMethod': 'CaseSelectionFromFile', 'case_name': 'testuno', 'TripTransfos': False, 'TripGenerators': True}, 'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/simulationDClog_complete_07h31m35.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'CONTINGENCY_OPTIONS': {'ActiveLimits': True, 'Vmin': 0.95, 'FlowLimitTransformers': 100, 'AdjustTaps': False, 'VarLimits': True, 'FlowLimitLines': 100, 'FlatStart': False, 'AdjustShunts': False, 'Vmax': 1.05, 'output_file_format': 'xls', 'DispatchMode': 'ReferenceMachine'}}
\ No newline at end of file
# dico = {'XLS_file': 'X:/Etudes/DEWA_SOLAR/DEWA_2020/tir8/Results/N_20180319_14h06m36/ACCCresults - save/FiveHundred Voltage 0_save.csv', 'TabList': ['FiveHundred Voltage 0_save'], 'Contingency_List_For_FiveHundred__Voltage__0_save': ['Contingency', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR4__3WNDTR4', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR3__3WNDTR3', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR2__3WNDTR2', 'HCCP_PH1_ST1__HSYANCOAL__TRT1'], "'Contingency_List_For_FiveHundred Voltage 0_save'": ['Contingency', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR4__3WNDTR4', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR3__3WNDTR3', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR2__3WNDTR2', 'HCCP_PH1_ST1__HSYANCOAL__TRT1'], 'Component_List_For_FiveHundred__Voltage__0_save': ['Bus', 'SKLN', 'MSJA']}
-dico = {'CONTINGENCY_PROCESSING': {'XLS_file': 'X:/Etudes/DEWA_SOLAR/DEWA_2020/tir8/Results/N_20180319_14h06m36/ACCCresults - save/FiveHundred Voltage 0.csv', 'TabList': ['FiveHundred Voltage 0'], "'Component_List_For_FiveHundred Voltage 0'": ['SKLN', 'MSJA'], "'Contingency_List_For_FiveHundred Voltage 0'": ['MUSH_400_KV__MUSH_132_KV__MUSH_TR4__3WNDTR4', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR3__3WNDTR3', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR2__3WNDTR2', 'HCCP_PH1_ST1__HSYANCOAL__TRT1']}, 'CONTINGENCY_SELECTION': {'N1TransformersList': [], 'TripLines': True, 'N1LinesList': [], 'N1BusesList': [], 'TripBuses': False, 'N1AreaList': [], 'TripTransfos': True, 'TripGenerators': True}, 'CASE_SELECTION': {'NewCsvFile': 'CleanedData.csv', 'DecimalSeparator': '.', 'PSSPY_path': 'C:\\Program Files (x86)\\PTI\\PSSE34\\PSSPY27', 'PSEN_results_csvfile_cleaned': False, 'MaxDepth': 5, 'PSSE_path': 'C:\\Program Files (x86)\\PTI\\PSSE34\\PSSBIN', 'OutputNewCsv': False}, 'CONTINGENCY_OPTIONS': {'SolutionMethod': '1 - FNSL', 'AdjustSwitchedShunts': '0 - Disable', 'Vmin': 0.9, 'FlowLimitTransformers':120, 'Tolerance': 0.5, 'VarLimits': 99, 'FlowLimitLines': 120, 'FlatStart': False, 'AdjustDCtaps': '0 - Disable', 'output_file_format': 'xls', 'AdjustTaps': '1 - Stepping', 'Vmax': 1.1, 'ContingencyRate': 'a', 'DispatchMode': '1 - Reserve'}, 'N_PROCESSING_OPTIONS': {'Output_bus_values': True, 'Output_transformer_values': True, 'Output_lines_values': True}}
+# dico = {'CONTINGENCY_PROCESSING': {'XLS_file': 'X:/Etudes/DEWA_SOLAR/DEWA_2020/tir8/Results/N_20180319_14h06m36/ACCCresults - save/FiveHundred Voltage 0.csv', 'TabList': ['FiveHundred Voltage 0'], "'Component_List_For_FiveHundred Voltage 0'": ['SKLN', 'MSJA'], "'Contingency_List_For_FiveHundred Voltage 0'": ['MUSH_400_KV__MUSH_132_KV__MUSH_TR4__3WNDTR4', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR3__3WNDTR3', 'MUSH_400_KV__MUSH_132_KV__MUSH_TR2__3WNDTR2', 'HCCP_PH1_ST1__HSYANCOAL__TRT1']}, 'CONTINGENCY_SELECTION': {'N1TransformersList': [], 'TripLines': True, 'N1LinesList': [], 'N1BusesList': [], 'TripBuses': False, 'N1AreaList': [], 'TripTransfos': True, 'TripGenerators': True}, 'CASE_SELECTION': {'NewCsvFile': 'CleanedData.csv', 'DecimalSeparator': '.', 'PSSPY_path': 'C:\\Program Files (x86)\\PTI\\PSSE34\\PSSPY27', 'PSEN_results_csvfile_cleaned': False, 'MaxDepth': 5, 'PSSE_path': 'C:\\Program Files (x86)\\PTI\\PSSE34\\PSSBIN', 'OutputNewCsv': False}, 'CONTINGENCY_OPTIONS': {'SolutionMethod': '1 - FNSL', 'AdjustSwitchedShunts': '0 - Disable', 'Vmin': 0.9, 'FlowLimitTransformers':120, 'Tolerance': 0.5, 'VarLimits': 99, 'FlowLimitLines': 120, 'FlatStart': False, 'AdjustDCtaps': '0 - Disable', 'output_file_format': 'xls', 'AdjustTaps': '1 - Stepping', 'Vmax': 1.1, 'ContingencyRate': 'a', 'DispatchMode': '1 - Reserve'}, 'N_PROCESSING_OPTIONS': {'Output_bus_values': True, 'Output_transformer_values': True, 'Output_lines_values': True}}
# ent_List_For_FiveHundred__Voltage__0_save': ['Bus', 'SKLN', 'MSJA']}
-# dico ={'CONTINGENCY_PROCESSING': {"'Component_List_For_MinAvgVolt Flows 0'": ['Aspretto_Aspretto_Vazzio_Vazzio_ASPRETTO_VAZZIO__LI'], 'XLS_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190529_09h33m33/ACCCresults.xls', "'Component_List_For_MinAvgVolt Voltage 0'": ['Castirla_Castirla'], "'Contingency_List_For_MinAvgVolt Flows 0'": ['LUCCIANA_HTB_2 [Lucciana]'], "'Contingency_List_For_MinAvgVolt Voltage 0'": ['FURIANI_ZI_OLETTA'], 'TabList': ['MinAvgVolt Flows 0', 'MinAvgVolt Voltage 0']}, 'CONTINGENCY_SELECTION': {'TripTransfos': False, 'TripLines': True, 'AvgLowVoltage': 1, 'SelectionMethod': 'SelectWorstCases', 'TripGenerators': True}, 'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190529_09h33m33/simulationDClog_complete_09h33m33.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190529_09h33m33', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'CONTINGENCY_OPTIONS': {'ActiveLimits': True, 'Vmin': 0.95, 'FlowLimitTransformers': 100, 'AdjustTaps': False, 'VarLimits': True, 'FlowLimitLines': 100, 'FlatStart': False, 'AdjustShunts': False, 'Vmax': 1.05, 'output_file_format': 'xls', 'DispatchMode': 'ReferenceMachine'}}
+dico ={'CONTINGENCY_PROCESSING': {'XLS_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/ACCCresults.xls', "'Contingency_List_For_testuno Flows 0'": ['VAZ_G10 [Vazzio]', 'CERVIONE_GHISONACCIA'], "'Component_List_For_testuno Flows 0'": ['Aspretto_Aspretto_Vazzio_Vazzio_ASPRETTO_VAZZIO__LI'], 'TabList': ['testuno Voltage 0', 'testuno Flows 0'], "'Component_List_For_testuno Voltage 0'": ['Corsica_Corsica', 'SainteLucie_SainteLucie'], "'Contingency_List_For_testuno Voltage 0'": ['CASTIRLA_CORSICA', 'FURIANI_ZI_OLETTA']}, 'CONTINGENCY_SELECTION': {'TripLines': True, 'csv_file': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/Test.csv', 'SelectionMethod': 'CaseSelectionFromFile', 'case_name': 'testuno', 'TripTransfos': False, 'TripGenerators': True}, 'CASE_SELECTION': {'TransformersList': [], 'PSEN_results_csvfile': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35/simulationDClog_complete_07h31m35.csv', 'DecimalSeparator': ',', 'MaxDepth': 5, 'NewCsvFile': 'CleanedData.csv', 'PSEN_results_csvfile_cleaned': False, 'Python3_path': 'C:/Python35', 'PF_path': 'C:\\Program Files\\DIgSILENT\\PowerFactory 2017 SP1\\Python\\3.5', 'LinesList': ['90.0'], 'PSEN_results_folder': 'C:/Users/H92579/Documents/PSEN_simu/ResultatSimu/N_20190621_07h31m35', 'OutputNewCsv': False, 'BusesList': ['90.0']}, 'CONTINGENCY_OPTIONS': {'ActiveLimits': True, 'Vmin': 0.95, 'FlowLimitTransformers': 100, 'AdjustTaps': False, 'VarLimits': True, 'FlowLimitLines': 100, 'FlatStart': False, 'AdjustShunts': False, 'Vmax': 1.05, 'output_file_format': 'xls', 'DispatchMode': 'ReferenceMachine'}}
\ No newline at end of file