def load_counters( samples: typing.Mapping[datetime, typing.Collection[JHUSample]], ) -> common.Counters: min_day = min(samples.keys()) max_day = max(samples.keys()) def keyfunc(s): return ((s.country, ), ) keys = common.build_axis_keys( (s for date_samples in samples.values() for s in date_samples), 1, keyfunc, ) key_indices = [{k: i for i, k in enumerate(ks)} for ks in keys] ndays = (max_day - min_day).days + 1 counters = np.zeros( (ndays, ) + tuple(len(ks) for ks in keys) + (3, ), dtype=np.float32, ) for i, date in enumerate(common.daterange(min_day, max_day)): date_samples = samples.get(date, []) for sample in date_samples: sample_keys = keyfunc(sample) indices = tuple(key_indices[i][k] for i, k in enumerate(sample_keys)) counters[(i, ) + indices + (sample.kind, )] += sample.cases print(f"proc: {date}", end="\r") return common.Counters( first_date=min_day, keys=keys, key_indices=key_indices, count_axis=len(keys) + 1, data=counters, )
def runTestDateRange(dateStart, dateEnd, number=1): """ run neuralNet for this daterange. Get the actual results. Compare them How many times did the winner win, second place win and third place win. If we add faveourite to the database then we can see how often the favorite wins and also use this as a parameter to the neuralNet""" dateStartSplit=dateStart.split('-') dateEndSplit=dateEnd.split('-') predictedWinner=[] pastperfWinner=[] numberOfRacesArray=[] for single_date in daterange(datetime.date(int(dateStartSplit[0]),int(dateStartSplit[1]),int(dateStartSplit[2])), datetime.date(int(dateEndSplit[0]),int(dateEndSplit[1]),int(dateEndSplit[2]))): date=time.strftime("%Y-%m-%d", single_date.timetuple()) print date winner=[0]*10 predicteds, actuals, pastperfs = neuralNet("5","testDate", "Result", date, number) numberOfRaces=len(predicteds) for idx, predicted in enumerate(predicteds): for jdx, predict in enumerate(predicted): try: if predict == actuals[idx].horseNames[0]: #this means the predicted winner was the winner winner[jdx]+=1 except IndexError: """ this will happen if there were not at least three horses""" for idx, win in enumerate(winner): print "predicted position " + str(idx) + " won " + str(win) + " times" print "numberOfRaces = " + str(numberOfRaces) predictedWinner.append(winner) winner=[0]*10 for idx, pastperf in enumerate(pastperfs): for jdx, predict in enumerate(pastperf): try: if predict == actuals[idx].horseNames[0]: #this means the predicted winner was the winner winner[jdx]+=1 except IndexError: """ this will happen if there were not at least three horses""" for idx, win in enumerate(winner): print "predicted position " + str(idx) + " won " + str(win) + " times" print "numberOfRaces = " + str(numberOfRaces) pastperfWinner.append(winner) numberOfRacesArray.append(numberOfRaces) print "final summary" ref=0 for idx, single_date in enumerate(daterange(datetime.date(int(dateStartSplit[0]),int(dateStartSplit[1]),int(dateStartSplit[2])), datetime.date(int(dateEndSplit[0]),int(dateEndSplit[1]),int(dateEndSplit[2])))): date=time.strftime("%Y-%m-%d", single_date.timetuple()) print date print "idx = " + str(idx) print "number of races = " + str(numberOfRacesArray[ref]) for jdx, numWin in enumerate(predictedWinner[ref]): print "number of times predicted place " + str(jdx) + " won was " + str(numWin) for jdx, numWin in enumerate(pastperfWinner[ref]): print "number of times pastperf place " + str(jdx) + " won was " + str(numWin) ref+=1
def makeAPoliteDatabase(dateStart, dateEnd, test = "false"): """ the polite database is based on the original database but has the extra fields... raceName, raceTime the going variable will be corrected so that goings with several words are stored correctly. The webpages will be retrieved with several minutes between them so as to be polite to the target website""" dateStartSplit=dateStart.split('-') dateEndSplit=dateEnd.split('-') SqlStuffInst=SqlStuff2() SqlStuffInst.createResultTable() """ user enters the date """ #date=raw_input("enter the required date yyyy-mm-dd") for single_date in daterange(datetime.date(int(dateStartSplit[0]),int(dateStartSplit[1]),int(dateStartSplit[2])), datetime.date(int(dateEndSplit[0]),int(dateEndSplit[1]),int(dateEndSplit[2]))): date=time.strftime("%Y-%m-%d", single_date.timetuple()) #date="2014-07-{}".format(day) print date ResultStuffInsts=[] """ for fullResultHref in fullResultHrefs: webpage=urllib2.urlopen(fullResultHref.get("href"))""" HrefStuffInst=webscrape.HrefStuff() """ get the hrefs that must be appended to http://www.racingpost.com/""" fullResultHrefs=HrefStuffInst.getFullResultHrefs(date) """loop through the number of races and make a ResultStuff object for each""" for fullResultHref in fullResultHrefs: HrefStuffInst.getFullResults(fullResultHref) #print "got full results webpage for..." fullResult=HrefStuffInst.getFullResultsGrid() fullHeader=HrefStuffInst.getFullResultsHeader() fullInfo=HrefStuffInst.getFullRaceInfo() ResultStuffInst=webscrape.ResultStuff(fullResult, fullHeader, fullInfo, date) ResultStuffInst.getAllResultInfo() """ResultStuffInst.getRaceDate() ResultStuffInst.getHorseNames() ResultStuffInst.getNumberOfHorses() ResultStuffInst.getRaceLength() ResultStuffInst.getHorseAge() ResultStuffInst.getHorseWeight() ResultStuffInst.getJockeyName() ResultStuffInst.getGoing()""" ResultStuffInsts.append(ResultStuffInst) """loop through the ResultStuff class objects and add them to the database""" for ResultStuffInst in ResultStuffInsts: if test == "false": SqlStuffInst.addResultStuffToTable(ResultStuffInst) else: for idx, horseName in enumerate(ResultStuffInst.horseNames): """create a string with this horses values""" val_str="'{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}, '{}', '{}', '{}', '{}', '{}', {}".format(\ ResultStuffInst.horseNames[idx].replace("'", "''"),\ ResultStuffInst.horseAges[idx], ResultStuffInst.horseWeights[idx], idx+1, \ ResultStuffInst.raceLength, ResultStuffInst.numberOfHorses, \ ResultStuffInst.jockeys[idx].replace("'", "''"), \ ResultStuffInst.going, ResultStuffInst.raceDate, ResultStuffInst.raceTime, \ ResultStuffInst.raceName, ResultStuffInst.draw[idx], \ ResultStuffInst.trainers[idx].replace("'", "''"), \ ResultStuffInst.jumps, \ ResultStuffInst.finishingTime) print val_str
def delDateRange(dateStart, dateStop): dateStartSplit=dateStart.split("-") dateStopSplit=dateStop.split("-") for single_date in daterange(datetime.date(int(dateStartSplit[0]),int(dateStartSplit[1]),int(dateStartSplit[2])), datetime.date(int(dateStopSplit[0]),int(dateStopSplit[1]),int(dateStopSplit[2]))): print single_date delDate(single_date)