def __init__(self): self.db = Database('loans.db') self.db.create_tables() self.db.delete_tables() self.file = FileUtil() self.file.clean_files() self.expected_yield = {}
def index(): config = DbConfig(request.form["host"], request.form["username"], request.form["password"], request.form["port"], request.form["dbname"]) db = Database(config.dbname, config.getConnection()) status = Status() status.OriginalDB = db status.DBName = db.name return render_template('index.html', database=db)
def conectOriginal(self, content, db_type): config = DbConfig(content["host"], content["username"], content["password"], content["port"], content["dbname"]) print("1111111111111") db = Database(content["dbname"], config.getConnection()) status = Status() if (db_type == 1): status.OriginalDB = db elif (db_type == 2): status.CopyDB = db
def setTables(): print("sendTables") print("JSON---", request) host = str(request).split("&") ipSplit = host[0].split("?") ipAddress = ipSplit[1].split("=") port = host[1].split("=") dbname = host[2].split("=") username = host[3].split("=") password = host[4].split("=") ipAddress = str(ipAddress[1]) port = str(port[1]) dbname = str(dbname[1]) username = str(username[1]) password = str(password[1]) print("/n host[0]===ipAddress====", ipAddress) print("host[1]===port====", port) print("host[2]===dbname====", dbname) print("host[3]====username===", username) print("host[4]===password====", password) info = host[-1].split("'") info2 = info[0].split(",") print("-.-.-.-222.-.-.-.-.- ", info2) global controller print("estoy en setTables") tables = info2 print("tb", tables) config = DbConfig(ipAddress, username, password, port, dbname) print("config creado--ip address = ", config.host) status = Status() config2 = DbConfig(ipAddress, username, password, port, status.OriginalDB.name) db = Database(status.OriginalDB.name, config2.getConnection()) status.CopyDB = db print("terminando set tables----", config, "tables", tables) controller.createDatabase(config) controller.copyTables(config2, tables) print("set tables listo!!")
from fastapi import FastAPI, Depends from auth.jwt_bearer import JWTBearer from models.Database import Database from routes.book import router as BookRouter from routes.user import router as UserRouter app = FastAPI() bearer = JWTBearer(Database()) @app.get("/") def read_root(): return {"message": "Welcome to Quidax Book API, use the /docs route,"} app.include_router(BookRouter, tags=["books"], prefix="/book", dependencies=[Depends(bearer)]) app.include_router(UserRouter, tags=["users"], prefix="/user")
from flask import Flask, jsonify, request, json from flask_cors import CORS from flask_bcrypt import Bcrypt from flask_jwt_extended import JWTManager from flask_jwt_extended import create_access_token from models.Database import Database from models import User from config import app_config # initialize flask app app = Flask(__name__) cors = CORS(app) config = app_config.config(app) bcrypt = Bcrypt(app) jwt = JWTManager(app) db = Database('config/db_config') @app.route('/api/db/connection', methods=['GET']) def db_conn(): if db.is_connected(): return 'success' return 'failed' # TODO: ajax request to server # TODO: user comments # @app.route('/comments', methods=['GET']) # def all_course(): # return jsonify({'status': 'Success', # 'comments': COMMENTS})
class App: def __init__(self): self.db = Database('loans.db') self.db.create_tables() self.db.delete_tables() self.file = FileUtil() self.file.clean_files() self.expected_yield = {} def loadData(self): banks = self.db.load_banks() convenants = self.db.load_covenants() facilities = self.db.load_facilities() def write_yield(self): output_yeild_file = self.file.get_file("yield.csv", "w") try: self.db.c.execute("select id, expected_yield from facilities") except sqlite3.Error: print("Error read from facilities.\n") for row in self.db.c: output_yeild_file.writerow({ 'facility_id': row['id'], 'expected_yield': int(row['expected_yield']) }) def get_yield(self, default_likelihood, interest_rate, amount, facility_interest_rate, expected_yield): return expected_yield + ( 1 - default_likelihood ) * interest_rate * amount - default_likelihood * amount - facility_interest_rate * amount def pickFacility(self, default_likelihood, state, amount, interest_rate): # selection logic: # 1) default_likelihood should be lower than facility max_default_likelihood # 2) state should not be banned_state # 3) amount should be lower than facility amount # 4) order by facility amount and interest rate # to pick the first facility available (todo: make this more intelligent) self.db.c.execute( '''select a.id as facility_id, a.amount as amount, a.interest_rate as facility_interest_rate, a.expected_yield as expected_yield from facilities a, banks b, covenants c where a.bank_id = b.id and a.bank_id = c.bank_id and a.id = c.facility_id and c.max_default_likelihood >= ? and c.banned_state<>? and a.amount >= ? and a.interest_rate <=? order by a.amount, a.interest_rate''', (default_likelihood, state, amount, interest_rate)) for row in self.db.c: facility_id = int(row['facility_id']) facility_interest_rate = float(row['facility_interest_rate']) new_amount_available = int(row['amount']) - int(amount) new_yield = self.get_yield(default_likelihood, interest_rate, amount, facility_interest_rate, row['expected_yield']) try: self.db.c.execute( "update facilities set amount = ?, expected_yield = ? where id =?", (new_amount_available, new_yield, facility_id)) self.db.conn.commit() except sqlite3.Error: print("Error updating a loan.\n") break return facility_id def processLoans(self): output_assignment_file = self.file.get_file("assignment.csv", "w") input_file = self.file.get_file("loans.csv") for row in input_file: interest_rate = float(row['interest_rate']) amount = float(row['amount']) id = row['id'] default_likelihood = float(row['default_likelihood']) state = row['state'] output_assignment_file.writerow({ 'loan_id': str(id), 'facility_id': self.pickFacility(default_likelihood, state, amount, interest_rate) })
return True def getNextPrime(dbSize: int): number: int = copy.copy(dbSize) while (not isPrime(number)): number += 1 return number ratio: float = 0 actionCode: int = -1 dbSize: int = int(input("insira o tamanho do seu banco de dados: ")) dbSize += dbSize // 2 dbSize = getNextPrime(dbSize) db: Database = Database(dbSize) menu: Menu = Menu() while actionCode != 0: actionCode = menu.fIndexer(db.createUser, db.tryToAuthenticate, db.deleteUser, db.checkAllUsers) if actionCode != 0: input("") os.system('clear') if db.getOperations() != 0: ratio = db.getAccess() / db.getOperations() print("Operação Finalizada! Média de acessos por operação igual a: {0:.2f}". format(ratio))