コード例 #1
0
ファイル: driver.py プロジェクト: numaner/TulaLens-analysis
def main(argv=None):
    #read in params
    if argv is None:
        argv = sys.argv[1:]
    
    file = 'tulalens_survey_sample.csv'
    facet = 'result id'
    
    #standard python parsing for command line options
    opts = []
    args = []

    try:
        opts, args = getopt.getopt(argv, "hl", ["help", "list", "file=", "facet="])
    except getopt.GetoptError as msg:
        print(sys.stderr, msg)
        print >>sys.stderr, "For help use --help"
        return 2
    
    if len(args):
        print >>sys.stderr, "Invalid arg(s) %s"%args
        usage()
        return 2

    for (opt, val) in opts:
        if opt in ("-h", "--help"):
            usage()
            return 0
        if opt in ("-l", "--list"):
            list()
            return 0
        elif opt in ("--file"):
            file = val
        elif opt in ("--facet"):
            facet = val.lower()
        else:
            usage()
            return 2
    
    print("facet: %s" % facet)
    #check if facet given is in the list of survey questions
    #ideally this allows for quick entries with just the 
    #question number, e.g. "--facet Q30"
    long_q = '' #keep track of the long form for later use
    valid_facet = False
    for long, short in SHORT_QUESTIONS.items():
        #print("checking question: %s" % question)
        if facet in long:
            #turn the facet into easy to use question ids
            #p = "(^q\d\d?[.]).*"
            #m = re.match(p, long)
            facet = short
            long_q = long
            print("Question selected: %s" % long_q)
            valid_facet = True
            break
    
    if not valid_facet:
        sys.exit("facet selected is not a survey question")
            
    #parse csv file
    parser = CsvParse(file)
    answers = parser.parse()
    
    #generate analysis based on options
    #print("number of answer rows after parse: %s" % len(answers))
    
    analyze = Analyzer(answers)
    #find the unique occurrence of each answer to the question
    answers_count = analyze.group_by(facet)
    
    mean = analyze.find_mean(facet, answers_count)
        
    sys.exit()
コード例 #2
0
def main(argv=None):
    #read in params
    if argv is None:
        argv = sys.argv[1:]

    file = 'tulalens_survey_sample.csv'
    facet = 'result id'

    #standard python parsing for command line options
    opts = []
    args = []

    try:
        opts, args = getopt.getopt(argv, "hl",
                                   ["help", "list", "file=", "facet="])
    except getopt.GetoptError as msg:
        print(sys.stderr, msg)
        print >> sys.stderr, "For help use --help"
        return 2

    if len(args):
        print >> sys.stderr, "Invalid arg(s) %s" % args
        usage()
        return 2

    for (opt, val) in opts:
        if opt in ("-h", "--help"):
            usage()
            return 0
        if opt in ("-l", "--list"):
            list()
            return 0
        elif opt in ("--file"):
            file = val
        elif opt in ("--facet"):
            facet = val.lower()
        else:
            usage()
            return 2

    print("facet: %s" % facet)
    #check if facet given is in the list of survey questions
    #ideally this allows for quick entries with just the
    #question number, e.g. "--facet Q30"
    long_q = ''  #keep track of the long form for later use
    valid_facet = False
    for long, short in SHORT_QUESTIONS.items():
        #print("checking question: %s" % question)
        if facet in long:
            #turn the facet into easy to use question ids
            #p = "(^q\d\d?[.]).*"
            #m = re.match(p, long)
            facet = short
            long_q = long
            print("Question selected: %s" % long_q)
            valid_facet = True
            break

    if not valid_facet:
        sys.exit("facet selected is not a survey question")

    #parse csv file
    parser = CsvParse(file)
    answers = parser.parse()

    #generate analysis based on options
    #print("number of answer rows after parse: %s" % len(answers))

    analyze = Analyzer(answers)
    #find the unique occurrence of each answer to the question
    answers_count = analyze.group_by(facet)

    mean = analyze.find_mean(facet, answers_count)

    sys.exit()
コード例 #3
0
    def parse(self):
        #first row should be the questions
        header = next(self.results)
        #print(header)

        #keep track of the questions and the range the answers should be in
        answer_ranges = {}

        #to keep track of where in the row each question and its answer(s) could be,
        #get the index of the question, and count its multi-choice answers if exist.
        #this provides a range to find the answer in for the answer rows.
        #print(header)
        for question in header:
            #print(question.lower())
            if question.lower() in SHORT_QUESTIONS.keys():
                short_q = SHORT_QUESTIONS[question.lower()]
                question_index = header.index(question)
                #print("'%s' is at index %s" % (question, question_index))
                answer_range = 0
                if short_q in MULTICHOICE:
                    answer_range = len(MULTICHOICE[short_q])
                #print("answer should be at index")
                if answer_range > 0:
                    for index in range(question_index,
                                       question_index + answer_range):
                        answer_ranges[index] = short_q
                        #print(index)
                else:
                    answer_ranges[question_index] = short_q
                    #print(question_index)
        #print(answer_ranges)

        #skipping the row with choices, but putting them in choices to use if needed
        choices = next(self.results)
        #print(choices)

        #print("compiling survey into answers map")
        count = 0
        for result in self.results:
            #skip blank rows
            if result[0] is "":
                #print("skipping blank row")
                continue
            #this dict keeps a 1:1 relationship of questions and answers and sidesteps
            #the multi-choice. each mapping should be at least { question : [answer] }
            survey_row = {}
            #print("at id %s" % result[0])
            count += 1
            for index, answer in enumerate(result):
                if answer is not "":
                    #print("index: %s" % index)
                    if index in answer_ranges:
                        curr_question = answer_ranges[index]
                        if curr_question not in survey_row:
                            survey_row[curr_question] = []
                        survey_row[curr_question].append(answer)
                        #print("at index %s: %s -> %s" % (index, curr_question, survey_row[curr_question]))
            self.answers.append(survey_row)

        print("Number of participants: %s" % count)
        #print("number of answer rows: %s" % len(self.answers))

        return self.answers
コード例 #4
0
ファイル: analysis.py プロジェクト: numaner/TulaLens-analysis
 def __init__(self, data):
     self.facets = SHORT_QUESTIONS.values()
     self.data = data
コード例 #5
0
    def parse(self):
        #first row should be the questions
        header = next(self.results)
        #print(header)

        #keep track of the questions and the range the answers should be in
        answer_ranges = {}

        #to keep track of where in the row each question and its answer(s) could be,
        #get the index of the question, and count its multi-choice answers if exist.
        #this provides a range to find the answer in for the answer rows.
        #print(header)
        for question in header:
            #print(question.lower())
            if question.lower() in SHORT_QUESTIONS.keys():
                short_q = SHORT_QUESTIONS[question.lower()]
                question_index = header.index(question)
                #print("'%s' is at index %s" % (question, question_index))
                answer_range = 0
                if short_q in MULTICHOICE:
                    answer_range = len(MULTICHOICE[short_q])
                #print("answer should be at index")
                if answer_range > 0:
                    for index in range(question_index, question_index + answer_range):
                        answer_ranges[index] = short_q
                        #print(index)
                else:
                    answer_ranges[question_index] = short_q
                    #print(question_index)
        #print(answer_ranges)

        #skipping the row with choices, but putting them in choices to use if needed
        choices = next(self.results)
        #print(choices)

        #print("compiling survey into answers map")
        count = 0
        for result in self.results:
            #skip blank rows
            if result[0] is "":
                #print("skipping blank row")
                continue
            #this dict keeps a 1:1 relationship of questions and answers and sidesteps
            #the multi-choice. each mapping should be at least { question : [answer] }
            survey_row = {}
            #print("at id %s" % result[0])
            count += 1
            for index, answer in enumerate(result):
                if answer is not "":
                    #print("index: %s" % index)
                    if index in answer_ranges:
                        curr_question = answer_ranges[index]
                        if curr_question not in survey_row:
                            survey_row[curr_question] = []
                        survey_row[curr_question].append(answer)
                        #print("at index %s: %s -> %s" % (index, curr_question, survey_row[curr_question]))
            self.answers.append(survey_row)

        print("Number of participants: %s" % count)
        #print("number of answer rows: %s" % len(self.answers))
        
        return self.answers
コード例 #6
0
 def __init__(self, data):
     self.facets = SHORT_QUESTIONS.values()
     self.data = data