diff --git a/src/main/java/keml/analysis/AnalysisProvider.java b/src/main/java/keml/analysis/AnalysisProvider.java index 8a1ce8e..f10e298 100644 --- a/src/main/java/keml/analysis/AnalysisProvider.java +++ b/src/main/java/keml/analysis/AnalysisProvider.java @@ -63,7 +63,7 @@ public static void main(String[] args) throws IOException { runFurtherAnalysis = Boolean.parseBoolean(args[0]); folder = args[1]; sourceFolder = new File(folder + "/keml/"); - file = new File(sourceFolder.getAbsolutePath() + args[2]); + file = new File(sourceFolder.getAbsolutePath() + "/" + args[2]); } runAnalysis(file.toPath(), runFurtherAnalysis, folder, ExecutionMode.STANDARD); } diff --git a/src/main/java/keml/analysis/PythonExecutor.java b/src/main/java/keml/analysis/PythonExecutor.java index 8082239..f08eeea 100644 --- a/src/main/java/keml/analysis/PythonExecutor.java +++ b/src/main/java/keml/analysis/PythonExecutor.java @@ -51,5 +51,9 @@ public static boolean runPythonScript(String filePath, String fileName, Executio } } } + + public static void main(String[] args) { + runPythonScript("../keml.sample/introductoryExamples/analysis/2-1-keml", "2-1-keml", ExecutionMode.STANDARD); + } } diff --git a/src/main/java/keml/analysis/WorkbookController.java b/src/main/java/keml/analysis/WorkbookController.java index 2499765..a91d72a 100644 --- a/src/main/java/keml/analysis/WorkbookController.java +++ b/src/main/java/keml/analysis/WorkbookController.java @@ -15,6 +15,7 @@ import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.xssf.usermodel.XSSFCellStyle; @@ -43,6 +44,8 @@ public class WorkbookController { XSSFCellStyle factStyle; XSSFCellStyle origLLMStyle; XSSFCellStyle origOtherStyle; + XSSFCellStyle targetStyle; + XSSFCellStyle repeatedStyle; // data properties int firstFreeColumn = 0; @@ -128,44 +131,60 @@ public WorkbookController() { trustStyle = wb.createCellStyle(); trustStyle.setDataFormat(floatStyle.getDataFormat()); trustStyle.setAlignment(HorizontalAlignment.CENTER); + trustStyle.setVerticalAlignment(VerticalAlignment.CENTER); trustStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#339966"), null)); trustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // *************** Distrust ************* distrustStyle = wb.createCellStyle(); trustStyle.setDataFormat(floatStyle.getDataFormat()); distrustStyle.setAlignment(HorizontalAlignment.CENTER); + distrustStyle.setVerticalAlignment(VerticalAlignment.CENTER); distrustStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FF5F5F"), null)); distrustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // *************** neutral about trust ************* neutTrustStyle = wb.createCellStyle(); - trustStyle.setDataFormat(floatStyle.getDataFormat()); + neutTrustStyle.setDataFormat(floatStyle.getDataFormat()); neutTrustStyle.setAlignment(HorizontalAlignment.CENTER); + neutTrustStyle.setVerticalAlignment(VerticalAlignment.CENTER); neutTrustStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex()); neutTrustStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // ************** isFact ************* factStyle = wb.createCellStyle(); factStyle.setAlignment(HorizontalAlignment.CENTER); + factStyle.setVerticalAlignment(VerticalAlignment.CENTER); factStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#99CC00"), null)); factStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // ************* is Instruction ********** instructionStyle = wb.createCellStyle(); instructionStyle.setAlignment(HorizontalAlignment.CENTER); + instructionStyle.setVerticalAlignment(VerticalAlignment.CENTER); instructionStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FFCC00"), null)); instructionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // *************** origin LLM style************** origLLMStyle = wb.createCellStyle(); + origLLMStyle.setWrapText(true); origLLMStyle.setAlignment(HorizontalAlignment.LEFT); origLLMStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#CCFFFF"), null)); origLLMStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // *************** origin Other style************** origOtherStyle = wb.createCellStyle(); + origOtherStyle.setWrapText(true); origOtherStyle.setAlignment(HorizontalAlignment.LEFT); origOtherStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FFFF99"), null)); origOtherStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - + + // *************** target style************** + targetStyle = wb.createCellStyle(); + targetStyle.setAlignment(HorizontalAlignment.CENTER); + targetStyle.setVerticalAlignment(VerticalAlignment.CENTER); + + // *************** repeated style************** + repeatedStyle = wb.createCellStyle(); + repeatedStyle.setAlignment(HorizontalAlignment.CENTER); + repeatedStyle.setVerticalAlignment(VerticalAlignment.CENTER); } public void initialize(List newInfos, List preKnowledge) { @@ -178,16 +197,21 @@ public void initialize(List newInfos, List preKnow t.setCellValue(-1); colorByIsInstruction(t, pre.isIsInstruction()); Cell msg = r.createCell(1); - msg.setCellValue(pre.getMessage()); + msg.setCellValue(pre.getMessage()); colorByOrigin(msg, false); - r.createCell(2).setCellValue(pre.getTargetedBy().size()); - r.createCell(3).setCellValue(pre.getRepeatedBy().size()); + Cell target = r.createCell(2); + target.setCellValue(pre.getTargetedBy().size()); + target.setCellStyle(targetStyle); + Cell repeated = r.createCell(3); + repeated.setCellValue(pre.getRepeatedBy().size()); + repeated.setCellStyle(repeatedStyle); Float fTi = pre.getFeltTrustImmediately(); Float fTa = pre.getFeltTrustAfterwards(); float fTiCellValue = fTi != null ? fTi.floatValue() : Float.NaN; float fTaCellValue = fTa != null ? fTa.floatValue() : Float.NaN; setAndColorByValue(r.createCell(4), fTiCellValue); setAndColorByValue(r.createCell(5), fTaCellValue); + r.setHeight((short)-1); } for (int i = 0; i < newInfos.size(); i++) { NewInformation info = newInfos.get(i); @@ -197,16 +221,21 @@ public void initialize(List newInfos, List preKnow t.setCellValue(info.getTiming()); colorByIsInstruction(t, info.isIsInstruction()); Cell msg = r.createCell(1); - msg.setCellValue(info.getMessage()); + msg.setCellValue(info.getMessage()); colorByOrigin(msg, info.getSourceConversationPartner().getName().equals("LLM")); - r.createCell(2).setCellValue(info.getTargetedBy().size()); - r.createCell(3).setCellValue(info.getRepeatedBy().size()); + Cell target = r.createCell(2); + target.setCellValue(info.getTargetedBy().size()); + target.setCellStyle(targetStyle); + Cell repeated = r.createCell(3); + repeated.setCellValue(info.getRepeatedBy().size()); + repeated.setCellStyle(repeatedStyle); Float fTi = info.getFeltTrustImmediately(); Float fTa = info.getFeltTrustAfterwards(); float fTiCellValue = fTi != null ? fTi.floatValue() : Float.NaN; float fTaCellValue = fTa != null ? fTa.floatValue() : Float.NaN; setAndColorByValue(r.createCell(4), fTiCellValue); setAndColorByValue(r.createCell(5), fTaCellValue); + r.setHeight((short)-1); } } @@ -240,7 +269,11 @@ public void addTrusts(HashMap> trusts, String na private void sizeColumns() { for (int i = 0; i < firstFreeColumn; i++) { - sheet.autoSizeColumn(i); + if (i == 1) { + sheet.setColumnWidth(i, 50*250); + } else { + sheet.autoSizeColumn(i); + } } } diff --git a/src/main/java/keml/analysis/py/main.py b/src/main/java/keml/analysis/py/main.py index ad940b5..bc05d21 100644 --- a/src/main/java/keml/analysis/py/main.py +++ b/src/main/java/keml/analysis/py/main.py @@ -19,8 +19,10 @@ def main(): continue f_s = os.path.join(user_dir_path, ana_file) h_t = f'{user_dir_path}/stats_{file_name}/{os.path.splitext(ana_file)[0]}' - workbook_editor.insert_rand_values(f_s) - workbook_analyser.run_wb_analysis(f_s, h_t) + success = workbook_analyser.run_wb_analysis(f_s, h_t) + if not success: + print("Cannot provide further analysis if felt trusts are not set.") + return if __name__ == '__main__': main() diff --git a/src/main/java/keml/analysis/py/workbook_analyser.py b/src/main/java/keml/analysis/py/workbook_analyser.py index 5fed447..f019aac 100644 --- a/src/main/java/keml/analysis/py/workbook_analyser.py +++ b/src/main/java/keml/analysis/py/workbook_analyser.py @@ -44,7 +44,7 @@ def add_new_columns(ws): for i in range(len(cells)): if (i % 2 == 0): cells[i].border = Border(left=b2) - cells[i].alignment = Alignment(horizontal='center') + cells[i].alignment = Alignment(horizontal='center', vertical='center') cells[i].number_format = "+0.00;-0.00;0.00" def fill_diff_columns(ws): @@ -73,9 +73,10 @@ def run_wb_analysis(path_f, path_h): ws = wb['Trust'] add_new_columns(ws) fill_diff_columns(ws) - create_stats(ws, path_h) + success = create_stats(ws, path_h) wb.save(path_f) wb.close() + return success def create_histograms(path_t_h, diffs_fT, key): fig = plt.figure(figsize=(10,4)) @@ -118,6 +119,8 @@ def create_stats(ws, path_t_h): for key in diffs_fT: diffs_fT[key][0] = [cells[0].value for cells in ws[f'{columns[key][0]}3:{columns[key][0]}{l}']] diffs_fT[key][1] = [cells[0].value for cells in ws[f'{columns[key][1]}3:{columns[key][1]}{l}']] + if '#NUM!' in diffs_fT[key][0]: + return False if not os.path.exists(path_t_h): os.mkdir(path_t_h) create_histograms(path_t_h, diffs_fT, key) @@ -148,15 +151,33 @@ def create_stats(ws, path_t_h): cells[1].value = std_abs_diffs_fT[key][1] i += 1 stat_names = ['Mean of |fT_ - F(mode)|', 'Variance of |fT_ - F(mode)|', 'Standard deviation of |fT_ - F(mode)|'] - b1 = Side(border_style="medium", color="000000") + b1 = Side(border_style="medium", color="FFFFFF") + mean_fill = PatternFill(start_color='629BF0', end_color='629BF0', fill_type='solid') + var_fill = PatternFill(start_color='E79221', end_color='E79221', fill_type='solid') + std_fill = PatternFill(start_color='8ECA3E', end_color='8ECA3E', fill_type='solid') k = 0 - ws.column_dimensions['N'].width = np.max([len(stat_name) for stat_name in stat_names]) - for cells in ws[f'N{l + 3}:V{l + 5}']: - cells[0].alignment = Alignment(horizontal='right') + for cells in ws[f'B{l + 3}:B{l + 5}']: + cells[0].alignment = Alignment(horizontal='left') cells[0].value = stat_names[k] - for i in range(1, len(cells)): - if (i % 2 != 0): + match k: + case 0: + cells[0].fill = mean_fill + case 1: + cells[0].fill = var_fill + case 2: + cells[0].fill = std_fill + k+=1 + k = 0 + for cells in ws[f'O{l + 3}:V{l + 5}']: + for i in range(0, len(cells)): + if ((i + 1) % 2 != 0): cells[i].border = Border(left=b1) + match k: + case 0: + cells[i].fill = mean_fill + case 1: + cells[i].fill = var_fill + case 2: + cells[i].fill = std_fill k+=1 - - \ No newline at end of file + return True \ No newline at end of file