import glob


def createPlotString(postAnalyzerPath, description):
    """ Create the plotFile readable by the PostPlot*.py program. 
    
        Args:
            postAnalyzerPath: Path to the output from PostAnalyzer
            description: description of the results (for instance canonical or submatrix)
            
        Returns:
            plotFile readable by the PostPlot*.py program
    """
    analyzedFolders = glob.glob(postAnalyzerPath+"*/")
    scriptLine = []
    script = []
    for folder in analyzedFolders:
        if not (folder.endswith('_rigid/') or folder.endswith('_medium/') or folder.endswith('_difficult/') or folder.endswith('_all/')):
            continue 
        scriptLine = []
        scriptLine.append(folder)
        scriptLine.append(description)
        scriptLine.append("AssessmentWhole") # for now, later this needs to be refactored to made the argument optional
        difficulty = folder[folder.rfind("_")+1:-1]
        difficulty = difficulty.upper()[0]+difficulty[1:]
        scriptLine.append("Difficulty"+difficulty)
        script.append(scriptLine)
    # sort to have all, difficult, medium, rigid in this order (a before d before m before r)
    script.sort(key=lambda x: x[3], reverse=False)
    return script