Example #1
0
#!/usr/bin/env python
import numpy as np
import os
import sys
from utils import parse_settings
import matplotlib.pyplot as plt

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "usage: ./train.py config_file_name.json"
        sys.exit(0)
    if not os.path.exists(sys.argv[1]):
        print "Config file does not exists!"
        sys.exit(0)

    settings = parse_settings(sys.argv[1])
    with open(os.path.join(settings["MODELS_PATH"], "trainlog.txt"), "r") as f:
        lines = f.read().splitlines()
    del lines[0]

    loss = []
    val_loss = []
    for line in lines:
        values = line.split(",")
        loss += [float(values[1])]
        val_loss += [float(values[2])]

    best_model = np.asarray(val_loss).argmin()
    print "Best Model:", best_model + 1, "Val_Loss:", val_loss[best_model]

    plt.plot(loss, "r", label="Loss")
Example #2
0
            totalRunning = 0
        
        
        return {"name": self.name, "ip":self.URI.netloc, "port":self.URI.port,
                "href":self.URI.geturl(), "details":details,
                "id":self.id, "totalClientProcesses":totalProcesses ,
                "totalClientRunning":totalRunning, "description":self.description}

    def get_process_info(self):
        try:
            return self.server.supervisor.getAllProcessInfo()
        except IOError:
            return None

    def __repr__(self):
        return self.__class__.__name__ + '(%s)' % (', '.join(map(repr, [self.name, self.URI.geturl()])))

if __name__ == '__main__':
    clientDetails = utils.parse_settings("../settings.conf")
    clients = []
    #Generate Supervisor clients
    for detail in clientDetails:
        if (len(detail) == 2):
            print detail
            continue
        if (len(detail) == 1):
            print detail
            continue
        else:
            print "Parsing Error in Settings, please check"
            sys.exit(1)
    parser.add_argument("-Pe", type=float, default=0, help="Peclet number")
    args = parser.parse_args()
    return args


def find_subfolder(Pe, rwfolder):
    for subfolder in os.listdir(rwfolder):
        if Pe == float(subfolder[2:]):
            return subfolder


if __name__ == "__main__":
    args = parse_args()

    settingsfile = os.path.join(args.folder, "Settings/config.case")
    settings = parse_settings(settingsfile)

    tsfolder = os.path.join(args.folder, "Timeseries")
    rwfolder = os.path.join(args.folder, "RandomWalkers")

    grid = parse_grid(settings["grid"])
    not_grid = np.logical_not(grid)

    ny, nx = grid.shape

    its = []
    for filename in os.listdir(tsfolder):
        if filename[:7] == "fields_" and filename[-4:] == ".dat":
            its.append(int(filename[7:-4]))
    its = sorted(its)
    it = its[-1]
Example #4
0
"""

from argparse import ArgumentParser
from dnslib import DNSRecord, DNSQuestion, QTYPE, RCODE
from utils import parse_settings, is_blacked

if __name__ == '__main__':
    arg_p = ArgumentParser(description="proxy_dns test")

    arg_p.add_argument('--tcp', action='store_true', default=False)
    arg_p.add_argument('domain')
    arg_p.add_argument('qtype', default='A')

    args = arg_p.parse_args()

    settings = parse_settings('settings.ini')
    blacklist = settings['BLACKLIST'].keys()
    black_code = settings['COMMON']['black_code']
    addr, port = settings['COMMON']['proxy'].split(':')

    question = DNSQuestion(args.domain, getattr(QTYPE, args.qtype))
    request = DNSRecord(q=question)
    response = request.send(addr, int(port), tcp=args.tcp)
    reply = DNSRecord.parse(response)

    blacked_flag = is_blacked(question.qname, blacklist)
    rcode_flag = reply.header.rcode == getattr(RCODE, black_code)

    if blacked_flag:
        print('--- {} is in the blacklist.'.format(question.qname))
        if rcode_flag: