def getPollObjectCandidate(candidate_name): start_date = "" end_date = "" poll_days = [] for day in days: if len(str(day)) < 2: #first month if day > end_day: poll_days.append("20160" + str(month_start_number) + "0" + str(day)) #end month else: poll_days.append("20160" + str(month_end_number) + "0" + str(day)) else: #first month if day > end_day: poll_days.append("20160" + str(month_start_number) + str(day)) #end month else: poll_days.append("20160" + str(month_end_number) + str(day)) poll_days_copy = poll_days[:] dp = DatabasePolls(poll_days_copy[0], poll_days_copy[len(poll_days_copy)-1], [candidate_name.capitalize()]) dp.queryDatabase() dp.cleanPolls() poll_data = dp.getCleanedPolls() rrp = RegressionReadyPolls(poll_data, candidate_name.capitalize(), poll_days_copy[0], poll_days_copy[len(poll_days_copy)-1]) rrp.makeSimplePollNumbers() rrp.fillGapsWithAvg() return AnalysisObject(candidate_name, "Polls", [], rrp.getPollNumbers())
def getPollObjectCandidate1(candidate_name): start_date = "" end_date = "" poll_days = [] for day in days: if len(str(day)) < 2: #first month if day > end_day: poll_days.append("20160" + str(month_start_number) + "0" + str(day)) #end month else: poll_days.append("20160" + str(month_end_number) + "0" + str(day)) else: #first month if day > end_day: poll_days.append("20160" + str(month_start_number) + str(day)) #end month else: poll_days.append("20160" + str(month_end_number) + str(day)) poll_days_copy = poll_days[:] dp = DatabasePolls(poll_days_copy[0], poll_days_copy[len(poll_days_copy)-1], candidate_name.title()) dp.queryDatabase() dp.cleanPolls() poll_data = dp.getCleanedPolls() list_of_data = [] while poll_days_copy: still_searching = True does_exist = False for poll in poll_data: if poll[0] == int(poll_days_copy[0]) and still_searching == True: i = 0 does_exist = False for candidateInPoll in poll[1]: if candidateInPoll == candidate_name.title(): does_exist = True list_of_data.append(poll[2][i]) i += 1 still_searching = False if does_exist == False: list_of_data.append("None") poll_days_copy.remove(poll_days_copy[0]) return AnalysisObject(candidate_name, "Polls", [], list_of_data)