def create_predict_pieseries(self, bots_part): human_part = 1 - bots_part percentage_bots_part = int(round(bots_part * 100)) percentage_human_part = 100 - percentage_bots_part # define the series slices of the pie series = QPieSeries() bot_slice = QPieSlice(f"Bot ({percentage_bots_part}%)", bots_part) human_slice = QPieSlice(f"Human ({percentage_human_part}%)", human_part) font = QFont() font.setBold(True) bot_slice.setColor(QColor("#3498db")) bot_slice.setLabelFont(font) human_slice.setColor(QColor("#a8e6cf")) human_slice.setLabelFont(font) series.append(bot_slice) series.append(human_slice) series.setLabelsVisible(False) series.setLabelsPosition(QPieSlice.LabelInsideHorizontal) series.setPieSize(0.94) return series
def create_piechart(self): Date = date.today() breakfastData = SQLStatements.getTotalBreakfastCalories( self.userID, Date) breakfastData = str(breakfastData) breakfastData = (breakfastData.replace("[", "")) breakfastData = (breakfastData.replace("]", "")) breakfastData = (breakfastData.replace("(", "")) breakfastData = (breakfastData.replace(")", "")) breakfastData = (breakfastData.replace(",", "")) breakfastData = int(breakfastData) lunchData = SQLStatements.getTotalLunchCalories(self.userID, Date) lunchData = str(lunchData) lunchData = (lunchData.replace("[", "")) lunchData = (lunchData.replace("]", "")) lunchData = (lunchData.replace("(", "")) lunchData = (lunchData.replace(")", "")) lunchData = (lunchData.replace(",", "")) lunchData = int(lunchData) dinnerData = SQLStatements.getTotalDinnerCalories(self.userID, Date) dinnerData = str(dinnerData) dinnerData = (dinnerData.replace("[", "")) dinnerData = (dinnerData.replace("]", "")) dinnerData = (dinnerData.replace("(", "")) dinnerData = (dinnerData.replace(")", "")) dinnerData = (dinnerData.replace(",", "")) dinnerData = int(dinnerData) snackData = SQLStatements.getTotalSnacksCalories(self.userID, Date) snackData = str(snackData) snackData = (snackData.replace("[", "")) snackData = (snackData.replace("]", "")) snackData = (snackData.replace("(", "")) snackData = (snackData.replace(")", "")) snackData = (snackData.replace(",", "")) snackData = int(snackData) series = QPieSeries() series.append("Breakfast calories", breakfastData) series.append("Lunch calories", lunchData) series.append("Dinner calories", dinnerData) series.append("Snack calories", snackData) labelFont = QFont("Sans Serif", ) labelFont.setPixelSize(16) slice = QPieSlice() slice.setLabelFont(labelFont) slice = series.slices()[0] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QPen(Qt.green, 2)) slice.setBrush(Qt.green) slice = QPieSlice() slice.setLabelFont(labelFont) slice = series.slices()[1] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QPen(Qt.white, 2)) slice.setBrush(Qt.white) slice = QPieSlice() slice.setLabelFont(labelFont) slice = series.slices()[2] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QPen(Qt.yellow, 2)) slice.setBrush(Qt.yellow) slice = QPieSlice() slice.setLabelFont(labelFont) slice = series.slices()[3] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QPen(Qt.yellow, 2)) slice.setBrush(Qt.yellow) chart = QChart() chart.legend().hide() chart.addSeries(series) chart.createDefaultAxes() chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Daily Calories") chart.setTheme(QChart.ChartThemeBlueCerulean) chart.setBackgroundVisible(False) # Title Font size font = QFont("Sans Serif", ) font.setPixelSize(18) chart.setTitleFont(font) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) return chartview