def load_data(): """ gets data from MySQL table and convert it to dataframe """ global df global categoricals global labels db_setup.init_db() pd.set_option('display.max_columns', 20) pd.set_option('expand_frame_repr', True) db_setup.cursor.execute(db_setup.statement) df = pd.read_sql(db_setup.statement, con=db_setup.db) labels = db_setup.all_labels() for col, col_type in df.dtypes.items(): if col_type == 'O': categoricals.append(col) else: # fill NA's with 0 for ints/floats, too generic df[col].fillna(0, inplace=True)
def xml_download(): init_db() r = requests.get("http://donnees.ville.montreal.qc.ca/dataset/" + "a5c1f0b9-261f-4247-99d8-f28da5000688/resource/" + "92719d9b-8bf2-4dfd-b8e0-1021ffcaee2f/download/" + "inspection-aliments-contrevenants.xml") with open('db/contrevenants.xml', 'wb') as f: f.write(r.content) conn = sqlite3.connect('db/contrevenants.db', check_same_thread=False) c = conn.cursor() tree = Et.parse('db/contrevenants.xml') root = tree.getroot() for contrevenant in root: resultats = [] infraction = dateparser.parse(contrevenant[6].text).date().isoformat() jugement = dateparser.parse(contrevenant[7].text).date().isoformat() qry = db_session.query(Contrevenants).filter( Contrevenants.proprietaire.contains(contrevenant[0].text)).filter( Contrevenants.categorie.contains(contrevenant[1].text)).filter( Contrevenants.etablissement.contains(contrevenant[2].text) ).filter(Contrevenants.adresse.contains( contrevenant[3].text)).filter( Contrevenants.ville.contains( contrevenant[4].text)).filter( Contrevenants.description.contains( contrevenant[5].text)).filter( Contrevenants.date_infraction. contains(infraction)).filter( Contrevenants.date_jugement. contains(jugement)).filter( Contrevenants.montant.contains( contrevenant[8].text)) resultats = qry.all() if not resultats: sql_statement = """insert into contrevenant(proprietaire, categorie, etablissement, adresse, ville, description, date_infraction, date_jugement, montant) VALUES(?,?,?,?,?,?,?,?,?)""" c.execute(sql_statement, (contrevenant[0].text, contrevenant[1].text, contrevenant[2].text, contrevenant[3].text, contrevenant[4].text, contrevenant[5].text, infraction, jugement, contrevenant[8].text)) conn.commit()
def setUp(self): self.db_fd, self.db_filename = tempfile.mkstemp() self.db_uri = 'sqlite:///' + self.db_filename init_db(self.db_uri) self.app = create_app(self.db_uri) self.client = self.app.test_client() self.booking = dict( user_id=1, amount=100, merchant_id=1, book_date='201801010000', flight_origin='Paris', flight_dest='Tokyo', flight_date='201801010000', flight_nr=123456789 )
def intialize_database(): """ Intializes the database for the application Args: None Returns: None Examples: >>> """ if database_exists("sqlite:///studentadmin.db") is False: init_db() insert_users() insert_contact() insert_course_info() insert_registered() insert_available()
def decode(prediction): """ :param prediction: encoded array of prediction returns string value of prediction based on encoded array :return: decoded prediction """ db_setup.init_db() if (not np.any(prediction)): result_text = "Electronic Device" else: result = (np.where(prediction == 1))[0] result = result[0] # print(result) result_text = db_setup.all_labels()[result] db_setup.close_db() return result_text
def insert_data(features): """ :param features: dictionary of features calculated for dataset inserts data into MySQL table with calculated """ global test_data db_setup.init_db() request = "INSERT INTO {0} (label, mean, median, sd, variance, iqr, mode, min, max) " \ "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)".format(db_setup.table_name) values = (dataset_label, features[columns[0]], features[columns[1]], features[columns[2]], features[columns[3]], features[columns[4]], features[columns[5]], features[columns[6]], features[columns[7]]) print(dataset_label) db_setup.cursor.execute(request, values) db_setup.db.commit() db_setup.close_db() model.train() test_data = pd.DataFrame(columns=model.get_columns())
from flask import render_template, request from src import MarioAndPrincess import time from form import GridInputForm from models import MarioMoves from app import app from db_setup import init_db, db_session from db_creator import create_table import ast import datetime create_table() init_db() @app.route('/', methods=['GET', 'POST']) def base(): return input() @app.route('/input', methods=['GET', 'POST']) def input(): grid = GridInputForm(request.form) if request.method == 'POST': return result(raw_grid=grid.grid.data, N=int(grid.n.data)) return render_template('input.html', form=grid) @app.route('/result', methods=['GET', 'POST']) def result(raw_grid, N):
import numpy as np import csv import pandas as pd from werkzeug.utils import secure_filename from bokeh.plotting import figure, ColumnDataSource, output_notebook, show from bokeh.resources import CDN, INLINE from bokeh.embed import file_html, components from bokeh.models import HoverTool, WheelZoomTool, PanTool, BoxZoomTool, ResetTool, TapTool, SaveTool from bokeh.palettes import brewer #import matplotlib.pyplot as plt #import datetime import re import requests ############################################################################### init_db() #initialise the database ############################################################################### @app.route("/") #define homepage route def index(): return render_template("index.html") ###### Kinase ################################################################# @app.route('/kinase', methods=['GET', 'POST']) def kinase(): search = KinaseSearchForm( request.form) # import search form and run a request if request.method == 'POST': # if the user is searching for information (ie posting a searchstring to retrieve data) return k_search_results(search) # run the kinase search function
import numpy as np import pandas as pd from flask import Flask, json, jsonify, render_template, request from scipy import stats import config import db_setup import model app = Flask(__name__) db_setup.init_db() dataset_label = "" state = False current_reading = 0 current_dataset = [] columns = model.get_columns() test_data = pd.DataFrame(columns=columns) table_name = db_setup.table_name statement = db_setup.statement @app.route("/") def home(): """ root directory of server :return: html template page with variables et for ui elements """
from flask import Flask, redirect, render_template, request from flask_sqlalchemy import SQLAlchemy #from datacreate import BlogPost from db_setup import init_db init_db() # added other datacreate & db_setup for db creation app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///posts.db' db = SQLAlchemy(app) # datacreate class is replaced @app.route('/') def index(): return render_template('index.html') @app.route('/posts', methods=['GET', 'POST']) def posts(): from datacreate import BlogPost if request.method == 'POST': post_title = request.form['title'] post_content = request.form['content'] post_author = request.form['author'] new_post = BlogPost(title=post_title, content=post_content, author=post_author)
#Article Extraction test case import db_setup import extract conn=db_setup.init_db() website_code_dict={ "livemint.com" : ''' #start of website-specific code #input: article_soup, from function def soup_recepie(url) website_base_url="livemint.com" headline_list=article_soup.find("h1", {"class":"sty_head_38"}) article_headline="" for i in headline_list: article_headline+=extraction_text_manip.properly_encode(str(i)) article_headline=extraction_text_manip.properly_format(article_headline) article_alt_headline_list=[] alt_headline_list=article_soup.find("div", {"class":"sty_sml_summary_18"}) article_alt_headline="" for i in alt_headline_list: article_alt_headline+=extraction_text_manip.properly_encode(str(i))