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() matchProfile.loadFromConfig(fileName) searchData.MatchProfiles.append(matchProfile) searchData.Charts["MatchAge"].incValue(int(matchProfile.Info["Age"]),1) if userAge < int(matchProfile.LookingFor["AgeLow"]): continue if userAge > int(matchProfile.LookingFor["AgeHigh"]): continue searchData.Charts["MutualAge"].incValue(int(matchProfile.Info["Age"]),1) searchData.MutualProfiles.append(matchProfile) searchData.Charts["Words"] = ProcessEssays(searchData.MutualProfiles) searchData.Charts["Answers"] = ProcessAnswers(searchData.MutualProfiles) searchData.InfoCharts["Ethnicity"] = (ProcessField("Details","Ethnicity",searchData.MatchProfiles),ProcessField("Details","Ethnicity",searchData.MutualProfiles)) searchData.InfoCharts["Relationship Type"] = (ProcessField("Details","Relationship Type",searchData.MatchProfiles),ProcessField("Details","Relationship Type",searchData.MutualProfiles))
def doExperiment(self): sys.stderr.write("Starting Experiment against profile [%s]\n" % self.getUserName()) profileManager = ProfileManager() session = profileManager.doLogin(self.getUserName()) self.__userProfile.loadFromSession(session,self.getUserName(),True) fileName = "%s.ini" % self.__userProfile.Info["Name"] fullName = os.path.join(self.getExperimentPath(),fileName) self.__userProfile.saveProfile(fullName) self.saveProfile("User",self.__userProfile.Info["Name"],fullName) radius = self.__config.get("Settings","Radius") locationId = getLocationId(session,self.__userProfile.Info["Location"]) baseAge = int(self.__userProfile.Info["Age"]) if self.__config.get("Settings","AgeRange") is None: ageHigh = baseAge ageLow = baseAge else: ageHigh = baseAge+int(self.__config.get("Settings","AgeRange")) ageLow = baseAge-int(self.__config.get("Settings","AgeRange")) if self.__config.get("Settings","AgeMin") is not None: ageLow = int(self.__config.get("Settings","AgeMin")) if self.__config.get("Settings","AgeMax") is not None: ageHigh = int(self.__config.get("Settings","AgeMax")) matchResults = [] def CountType(results,type): rv = 0 for result in results: if result.Type == type: rv+=1 return rv def GetTypes(results): rv = [] for result in results: if result.Type not in rv: rv.append(result.Type) return rv for searchType in self.getSearchTypes(): matches = [] for i in range(ageLow,ageHigh+1): gc.collect() url = genSearchURL(MatchOrder(searchType.upper()),AgeFilter(i,i),LastOnFilter(LastOnFilter.WEEK),LocationIdFilter(locationId,radius),GentationFilter(self.getGentation()),PhotoFilter(False),StatusFilter(StatusFilter.ANY)) sys.stderr.write("[%s][%s] Search [%s]\n" % (searchType,i,url)) results = doSearch(session,url) self.saveSearch(searchType,i,results) saved = 0 for result in results: sys.stderr.write("[%s][%s] Loading [%s]\n" % (searchType,i,result)) matchProfile = MatchProfile() if not matchProfile.loadFromSession(session,result): self.saveProfile("Error",result,"%s" % str(matchProfile.Error)) continue sys.stderr.write("[%s][%s] Answers [%s]\n" % (searchType,i,len(matchProfile.Answers))) percent = matchProfile.Percentages[searchType] sys.stderr.write("[%s][%s] Filtering - [%s]\n" % (searchType,i,percent)) if self.getMinMatch() != -1 and percent < self.getMinMatch(): break if self.getMaxResults() != -1: if len(matches) < self.getMaxResults(): #sys.stderr.write("\tAdding\n") matches.append(matchProfile) elif matches[-1].Percentages[searchType] < percent: #sys.stderr.write("\tReplacing\n") matches[-1] = matchProfile else: #sys.stderr.write("\tSkipping\n") break def keyFxn(value): return value.Percentages[searchType] matches = sorted( matches,key=keyFxn,reverse=True) else: matches.append(matchProfile) #sys.stderr.write("\tSorted - %s\n" % [ x.Percentages[searchType] for x in matches[searchType] ]) saved += 1 sys.stderr.write("Slice [%s] Type [%s] Results [%s] Saved [%s] Cumulative [%s]\n" % (i,searchType,len(results),saved,len(matches))) for match in matches: sys.stderr.write("Saving [%s]\n" % match.Info["Name"]) fileName = "%s.ini" % match.Info["Name"] fullName = os.path.join(self.getExperimentPath(),fileName) match.saveProfile(fullName) self.saveProfile(searchType,match.Info["Name"],fullName) sys.stderr.write("Finished Experiment\n")