Exemplo n.º 1
0
def to_ascii_from_image(image,
                        name='image',
                        invert=True,
                        char_type=CharType.BRAILLE,
                        image_type=ImageType.DITHER):
    """
    convert to text via the following steps:
    1. fit image to terminal screen size
    2. invert image if needed
    3. convert image based on given ImageType
    4. convert pixels in image to their given CharType equivalent
    5. join the 2d image array into a single string
    """
    image = Helper.fit_image_to_terminal(image, char_type == CharType.BRAILLE)
    if invert:
        image = ImageHelper.invert(image)

    image = ImageHelper.convert_image(image, image_type)

    text_array = convert_to_text(image, char_type)

    ascii_text = setup_text_image(text_array)
    if ImageHelper.DEBUG:
        store_text(ascii_text, name)

    return ascii_text
Exemplo n.º 2
0
import pycurl
from io import BytesIO
from pprint import pprint

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

AppId = 'wxb9db0419592dbe7f'
AppSecret = '3a54d5663c95800880c927b124a31ead'
from util import Helper
helper = Helper(AppId, AppSecret)

#存放自定义回复规则
rules = []

#自定义菜单
menuData = """
{
    "button":[
        {
            "name":"i学习",
            "sub_button":[
                {
                    "name":"校内常用网站",
                    "type":"view",
                    "url":"http://mp.weixin.qq.com/s?__biz=MzA3MDc5NjAyOA==&mid=205420177&idx=1&sn=127a582cd5adef81f22fdb3560e61672&scene=18#wechat_redirect"
Exemplo n.º 3
0
import pycurl
from io import BytesIO
from pprint import pprint

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

AppId = 'wxb9db0419592dbe7f'
AppSecret = '3a54d5663c95800880c927b124a31ead'
from util import Helper
helper = Helper(AppId, AppSecret)

Debug = True


def getKeyValueByURL(url, key):
    buffers = BytesIO()
    request_page = pycurl.Curl()
    request_page.setopt(request_page.URL, url)
    request_page.setopt(request_page.WRITEDATA, buffers)
    try:
        request_page.perform()
        request_page.close()
        jsonData = buffers.getvalue().decode()
        return json.loads(jsonData)[key]
    except pycurl.error, error:
#Euler's Totient function, tot(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, tot(9)=6.
#The number 1 is considered to be relatively prime to every positive number, so tot(1)=1.
#
#Interestingly, tot(87109)=79180, and it can be seen that 87109 is a permutation of 79180.
#
#Find the value of n, 1  n  107, for which tot(n) is a permutation of n and the ratio n/tot(n) produces a minimum.
from util import Helper
from datetime import datetime
import math
helper = Helper()
MAX = 10000000
helper.build_primes(int(math.sqrt(MAX)))
def totient(n):
    primes = helper.prime_divisors(n)
    del primes[1]
    total = n-1
    for prime in primes.keys():
        count = n/prime-1
        total -= count 
    return total

def is_permutation(a,b):
    return sorted(list(str(a))) == sorted(list(str(b)))

best = 1000
now = datetime.now()
for i in range(MAX*831/1000,MAX*832/1000):
    tot = totient(i)
    if is_permutation(i, tot):
        ratio = float(i)/tot
#        print i
        mean_ndcgs.append(ndcg)
    return mean_hrs, mean_ndcgs


if __name__ == '__main__':
    args = parse_args()
    args.lr = eval(args.lr)

    args.path = './data/' + args.dataset + '/'
    args.user_dataset = args.path + 'userRating'
    args.group_dataset = args.path + 'groupRating'
    args.user_in_group_path = "./data/" + args.dataset + "/groupMember.txt"

    print('args', args)
    # initial helper
    helper = Helper()

    # get the dict of users in group
    g_m_d = helper.gen_group_member_dict(args.user_in_group_path)

    # initial dataSet class
    dataset = GDataset(args.user_dataset, args.group_dataset,
                       args.num_negatives, g_m_d)

    # get group number
    num_group = max(g_m_d.keys()) + 1
    num_users, num_items = dataset.num_users, dataset.num_items
    # print('num_users',num_users)
    # build AGREE model
    agree = AGREE(num_users, num_items, num_group, args.embedding_size, g_m_d,
                  args.drop_ratio).to(device)
#Euler's Totient function, tot(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, tot(9)=6.
#The number 1 is considered to be relatively prime to every positive number, so tot(1)=1.
#
#Interestingly, tot(87109)=79180, and it can be seen that 87109 is a permutation of 79180.
#
#Find the value of n, 1  n  107, for which tot(n) is a permutation of n and the ratio n/tot(n) produces a minimum.
from util import Helper
from datetime import datetime
import math
helper = Helper()
MAX = 10000000
helper.build_primes(int(math.sqrt(MAX)))


def totient(n):
    primes = helper.prime_divisors(n)
    del primes[1]
    total = n - 1
    for prime in primes.keys():
        count = n / prime - 1
        total -= count
    return total


def is_permutation(a, b):
    return sorted(list(str(a))) == sorted(list(str(b)))


best = 1000
now = datetime.now()
for i in range(MAX * 831 / 1000, MAX * 832 / 1000):
Exemplo n.º 7
0
import tornado.web
import tornado.wsgi
import xml.etree.ElementTree as ET

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

import time
import random
import string
import hashlib

AppId = 'wxb9db0419592dbe7f'
AppSecret = '3a54d5663c95800880c927b124a31ead'
from util import Helper
helper = Helper(AppId, AppSecret)
import replyer

Debug = False

#存放自定义回复规则
rules = []

#Event回复模板
eventReply = """
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%d</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
Exemplo n.º 8
0
}
RABBIT_INFO = {
    "host":
    "nugura.research.nicta.com.au",
    "port":
    5672,
    "credentials":
    pika.credentials.PlainCredentials(username="******",
                                      password="")
}
BLOCK_LOAD_REPORT_FREQUENCY = 500
HIGHEST_BLOCK = 1358548

LAST_TIME = time.time()

helper = Helper()


class Block(object):

    pending_addresses = []

    def __init__(self, block_data=None, db=None):
        self.db = db
        self.cursor = db.cursor()
        if int(block_data["number"]) % BLOCK_LOAD_REPORT_FREQUENCY == 0:
            print("Loading %d blocks to DB from #%s (at % 11.2f )" %
                  (BLOCK_LOAD_REPORT_FREQUENCY, block_data["number"],
                   time.time()))
        try:
            self.block_number = block_data["number"]
Exemplo n.º 9
0
from pprint import pprint

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options

define("port", default=8000, help="run on the given port", type=int)

AppId = 'wxb9db0419592dbe7f'
AppSecret = '3a54d5663c95800880c927b124a31ead'
from util import Helper

helper = Helper(AppId, AppSecret)

#存放自定义回复规则
rules = []

#自定义菜单
menuData = """
{
    "button":[
        {
            "name":"i学习",
            "sub_button":[
                {
                    "name":"校内常用网站",
                    "type":"view",
                    "url":"http://mp.weixin.qq.com/s?__biz=MzA3MDc5NjAyOA==&mid=205420177&idx=1&sn=127a582cd5adef81f22fdb3560e61672&scene=18#wechat_redirect"