예제 #1
0
def client(queue, method, clean, epochs):
    from utils import root_path, my_acc, my_rmse, randomword
    from config import Config
    from model import SVD, RandomGuess, DeepCF

    if method == 'svd':
        config = Config('train_sub_txt',
                        dim=100,
                        epochs=epochs,
                        layers=0,
                        reg=.02,
                        keep_prob=.9,
                        clean=clean)
        name = 'svd_' + randomword(10)

        test = np.array(config.data.df_test)
        svd = SVD(config, model_name=name)
        acc, max_acc = svd.train()
        print 'final acc', acc, 'max acc', max_acc
        rate = svd.predict(test)
        final_acc = my_acc(rate, test[:, 2])
        print 'mse', my_rmse(rate, test[:, 2]), 'final test acc', final_acc

        all_test = config.data.get_all_test()
        rate = svd.predict(all_test)
        array = config.data.get_origin_array(rate)

        config.data.save_res(array, name=name)
        assert not queue.full()
        queue.put((name, final_acc))
    else:
        config = Config('train_sub_txt',
                        dim=100,
                        epochs=epochs,
                        layers=4,
                        reg=.02,
                        keep_prob=.9,
                        clean=clean)
        _, test = config.data.make_batch()
        name = 'deep_cf_' + randomword(10)

        deep_cf = DeepCF(config, model_name=name)
        acc, max_acc = deep_cf.train()
        print 'final acc', acc, 'max acc', max_acc

        rate = deep_cf.predict(test)
        rate_gt = np.argmax(test[2], axis=1) + 1
        final_acc = my_acc(rate, rate_gt)
        print 'rmse', my_rmse(rate, rate_gt), 'final test acc', final_acc

        rate = deep_cf.predict(config.data.make_all_test_batch())
        array2 = config.data.get_origin_array(rate)

        config.data.save_res(array2, name=name)

        queue.put((name, final_acc))
    return 0
예제 #2
0
파일: views.py 프로젝트: wienczny/merchant
def offsite_ogone(request):
    from utils import randomword
    fields = {
        # Required
        # orderID needs to be unique per transaction.
        'orderID': randomword(6),
        'currency': 'INR',
        'amount': '10000',  # 100.00
        'language': 'en_US',

        # Optional; Can be configured in Ogone Account:

        'exceptionurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'declineurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'cancelurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'accepturl': request.build_absolute_uri(reverse("ogone_notify_handler")),

        # Optional fields which can be used for billing:

        # 'homeurl': 'http://127.0.0.1:8000/',
        # 'catalogurl': 'http://127.0.0.1:8000/',
        # 'ownerstate': '',
        # 'cn': 'Venkata Ramana',
        # 'ownertown': 'Hyderabad',
        # 'ownercty': 'IN',
        # 'ownerzip': 'Postcode',
        # 'owneraddress': 'Near Madapur PS',
        # 'com': 'Order #21: Venkata Ramana',
        # 'email': '*****@*****.**'
    }
    ogone_obj.add_fields(fields)
    return render(request, "app/ogone.html", {"og_obj": ogone_obj})
예제 #3
0
def offsite_ogone(request):
    from utils import randomword
    fields = {
        # Required
        # orderID needs to be unique per transaction.
        'orderID': randomword(6),
        'currency': u'INR',
        'amount': u'10000',  # 100.00
        'language': 'en_US',

        # Optional; Can be configured in Ogone Account:

        'exceptionurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'declineurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'cancelurl': request.build_absolute_uri(reverse("ogone_notify_handler")),
        'accepturl': request.build_absolute_uri(reverse("ogone_notify_handler")),

        # Optional fields which can be used for billing:

        # 'homeurl': u'http://127.0.0.1:8000/',
        # 'catalogurl': u'http://127.0.0.1:8000/',
        # 'ownerstate': u'',
        # 'cn': u'Venkata Ramana',
        # 'ownertown': u'Hyderabad',
        # 'ownercty': u'IN',
        # 'ownerzip': u'Postcode',
        # 'owneraddress': u'Near Madapur PS',
        # 'com': u'Order #21: Venkata Ramana',
        # 'email': u'*****@*****.**'
    }
    ogone_obj.add_fields(fields)
    return render(request, "app/ogone.html", {"og_obj": ogone_obj})
예제 #4
0
 def play(self,
          url,
          type_='video',
          title=None,
          description=None,
          image=None,
          imdb=None,
          season=None,
          episode=None,
          stop_completion=None):
     """Plays a url"""
     print 'Playing {}'.format(url)
     self.play = url
     _id = utils.randomword()
     p = multiprocessing.Process(target=play_stop,
                                 args=(self, _id, stop_completion))
     p.daemon = True
     p.start()
     self._message({
         'type': 'play',
         'url': url,
         'stop': '/response/{}/{}'.format(self.thread.id, _id),
         'playtype': type_,
         'title': title,
         'description': description,
         'image': image,
         'imdb': imdb,
         'season': season,
         'episode': episode
     })
     return
예제 #5
0
	def _message(self, msg, wait=False, _id=None):			
		if not self.thread:
			return None
		if not _id:
			_id = utils.randomword()
			msg['id'] = '{}/{}'.format(self.thread.id, _id)						
		
		print 'adding message: {}'.format(msg)
		self.thread.message(msg)
		if not wait:
			return
		start = time.time()		
		while not self.thread.stop and time.time() - start < 3600: #wait for response at most 1 hour. This is meant to limit amount of threads on web server			
			try:
				r = self.thread.responses.get(False)
				print 'found response for {}'.format(r['id'])
				if r['id'] == _id:
					print 'received response to {}'.format(_id)
					return r['response']
				else:
					self.thread.responses.put(r)
			except:
				gevent.sleep(0.1)
		if self.thread.stop:
			print 'finished waiting for response {} due to thread stop'.format(_id)
		else:
			print 'Aborting response wait due to time out'
		return None
예제 #6
0
    def _message(self, msg, wait=False, _id=None):
        if not self.thread:
            return None
        if not _id:
            _id = utils.randomword()
            msg['id'] = '{}/{}'.format(self.thread.id, _id)

        print 'adding message: {}'.format(msg)
        self.thread.message(msg)
        if not wait:
            return
        start = time.time()
        while not self.thread.stop and time.time(
        ) - start < 3600:  #wait for response at most 1 hour. This is meant to limit amount of threads on web server
            try:
                r = self.thread.responses.get(False)
                print 'found response for {}'.format(r['id'])
                if r['id'] == _id:
                    print 'received response to {}'.format(_id)
                    return r['response']
                else:
                    self.thread.responses.put(r)
            except:
                gevent.sleep(0.1)
        if self.thread.stop:
            print 'finished waiting for response {} due to thread stop'.format(
                _id)
        else:
            print 'Aborting response wait due to time out'
        return None
예제 #7
0
	def progressdialog(self, heading, text=''):
		"""Shows a progress dialog to the user"""
		_id = utils.randomword()
		self.progress={'title': heading, 'id': _id}					
		p = multiprocessing.Process(target=progress_stop, args=(self, _id))
		p.daemon = True
		p.start()
		self._message({'type':'progressdialog', 'title':heading, 'text':text, 'value':'0', 'id':'{}/{}'.format(self.thread.id, _id)}, False, _id)
예제 #8
0
	def play(self, url, type_='video', title=None, description=None, image=None, imdb=None, season=None, episode=None, stop_completion=None):
		"""Plays a url"""
		print 'Playing {}'.format(url)
		self.play = url
		_id = utils.randomword()		
		p = multiprocessing.Process(target=play_stop, args=(self, _id, stop_completion))
		p.daemon = True
		p.start()
		self._message({'type':'play', 'url':url, 'stop':'/response/{}/{}'.format(self.thread.id, _id), 'playtype': type_, 'title':title, 'description':description, 'image':image, 'imdb':imdb, 'season':season, 'episode':episode})
		return 
예제 #9
0
def text2img(text, shape):
    import matplotlib.pylab as plt

    fig = plt.figure(figsize=shape)
    plt.text(0.5, 0.5, text, horizontalalignment='center',
             verticalalignment='center', fontsize=30)
    name = '/tmp/' + utils.randomword(5) + '.png'
    plt.savefig(name)
    im = plt.imread(name)[:, :, :3]
    tensor = tf.convert_to_tensor(im)
    # tensor = tf.image.resize_bilinear(tf.expand_dims(tensor, 0))
    return tf.expand_dims(tensor, 0)
예제 #10
0
 def progressdialog(self, heading, text=''):
     """Shows a progress dialog to the user"""
     _id = utils.randomword()
     self.progress = {'title': heading, 'id': _id}
     p = multiprocessing.Process(target=progress_stop, args=(self, _id))
     p.daemon = True
     p.start()
     self._message(
         {
             'type': 'progressdialog',
             'title': heading,
             'text': text,
             'value': '0',
             'id': '{}/{}'.format(self.thread.id, _id)
         }, False, _id)
예제 #11
0
def train(queue, dim):
    sucess = False
    while not sucess:
        try:
            from config import Config
            from model import SVD
            config = Config('train_sub_txt',
                            dim=dim,
                            epochs=1000,
                            layers=0,
                            reg=.02,
                            keep_prob=.9)
            svd = SVD(config, model_name='svd_' + randomword(10))
            acc = svd.train()
            print dim, acc
            queue.put((dim, acc))
            sucess = True
        except Exception as inst:
            print dim, inst
            # queue.put((dim,str(inst)))
            # exit(-100)
            sucess = False
예제 #12
0
def train2(queue, size):
    sucess = False
    from config import Config
    from model import SVD, DeepCF
    while not sucess:
        try:
            config = Config('train_sub_txt',
                            dim=100,
                            epochs=200,
                            layers=4,
                            reg=.02,
                            keep_prob=.9)
            deep_cf = DeepCF(config,
                             model_name='deep_cf_' + randomword(10),
                             size=size)
            acc = deep_cf.train()
            print size, acc
            queue.put((size, acc))
            sucess = True
        except Exception as inst:
            print size, inst
            sucess = False
            exit(-100)
            time.sleep(600)
예제 #13
0
파일: conf.py 프로젝트: Chris7/merchant
        'EWAY_CARDCVN': '100',
    },

    "braintree_payments": {
        "transaction": {
            "order_id": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
            "type": "sale",
            "options": {
                "submit_for_settlement": True
            },
        },
        "site": "{HOST}:8000".format(HOST=HOST)
    },

    "ogone_payments": {
        'orderID': randomword(6),
        'currency': u'INR',
        'amount': u'10000',  # Rs. 100.00
        'language': 'en_US',
        'exceptionurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'declineurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'cancelurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'accepturl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
    }
}

for k, v in GATEWAY_INITIAL.iteritems():
    v.update(COMMON_INITIAL)

for k, v in INTEGRATION_INITIAL.iteritems():
    v.update(COMMON_INITIAL)
예제 #14
0
            reqQueue.put(command)


'''
# Configure logging
logger = logging.getLogger("AWSIoTPythonSDK.core")
logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)
'''

# Init AWSIoTMQTTShadowClient
ShadowClient = None
ShadowClient = AWSIoTMQTTShadowClient("OpenEvseGate_" + utils.randomword(10))
ShadowClient.configureEndpoint(host, 8883)
ShadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)

# AWSIoTMQTTShadowClient configuration
ShadowClient.configureAutoReconnectBackoffTime(1, 32, 20)
ShadowClient.configureConnectDisconnectTimeout(10)  # 10 sec
ShadowClient.configureMQTTOperationTimeout(5)  # 5 sec
lwttopic = 'my/things/' + shadowName + '/shadow/update'
ShadowClient.configureLastWill(lwttopic,
                               '{"state":{"desired":{"iotconnected":false}}}',
                               0)

# Connect to AWS IoT
ShadowClient.connect()
예제 #15
0
from PIL import Image
from PIL import ImageDraw

DIR_NAME = '0001'

img_width = 28
img_height = 28
font_path = "/Library/Fonts/Arial Unicode.ttf"

rgb_bg = (255, 255, 255)
rgb_letter = (0, 0, 0)

for i in range(10000):

    font_size = random.randrange(10, 20)
    font_width = font_size
    font_height = font_size + 1

    img_l_padding = random.randrange(0, int(img_width - font_width) + 1)
    img_t_padding = random.randrange(0, int(img_height - font_height) + 1)

    letter = utils.gen_korean_letter()
    font = ImageFont.truetype(font_path, font_size)
    img = Image.new("RGBA", (img_width, img_height), rgb_bg)
    draw = ImageDraw.Draw(img)
    draw.text((img_l_padding, img_t_padding), letter, rgb_letter, font=font)
    draw = ImageDraw.Draw(img)

    img_filename = str(ord(letter)) + '_' + utils.randomword(16)
    img.save("_data/" + DIR_NAME + '/' + img_filename + ".png")
예제 #16
0
# subprocess.call('./clean.sh')

clean = True
epochs = 140 * 30
# svd

config = Config('train_sub_txt',
                dim=100,
                epochs=epochs,
                layers=0,
                reg=.02,
                keep_prob=.9,
                clean=clean)
test = np.array(config.data.df_test)

svd = SVD(config, 'svd_' + randomword(10))
acc, max_acc = svd.train()
print 'final acc', acc, 'max acc', max_acc
rate = svd.predict(test)
print 'mse', my_rmse(rate,
                     test[:, 2]), 'final test acc', my_acc(rate, test[:, 2])

all_test = config.data.get_all_test()
rate = svd.predict(all_test)
array = config.data.get_origin_array(rate)
# config.data.save_res(array, name='svd' + str(clean))

# daul net

config = Config('train_sub_txt',
                dim=100,
예제 #17
0
def download_files(msg):
    filename, file_extension = os.path.splitext(msg.fileName)
    real_file_name = utils.randomword(32) + file_extension
    msg.download("cache/files/" + real_file_name)
    msg_handler.msg_handle(msg, {'file_name': real_file_name, 'file_ext': file_extension})
예제 #18
0
        'EWAY_CARDMONTH': '01',
        'EWAY_CARDYEAR': '2020',
        'EWAY_CARDCVN': '100',
    },
    "braintree_payments": {
        "transaction": {
            "order_id": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
            "type": "sale",
            "options": {
                "submit_for_settlement": True
            },
        },
        "site": "{HOST}:8000".format(HOST=HOST)
    },
    "ogone_payments": {
        'orderID': randomword(6),
        'currency': u'INR',
        'amount': u'10000',  # Rs. 100.00
        'language': 'en_US',
        'exceptionurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'declineurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'cancelurl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
        'accepturl': "{HOST}:8000/ogone_notify_handler".format(HOST=HOST),
    }
}

for k, v in GATEWAY_INITIAL.iteritems():
    v.update(COMMON_INITIAL)

for k, v in INTEGRATION_INITIAL.iteritems():
    v.update(COMMON_INITIAL)