def init(self, token): self.token = token self.charts = [ Chart(n, self.token[n], self.debug) for n in range(len(self.token)) ] self.charts.append(Chart(len(self.token), None, self.debug)) if self.debug: print "Initial" s = State(self.GFG.start, 0) self.charts[0].add_state(s)
def testaddDataSimple(self): c = Chart.Chart() c.chs = "450x150" c.addData([12, 40, 39, 36, 30, 50, 44]) c.processData() self.assertEquals("0,50", c.chds) self.assertEquals("0,6,0,1|1,0,50|2,6,0", c.chxr) self.assertEquals("s:Pxwsl92", c.chd)
def testaddDataExtended(self): c = Chart.Chart() c.chs = "450x150" c.addData([808, 2532, 1970, 2879]) c.processData() self.assertEquals("0,2879", c.chds) self.assertEquals("0,3,0,1|1,0,2879|2,3,0", c.chxr) self.assertEquals("e:R94Rry..", c.chd)
def testaddDataTwoSets(self): c = Chart.Chart() c.chs = "450x150" c.addData([12, 40, 39, 36, 30, 50, 44]) c.addData([44, 50, 30, 36, 39, 40, 12]) c.processData() self.assertEquals("0,50", c.chds) self.assertEquals("0,6,0,1|1,0,50|2,6,0", c.chxr) self.assertEquals("s:Pxwsl92,29lswxP", c.chd)
def graphSelection(self): self.printHeader("Graph selection", True) if int( raw_input("Show time vs. frequency chart for " + self.type + " type? Enter 1 for 'yes': ")) == 1: graphData = self.dataset.getDataPoints(self.topic, 1) Chart(graphData, 1, "Years", "Frequency", ' '.join(self.topic)) if int(raw_input( "Show type vs. frequency chart? Enter 1 for 'yes': ")) == 1: graphData = self.dataset.getDataPoints(self.topic, 2) Chart(graphData, 2, "Type", "Frequency", ' '.join(self.topic)) if int( raw_input( "Show time and type vs. frequency chart? Enter 1 for 'yes': " )) == 1: graphData = self.dataset.getDataPoints(self.topic, 3) Chart(graphData, 3, "Years-Type", "Frequency", ' '.join(self.topic))
def draw_new_chart(self, type='column'): """Delegates drawing of a new chart to self.plot_area. Args: type: The type of chart to draw. Types: 'column'. """ self.clear_plot_area() chart = Chart(self.plot_area, self.plot_configuration) self.set_status_label('New chart drawn.')
def init(self, token): self.token = token self.chart = [Chart(n, self.debug) for n in range(len(token) + 1)] if self.debug: print "Initial" for prod in self.grammar.production: if prod.left == self.grammar.start: #tuple (grammar,dot,start) s = State(prod, 0, 0) self.chart[0].add_state(s)
def testasUrl(self): c = Chart.Chart() c.chco = "00FF00" c.chs = "450x150" c.addData([42]) actual = c.asUrl() self.assertEquals("http://chart.apis.google.com/chart?" + "chof=png" + "&chco=00FF00" + "&chd=s:9" + "&chds=0,42" + "&chs=450x150" + "&chxr=0,0,0,1|1,0,42|2,0,0", actual)
def searchTrackUserKeywordUsage(self, wordsDict): #redditor/person is of type subreddit person = self.reddit.redditor(self.userToTrack) comments = [] for comment in person.comments.new(limit=50): comments.append(comment.body) #print(comment.body.split("\n", 1)[0][:79]) keys_list = list(wordsDict) for comment in comments: #wordIndex = 0 for word in keys_list: #key = keys_list[wordIndex] i = self.countOccurences(comment, word) #wordIndex += 1 wordsDict[word] += i #print(*comments, sep="\n") #print(wordsDict) Chart.createPieGraph(wordsDict)
def testasImgElement(self): c = Chart.Chart() c.chco = "00FF00" c.chs = "450x150" c.addData([42]) actual = c.asImgElement() self.assertEquals("<img src='http://chart.apis.google.com/chart?" + "chof=png" + "&chco=00FF00" + "&chd=s:9" + "&chds=0,42" + "&chs=450x150" + "&chxr=0,0,0,1|1,0,42|2,0,0" + "' width='450' height='150' />", actual)
def testrenderChartDataSimple(self): lastDay = "2009/12/05" rac = RecentActivityCollection.RecentActivityCollection(lastDay) ra = RecentActivity.RecentActivity(lastDay) ra["2009-12-05T03:13:15Z"] = 1 ra["2009-12-04T15:54:38Z"] = 1 ra["2009-11-25T22:56:03Z"] = 1 ra["2009-11-22T20:18:28Z"] = 1 rac.append(ra) c = Chart.Chart() c.chs = "450x150" actualEarliestDay, actualMaxValueCount = rac.renderChartData(c) c.processData() self.assertEquals("s:9AA9AAAAAAAA99", c.chd) self.assertEquals(datetime(2009, 11, 22), actualEarliestDay) self.assertEquals(14, actualMaxValueCount)
def visualizeResults(bases, dirs, titles, model, saveChart, showChart, folderToSave, maxHiddenNodes): for base in bases: mseVal = [] mseTest = [] chart:Chart = Chart() for folder, title in zip(dirs, titles): fileName = folder+base loadedDict = readJsonFile(fileName+'.json') mapeValArray, mseValArray, mapeTestArray, mseTestArray = getErrors(loadedDict) mseVal.append(mseValArray) mseTest.append(mseTestArray) predVal, trueVal, predTest, trueTest = getPredAndTrueValues(loadedDict,2) chart.plotValidationAndTest(base, model, maxHiddenNodes, mseVal, mseTest, "Validation", "Test", titles, showChart, saveChart, folderToSave)
def testrenderChartDataTwoSetsWithDisconnectedData(self): lastDay = "2010/04/06" rac = RecentActivityCollection.RecentActivityCollection(lastDay) firstRa = RecentActivity.RecentActivity(lastDay) firstRa["2010-04-04T18:12:26Z"] = 1 firstRa["2009-11-22T23:01:37Z"] = 1 rac.append(firstRa) secondRa = RecentActivity.RecentActivity(lastDay) secondRa["2010-04-04T18:12:26Z"] = 1 secondRa["2010-04-03T18:18:21Z"] = 1 rac.append(secondRa) c = Chart.Chart() c.chs = "450x150" actualEarliestDay, actualMaxValueCount = rac.renderChartData(c) self.assertEquals(datetime(2009, 11, 22), actualEarliestDay) self.assertEquals(136, len(c.dataSets[0])) self.assertEquals(136, len(c.dataSets[1]))
def race(): Settings.Setting_bg() x = turtle.Screen() length = x.numinput("Length of Race Track", "Input length of Race Track:(100-900)", 400, 100, 900) width = x.numinput("Width of Race Track", "Input width of Race Track:(300-400)", 400, 300, 400) choice = x.numinput( "Choose Set Characters", "There are 5 set of characters:\n 1.Animal\n 2.Marvel\n 3.Monsters\n 4.Pokemon\n " "5.SpaceShip\nInput number of the set you want to choose:", 1, 1, 5) list_characters = Character_Implement.Settings_Characters(choice) list_names = [ list_characters[0].Name, list_characters[1].Name, list_characters[2].Name, list_characters[3].Name, list_characters[4].Name ] list_score = [0, 0, 0, 0, 0] list_bet_score = [0, 0, 0, 0, 0] Player_Bet = x.numinput( "Place Your Bet", "Input the character you think will win:\n 1.%s\n 2.%s\n 3.%s\n " "4.%s\n 5.%s" % (list_names[0], list_names[1], list_names[2], list_names[3], list_names[4]), 1, 1, 5) play(length, width, choice, Player_Bet, list_score, list_bet_score) replay = x.numinput( "Guess again", "Do you want to bet on your character again?\n yes(1) \n no(0):", 1, 0, 1) while replay == 1: play(length, width, choice, Player_Bet, list_score, list_bet_score) replay = x.numinput( "Guess again", "Do you want to bet on your character again?\n yes(1) \n no(0):", 1, 0, 1) Chart.Chart(list_score, Score.Count_Win_Rate(list_bet_score), list_names)
def create_standard_chart(name, dataset): chart = Chart.Chart(name=name, dataset=dataset) chart.set_start_bar(-100) # 100 bars from the end chart.set_numbars(100) sc = Subchart.Subchart(name, chart) sc.set_vertical_grid_lines_on() sc.set_horizontal_grid_lines_on() barchart = sc.create_drawable("BarChart", title='OHLC', fs=chart.get_current_scale()) chart.add_subchart('OHLC', sc) # setup the volume subchart if 'volume' in dataset.get_headers(): volume = dataset.get('volume') scv = Subchart.Subchart('volume', chart) scv.set_vertical_grid_lines_on() scv.set_horizontal_grid_lines_on() volumehisto = scv.create_drawable("SingleSeries", title='volume', fs=chart.get_current_scale()) chart.add_subchart('volume', scv) set_scroller_values(chart.get_total_bars(), chart.get_numbars()) return chart
class MainWindow(QMainWindow): def __init__(self, parent = None): QMainWindow.__init__(self) self.statusBar() self.setWindowTitle("Paint") #self.canvas = Canvas(self) #self.textEdit = QTextEdit(self) self.chart = Chart() self.view = QChartView(self.chart) self.chart.set_view(self.view) #self.statusBar() self.canvas = Canvas(self.chart) self.textEdit = QTextEdit(self) mainLayout = QGridLayout(self) mainLayout.addWidget(self.canvas, 1, 1) mainLayout.addWidget(self.textEdit, 2, 1) mainLayout.addWidget(self.view, 1, 2, 5, 1) ''' top_layout = QVBoxLayout() top_layout.addWidget(self.canvas) top_layout.addWidget(self.textEdit) ''' #top_layout.addLayout( h_layout ); container = QWidget() container.setLayout(mainLayout) self.setCentralWidget(container) #self.setCentralWidget(self.canvas) self.resize(1000, 700) bar = self.menuBar() fileMenu = bar.addMenu("File") fileToolBar = QToolBar("File") openFile = QAction(QIcon(":/icons/open.png"), "Open...", self) openFile.setShortcut(QKeySequence("Ctrl+O")) openFile.setToolTip("Open") openFile.setStatusTip("Open") fileMenu.addAction(openFile) fileToolBar.addAction(openFile) openFile.triggered.connect(self.open) saveFile = QAction(QIcon(":/icons/save.png"), "Save...", self) saveFile.setShortcut(QKeySequence("Ctrl+S")) saveFile.setToolTip("Save") saveFile.setStatusTip("Save") fileMenu.addAction(saveFile) fileToolBar.addAction(saveFile) saveFile.triggered.connect(self.save) quitFile = QAction(QIcon(":/icons/quit.png"), "Quit", self) quitFile.setShortcut(QKeySequence("Ctrl+W")) quitFile.setToolTip("Quit") quitFile.setStatusTip("Quit") fileMenu.addAction(quitFile) fileToolBar.addAction(quitFile) quitFile.triggered.connect(self.quit) self.addToolBar(fileToolBar) colorMenu = bar.addMenu("Color") actPen = colorMenu.addAction(QIcon(":/icons/pen.png"), "&Pen color", self.pen_color, QKeySequence("Ctrl+P")) actBrush = colorMenu.addAction(QIcon(":/icons/brush.png"), "&Brush color", self.brush_color, QKeySequence("Ctrl+B")) colorToolBar = QToolBar("Color") self.addToolBar( colorToolBar ) colorToolBar.addAction( actPen ) colorToolBar.addAction( actBrush ) shapeMenu = bar.addMenu("Shape") actRectangle = shapeMenu.addAction(QIcon(":/icons/rectangle.png"), "&Rectangle", self.rectangle ) actEllipse = shapeMenu.addAction(QIcon(":/icons/ellipse.png"), "&Ellipse", self.ellipse) shapeToolBar = QToolBar("Shape") self.addToolBar( shapeToolBar ) shapeToolBar.addAction( actRectangle ) shapeToolBar.addAction( actEllipse ) modeMenu = bar.addMenu("Mode") actMove = modeMenu.addAction(QIcon(":/icons/move.png"), "&Move", self.move) actDraw = modeMenu.addAction(QIcon(":/icons/draw.png"), "&Draw", self.draw) actSelect = modeMenu.addAction(QIcon(":/icons/select.png"), "&Select", self.select) actFree = modeMenu.addAction(QIcon(":/icons/free.png"), "&Free drawing", self.free_drawing) modeToolBar = QToolBar("Navigation") self.addToolBar( modeToolBar ) modeToolBar.addAction( actMove ) modeToolBar.addAction( actDraw ) modeToolBar.addAction( actSelect ) modeToolBar.addAction( actFree ) ''' copy = QAction(QIcon("copy.png"), "Copy", self) copy.setShortcut(QKeySequence("Ctrl+C")) copy.setToolTip("Copy") copy.setStatusTip("Copy") fileMenu.addAction(copy) fileToolBar.addAction(copy) copy.triggered.connect(self.copy) cut = QAction(QIcon("cut.png"), "Cut", self) cut.setShortcut(QKeySequence("Ctrl+X")) cut.setToolTip("Cut") cut.setStatusTip("Cut") fileMenu.addAction(cut) fileToolBar.addAction(cut) cut.triggered.connect(self.cut) paste = QAction(QIcon("paste.png"), "Paste", self) paste.setShortcut(QKeySequence("Ctrl+V")) paste.setToolTip("Paste") paste.setStatusTip("Paste") fileMenu.addAction(paste) fileToolBar.addAction(paste) paste.triggered.connect(self.paste) pipette = QAction(QIcon("lab.png"), "Color", self) pipette.setShortcut(QKeySequence("Ctrl+V")) pipette.setToolTip("Color") pipette.setStatusTip("Color") fileMenu.addAction(pipette) fileToolBar.addAction(pipette) pipette.triggered.connect(self.color) ''' ############## def pen_color(self): self.log_action("choose pen color") self.canvas.set_color() def brush_color(self): self.log_action("choose brush color") self.canvas.set_bgcolor() def rectangle(self): self.log_action("Shape mode: rectangle") self.canvas.rectangle() def ellipse(self): self.log_action("Shape Mode: circle") self.canvas.ellipse() def free_drawing(self): self.log_action("Shape mode: free drawing") self.canvas.drawLasso() def move(self): self.log_action("Mode: move") self.canvas.move() def draw(self): self.log_action("Mode: draw") self.canvas.draw() def select(self): self.log_action("Mode: select") self.canvas.select() def log_action(self, str): content = self.textEdit.toPlainText() self.textEdit.setPlainText( content + "\n" + str) def open(self): print("Open...") openDialog = QFileDialog.getOpenFileName(self, "Open file", "", "*") try: fileName = openDialog[0].rsplit('/', 1)[-1] file = open(fileName, "r+") text = file.read() self.textEdit.setPlainText(text) openDialog.show() except: pass ############### def save(self): print("Save") saveDialog = QFileDialog.getSaveFileName(self, "Save file", "", "*") file = open(saveDialog[0],'w') text = self.textEdit.toPlainText() file.write(text) file.close() saveDialog.show() def quit(self): print("Quit") self.close() def closeEvent(self, event): quitDialog = QMessageBox.question(self, 'Continue?', 'Are you sure ?', QMessageBox.Yes, QMessageBox.No) if quitDialog == QMessageBox.Yes: event.accept() else: event.ignore() def statusBar(self): self.statusBar = QStatusBar() def copy(self): print("copy") cb = QApplication.clipboard() cb.setText(self.textEdit.toPlainText()) def cut(self): print("cut") cb = QApplication.clipboard() cb.setText(self.textEdit.toPlainText()) self.textEdit.setPlainText("") def paste(self): print("paste") cb = QApplication.clipboard() self.textEdit.setPlainText(cb.text())
import Playlists import Chart import Comparison # Make Radar chart Chart.make_radar_chart( Playlists.get_graphing_data([ Playlists.TOP_PLAYLIST_DICT['Malaysia'], Playlists.TOP_PLAYLIST_DICT['Israel'] ]), 'Malaysia and Israel') # Make Comparison chart Chart.make_comparison_chart("Malaysia") Chart.plt.show() # Print Comparison Data # Comparison.print_comparisons(Playlists.TOP_PLAYLISTS)
def test_chart_is_abstract_enough(): with pytest.raises(TypeError): Chart("Derp").get_config()
def chart(): img = Chart.renderChart(Readings, dbFileName) return send_file(img, mimetype='image/png')
def teststrWithValue(self): c = Chart.Chart() c.chs = "450x150" c.addData([42]) self.assertEquals("chof=png&chd=s:9&chds=0,42&chs=450x150&chxr=0,0,0,1|1,0,42|2,0,0", c.str())
def testaxisRange(self): self.assertEquals("0,0,0", Chart.axisRange(0, 0, 0)) self.assertEquals("0,0.0,42.0", Chart.axisRange(0, 0.0, 42.0, 0)) self.assertEquals("0,0,42,1", Chart.axisRange(0, 0, 42, 1))
def testrenderMetadata(self): c = Chart.Chart() RecentActivitySource.renderMetadata(c, datetime(2010, 01, 01), 2) self.assertEquals("2:|today|2010/01/01", c.chxl) self.assertEquals("2,0,1", c.chxp)
def testprocessDataWithNoData(self): c = Chart.Chart() c.chs = "450x150" c.processData()
def main(): weatherAnal = WeatherAnalyzer.WeatherAnalyzer('CalgaryWeather.csv') chart = Chart.Chart() running = True while running: print('1- Get Minimum Temperature of 1990-2019') print('2- Get Maximum Temperature of 1990-2019') print('3- Get Minimum Temperature of 1990-2019 Annually') print('4- Get Maximum Temperature of 1990-2019 Annually') print('5- Get Average Snowfall between 1990-2019 Annually') print('6- Get Average Temperature between 1990-2019 Annually') print('7- Graph Minimum Temperatures of 1990-2019 annually') print('8- Graph Maximum Temperatures of 1990-2019 annually') print('9- Graph Average Snowfall between 1990-2019 annually') print('10- Graph Average Temperature between 1990-2019 annually') try: choice = int(input('11- Exit Program')) if choice == 1: print(weatherAnal.getMinTemp()) elif choice == 2: print(weatherAnal.getMaxTemp()) elif choice == 3: matrix = weatherAnal.getMinTempAnnually() for row in matrix: for col in row: print(col, end=' ') print() elif choice == 4: matrix = weatherAnal.getMaxTempAnnually() for row in matrix: for col in row: print(col, end=' ') print() elif choice == 5: matrix = weatherAnal.getAvgSnowfallAnnually() for row in matrix: for col in row: print(col, end=' ') print() elif choice == 6: matrix = weatherAnal.getAvgTempAnnually() for row in matrix: for col in row: print(col, end=' ') print() elif choice == 7: # Since we can't slice the array when it's nested we convert it to a numpy array first then slice data = np.array(weatherAnal.getMinTempAnnually()) chart.drawLineChart(data[:, 0], data[:, 1], 'Minimum Temperatures of 1990-2019 annually', 'Year', 'Min Temp') elif choice == 8: # Since we can't slice the array when it's nested we convert it to a numpy array first then slice data = np.array(weatherAnal.getMaxTempAnnually()) chart.drawLineChart(data[:, 0], data[:, 1], 'Maximum Temperatures of 1990-2019 annually', 'Year', 'Max Temp') elif choice == 9: # Since we can't slice the array when it's nested we convert it to a numpy array first then slice data = np.array(weatherAnal.getAvgSnowfallAnnually()) chart.drawBarChart(data[:, 0], data[:, 1], 'Average Snowfall between 1990-2019 annually', 'Year', 'Average snowfall (cm)') elif choice == 10: # Since we can't slice the array when it's nested we convert it to a numpy array first then slice data = np.array(weatherAnal.getAvgTempAnnually()) chart.drawBarChart(data[:, 0], data[:, 1], 'Average Temperature between 1990-2019 annually', 'Year', 'Average Temp') elif choice == 11: running = False else: raise ValueError except ValueError: print('Invalid selection, try again')
def __init__(self, parent = None): QMainWindow.__init__(self) self.statusBar() self.setWindowTitle("Paint") #self.canvas = Canvas(self) #self.textEdit = QTextEdit(self) self.chart = Chart() self.view = QChartView(self.chart) self.chart.set_view(self.view) #self.statusBar() self.canvas = Canvas(self.chart) self.textEdit = QTextEdit(self) mainLayout = QGridLayout(self) mainLayout.addWidget(self.canvas, 1, 1) mainLayout.addWidget(self.textEdit, 2, 1) mainLayout.addWidget(self.view, 1, 2, 5, 1) ''' top_layout = QVBoxLayout() top_layout.addWidget(self.canvas) top_layout.addWidget(self.textEdit) ''' #top_layout.addLayout( h_layout ); container = QWidget() container.setLayout(mainLayout) self.setCentralWidget(container) #self.setCentralWidget(self.canvas) self.resize(1000, 700) bar = self.menuBar() fileMenu = bar.addMenu("File") fileToolBar = QToolBar("File") openFile = QAction(QIcon(":/icons/open.png"), "Open...", self) openFile.setShortcut(QKeySequence("Ctrl+O")) openFile.setToolTip("Open") openFile.setStatusTip("Open") fileMenu.addAction(openFile) fileToolBar.addAction(openFile) openFile.triggered.connect(self.open) saveFile = QAction(QIcon(":/icons/save.png"), "Save...", self) saveFile.setShortcut(QKeySequence("Ctrl+S")) saveFile.setToolTip("Save") saveFile.setStatusTip("Save") fileMenu.addAction(saveFile) fileToolBar.addAction(saveFile) saveFile.triggered.connect(self.save) quitFile = QAction(QIcon(":/icons/quit.png"), "Quit", self) quitFile.setShortcut(QKeySequence("Ctrl+W")) quitFile.setToolTip("Quit") quitFile.setStatusTip("Quit") fileMenu.addAction(quitFile) fileToolBar.addAction(quitFile) quitFile.triggered.connect(self.quit) self.addToolBar(fileToolBar) colorMenu = bar.addMenu("Color") actPen = colorMenu.addAction(QIcon(":/icons/pen.png"), "&Pen color", self.pen_color, QKeySequence("Ctrl+P")) actBrush = colorMenu.addAction(QIcon(":/icons/brush.png"), "&Brush color", self.brush_color, QKeySequence("Ctrl+B")) colorToolBar = QToolBar("Color") self.addToolBar( colorToolBar ) colorToolBar.addAction( actPen ) colorToolBar.addAction( actBrush ) shapeMenu = bar.addMenu("Shape") actRectangle = shapeMenu.addAction(QIcon(":/icons/rectangle.png"), "&Rectangle", self.rectangle ) actEllipse = shapeMenu.addAction(QIcon(":/icons/ellipse.png"), "&Ellipse", self.ellipse) shapeToolBar = QToolBar("Shape") self.addToolBar( shapeToolBar ) shapeToolBar.addAction( actRectangle ) shapeToolBar.addAction( actEllipse ) modeMenu = bar.addMenu("Mode") actMove = modeMenu.addAction(QIcon(":/icons/move.png"), "&Move", self.move) actDraw = modeMenu.addAction(QIcon(":/icons/draw.png"), "&Draw", self.draw) actSelect = modeMenu.addAction(QIcon(":/icons/select.png"), "&Select", self.select) actFree = modeMenu.addAction(QIcon(":/icons/free.png"), "&Free drawing", self.free_drawing) modeToolBar = QToolBar("Navigation") self.addToolBar( modeToolBar ) modeToolBar.addAction( actMove ) modeToolBar.addAction( actDraw ) modeToolBar.addAction( actSelect ) modeToolBar.addAction( actFree ) '''
def testcomputeAxisRanges(self): actual = Chart.computeAxisRanges(1, 42, 450, 150) self.assertEquals("0,0,0,1|1,0,42|2,0,0", actual)