changeset 264:4345ba8a1b6e

Scripts: choose input/output folder from command line; score_plot also choose options from command line (WIP)
author Brecht De Man <b.deman@qmul.ac.uk>
date Mon, 20 Jul 2015 12:47:16 +0100
parents ef2d63555702
children 8020152a36af
files scripts/evaluation_stats.py scripts/score_parser.py scripts/score_plot.py scripts/timeline_view.py
diffstat 4 files changed, 116 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/evaluation_stats.py	Wed Jul 15 15:52:56 2015 +0100
+++ b/scripts/evaluation_stats.py	Mon Jul 20 12:47:16 2015 +0100
@@ -4,9 +4,19 @@
 import xml.etree.ElementTree as ET
 import os       # for getting files from directory
 import operator # for sorting data with multiple keys
+import sys      # for accessing command line arguments
 
-# XML results files location (modify as needed):
-folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+# Command line arguments
+assert len(sys.argv)<3, "evaluation_stats takes at most 1 command line argument\n"+\
+                        "Use: python evaluation_stats.py [results_folder]"
+
+# XML results files location
+if len(sys.argv) == 1:
+    folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+    print "Use: python evaluation_stats.py [results_folder]"
+    print "Using default path: " + folder_name
+elif len(sys.argv) == 2:
+    folder_name = sys.argv[1]   # First command line argument is folder
 
 # Turn number of seconds (int) to '[minutes] min [seconds] s' (string)
 def seconds2timestr(time_in_seconds):
@@ -126,6 +136,8 @@
 print "Number of fragments: " + str(number_of_fragments)
 print "Number of empty comments: " + str(total_empty_comments)
 print "Average time per page: " + seconds2timestr(time_per_page_accum/number_of_pages)
+
+# Pages and number of times tested
 page_count_strings = list(str(x) for x in page_count)
 count_list = page_names + page_count_strings
 count_list[::2] = page_names
--- a/scripts/score_parser.py	Wed Jul 15 15:52:56 2015 +0100
+++ b/scripts/score_parser.py	Mon Jul 20 12:47:16 2015 +0100
@@ -2,12 +2,23 @@
 
 import xml.etree.ElementTree as ET
 import os
+import sys
 import csv
 
 #TODO Remove DEBUG statements
 
-# XML results files location (modify as needed):
-folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+# COMMAND LINE ARGUMENTS
+
+assert len(sys.argv)<3, "score_parser takes at most 1 command line argument\n"+\
+                        "Use: python score_parser.py [rating_folder_location]"
+
+# XML results files location
+if len(sys.argv) == 1:
+    folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+    print "Use: python score_parser.py [rating_folder_location]"
+    print "Using default path: " + folder_name
+elif len(sys.argv) == 2:
+    folder_name = sys.argv[1]   # First command line argument is folder
 
 # get every XML file in folder
 for file in os.listdir(folder_name):
--- a/scripts/score_plot.py	Wed Jul 15 15:52:56 2015 +0100
+++ b/scripts/score_plot.py	Mon Jul 20 12:47:16 2015 +0100
@@ -8,17 +8,84 @@
 import scipy as sp
 import scipy.stats
 
-# CONFIGURATION
+# COMMAND LINE ARGUMENTS
 
-# Which type(s) of plot do you want? 
-enable_boxplot    = True      # show box plot
+#TODO: Merge, implement this functionality
+#TODO: Control by CLI arguments (plot types, save and/or show, ...) 
+
+assert len(sys.argv)<4, "score_plot takes at most 2 command line arguments\n"+\
+                        "Use: python score_plot.py [ratings_folder_location]."+\
+                        "Type 'python score_plot.py -h' for more options"
+
+# initialise plot types (false by default) and options
+enable_boxplot    = False     # show box plot
 enable_confidence = False     # show confidence interval
 confidence        = 0.90      # confidence value (for confidence interval plot)
 enable_individual = False     # show all individual ratings
-show_individual   = []        # show specific individuals
+show_individual   = []        # show specific individuals (empty: show all individuals found)
 show_legend       = False     # show names of individuals
-#TODO: Merge, implement this functionality
-#TODO: Control by CLI arguments (plot types, save and/or show, ...) 
+
+# DEFAULT: Looks in 'saves/ratings/' folder from 'scripts/' folder
+rating_folder = "../saves/ratings/" 
+
+# XML results files location
+if len(sys.argv) == 1: # no extra arguments
+    enable_boxplot    = True # show box plot
+    print "Use: python score_plot.py [rating folder] [plot_type] [-l/-legend]"
+    print "Type 'python score_plot.py -h' for help."
+    print "Using default path: " + rating_folder + " with boxplot."
+else:
+    for arg in sys.argv: # go over all arguments
+        if arg == '-h':
+            # show help
+            #TODO: replace with contents of helpfile score_plot.info (or similar)
+            print "Use: python score_plot.py [rating_folder] [plot_type] [-l] [confidence]"
+            print "   rating_folder:"
+            print "            folder where output of 'score_parser' can be found, and"
+            print "            where plots will be stored."
+            print "            By default, '../saves/ratings/' is used."
+            print ""
+            print "PLOT TYPES"
+            print " Can be used in combination."
+            print "    box | boxplot | -b"
+            print "            Enables the boxplot" 
+            print "    conf | confidence | -c"
+            print "            Enables the confidence interval plot" 
+            print "    ind | individual | -i"
+            print "            Enables plot of individual ratings" 
+            print ""
+            print "PLOT OPTIONS"
+            print "    legend | -l"
+            print "            For individual plot: show legend with individual file names"
+            print "    "
+            assert False, ""# stop immediately after showing help #TODO cleaner way
+            
+        # PLOT TYPES
+        elif arg == 'box' or arg == 'boxplot' or arg == '-b':
+            enable_boxplot    = True     # show box plot
+        elif arg == 'conf' or arg == 'confidence' or arg == '-c':
+            enable_confidence = True     # show confidence interval
+            #TODO add confidence value input
+        elif arg == 'ind' or arg == 'individual' or arg == '-i':
+            enable_individual = True     # show all individual ratings
+            
+        # PLOT OPTIONS
+        elif arg == 'leg' or arg == 'legend' or arg == '-l':
+            if not enable_individual: 
+                print "WARNING: The 'legend' option is only relevant to plots of individual ratings"
+            show_legend = True     # show all individual ratings
+            
+         # FOLDER NAME
+         else: 
+            # assume it's the folder name
+            rating_folder = arg
+            #TODO try it exists, otherwise show exception
+
+# at least one plot type should be selected: box plot by default
+if not enable_boxplot and not enable_confidence and not enable_individual:
+    enable_boxplot = True
+
+# CONFIGURATION
 
 # Enter folder where rating CSV files are (generated with score_parser.py or same format).
 rating_folder = '../saves/ratings/' # folder with rating csv files
--- a/scripts/timeline_view.py	Wed Jul 15 15:52:56 2015 +0100
+++ b/scripts/timeline_view.py	Mon Jul 20 12:47:16 2015 +0100
@@ -1,14 +1,25 @@
 #!/usr/bin/python
 
 import xml.etree.ElementTree as ET
-import os
-import matplotlib.pyplot as plt
+import os # list files in directory
+import sys # command line arguments
+import matplotlib.pyplot as plt # plots
+
+# COMMAND LINE ARGUMENTS
+
+assert len(sys.argv)<3, "timeline_view takes at most 1 command line argument\n"+\
+                        "Use: python timeline_view.py [timeline_folder_location]"
+
+# XML results files location
+if len(sys.argv) == 1:
+    folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+    print "Use: python timeline_view.py [timeline_folder_location]"
+    print "Using default path: " + folder_name
+elif len(sys.argv) == 2:
+    folder_name = sys.argv[1]   # First command line argument is folder
 
 # CONFIGURATION 
 
-# XML results files location (modify as needed):
-folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
-
 # Folder where to store timelines
 timeline_folder = folder_name + '/timelines/'    # Stores in 'saves/timelines/'