def calculateHanziData(self, graphwindow, days): log.info("Calculating %d days worth of Hanzi graph data", days) # NB: must lazy-load matplotlib to give Anki a chance to set up the paths # to the data files, or we get an error like "Could not find the matplotlib # data files" as documented at <http://www.py2exe.org/index.cgi/MatPlotLib> try: from matplotlib.figure import Figure except UnicodeEncodeError: # Haven't tracked down the cause of this yet, but reloading fixes it log.warn("UnicodeEncodeError loading matplotlib - trying again") from matplotlib.figure import Figure # Use the statistics engine to generate the data for graphing. # NB: should add one to the number of days because we want to # return e.g. 8 days of data for a 7 day plot (the extra day is "today"). xs, _totaly, gradeys = pinyin.statistics.hanziDailyStats( self.hanziData(), days + 1) # Set up the figure into which we will add all our graphs figure = Figure(figsize=(graphwindow.dg.width, graphwindow.dg.height), dpi=graphwindow.dg.dpi) self.addLegend(figure) self.addGraph(figure, graphwindow, days, xs, gradeys) return figure
def chooseField(candidateFieldNames, targetkeys): # Find the first field that is present in the fact for candidateField in candidateFieldNames: for factfieldname in [factfieldname for factfieldname in targetkeys if factfieldname.lower() == candidateField.lower()]: return factfieldname # No suitable field found! log.warn("No field matching %s in the fact", candidateFieldNames) return None
def chooseField(candidateFieldNames, fact): # Find the first field that is present in the fact for candidateField in candidateFieldNames: for factfieldname in [factfieldname for factfieldname in fact.keys() if factfieldname.lower() == candidateField.lower()]: log.info("Choose %s as a field name from the fact for %s", factfieldname, candidateField) return factfieldname # No suitable field found! log.warn("No field matching %s in the fact", candidateFieldNames) return None
def chooseField(candidateFieldNames, fact): # Find the first field that is present in the fact for candidateField in candidateFieldNames: for factfieldname in [ factfieldname for factfieldname in fact.keys() if factfieldname.lower() == candidateField.lower() ]: log.info("Choose %s as a field name from the fact for %s", factfieldname, candidateField) return factfieldname # No suitable field found! log.warn("No field matching %s in the fact", candidateFieldNames) return None
def calculateHanziData(self, graphwindow, days): log.info("Calculating %d days worth of Hanzi graph data", days) # NB: must lazy-load matplotlib to give Anki a chance to set up the paths # to the data files, or we get an error like "Could not find the matplotlib # data files" as documented at <http://www.py2exe.org/index.cgi/MatPlotLib> try: from matplotlib.figure import Figure except UnicodeEncodeError: # Haven't tracked down the cause of this yet, but reloading fixes it log.warn("UnicodeEncodeError loading matplotlib - trying again") from matplotlib.figure import Figure # Use the statistics engine to generate the data for graphing. # NB: should add one to the number of days because we want to # return e.g. 8 days of data for a 7 day plot (the extra day is "today"). xs, _totaly, gradeys = pinyin.statistics.hanziDailyStats(self.hanziData(), days + 1) # Set up the figure into which we will add all our graphs figure = Figure(figsize=(graphwindow.dg.width, graphwindow.dg.height), dpi=graphwindow.dg.dpi) self.addLegend(figure) self.addGraph(figure, graphwindow, days, xs, gradeys) return figure