Esempio n. 1
0
class Server():
    def __init__(self):
        self.config = Configure()
        self.start_server, self.client_ip, self.server_name, self.server_pass = self.config.read_server()
        if self.start_server == False:
            sys.exit()
        say('Starting Server')
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = ''
        self.port = 5150
        self.server.bind((self.host, self.port))
        self.server.listen(5)
        print 'Listing for a client...'
        self.client, self.addr = self.server.accept()
        print 'Accepted connection from ', self.addr
        self.client.send(str.encode('Connection made with Andy'))

    def get_cmd(self):
        try:
            self.data = self.client.recv(1024)
        except:
            print 'Lost Connection with ', self.addr
            return None
        print 'Recieved data from client: ', bytes.decode(self.data)

        return bytes.decode(self.data)

    def end(self):
        print 'Closing connection...'
        self.client.close()
Esempio n. 2
0
class Server():
    def __init__(self):
        self.config = Configure()
        self.start_server, self.client_ip, self.server_name, self.server_pass = self.config.read_server(
        )
        if self.start_server == False:
            sys.exit()
        say('Starting Server')
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = ''
        self.port = 5150
        self.server.bind((self.host, self.port))
        self.server.listen(5)
        print('Listing for a client...')
        self.client, self.addr = self.server.accept()
        print('Accepted connection from ', self.addr)
        self.client.send(str.encode('Connection made with Andy'))

    def get_cmd(self):
        try:
            self.data = self.client.recv(1024)
        except:
            print('Lost Connection with ', self.addr)
            return None
        print('Recieved data from client: ', bytes.decode(self.data))

        return bytes.decode(self.data)

    def end(self):
        print('Closing connection...')
        self.client.close()
Esempio n. 3
0
 def __init__(self):
     self.config = Configure()
     self.start_server, self.client_ip, self.server_name, self.server_pass = self.config.read_server(
     )
     if self.start_server == False:
         sys.exit()
     say('Starting Server')
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.host = ''
     self.port = 5150
     self.server.bind((self.host, self.port))
     self.server.listen(5)
     print('Listing for a client...')
     self.client, self.addr = self.server.accept()
     print('Accepted connection from ', self.addr)
     self.client.send(str.encode('Connection made with Andy'))
Esempio n. 4
0
class Util(object):
    '''
    工具类,这么个破东西,整个还像个样子,doubi
    '''
    config = Configure()
    _m_days_o = [31, 28, 31, 30, 31, 30 ,31, 31, 30, 31, 30, 31]
    _m_days_n = [31, 29, 31, 30, 31, 30 ,31, 31, 30, 31, 30, 31]
    @staticmethod  
    def get_time():
        if Util.config.get_time_type() == 0:
            return Util._get_system_time()
        else:
            return Util._get_network_time()
        
    @staticmethod
    def get_day_before(cur_day):
        if len(cur_day) != 3:
            return cur_day
        day = int(cur_day[2])
        mon = int(cur_day[1])
        year = int(cur_day[0])
        new_day = cur_day[:]
        if day != 1:
            new_day[2] = str(day - 1)
            return new_day
        days = Util._get_days(cur_day)
        new_day = cur_day[:]
        if mon-1 != 0:
            new_day[1] = str(mon-1)
            new_day[2] = str(days[mon-1])
        else:
            new_day[0] = str(year-1)
            new_day[1] = '12'
            new_day[2] = '31'
        return new_day
        
    @staticmethod
    def _get_days(cur_day):
        if len(cur_day) != 3:
            return Util._m_days_o
        year = int(cur_day[0])
        if (year%4 == 0 and year%100 != 0 ) or year%400 == 0:
            return Util._m_days_n
        return Util._m_days_o
    @staticmethod  
    def _get_system_time():
        ltime = time.localtime()
        if ltime != None:
            return [str(ltime.tm_year),"%02d" % ltime.tm_mon, "%02d" % ltime.tm_mday]
        else:
            return None
    
    @staticmethod
    def _get_network_time():
        '''
        Currently we just use local time
        Otherwise we should specify an timezone
        '''
        return Util._get_system_time()
        
Esempio n. 5
0
    def __init__(self, group=None, target=None, name=None,  *args, **kwargs):
        super(BaseService, self).__init__(group=group, target=target, name=name, args = args, kwargs = kwargs)  
        self.exit = mp.Event()

        self.dbsession = None
        self.pname = name
        self.conf = Configure()
        self.url_pfx = self.conf.get_default('Service', 'UploadURL', 'http://pacs.winning.com.cn/platform')
        self.url_path = ''
Esempio n. 6
0
    def __init__(self, path, default, quiet):
        '''Constructs the bot object. Takes path, default, and quiet arguments from the command
        line input and sets the bot accordingly. Initializes logging, creates instances of
        necessary classes. Loads plugins, begins the connection.'''
        self._config_path = path
        self._default = default
        self._quiet = quiet
        self.logger = logging.getLogger("GorillaBot")
        self._configuration = Configure(self._config_path, self._default,
                                        self._quiet)
        settings = self._configuration.get_configuration()

        self.GorillaConnection = Connection(
            self, settings["host"], settings["port"], settings["nick"],
            settings["ident"], settings["realname"], settings["chans"],
            settings["botop"], settings["fullop"])
        self.GorillaCommander = CommandManager(self, self.GorillaConnection)
        self.GorillaConnection._connect()
Esempio n. 7
0
def calculate_index():
    print '%s\tstart update index' % str(datetime.now())
    cfg = Configure('./config/config.cfg')
    article_repo = cfg.get_config('running', 'article_repo')
    file_names = os.listdir(
        os.path.join(article_repo,
                     datetime.today().strftime('%m%d%Y')))
    doc_count = 0
    for filename in file_names:
        if not filename.endswith('_DONE'):
            process(os.path.join(article_repo, filename), filename)
            os.rename(os.path.join(article_repo, filename),
                      os.path.join(article_repo, filename + '_DONE'))
            doc_count += 1

    if doc_count:
        update_tfidf(doc_count)
    print '%s\tend update index' % str(datetime.now())
Esempio n. 8
0
class Bot(object):
    '''The Bot class is the core of the bot. It creates the connection and the responder. All messages
    that are received come through here, and are dispatched accordingly.'''
    def __init__(self, path, default, quiet):
        '''Constructs the bot object. Takes path, default, and quiet arguments from the command
        line input and sets the bot accordingly. Initializes logging, creates instances of
        necessary classes. Loads plugins, begins the connection.'''
        self._config_path = path
        self._default = default
        self._quiet = quiet
        self.logger = logging.getLogger("GorillaBot")
        self._configuration = Configure(self._config_path, self._default,
                                        self._quiet)
        settings = self._configuration.get_configuration()

        self.GorillaConnection = Connection(
            self, settings["host"], settings["port"], settings["nick"],
            settings["ident"], settings["realname"], settings["chans"],
            settings["botop"], settings["fullop"])
        self.GorillaCommander = CommandManager(self, self.GorillaConnection)
        self.GorillaConnection._connect()

    def dispatch(self, line):
        '''Determines the type of message received:
                If the message is a ping, it pongs back.
                If the message is from NickServ, it determines identification status.
                If the message contains a reply code, it forwards it to parse_number.
                If the message is a PRIVMSG, it forwards it to parse_message.'''

        # Probably will want to remove this at some point in the future, but for now I'm going
        # to hold on to it for debugging.
        self.logger.debug(line)

        # Responds to ping messages. Doesn't bother to send it to the CommandManager.
        if "PING" in line[0]:
            self.logger.debug("Ping received.")
            self.GorillaConnection.pong(line[1][1:])

        # Identifies messages from NickServ, sends to CommandManager
        elif "NickServ" in line[0]:
            self.GorillaCommander.nickserv_parse(line)

        # Identifies server message codes, sends to CommandManager
        elif len(line[1]) == 3:
            self.GorillaCommander.process_numcode(line[1], line)

        # Identifies PRIVMSGs, sends to CommandManager
        elif line[1] == "PRIVMSG":
            self.GorillaCommander.check_command(line)

        # Nick changes
        elif line[1] == "NICK":
            self.GorillaCommander.nick_change(line)
Esempio n. 9
0
class Bot(object):
    '''The Bot class is the core of the bot. It creates the connection and the responder. All messages
    that are received come through here, and are dispatched accordingly.'''
    
    def __init__(self, path, default, quiet):
        '''Constructs the bot object. Takes path, default, and quiet arguments from the command
        line input and sets the bot accordingly. Initializes logging, creates instances of
        necessary classes. Loads plugins, begins the connection.'''
        self._config_path = path
        self._default = default
        self._quiet = quiet
        self.logger = logging.getLogger("GorillaBot")
        self._configuration = Configure(self._config_path, self._default, self._quiet)
        settings = self._configuration.get_configuration()
        
        self.GorillaConnection = Connection(self, settings["host"], settings["port"],
                                            settings["nick"], settings["ident"],
                                            settings["realname"], settings["chans"],
                                            settings["botop"], settings["fullop"])
        self.GorillaCommander = CommandManager(self, self.GorillaConnection)
        self.GorillaConnection._connect()
        
    def dispatch(self, line):
        '''Determines the type of message received:
                If the message is a ping, it pongs back.
                If the message is from NickServ, it determines identification status.
                If the message contains a reply code, it forwards it to parse_number.
                If the message is a PRIVMSG, it forwards it to parse_message.'''
        
        # Probably will want to remove this at some point in the future, but for now I'm going
        # to hold on to it for debugging.
        self.logger.debug(line)
        
        # Responds to ping messages. Doesn't bother to send it to the CommandManager.
        if "PING" in line[0]:
            self.logger.debug("Ping received.")
            self.GorillaConnection.pong(line[1][1:])
            
        # Identifies messages from NickServ, sends to CommandManager
        elif "NickServ" in line[0]:
            self.GorillaCommander.nickserv_parse(line)
            
        # Identifies server message codes, sends to CommandManager
        elif len(line[1])==3:
            self.GorillaCommander.process_numcode(line[1], line)
            
        # Identifies PRIVMSGs, sends to CommandManager
        elif line[1]=="PRIVMSG":
            self.GorillaCommander.check_command(line)
           
        # Nick changes 
        elif line[1] == "NICK":
            self.GorillaCommander.nick_change(line)
Esempio n. 10
0
 def __init__(self):
     self.config = Configure()
     self.start_server, self.client_ip, self.server_name, self.server_pass = self.config.read_server()
     if self.start_server == False:
         sys.exit()
     say('Starting Server')
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.host = ''
     self.port = 5150
     self.server.bind((self.host, self.port))
     self.server.listen(5)
     print 'Listing for a client...'
     self.client, self.addr = self.server.accept()
     print 'Accepted connection from ', self.addr
     self.client.send(str.encode('Connection made with Andy'))
Esempio n. 11
0
def freezeService(code):
    c = Configure()
    c.setStatus({
        'message': '发生异常,系统自动冻结服务。',
        'title': '服务已冻结',
        'me': False,
        'tomorrow': True,
        'today': True,
        'mon': False,
        'detect': False,
        'isRed': True
    })
    data = {
        'service_name': {
            'value': '全服务'
        },
        'reason': {
            'value': '网络异常:code:' + code
        },
        'mess': {
            'value': '服务已自动冻结'
        }
    }
    pushRunningMessage('warn',data)
Esempio n. 12
0
 def __init__(self, path, default, quiet):
     '''Constructs the bot object. Takes path, default, and quiet arguments from the command
     line input and sets the bot accordingly. Initializes logging, creates instances of
     necessary classes. Loads plugins, begins the connection.'''
     self._config_path = path
     self._default = default
     self._quiet = quiet
     self.logger = logging.getLogger("GorillaBot")
     self._configuration = Configure(self._config_path, self._default, self._quiet)
     settings = self._configuration.get_configuration()
     
     self.GorillaConnection = Connection(self, settings["host"], settings["port"],
                                         settings["nick"], settings["ident"],
                                         settings["realname"], settings["chans"],
                                         settings["botop"], settings["fullop"])
     self.GorillaCommander = CommandManager(self, self.GorillaConnection)
     self.GorillaConnection._connect()
Esempio n. 13
0
            def wrapper(*args, **kwargs):
                cfg = Configure('./config/config.cfg')
                mongo_url = cfg.get_config('mongodb', 'url')
                mongo_port = int(cfg.get_config('mongodb', 'port'))
                dbname = cfg.get_config('mongodb', 'dbname')
                collection_name = cfg.get_config('mongodb', tablename)

                client = MongoClient(mongo_url, mongo_port)
                db=client[dbname]
                collection = db[collection_name]

                res = func(*args, c = collection, **kwargs)

                return res
Esempio n. 14
0
class BaseService(mp.Process):
    """
    需要实现do_work内容,完成具体的业务流程,
    需要实例赋值upload_url
    调用endloop停止work
    """

    def __init__(self, group=None, target=None, name=None,  *args, **kwargs):
        super(BaseService, self).__init__(group=group, target=target, name=name, args = args, kwargs = kwargs)  
        self.exit = mp.Event()

        self.dbsession = None
        self.pname = name
        self.conf = Configure()
        self.url_pfx = self.conf.get_default('Service', 'UploadURL', 'http://pacs.winning.com.cn/platform')
        self.url_path = ''
        
    def run(self):
        if not self.pname:
            self.pname = mp.current_process().name

        self.init_logger()
        self.dbsession =  DBSession().get_session()

        logging.info(self.pname + ' Starting')

        self.do_work()

        logging.info(self.pname + ' Exit')

    def endloop(self):
        logging.info(self.pname + ' Exiting')
        self.exit.set()

    def init_logger(self):
        if not os.path.exists('./log'):
            os.mkdir('./log')

        logfile = TimedRotatingFileHandler('./log/'+'t_'+self.pname+'.log', when='D', backupCount=5)
        formatter = logging.Formatter('[%(asctime)s P:%(process)-5d %(funcName)s:%(lineno)d %(levelname)5s] %(message)s', '%Y-%m-%d %H:%M:%S')
        logfile.setFormatter(formatter)
        logging.getLogger('').setLevel(logging.INFO)
        logging.getLogger('').addHandler(logfile) 

        console = logging.StreamHandler()
        console.setLevel(logging.INFO)
        formatter = logging.Formatter('[' + self.pname + '-%(levelname)5s] %(message)s')
        console.setFormatter(formatter)
        logging.getLogger('').addHandler(console)

    def upload(self, data):
        try:
            logging.info('%s:%s',self.pname,json.dumps(data, ensure_ascii=False) if data else None)

            success = False
            errdesc = ''
            ret = requests.post(self.url_pfx+self.url_path, json=data, timeout=2)
            ret.raise_for_status()
            
            if ret.json() and ret.json().get('msg','') == 'OK':   # if ret.text and json.loads(ret.text).get('msg','') == 'OK':
                success = True
            else:
                logging.error(ret.text)
                # errdesc = 'upload failed'
            
        except Exception as e:
            logging.exception(e)
            # errdesc += e.message
        finally:
            # logging.error(errdesc) if errdesc else None
            return success    

    def do_work(self):
        raise NotImplementedError()       
Esempio n. 15
0
sys.setdefaultencoding('utf-8')

import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))

import hashlib
import time
import newspaper
import feedparser
from datetime import datetime
from random import shuffle
from config import Configure

from util import Util

CFG = Configure('./config/config.cfg')
ARTICLEREPO = os.path.join(CFG.get_config('running', 'article_repo'),
                           datetime.today().strftime('%m%d%Y'))
if not os.path.isdir(ARTICLEREPO):
    os.makedirs(ARTICLEREPO)


def crawl_web_categorypage(url):
    paper = newspaper.build(url, memoize_articles=False, language='en')

    for category in paper.category_urls():
        crawl_web(category)


def crawl_web(url):
    paper = newspaper.build(url, memoize_articles=False, language='en')
 def set_manual_transformation(self):
     settings = Configure()
     settings.set_pre_processing_params()
     rules = settings.pre_processing_params['manual_encoding']
     return rules
Esempio n. 17
0
          backup = int(not working)

          if adhoc_interface == "ath0" and monitor_interface == "ath1":
             working_iface_monitor = re.compile('[0]').sub('2', adhoc_interface)
             backup_iface_monitor = re.compile('[1]').sub('3', monitor_interface)
          elif adhoc_interface == "ath1" and monitor_interface == "ath0":
             working_iface_monitor = re.compile('[1]').sub('3', adhoc_interface)
             backup_iface_monitor = re.compile('[0]').sub('2', monitor_interface)
          else:
             print "Please specify [ath0, ath1] for each interface. "
             sys.exit(0)
       
          print "Current Interfaces: [wa: %s] [wm: %s] [ba: %s] [bm: %s]" % (working_iface_adhoc, working_iface_monitor, backup_iface_adhoc, backup_iface_monitor)
          print "Current Interface: [wa: ath%s] [ba: ath%s]" % (working, backup)
          
          cf = Configure(working_iface_adhoc, backup_iface_adhoc)
          ff = FrameFilter(cf, snr_threshold, FILTER)
          p = pcap.pcapObject()
          p.open_live(backup_iface_monitor, 96, 0, 100)

          while 1:
             while ff.rx_frame < 101: # Approx. 100ms * 100 = 10s ; Only beacon frames counted
                apply(ff.filter, p.next())
                #ff.print_tx_filter(working_iface_adhoc) # maybe 1s

             stime = time.time()
             #print "loop starts %f" % stime

             try:
                for daddr in ['00:80:92:3e:18:11', '00:80:92:3e:18:18']:
                   print "XXXXXXXXXXXXXXXX"
Esempio n. 18
0
 def __init__(self):
     self.config = Configure()
     self.errors = []
     self.meta = {'info':'', 'real_url':'', 'code':0}
Esempio n. 19
0
def main(DEBUG=False):
    #Start LEDs
    write('load')
    subprocess.Popen(['python', 'LED.py'])
    #Read from configuration files and apply settings.
    config = Configure()
    start_andy_on_boot, social_mode, rebel_mode, wander_mode = config.read()
    if start_andy_on_boot == False:
        sys.exit()

    #Say start up slogan and check for command.
    say('Hello. My name is Andy. Please wait while my system starts up.')
    getit = Get_cmd()
    #Start server process
    subprocess.Popen(['python', 'server.py'])
    write(None)
    #Enter main loop
    while True:
        print()
        #Get the command and convert it to a list
        cmd = getit.get().split()
        write('load')
        if DEBUG: print('COMMAND:', cmd)

        #Remove unused words from command
        num = 0
        for word in cmd:
            cmd[num] = word.lower()
            num += 1
        if len(cmd) == 0:
            cmd.append('')
        #Determin master command
        if cmd[0] == 'what':
            cmds.What(cmd, DEBUG)
        elif cmd[0] == 'walk' or cmd[0] == 'turn':
            cmds.Walk(cmd, DEBUG)
        elif cmd[0] == 'stop':
            cmds.Walk(cmd, DEBUG).stop()
        elif cmd[0] == 'pickup' or cmd[0] == 'pick' and cmd[1] == 'up':
            cmds.Arm(cmd, DEBUG).pickup()
        elif cmd[0] == 'set' and cmd[1] == 'down':
            cmds.Arm(cmd, DEBUG).setdown()
        elif cmd[0] == 'where':
            cmds.Where(cmd, DEBUG)
        elif cmd[0] == 'take':
            cmds.Take(cmd, DEBUG)
        elif cmd[0] == 'set':
            pass  #TODO
        elif cmd[0] == 'tell':
            cmds.Tell(cmd, DEBUG)
        elif cmd[0] == 'who':
            cmds.Who(cmd, DEBUG)
        elif cmd[0] == 'shutdown':
            cmds.shutdown()
        elif cmd[0] == 'sleep':
            cmds.sleep()
        elif cmd[0] == 'meet':
            Meet(cmd, DEBUG)
        else:
            say('Not valid command')
        write(None)
        time.sleep(1)
Esempio n. 20
0
from config import Configure
from model import Net
from data_process import data_loader
import torch
import torch.nn as nn


config = Configure()
args = config.get_args()

train_set, val_set, num_total_words = data_loader(args)

device = torch.device("cuda:2" if torch.cuda.is_available() else "cpu")
net = Net(num_total_words*args.max_features, args.embedding_size,
          args.num_hiddens, args.num_layers, num_classes=len(args.catogories))
net.to(device)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(net.parameters(), lr=args.lr)


for epoch in range(args.num_epochs):
    train_set, val_set, num_total_words = data_loader(args)
    train_loss, val_loss = 0., 0.
    train_acc, val_acc = 0., 0.
    num_correct = 0
    for step, (feature, label) in enumerate(train_set):
        feature = torch.from_numpy(feature).to(device)
        label = torch.from_numpy(label).to(device)

        net.zero_grad()
        scores = net(feature)
Esempio n. 21
0
def main(DEBUG=False):
    #Start LEDs
    write('load')
    subprocess.Popen(['python', 'LED.py'])
    #Read from configuration files and apply settings.
    config = Configure()
    start_andy_on_boot, social_mode, rebel_mode, wander_mode = config.read()
    if start_andy_on_boot == False:
        sys.exit()

    #Say start up slogan and check for command.
    say('Hello. My name is Andy. Please wait while my system starts up.')
    getit = Get_cmd()
    #Start server process 
    subprocess.Popen(['python', 'server.py'])
    write(None)
    #Enter main loop
    while True:
        print
        #Get the command and convert it to a list
        cmd = getit.get().split()
        write('load')
        if DEBUG: print 'COMMAND:', cmd

        #Remove unused words from command
        num = 0
        for word in cmd:
            cmd[num] = word.lower()
            num += 1
        if len(cmd) == 0:
            cmd.append('')
        #Determin master command
        if cmd[0] == 'what':
            cmds.What(cmd, DEBUG)
        elif cmd[0] == 'walk' or cmd[0] == 'turn':
            cmds.Walk(cmd, DEBUG)
        elif cmd[0] == 'stop':
            cmds.Walk(cmd, DEBUG).stop()
        elif cmd[0] == 'pickup' or cmd[0] == 'pick' and cmd[1] == 'up':
            cmds.Arm(cmd, DEBUG).pickup()
        elif cmd[0] == 'set' and cmd[1] == 'down':
            cmds.Arm(cmd, DEBUG).setdown()
        elif cmd[0] == 'where':
            cmds.Where(cmd, DEBUG)
        elif cmd[0] == 'take':
            cmds.Take(cmd, DEBUG)
        elif cmd[0] == 'set':
            pass #TODO
        elif cmd[0] == 'tell':
            cmds.Tell(cmd, DEBUG)
        elif cmd[0] == 'who':
            cmds.Who(cmd, DEBUG)
        elif cmd[0] == 'shutdown':
            cmds.shutdown()
        elif cmd[0] == 'sleep':
            cmds.sleep()
        elif cmd[0] == 'meet':
            Meet(cmd, DEBUG)
        else:
            say('Not valid command')
        write(None)
        time.sleep(1)
Esempio n. 22
0
import os
import time
import numpy as np
from shutil import copyfile
from datetime import datetime

from config import Configure
from utils.vocab import Vocab
from data.loader import DataLoader
from utils import scorer, constant, helper

from model.base import BaseModel

# make opt
opt = vars(Configure.c_gcn())
opt['num_class'] = len(constant.LABEL_TO_ID)

# load vocab
vocab_file = opt['vocab_dir'] + '/vocab.pkl'
vocab = Vocab(vocab_file, load=True)
opt['vocab_size'] = vocab.size
emb_file = opt['vocab_dir'] + '/embedding.npy'
emb_matrix = np.load(emb_file)
assert emb_matrix.shape[0] == vocab.size
assert emb_matrix.shape[1] == opt['emb_dim']

# load data
print("Loading data from {} with batch size {}...".format(
    opt['data_dir'], opt['batch_size']))
train_batch = DataLoader(opt['data_dir'] + '/train.json',
from feature_selection import FeatureSelection
from config import Configure
import pandas as pd

print('\n Aplicando algoritmo de seleção de parâmetros')
settings = Configure()
settings.set_fs_params()
settings.set_pre_processing_params()
pp_params = settings.pre_processing_params
fs_params = settings.feature_selection_params
df1 = pd.read_csv(settings.pf1_folder)
df2 = pd.read_csv(settings.pf2_folder)
df3 = pd.read_csv(settings.pf3_folder)
mkt = pd.read_csv(settings.mkt_folder)
fs = FeatureSelection(mkt, df1, df2, df3, pp_params, fs_params)
values, features = fs.feature_selection_algorithm(m='RFECV')
columns = features.values[features.values != 'Unnamed: 0']
mkt = mkt[columns]
Esempio n. 24
0
 def __init__(self):
     self.serverName, self.serverPort, self.clientPort, self.downloadPath = Configure(
     ).client_config()
Esempio n. 25
0
from config import Configure

__author__ = "Andrew Gafiychuk"

if __name__ == '__main__':
    # Test Singleton also
    cfg2 = Configure(file="../config.cfg")
    print(cfg2._singleton_mark)

    cfg = Configure(file="../config.cfg")
    print(cfg._singleton_mark)

    print(cfg2 is cfg)  # Must be a True

    cfg.show_config()

    config = cfg.getConfiguration()

    print("=" * 100)
    print("User: {0}".format(config["user"]))
    print("Passowrd: {0}".format(config["password"]))
    print("=" * 100)

    print("Host: {0}".format(cfg.get_host()))
    print("Port: {0}".format(cfg.get_port()))
Esempio n. 26
0
def start_recording(config_name, recording_num_scale, flag_show_windows, auto_save, port=None, weathers=None, vehicle_nums=None):
    config, config_file = Configure.get_config(config_name)
    if port is None:
        port = config['port']

    cameras = config['cameras']
    if vehicle_nums is None:
        vehicle_nums = config['vehicle_num']
    if weathers is None:
        weathers = config['weathers']

    all_conditions = [(w, v) for w in weathers for v in vehicle_nums]

    if config["mode"] == "parallel":
        for cond in all_conditions:
            recorder = SRecorder(host=config['host'],
                                 port=port,
                                 save_root=config['save_root'],
                                 weather_name=cond[0],
                                 vehicle_num=cond[1],
                                 flag_show_windows=flag_show_windows,
                                 auto_save=auto_save,
                                 config=config,
                                 config_file = config_file
                                 )
            camera_keys = cameras.keys()

            for _, k in zip(trange(len(cameras)), cameras.keys()):
                recorder.create_rgb_camera(
                    width=cameras[k]["width"],
                    height=cameras[k]["height"],
                    x=cameras[k]["x"],
                    y=cameras[k]["y"],
                    z=cameras[k]["z"],
                    fov=cameras[k]["fov"],
                    pitch=cameras[k]["pitch"],
                    yaw=cameras[k]["yaw"],
                    roll=cameras[k]["roll"],
                    max_record_frame=int(cameras[k]["max_record_frame"]*recording_num_scale),
                    camera_tag=k
                )
            recorder.run()

    elif config["mode"] == "serial":
        for cond in all_conditions:
            for k in cameras.keys():
                recorder = SRecorder(host=config['host'],
                                     port=port,
                                     save_root=config['save_root'],
                                     weather_name=cond[0],
                                     vehicle_num=cond[1],
                                     flag_show_windows=flag_show_windows,
                                     auto_save=auto_save,
                                     config=config,
                                     config_file = config_file
                                     )
                recorder.create_rgb_camera(
                    width=cameras[k]["width"],
                    height=cameras[k]["height"],
                    x=cameras[k]["x"],
                    y=cameras[k]["y"],
                    z=cameras[k]["z"],
                    fov=cameras[k]["fov"],
                    pitch=cameras[k]["pitch"],
                    yaw=cameras[k]["yaw"],
                    roll=cameras[k]["roll"],
                    max_record_frame=int(cameras[k]["max_record_frame"]*recording_num_scale),
                    camera_tag=k
                )
                recorder.run()
Esempio n. 27
0
            elif adhoc_interface == "ath1" and monitor_interface == "ath0":
                working_iface_monitor = re.compile('[1]').sub(
                    '3', adhoc_interface)
                backup_iface_monitor = re.compile('[0]').sub(
                    '2', monitor_interface)
            else:
                print "Please specify [ath0, ath1] for each interface. "
                sys.exit(0)

            print "Current Interfaces: [wa: %s] [wm: %s] [ba: %s] [bm: %s]" % (
                working_iface_adhoc, working_iface_monitor, backup_iface_adhoc,
                backup_iface_monitor)
            print "Current Interface: [wa: ath%s] [ba: ath%s]" % (working,
                                                                  backup)

            cf = Configure(working_iface_adhoc, backup_iface_adhoc)
            ff = FrameFilter(cf, snr_threshold, FILTER)
            p = pcap.pcapObject()
            p.open_live(backup_iface_monitor, 96, 0, 100)

            while 1:
                while ff.rx_frame < 101:  # Approx. 100ms * 100 = 10s ; Only beacon frames counted
                    apply(ff.filter, p.next())
                    #ff.print_tx_filter(working_iface_adhoc) # maybe 1s

                stime = time.time()
                #print "loop starts %f" % stime

                try:
                    for daddr in ['00:80:92:3e:18:11', '00:80:92:3e:18:18']:
                        print "XXXXXXXXXXXXXXXX"
Esempio n. 28
0
        """
        Disable all elements while operations working.

        """
        self.btn_fill.setDisabled(True)
        self.btn_exp.setDisabled(True)
        self.btn_scrapp.setDisabled(True)
        self.btn_save.setDisabled(True)

        self.cmb_ds.setDisabled(True)
        self.cmb_exp.setDisabled(True)
        self.cmb_save.setDisabled(True)

        self.page_count_box.setDisabled(True)


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.debug("[+]App started...")

    # Configure main program params...
    cfg = Configure()

    app = QtWidgets.QApplication(sys.argv)

    form = MainForm(config=cfg)
    form.show()

    logging.debug("[+]App set_enable...")
    sys.exit(app.exec_())
Esempio n. 29
0
def initConf(file):
    try:
        conf = Configure(file)
        return conf
    except Exception as ex:
        raise ex
Esempio n. 30
0
from data.dataloader import generate_loader
from config import Configure
from networks.RCNN import BiGruCNN
from framework import MyFrame
from utils import initLogging

name = 'HAN_rcnn_drop0.2'
mylog = 'logs/' + name + '.log'
path = 'weights/' + name + '.pkl'
initLogging(mylog)
device = 2
total_epochs = 30
valid_best_score = 0.

train_loader, valid_loader, testa_loader = generate_loader(train_bs=32)
opt = Configure()
net = BiGruCNN
loss_func = CrossEntropyLoss(size_average=True)
solver = MyFrame(net=net, loss=loss_func, opt=opt, lr=1e-3, device=device)
solver.load(path)
# solver.net.embedding.weight.requires_grad = True

no_optim_round = 0
for epoch in range(total_epochs):
    # train
    solver.train_mode()
    train_loss = 0.
    for X, y in tqdm(train_loader):
        solver.set_input(X, y)
        step_loss = solver.optimize()
        train_loss += step_loss
Esempio n. 31
0
"""
Run evaluation with saved models for student network.
"""

import json
from config import Configure
from utils.vocab import Vocab
from data.loader import DataLoader
from model.student import StudentModel
from utils import torch_utils, scorer, constant, helper

args = Configure.eval()

# load opt
model_file = 'saved_models/' + args.model_id + '/' + args.model
print("Loading model from {}".format(model_file))
opt = torch_utils.load_config(model_file)
student_model = StudentModel(opt)
student_model.load(model_file)

# load vocab
vocab_file = 'saved_models/' + args.model_id + '/vocab.pkl'
vocab = Vocab(vocab_file, load=True)
assert opt[
    'vocab_size'] == vocab.size, "Vocab size must match that in the saved model."

# load data
data_file = opt['data_dir'] + '/{}.json'.format(args.dataset)
print("Loading data from {} with batch size {}...".format(
    data_file, opt['batch_size']))
batch = DataLoader(data_file, opt['batch_size'], opt, vocab, evaluation=True)
Esempio n. 32
0
import os
from tqdm import tqdm
from visdom import Visdom
import numpy as np

from torch.autograd import Variable
from torch.autograd import Function
import torch.backends.cudnn as cudnn

from dataset import SiameseWhaleDataset
from model import SiameseNetwork
from config import Configure
from utils import PairwiseDistance, DlibLoss, ContrastiveLoss

# Global config
config = Configure()

transform = transforms.Compose([
    # Scale(96),
    transforms.Resize((224, 224)),
    transforms.RandomHorizontalFlip(),
    transforms.ColorJitter(),
    transforms.RandomRotation(15),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])

# Train_dir
# Number of training example: n_batch * n_cls * n_same
train_dir = SiameseWhaleDataset(config.dataroot, config.n_batch, config.n_cls,
                                config.n_same, transform)