Skip to content

Commit

Permalink
Near working
Browse files Browse the repository at this point in the history
Krippendorf left and consistencies
  • Loading branch information
grigsos committed Mar 27, 2023
1 parent f7cb128 commit 20e013e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 35 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 6 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.methods import data_processing, data_validation, initialisation, data_import
from src.methods import data_processing, initialisation, data_import
import time #to remove possibly as log time is enough
import logging

Expand All @@ -9,12 +9,13 @@ def main():
start_time = time.time()

mainFolderPath,configFileMain,hashL, xlsxList = initialisation.main()
levelListM,weightListM, dimensionListM, interDimensionalListM, kripSimplifiedListM=data_import.main(mainFolderPath,configFileMain, xlsxList)
#data_processing.main(testVar)
#dontforget to use hashList
levelListM,inputsSubListM, inputsDimListM, inputsInterDimensionalListM, kripSimplifiedListM=data_import.main(mainFolderPath,configFileMain, xlsxList)
outputDataframeMain, subDimConsistencyListMain, DimConsistencyListMain, DimWeightListMain,DimConsistencyListMain=data_processing.main(inputsSubListM, inputsDimListM)

from src.methods import report_generator # to make global variable work
report_generator.main(mainFolderPath,configFileMain,len(xlsxList),levelListM,weightListM, dimensionListM, interDimensionalListM, kripSimplifiedListM)
report_generator.main(mainFolderPath,configFileMain,len(xlsxList),levelListM,inputsSubListM, inputsDimListM,
inputsInterDimensionalListM, kripSimplifiedListM,outputDataframeMain,
subDimConsistencyListMain, DimConsistencyListMain,DimWeightListMain)

logging.info("Program ended")
logging.info("Program runtime: " + f"{(time.time() - start_time):.2f}" + " seconds")
Expand Down
20 changes: 3 additions & 17 deletions src/methods/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,7 @@ def start_import(pathList, worksheetList, comparisonColumn, startingRow,subCompy
#print(get_krippendorff_DF(pd.concat(wList,axis=0)))
kripSimpleList = []

"""
for num in [15,13,11,9, 7, 5, 3]:
mWL, oG = simplify_krip(num)
for i, df in enumerate(wList):
wList[i] = df.applymap(lambda x: replace_with_lists(x, oG, mWL))
kripSimpleList.append(wList.copy())
concatKripSimpleList = concat_dataframes(kripSimpleList)
resultKripSimpleList = []
for df in concatKripSimpleList:
resultKripSimpleList.append(get_krippendorff_DF(df))
print (resultKripSimpleList)
"""

#verticalAdd= pd.concat(wList,axis=0) #join all dataframes vertically
#print(get_krippendorff_DF(verticalAdd))
#print(get_krippendorff_DF(pd.concat(lList,axis=0)))
Expand All @@ -87,7 +74,7 @@ def get_data(pathList, worksheetList, levelColumn, weightColumn, startingRow, su
levelList = [pd.DataFrame() for _ in range(len(worksheetList))]
weightList = [pd.DataFrame() for _ in range(len(worksheetList))]
dimensionList = pd.DataFrame()
interdimensionalList = []
interdimensionalList = pd.DataFrame()

for filePath in pathList:
filename = os.path.splitext(os.path.basename(filePath))[0]
Expand All @@ -105,12 +92,11 @@ def get_data(pathList, worksheetList, levelColumn, weightColumn, startingRow, su
sheet = xl.parse(sheet_name=sSL[0][0], skiprows=sSL[0][2]-2, usecols=sSL[0][1], nrows=sSL[0][3]-sSL[0][2]+1, names=[filename])
sheet = sheet.applymap(lambda x: round(x, 4))
dimensionList = pd.concat([dimensionList, sheet], axis=1)
#dimensionList.append(sheet)

sheet = xl.parse(sheet_name=sSL[1][0], skiprows=sSL[1][2]-2, usecols=sSL[1][1], nrows=sSL[1][3]-sSL[1][2]+1, names=[filename])
sheet = sheet.fillna(0)
sheet = sheet.applymap(lambda x: round(x, 4))
interdimensionalList.append(sheet)
interdimensionalList = pd.concat([interdimensionalList,sheet], axis=1)
xl.close()


Expand Down
75 changes: 72 additions & 3 deletions src/methods/data_processing.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,89 @@
import pandas as pd
import logging
import numpy as np

from src.methods.math_model.AHP_analysis import ahp
from src.methods.math_model.MatrixMake import main as matrix_make


def main(data):
def main(subInputList,dimInputList):
logging.info("M - Data processing started")

RI=[0,0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49,1.51,1.48,1.56,1.57,1.59] # for consistency index
#RI=[0,0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49,1.51,1.48,1.56,1.57,1.59] # for consistency index

#data = pd.DataFrame({'a': [3,0.5,0.5,1,0.5,0.25,0.25,0.25,0.25,0.3333,2,0.5,3,2,0.3333]})
#print(data)
#matrix = matrix_make(data)
#print(ahp(matrix,RI[matrix.shape[0]]))
subDimListWeights, subDimConsistencyList = process_list_to_usable(subInputList)
DimWeightList,DimConsistencyList,colList = process_dataframe_to_usable(dimInputList)

outputList = multiply_weights(subDimListWeights,DimWeightList)
outputCalcWeights= convert_to_dataframe(outputList,colList)
#outputDimWeights = convert_to_dataframe(DimWeightList,colList)
outputSubDimweights = convert_to_dataframe(subDimListWeights,colList)
outputConsistency = convert_to_dataframe(subDimConsistencyList,colList)
#outputDimConsistency = convert_to_dataframe(DimConsistencyList,colList)


logging.info("M - Data processing finished successfully")
return None
return outputCalcWeights,outputSubDimweights,outputConsistency, DimWeightList,DimConsistencyList


def process_list_to_usable(uncutList):
RI=[0,0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49,1.51,1.48,1.56,1.57,1.59] # for consistency index
workingListWeights = []
workingConsistencyIndexList = []
for subInput in range(len(uncutList)):
currentSubDimWeight = []
curentSubConsistency = []
for col_name in uncutList[subInput].columns:
col = uncutList[subInput][col_name]
working_matrix = matrix_make(col)
working_weight_list, working_consistency_index = ahp(working_matrix,RI[working_matrix.shape[0]])
currentSubDimWeight.append(working_weight_list)
curentSubConsistency.append(working_consistency_index)

workingListWeights.append(currentSubDimWeight)
workingConsistencyIndexList.append(curentSubConsistency)

return workingListWeights, workingConsistencyIndexList

def process_dataframe_to_usable(uncutDataframe):
RI=[0,0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49,1.51,1.48,1.56,1.57,1.59] # for consistency index
workingListWeights = []
workingConsistencyIndexList = []
columnList = []

for col_name in uncutDataframe.columns:
columnList.append(col_name)
col = uncutDataframe[col_name]
working_matrix = matrix_make(col)
working_weight_list, working_consistency_index = ahp(working_matrix,RI[working_matrix.shape[0]])
workingListWeights.append(working_weight_list)
workingConsistencyIndexList.append(working_consistency_index)



return workingListWeights, workingConsistencyIndexList, columnList

def multiply_weights(sudDimWeights, dimWeights):
finalList=[]
for dim in range(len(sudDimWeights)):
workingListWeights = []
#print(len(subDimListWeights[dim]))
for file in range(len(dimWeights)):
#print(type(sudDimWeights[dim][file]))
#print(type(dimWeights[file][dim]))
workingListWeights.append(sudDimWeights[dim][file]*dimWeights[file][dim])
finalList.append(workingListWeights)

return finalList

def convert_to_dataframe(listToConvert,columnList):
outDF = pd.DataFrame()
for i in range(len(listToConvert)):
workDf = pd.concat([pd.Series(arr) for arr in listToConvert[i]], axis=1)
outDF = pd.concat([outDF,workDf],axis=0)
outDF.columns = columnList
return outDF
Empty file removed src/methods/data_validation.py
Empty file.
61 changes: 52 additions & 9 deletions src/methods/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import sys
import datetime
import pandas as pd
import numpy as np

from src.methods.data_import import subCompListy

##############Main function##############
def main(mFP,cFM,nList,levelListSM,weightListSM, dimensionListSM, interDimensionalListSM, kripSimplifiedListSM):
logging.info("Report generation started")
def main(mFP,cFM,nList,levelListSM,weightListSM, dimensionListSM,
interDimensionalListSM, kripSimplifiedListSM, outputDataframeSM,
subDimConsistencyListSM, DimConsistencyListSM,DimWeightListSM):
logging.info("M - Report generation started")
outFolderPath = check_output_folder(cFM.get("Settings", "outputFolder"),mFP) #check if output folder exists
listDimension,combinedList=get_subsection(cFM) #get subsections and dimensions from config file
sOF=make_folder(outFolderPath,nList) #returns specific output folder
Expand All @@ -18,7 +21,11 @@ def main(mFP,cFM,nList,levelListSM,weightListSM, dimensionListSM, interDimension
csv_levels(levelListSM,sOF,combinedList) #generates csv file with levels
csv_sub_inputs_pre(weightListSM,sOF) #generates csv file with subdimension inputs
csv_dim_inputs_pre(dimensionListSM,sOF) #generates csv file with dimensions inputs
logging.info("Report generation finished successfully")
csv_interdim_comparisions_input(interDimensionalListSM,sOF) #generates csv file with interdimensional comparisions
csv_calculated_weights(outputDataframeSM,sOF,combinedList,DimWeightListSM,listDimension) #generates csv file with calculated weights


logging.info("M - Report generation finished successfully")
return None


Expand Down Expand Up @@ -49,10 +56,6 @@ def check_output_folder(folderName,pathFold): #check if excel survey folder exis
logging.info("'" + folderName + "' folder created")
return joinedOutputPath

def make_header():

return -1

def make_folder(oFP,num_participants):
folder_name = get_current_time() + " - " + str(num_participants) + " participant(s)"
specificOutFolder = os.path.join(oFP, folder_name)
Expand All @@ -75,12 +78,12 @@ def get_current_time():

def csv_sub_inputs_pre(wL,sOF):
verticalAdd= pd.concat(wL,axis=0)
outPath=os.path.join(sOF, "inputs_subdimensions_pre_transf.csv")
outPath=os.path.join(sOF, "inputs_subdimensions.csv")
verticalAdd.to_csv(outPath, index=True)
return None

def csv_dim_inputs_pre(dL,sOF):
outPath=os.path.join(sOF, "inputs_dimensions_pre_transf.csv")
outPath=os.path.join(sOF, "inputs_dimensions.csv")
dL.to_csv(outPath, index=True)
return None

Expand All @@ -89,4 +92,44 @@ def csv_levels(df,sOF,combL):
verticalAdd.index=combL
outPath=os.path.join(sOF, "levels.csv")
verticalAdd.to_csv(outPath, index=True)
return None

def csv_kripke_simplified(kSL,sOF): #doesn't work
verticalAdd= pd.concat(kSL,axis=0)
outPath=os.path.join(sOF, "kripke_simplified.csv")
verticalAdd.to_csv(outPath, index=True)
return None

def csv_calculated_weights(df,sOF,combL,DimWeightListSMFunc,listDimensionFunc):
data = {}

# Loop through each array in the list and create a column name and add to the dictionary
for i, array in enumerate(DimWeightListSMFunc):
column_name = 'col' + str(i + 1) # Create a column name for the array
data[column_name] = array # Add the array to the dictionary with its column name

# Create a pandas dataframe using the dictionary
dfDimension = pd.DataFrame(data)
dfDimension.index=listDimensionFunc


df.index=combL
dfDimension.columns=df.columns


finalout = pd.concat([dfDimension,df],axis=0)
outPath=os.path.join(sOF, "Calculated_weights.csv")
finalout.to_csv(outPath, index=True)
return None

def csv_consistency_indexes():
return None


def csv_interdim_comparisions_input(iDL,sOF):
outPath=os.path.join(sOF, "inputs_interdimensions.csv")
iDL.to_csv(outPath, index=True)
return None

def csv_base_math_model():
return None
1 change: 0 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_program_files_present():
assert os.path.isfile(os.path.join ("src","methods","initialisation.py"))
assert os.path.isfile(os.path.join ("src","methods","data_processing.py"))
assert os.path.isfile(os.path.join ("src","methods","report_generator.py"))
assert os.path.isfile(os.path.join ("src","methods","data_validation.py"))

def test_aditional_files_present():
test_program_files_present()
Expand Down

0 comments on commit 20e013e

Please sign in to comment.