コード例 #1
0
ファイル: Profile.py プロジェクト: Neeneko/OKMiner
    def __fillFromLink(self,link,session):
        #sys.stderr.write("Filling From [%s]\n" % link)
        page = session.get(link)
        tree            =   html.fromstring(page.text)
        questionIds     =   []
        for divId in tree.xpath('//div[@id]/@id'):
            if divId.startswith("question"):
                splitList = re.split("_",divId)
                if len(splitList) != 2:
                    continue
                try:
                    questionId = int(splitList[1])
                    questionIds.append(questionId)
                except ValueError:
                    pass 
        for questionId in questionIds:
            #sys.stderr.write("QuestionId [%d]\n" % questionId)
            #----------------------------------------------------------------------------
            if not QuestionDB.hasQuestion(questionId):
                text    =   tree.xpath('//div[@id="qtext_%d"]/p/text()' % questionId)[0].encode('ascii','ignore').strip() 

                answers = tree.xpath('//form[@name="answer_%s"]/div/label[@class="radio"]/text()' % questionId)
                QuestionDB.addQuestion(questionId,text,answers)
            #----------------------------------------------------------------------------
            self.Answers.append(questionId)
            #----------------------------------------------------------------------------
        nextLink = tree.xpath('//li[@class="next"]/a/@href')
        if len(nextLink) != 0:
            return nextLink[0]
        else:
            return None
コード例 #2
0
ファイル: Profile.py プロジェクト: Neeneko/OKMiner
    def __fillFromLink(self,link,session):
        sys.stderr.write("Filling From [%s]\n" % link)
        page = session.get(link)
        tree            =   html.fromstring(page.text)
        questionIds     =   []
        for divId in tree.xpath('//div[@id]/@id'):
            if divId.startswith("question"):
                splitList = re.split("_",divId)
                if len(splitList) != 2:
                    continue
                try:
                    questionId = int(splitList[1])
                    questionIds.append(questionId)
                except ValueError:
                    pass 
        for questionId in questionIds:
            #sys.stderr.write("QuestionId [%d]\n" % questionId)
            #----------------------------------------------------------------------------
            if not QuestionDB.hasQuestion(questionId):
                try:
                    text    =   tree.xpath('//div[@id="qtext_%d"]/p/text()' % questionId)[0].encode('ascii','ignore').strip() 
                    answers =   tree.xpath('//ul[@id="self_answers_%s"]/li/text()' % questionId)
                    QuestionDB.addQuestion(questionId,text,answers)
                except:
                    continue
            #----------------------------------------------------------------------------
            answer      =   UserProfile.UserAnswer(questionId)
            selected = tree.xpath('//form[@name="answer_%s"]/div/input[@name="my_answer"]' % questionId)

            for idx in range(len(selected)):
                if "checked" in selected[idx].values():
                    answer.Selected = idx+1

            acceptable  = tree.xpath('//form[@name="answer_%s"]/div[@class="container acceptable_answers"]/input[@checked]/@value' % questionId)
            for accept in acceptable:
                if accept == 'irrelevant':
                    continue
                answer.Accepted += (1<<(int(accept)))
            importance = tree.xpath('//form[@name="answer_%s"]/div[@class="container importance"]/div[@class="importance_radios"]/input[@checked]/@value' % questionId)
            if len(importance) == 1:
                answer.Importance = int(importance[0])

            explination = tree.xpath('//textarea[@id="answer_%s_explanation"]/text()' % questionId)
            if len(explination) == 1:
                answer.Explination = explination[0]


            if answer.Selected != 0:
                self.Answers[questionId] = answer
        nextLink = tree.xpath('//li[@class="next"]/a/@href')
        if len(nextLink) != 0:
            return nextLink[0]
        else:
            return None
コード例 #3
0
ファイル: ExperimentViewer.py プロジェクト: Neeneko/OKMiner
def ProcessAnswers(profiles):
    aStats  =   {}
    for questionId in QuestionDB.getQuestionIds():
        aStats[questionId] = StatContainer(questionId)

    for profile in profiles:
        for idx in range(len(profile.Answers)):
            aStats[profile.Answers[idx]].addWeight( float(idx)/float(len(profile.Answers)))
    reportTable = ReportTable("Id","Count","Score","Text")
    sortedStats = sorted(aStats.values())
    for idx in range(128):
        aStat = sortedStats[len(sortedStats) - idx - 1]
        reportTable.addRow(aStat.getId(),aStat.getCount(),int(aStat.getScore()),QuestionDB.getText(aStat.getId()))

    return reportTable
コード例 #4
0
ファイル: SetManager.py プロジェクト: Neeneko/OKMiner
    def printSet(answer_set):
        sys.stderr.write("Set Contains %d of %d Questions\n" % (len(answer_set),len(QuestionDB.getQuestionIds())))
        for questionId,answer in answer_set.iteritems():
            text    =   QuestionDB.getText(questionId)
            sys.stderr.write("[%8d] Question:   %s\n" % (questionId,text))
            Answers = QuestionDB.getAnswers(questionId)
            for idx in range(len(Answers)):
                if idx+1 == answer.Selected:
                    selected = "[X]"
                else:
                    selected = "[ ]"

                if (1 << idx+1) & answer.Accepted:
                    accepted = "[X]"
                else:
                    accepted = "[ ]"

                sys.stderr.write("[%8d]\t%s%s %s\n" % (questionId,selected,accepted,Answers[idx]))
            sys.stderr.write("[%8d]\tImportance: %s\n" % (questionId,answer.Importance))
            sys.stderr.write("[%8d]\tExplination: %s\n" % (questionId,answer.Explination))
            sys.stderr.write("[%8d]\tRaw: (%s,%s,%s)\n" % (questionId,answer.Selected,answer.Accepted,answer.Importance))
コード例 #5
0
ファイル: ExperimentViewer.py プロジェクト: Neeneko/OKMiner
    folderName      =   args[0]
    maxQuestions    =   16
    minAnswers      =   16
    profileAge      =   35


    if not os.path.exists(folderName):
        sys.stderr.write("No such folder [%s]\n" % folderName)
        sys.exit() 


    experiment  =   MinerExperiment()
    experiment.loadExperiment(folderName)
    reportData  =   ReportData(experiment)
    sys.stderr.write("Loaded Experiment for [%s]\n" % (experiment.getUserName()))
    sys.stderr.write("Total Questions [%s]\n" %  QuestionDB.getCount())

    userAge     =   int(experiment.getUserProfile().Info["Age"])
    #--------------------------------------------
    for searchType in experiment.getSearchTypes():
        searchData                      =   reportData.SearchTypes[searchType]
        searchData.Charts["ResultAge"]  =   ReportGraph()   
        searchData.Charts["MatchAge"]   =   ReportGraph()   
        searchData.Charts["MutualAge"]  =   ReportGraph()   
        for age,searchSet in experiment.getSearches(searchType).iteritems():
            searchData.RawNames += searchSet
            searchData.Charts["ResultAge"].setValue(age,len(searchSet))
            
        for profileName,fileName in experiment.getProfiles(searchType):
            searchData.MatchNames.append(profileName)
            matchProfile = MatchProfile()