Esempio n. 1
0
    def __init__(self, startingState='idle', triggerPin=25):
        self.state = startingState

        with open('ports.json', 'r') as f:
            self.ports = json.load(f)
        with open('bins.json', 'r') as f:
            self.bins = json.load(f)

        # set up the magnetic trigger
        self.triggerPin = triggerPin
        gpio_setup(self.triggerPin)

        # set up the cameras
        # self.camera_top = Camera('1.1.3') # when installing make sure the usb port ids match
        self.camera_side = Camera('1.2')

        # connecting to the classifier server
        self.MLServer = WebClient('http://192.168.192.200:5000')

        # initialise the electro magnet locks
        stopMagnet()  # release the locks

        # initialise the i2c lcd screen
        self.ledRed = pinMode(ports['sensors']['digital']['ledRed'], "OUTPUT")
        self.lastText = None
Esempio n. 2
0
    def __init__(self, url, port):
        self.client = WebClient(url)
        self.port = port
        self.app = Flask(__name__)
        self.recycalbe = ['paper', 'plastic', 'glass']

        # when installing make sure the usb port ids match
        self.camera_top = Camera('1.1.3')
        self.camera_side = Camera('1.2')
Esempio n. 3
0
    def login(self, login, password):
        wait = WebDriverWait(self.driver, 10)
        if not self.driver.title == "Odoo" and not self.driver.current_url.endswith(
                "/web/login"):
            self.driver.get(self.instance_url)
        wait.until(
            expected_conditions.presence_of_element_located(
                (By.NAME, "login")))

        self.driver.find_element_by_name("login").send_keys(login)
        self.driver.find_element_by_name("password").send_keys(password)
        self.driver.find_element_by_name("password").submit()

        wait.until(
            expected_conditions.presence_of_element_located(
                (By.CLASS_NAME, "o_web_client")))
        wait.until(
            expected_conditions.invisibility_of_element_located(
                (By.CLASS_NAME, "o_loading")))
        wait.until(
            expected_conditions.visibility_of_element_located(
                (By.CLASS_NAME, "o_main_navbar")))
        wait.until(
            expected_conditions.visibility_of_element_located(
                (By.CLASS_NAME, "o_user_menu")))

        return WebClient(self.driver)
Esempio n. 4
0
class Controller():
    def __init__(self, url, port):
        self.client = WebClient(url)
        self.port = port
        self.app = Flask(__name__)
        self.recycalbe = ['paper', 'plastic', 'glass']

        # when installing make sure the usb port ids match
        self.camera_top = Camera('1.1.3')
        self.camera_side = Camera('1.2')

    @app.route('/', methods=['GET'])
    def run(self):
        template = open('demo1.html').read()
        image_top = camera_top.capture()
        image_side = camera_side.capture()
        plt.imsave('top.png', image_top)
        plt.imsave('side.png', image_side)
        pred_label = self.client.classify(image_top=image_top,
                                          image_side=image_side)
        return template.replace('{pred_label}', pred_label)

    @app.route('/file/<filename>', methods=['GET'])
    def file(self, filename):
        return open(filename, 'rb').read()

    def start(self):
        while (True):
            print("Please select a mode:")
            print("\tInput \"a\" to run")
            print("\tInput else to exit")
            print("> ")
            user_input = str(input()).strip()

            if user_input == 'a':
                result_class = app.run(port=self.port)
                print("The result class is: {}" % (result_class))
                if result_class in self.recycalbe:
                    # move machine to bin 1
                    print("The trash is recycable, dumping to bin 0")
                    cmd = "bin0.py"
                    process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
                    output, error = process.communicate()
                    print("Finished\n\twith output: {} \n\tError{}" %
                          (output, error))
                else:
                    # move machine to bin 2
                    print("The trash is non-recycable, dumping to bin 1")
                    cmd = "bin1.py"
                    process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
                    output, error = process.communicate()
                    print("Finished\n\twith output: {} \n\tError{}" %
                          (output, error))
            else:
                print("Thank you. bye!")
                break
Esempio n. 5
0
    def _process_task(self, client_id, action_id, action, args):
        self.logger.info("start to process task for id:%s" % client_id)

        client = self._web_clients.get(client_id, None)
        if client is None:
            client = WebClient(client_id, "", "clients")
            client.start_client()
            self._web_clients[client_id] = client

        try:
            handler = self.actions.get(action, None)
            self.logger.debug("[%s] %s, args:%s" % (client_id, action, str(args)))
            if handler is not None:
                result = handler(client, self.robot_api, **args)
                self.action_done(action_id, client, result, self.robot_api)
            else:
                self.logger.error("not found sipder action:'%s'", action)

        except Exception, e:
            self.logger.exception(e)
Esempio n. 6
0
    def _process_task(self, client_id, action_id, action, args):
        self.logger.info("start to process task for id:%s" % client_id)        
        
        client = self._web_clients.get(client_id, None) 
        if client is None:
            client = WebClient(client_id, "", "clients")
            client.start_client()
            self._web_clients[client_id] = client

        try:
            handler = self.actions.get(action, None)
            self.logger.debug("[%s] %s, args:%s" % (client_id, action, str(args)))
            if handler is not None:
                result = handler(client, self.robot_api, **args)
                self.action_done(action_id, client, result, self.robot_api)
            else:
                self.logger.error("not found sipder action:'%s'", action)
                                    
        except Exception, e:
            self.logger.exception(e)
 def get_items(self):
     web_client = WebClient(WANIKANI_PROFILE_URL + self.username)
     wanikani_soup = BeautifulSoup(web_client.html, features='html.parser')
     apprentice_element = wanikani_soup.find('li', {'id': 'apprentice'})
     apprentice_count = apprentice_element.find('span').text if apprentice_element else None
     guru_element = wanikani_soup.find('li', {'id': 'guru'})
     guru_count = guru_element.find('span').text if apprentice_element else None
     master_element = wanikani_soup.find('li', {'id': 'master'})
     master_count = master_element.find('span').text if apprentice_element else None
     enlightened_element = wanikani_soup.find('li', {'id': 'enlightened'})
     enlightened_count = enlightened_element.find('span').text if apprentice_element else None
     burned_element = wanikani_soup.find('li', {'id': 'burned'})
     burned_count = burned_element.find('span').text if apprentice_element else None
     level_element = wanikani_soup.find('span', {'class': 'level'})
     level = level_element.text if level_element else None
     return {'apprentice': apprentice_count, 'guru': guru_count, 'master': master_count,
             'enlightened': enlightened_count, 'burned': burned_count, 'level': level}
Esempio n. 8
0
def loop(scheme, host, port, path):

    try:
        server = WebClient(scheme, host, port, path)
        network = GetSpeed()
        int_addr = InterAddr()

        d1 = threads.deferToThread(network.get_speed)
        d2 = threads.deferToThread(int_addr.get_addr)
        d1.addCallback(server.post_data)
        d2.addCallback(server.post_data)
        d1.addErrback(server.failure)
        d2.addErrback(server.failure)
    except Exception:
        log.critical('Uncaught exception: ', exc_info=sys.exc_info())

    reactor.callLater(1200, loop, scheme, host, port, path)
Esempio n. 9
0
from web_client import WebClient
from camera import Camera
import time

client = WebClient('http://localhost:5000')
camera_top = Camera(
    '1.1.3')  # when installing make sure the usb port ids match
camera_side = Camera('1.2')

print('entering main loop')
while True:
    print('input signal?')
    input()
    time1 = time.time()
    image_top = camera_top.capture()
    image_side = camera_side.capture()
    time2 = time.time()
    pred_label = client.classify(image_top=image_top, image_side=image_side)
    time3 = time.time()
    print('capture time, prediction time', time2 - time1, time3 - time2)
    print('prediction label:', pred_label)
    if pred_label == 'unknown':
        print('need manual label for unknown item:')
        mann_label = input()
        print(client.update(mann_label))
Esempio n. 10
0
from flask import Flask, request
import redis

from jnt_client import JnTClient
from web_client import WebClient

app = Flask(__name__)

r = redis.Redis(host="localhost", port=6379, db=0)
web_client = WebClient()
jnt_client = JnTClient()


def check_stock(user_id, name, msg):
    product_name = " ".join(msg.split()[:-2])
    sku, stock = web_client.get_detail(product_name)
    if stock:
        r.set(user_id, f"order|{sku}|{product_name}")
        return f"Ready gan, sisa {stock} nih"
    else:
        r.set(user_id, "default")
        return f"Wah sori gan, kosong..."


def accept_order(user_id, name, msg):
    state, sku, product_name = str(r.get(user_id))[2:-1].split("|")
    r.set(user_id, f"address|{sku}|{product_name}")
    return f"{product_name} kan? Bisa gan, mau dikirim ke mana?"


def send_bill(user_id, name, msg):
Esempio n. 11
0
from threading import Thread
import move
from matplotlib import pyplot as plt
from web_client import WebClient
from camera import Camera
from flask import Flask

client = WebClient('http://*****:*****@app.route('/', methods=['GET'])
def run():
    template = open('demo1.html').read()
    image_top = camera_top.capture()
    image_side = camera_side.capture()
    plt.imsave('top.png', image_top)
    plt.imsave('side.png', image_side)
    pred_label = client.classify(image_top=image_top, image_side=image_side)
    if pred_label == 'recyclable':
        move_thread = Thread(target=move.bin0)
    else:
        move_thread = Thread(target=move.bin1)
    # start moving in a separate thread so the webpage is returned immediately
    move_thread.start()
    return template.replace('{pred_label}', pred_label)
Esempio n. 12
0
def part_1():
    print("Downloading {}".format(TEST_FILE))
    client = WebClient()
    client.download(TEST_URL, TEST_FILE)
Esempio n. 13
0
import ConfigParser
import auth
from web_client import WebClient

configParser = ConfigParser.ConfigParser()
configParser.read('booli.config')

host = configParser.get('auth', 'host')
caller_id = configParser.get('auth', 'caller_id')
api_key = configParser.get('auth', 'api_key')

print 'Collecting data from {} with caller id {}'.format(host, caller_id)

client = WebClient(host, caller_id, api_key)
print client.get('/listings?q=nacka')

Esempio n. 14
0
class Recycltron:
    States = {
        'idle': "idle",
        'lidUp': "lidUp",
        'lidDown': "lidDown",
        'processing': "processing",
        # 'moving': "moving",
        # 'returning': "returning",
        # 'shutDown': "shutDown"
    }

    def __init__(self, startingState='idle', triggerPin=25):
        self.state = startingState

        with open('ports.json', 'r') as f:
            self.ports = json.load(f)
        with open('bins.json', 'r') as f:
            self.bins = json.load(f)

        # set up the magnetic trigger
        self.triggerPin = triggerPin
        gpio_setup(self.triggerPin)

        # set up the cameras
        # self.camera_top = Camera('1.1.3') # when installing make sure the usb port ids match
        self.camera_side = Camera('1.2')

        # connecting to the classifier server
        self.MLServer = WebClient('http://192.168.192.200:5000')

        # initialise the electro magnet locks
        stopMagnet()  # release the locks

        # initialise the i2c lcd screen
        self.ledRed = pinMode(ports['sensors']['digital']['ledRed'], "OUTPUT")
        self.lastText = None

    def isLidOpen(self, N=100):
        # drift towards -inf if open else towards +inf
        counter = 0
        while abs(counter) < N:
            res = gpio_read(self.triggerPin)
            if res == 1:
                counter += 1
            else:
                counter -= 1
        #print('islidopen', counter, res)
        if counter < 0: return True
        else: return False

    def output_screen(self,
                      text,
                      color="green"):  ###########didnt mention port number
        pallete = {
            "white": (255, 255, 255),
            "red": (255, 0, 0),
            "green": (0, 255, 0),
            "blue": (0, 0, 255),
            "black": (0, 0, 0)
        }
        # port = ports["sensors"]["I2C"]["lcd"]
        if text != self.lastText:
            # lcd.setRGB(pallete[color][0], pallete[color][1], pallete[color][2])
            lcd.setText_norefresh(text)
            self.lastText = text

    def input_with_timeout(self, timeout):
        ready, _, _ = select.select([sys.stdin], [], [], timeout)
        if ready:
            return sys.stdin.readline().rstrip(
                '\n')  # expect stdin to be line-buffered
        return False

    def move_to_bin(self, category):
        port = ports["sensors"]["digital"]["ultrasonic_horizontal"]
        dist = usread()  #grovepi.ultrasonicRead(port)
        bin = bins[category]
        print("dist", dist, bin)
        if (dist < bin["start_pos"]):
            move.move_front()
        if (dist > bin["end_pos"]):
            move.move_back()
        while (dist > bin["end_pos"] or dist < bin["start_pos"]):
            sleep(0.1)
            dist = usread()  #grovepi.ultrasonicRead(port)
            print("dist", dist)
        move.stop_motors()

        if self.is_bin_full():
            if category == 'non-recyclable':
                # ask user to clear up the bin, stop here
                self.output_screen('The bins are full!!!')
                digitalWrite(self.ledRed, 1)
            else:
                self.move_to_bin('non-recyclable')
        else:
            self.operate_hatch()
            digitalWrite(self.ledRed, 1)

    def is_bin_full(self):
        return False
        port = ports["sensors"]["digital"]["ultrasonic_vertical"]
        dist = grovepi.ultrasonicRead(port)
        print(dist)
        if (dist > 50):  #bin is empty
            print('bin empty')
            return 0
        elif (dist > 25):
            print('bin half')
            return 0.5
        else:
            print('bin full')
            return 1

    def operate_hatch(self):
        move.hatch()

    def ring_buzzer(self):
        port = ports["sensors"]["digital"]["buzzer"]
        grovepi.pinMode(port, "OUTPUT")
        grovepi.digitalWrite(port, 1)
        sleep(0.5)
        grovepi.digitalWrite(port, 0)

    def run(self):
        global n_collects
        global collect_mode

        # the main loop:
        while True:
            print(f'State update: {self.state}')
            if self.state == 'idle':
                self.output_screen('Machine: idle.')
                WebInterface.get('http://localhost:5000/idle')
                stopMagnet()
                # turn off the lights
                while not self.isLidOpen():
                    pass
                # if self.isLidOpen():
                self.state = 'lidUp'

            elif self.state == 'lidUp':
                self.output_screen('Lid is open')
                while self.isLidOpen():
                    pass
                self.state = 'lidDown'

            elif self.state == 'lidDown':
                self.output_screen('Lid closed      and locked')
                # lit up the lights

                # lock the lid
                runMagnet()
                time.sleep(3)
                self.state = 'processing'

            elif self.state == 'processing':
                WebInterface.get('http://localhost:5000/idle')

                userLabel = getUserInput()
                if userLabel != 'No label':
                    pred_label = userLabel
                else:
                    self.output_screen('Processing      item')
                    # image_top = camera_top.capture()
                    image_top = image_side = self.camera_side.capture()
                    sound_clip = self.camera_side.record_binary()

                    if collect_mode:
                        n_collects += 1
                        with wave.open(f'collects/{n_collects}.wav',
                                       'wb') as wavefile:
                            wavefile.setnchannels(1)
                            wavefile.setsampwidth(2)  # s16_le
                            wavefile.setframerate(48000)
                            wavefile.writeframes(sound_clip)
                        plt.imsave(f'collects/{n_collects}.png', image_top)
                        print('collected sample', n_collects)
                    #plt.imsave('top.png', image_top)
                    #plt.imsave('side.png', image_side)

                    # TODO: fix here
                    if collect_mode:
                        pred_label = 'trash'
                    else:
                        pred_label = self.MLServer.classify(
                            image_top=image_top, image_side=image_side)

                print(f'the predicted label is {pred_label}')
                if pred_label == 'metal':
                    pred_label = 'metal'
                elif pred_label != 'trash':
                    pred_label = 'recyclable'
                else:
                    pred_label = 'non-recyclable'

                if pred_label == 'metal':
                    lcd_content = 'Metal recyclable'
                elif pred_label == 'cardboard':
                    lcd_content = 'Cardboard recyclable'
                elif pred_label == 'recyclable':
                    lcd_content = 'Other recyclable'
                elif pred_label == 'non-recyclable':
                    lcd_content = 'Non-recyclable'
                else:
                    lcd_content = 'Error, dump into trash'
                    pred_label = 'non-recyclable'

                self.output_screen(lcd_content)
                if not collect_mode:
                    self.move_to_bin(pred_label)

                # finished trash sorting
                self.state = 'idle'

            # elif self.state == 'moving':
            #     pass
            # elif self.state == 'returning':
            #     pass
            elif self.state == 'shutDown':
                self.output_screen('Error, dump into trash')
                break