def load_sample_data(): """ This will load sample data. The following users are created: Root / password Jim / bunny Bill / gopher :return: """ db = Database() db.start_engine() content_key = generate_key() user1_key = generate_key() content_key_encrypted = Encrypter(user1_key).encrypt(content_key) user1 = User(username='******',password='******',content_key=content_key_encrypted,encrypt_key=user1_key) db.session.add(user1) user2_key = generate_key() content_key_encrypted = Encrypter(user2_key).encrypt(content_key) user2 = User(username='******',password='******',content_key=content_key_encrypted,encrypt_key=user2_key) db.session.add(user2) user3_key = generate_key() content_key_encrypted = Encrypter(user3_key).encrypt(content_key) user3 = User(username='******',password='******',content_key=content_key_encrypted,encrypt_key=user3_key) db.session.add(user3) db.session.commit()
def setup(): db = Database() db.createMatchTable() employeePath = '../data/employees.csv' employerPath = '../data/employers.csv' model = pickle.load(open('/data/model.pickle', 'rb')) employeeData = pd.read_csv(employeePath, sep=',') employeeData['merge'] = 1 employerDataReader = pd.read_csv(employerPath, sep=',', chunksize=1) for employerData in employerDataReader: employerData['merge'] = 1 df = pd.merge(employerData, employeeData, on='merge') del df['merge'] attrs = set(df.columns.values) ignoredAttrs = set([ 'id_x', 'id_y', 'nameFirst_x', 'nameFirst_y', 'nameLast_x', 'nameLast_y', 'origin_x', 'origin_y' ]) inputAttrs = list(attrs - ignoredAttrs) inputsMap = DataFrameMapper([(inputAttrs, None)]) inputSamples = inputsMap.fit_transform(df) #print(df) result = pd.DataFrame( data={ 'id_x': df['id_x'], 'id_y': df['id_y'], 'score': model.predict(inputSamples) }) id = 0 result.sort_values(by=['score'], ascending=False, inplace=True) result = result.head(5) for index, row in result.iterrows(): id += 1 print(row) print(row[0]) print(row[1]) print(row[2]) db.insertMatchTable(id, row[0], row[1], row[2])
# -*- coding: utf-8 -*- from flask import Flask,request, jsonify from dbmanager import Database db = Database() db.start_engine() app = Flask(__name__) @app.route('/api/v1.0/data',methods=['GET','POST']) def index(): if request.method == 'GET': #Fetch data username = request.args.get('user','') password = request.args.get('password','') print 'Username = %s, password = %s'%(username,password) content = db.get_data(username,password) return jsonify(data=content) elif request.method == 'POST': #Update data username = request.form.get('user','') password = request.form.get('password','') data = request.form.get('content','') print 'Username = %s, password = %s'%(username,password) print 'Data %s'%data db.save_data(data,username,password) else : print 'Not handling it' return jsonify(data=data) @app.route('/api/v1.0/rotate',methods=['GET'])
config = SafeConfigParser() config.read('hermes.cfg') notifyAgent = hermes.Hermes(config) server_ipaddr = config.get('server', 'addr') server_port = config.get('server', 'port') server_whitelist = config.get('server', 'whitelist') server_debug = config.get('server', 'debug') #--- valid parameters --- twitter_required_parameters = set(['msg', 'log_level']) mail_required_parameters = set(['msg', 'log_level', 'to', 'subject']) #--- init dbmanager --- db = Database() app = Flask(__name__) #--- Loggining --- app.secret_key = '\x16\x91\xa4ZPL\xe6=%\xb6\x94\xe3<Cg\x1e\x00f21\x92\x8aq\x15' login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' user = user.User(config) @app.before_request def before_request(): g.user = current_user
#!/usr/bin/env python3 # match.py import sys import pickle import pandas as pd from sklearn_pandas import DataFrameMapper from dbmanager import Database db = Database() db.createMatchTable() employeePath = '../data/employees.csv' employerPath = '../data/employers.csv' model = pickle.load(open('../data/model.pickle', 'rb')) employeeData = pd.read_csv(employeePath, sep=',') employeeData['merge'] = 1 employerDataReader = pd.read_csv(employerPath, sep=',', chunksize=1) for employerData in employerDataReader: employerData['merge'] = 1 df = pd.merge(employerData, employeeData, on='merge') del df['merge'] attrs = set(df.columns.values) ignoredAttrs = set([ 'id_x', 'id_y', 'nameFirst_x',