Exemple #1
0
    def test_similar(self):
        ctx = app.test_request_context()
        ctx.push()

        from engines import content_engine

        #content_engine.train('sample-data.csv')
        #content_engine.train('result.csv')

        data = {'item': 56753, 'num': NUM_DATA}
        headers = [('Content-Type', 'application/json'),
                   ('X-API-TOKEN', current_app.config['API_TOKEN'])]
        json_data = json.dumps(data)
        json_data_length = len(json_data)
        headers.append(('Content-Length', str(json_data_length)))
        print json_data
        response = app.test_client().post('/predict',
                                          headers=headers,
                                          data=json_data)
        print response
        response = json.loads(response.data)
        #fp=open("data_test.csv",'r')
        #content = fp.read()
        #fp.close()
        #cdata = content.split('\n')
        #print response
        print "search:56753"
        num = 10
        if num > len(response):
            num = len(response)

        for i in range(0, num):
            print response[i][0], response[i][1]
Exemple #2
0
def requireHeartBeat():
    with app.test_request_context():
        url_for('pcHeartBeat', ip='172.21.14.35')


# if __name__ == '__main__':
#     app.run()
Exemple #3
0
    def test_similar(self):
        ctx = app.test_request_context()
        ctx.push()

        from engines import content_engine

        #content_engine.train('sample-data.csv')
        content_engine.train('/home/ubuntu/teamHTTP/serverPHP/engine/tfidf-item/iroya_data.csv')
Exemple #4
0
    def test_similar(self):
        ctx = app.test_request_context()
        ctx.push()

        from engines import content_engine

        #content_engine.train('sample-data.csv')
        content_engine.train('result.csv')
        '''
Exemple #5
0
def send(MessageClass, **kwargs):
    with app.test_request_context():
        mailer = Mail(app)
        mailer.send(MessageClass(**kwargs))

    if 'to' in kwargs:
        return "Mail type: %s, recipient: %s" % (MessageClass.desc(), kwargs['to'])

    return True
Exemple #6
0
    def test_similar(self):
        ctx = app.test_request_context()
        ctx.push()

        from engine import content_engine

        content_engine.train('sample-data.csv')

        data = {'item': 1, 'num': 10}
        headers = [('Content-Type', 'application/json'), ('X-API-TOKEN', current_app.config['API_TOKEN'])]
        json_data = json.dumps(data)
        json_data_length = len(json_data)
        headers.append(('Content-Length', str(json_data_length)))

        response = app.test_client().post('/score', headers=headers, data=json_data)
        response = json.loads(response.data)
        self.assertEqual(len(response), 10)
        self.assertEqual(response[0][0], "19")
Exemple #7
0
    def test_similar(self,item,NUM_DATA):
        ctx = app.test_request_context()
        ctx.push()
	

        from engines import content_engine

        #content_engine.train('sample-data.csv')
       	#content_engine.train('result.csv')
	items=item.split('-')
	result=[]
	k={}
	for i in items:
       		data = {'item': i, 'num': int(NUM_DATA)}
        	headers = [('Content-Type', 'application/json'), ('X-API-TOKEN', current_app.config['API_TOKEN'])]
        	json_data = json.dumps(data)
        	json_data_length = len(json_data)
        	headers.append(('Content-Length', str(json_data_length)))
#	print json_data
        	response = app.test_client().post('/predict', headers=headers, data=json_data)
#		print response
        	response = json.loads(response.data)
		result = result+response
	for i,j in result:  
		if i not in k.keys():  
	            	k[i]=1
        	else:  
		        k[i]=k[i]+1
	s=sorted(k.items(),key=lambda item:item[1],reverse=True)
	#print s
	result=[]
	num=0
	for key in s:
		if key in items:
			continue
		result.append(int(key[0]))
		num = num +1
		if (num > int(NUM_DATA)):
			break
	print result
	return result
Exemple #8
0
 def test_keyword(self):
     with app.test_request_context('/api/keyword/56'):
         print(keyword(_id=56))
Exemple #9
0
 def test_page(self):
     with app.test_request_context('/api/page/404'):
         print(page(_id=404))
Exemple #10
0
 def test_speciality(self):
     with app.test_request_context('/api/speciality/132'):
         print(speciality(_id=132))
Exemple #11
0
 def test_station(self):
     with app.test_request_context('/api/station/10'):
         print(station(_id=10))
 def setUp(self):
     app.config['TESTING'] = True
     app.config['CSRF_ENABLED'] = False
     with app.test_request_context():
         self.form = UserProfileForm()
 def setUp(self):
     app.config['TESTING'] = True
     app.config['CSRF_ENABLED'] = False
     with app.test_request_context():
         self.form = AccountSettingsForm()
Exemple #14
0
from flask import render_template
import codecs
import csv

from web import app


def unicodeit(d):
    for k in list(d.keys()):
        d[k] = d[k] if isinstance(d[k], unicode) else unicode(d[k], 'utf-8')
    return d


with app.test_request_context(''):

    app.preprocess_request()

    with open('data/organizations.csv') as infile:

        orgs = [unicodeit(r) for r in csv.DictReader(infile)]
        orgs = sorted(orgs, cmp=lambda x, y: cmp(x['country'] + x['name'], y['country'] + y['name']))

        countries = sorted(set(o['country'] for o in orgs))

        with codecs.open('templates/_orgs.html', 'w', 'utf-8') as outfile:
            outfile.write(render_template('_orgs-template.html', orgs=orgs, countries=countries))