Exemplo n.º 1
0
 def __init__(self, name, dacs = DAC_ROUT, dacranges = None):
     """
     init virtual instrument object
     Inputs:
         - name: qt instrument name
         - dacs: list of routes of channels in use, e.g. [5] or [5,9,2]
         - dacranges: list of length len(dacs) indicating the dac ranges set at the device, list entries one of 'bi' for -2000,2000, 'pos' for 0,4000, 'neg' for -4000,0
     """
     Instrument.__init__(self, name, tags=['virtual'])
     
     self.dacs = dacs
     try:
         self.channels = len(self.dacs)
     except TypeError:
         logging.error('Error reading dac ports to be used. Import as list.')
     if dacranges == None:
         dacranges = ['bi']*self.channels
     else:
         if len(dacranges) != self.channels:
             logging.errors('dacranges not specified properly')
     limits_dict = {'bi':[-2000,2000],'pos':[0,4000],'neg':[-4000,0]}
     self.range_limits = [limits_dict[dacranges[i]] for i in range(self.channels)]
     #print self.range_limits
     if self.channels == 1:
         self.add_parameter('current', type=types.FloatType, flags=Instrument.FLAG_GETSET, units='mA')
         self.add_parameter('range', type=types.StringType, flags=Instrument.FLAG_GETSET)
     elif self.channels > 1 and self.channels <= 16:
         self.add_parameter('current', type=types.FloatType, flags=Instrument.FLAG_GETSET, units='mA', channels=(1, self.channels), channel_prefix='ch%d_')
         self.add_parameter('range', type=types.StringType, flags=Instrument.FLAG_GETSET, channels=(1, self.channels), channel_prefix='ch%d_')
     else:
         logging.error('incorrect number of channels specified')
     
     self.c_ranges = ['1m']*self.channels
Exemplo n.º 2
0
    def __init__(self, name, dacs=DAC_ROUT, dacranges=None):
        """
        init virtual instrument object
        Inputs:
            - name: qt instrument name
            - dacs: list of routes of channels in use, e.g. [5] or [5,9,2]
            - dacranges: list of length len(dacs) indicating the dac ranges set at the device, list entries one of 'bi' for -2000,2000, 'pos' for 0,4000, 'neg' for -4000,0
        """
        Instrument.__init__(self, name, tags=['virtual'])

        self.dacs = dacs
        try:
            self.channels = len(self.dacs)
        except TypeError:
            logging.error(
                'Error reading dac ports to be used. Import as list.')
        if dacranges == None:
            dacranges = ['bi'] * self.channels
        else:
            if len(dacranges) != self.channels:
                logging.errors('dacranges not specified properly')
        limits_dict = {
            'bi': [-2000, 2000],
            'pos': [0, 4000],
            'neg': [-4000, 0]
        }
        self.range_limits = [
            limits_dict[dacranges[i]] for i in range(self.channels)
        ]
        #print self.range_limits
        if self.channels == 1:
            self.add_parameter('current',
                               type=types.FloatType,
                               flags=Instrument.FLAG_GETSET,
                               units='mA')
            self.add_parameter('range',
                               type=types.StringType,
                               flags=Instrument.FLAG_GETSET)
        elif self.channels > 1 and self.channels <= 16:
            self.add_parameter('current',
                               type=types.FloatType,
                               flags=Instrument.FLAG_GETSET,
                               units='mA',
                               channels=(1, self.channels),
                               channel_prefix='ch%d_')
            self.add_parameter('range',
                               type=types.StringType,
                               flags=Instrument.FLAG_GETSET,
                               channels=(1, self.channels),
                               channel_prefix='ch%d_')
        else:
            logging.error('incorrect number of channels specified')

        self.c_ranges = ['1m'] * self.channels
def remove_inappropriate_characters_from_attribute_name(attribute_string):
    attribute_string = str(attribute_string)
    if "Inve$tWare" in attribute_string: # weird inve$tware names throwing errors below due to "$".
        attribute_string = attribute_string.replace("Inve$tWare", "InvestWare")
    acceptable_characters = list(string.ascii_letters + string.digits + "_")
    new_attribute_name = ""
    unacceptible_characters = [" ", "-", ".", ",", "(", ")", u" ", u"-", u".", u",", u"(", u")", "/", u"/", "&", u"&", "%", u"%", "#", u"#", ":", u":", "*", u"*"]
    string_fails = [char for char in unacceptible_characters if char in attribute_string]
    if string_fails:
        #logging.info(string_fails)
        for char in attribute_string:
            if char not in acceptable_characters:
                if char in [" ", "-", ".", ",", "(", ")", u" ", u"-", u".", u",", u"(", u")", "#", u"#", ":", u":", "*", u"*"]:
                    new_char = "_"
                elif char in ["/", u"/"]:
                    new_char = "_to_"
                elif char in ["&", u"&"]:
                    new_char = "_and_"
                elif char in ["%", u"%"]:
                    new_char = "percent"
                elif char in ["'"]:
                    new_char = ""
                else:
                    logging.errors(("Error:", char, ":", attribute_string))
                    sys.exit()
            else:
                new_char = str(char)

            new_attribute_name += new_char
    if new_attribute_name:
        attribute_string = new_attribute_name

    attribute_string = utils.remove_leading_underscores(attribute_string)
    return attribute_string











# end of line
def remove_inappropriate_characters_from_attribute_name(attribute_string):
    attribute_string = str(attribute_string)
    if "Inve$tWare" in attribute_string:  # weird inve$tware names throwing errors below due to "$".
        attribute_string = attribute_string.replace("Inve$tWare", "InvestWare")
    acceptable_characters = list(string.ascii_letters + string.digits + "_")
    new_attribute_name = ""
    unacceptible_characters = [
        " ", "-", ".", ",", "(", ")", u" ", u"-", u".", u",", u"(", u")", "/",
        u"/", "&", u"&", "%", u"%", "#", u"#", ":", u":", "*", u"*"
    ]
    string_fails = [
        char for char in unacceptible_characters if char in attribute_string
    ]
    if string_fails:
        #logging.info(string_fails)
        for char in attribute_string:
            if char not in acceptable_characters:
                if char in [
                        " ", "-", ".", ",", "(", ")", u" ", u"-", u".", u",",
                        u"(", u")", "#", u"#", ":", u":", "*", u"*"
                ]:
                    new_char = "_"
                elif char in ["/", u"/"]:
                    new_char = "_to_"
                elif char in ["&", u"&"]:
                    new_char = "_and_"
                elif char in ["%", u"%"]:
                    new_char = "percent"
                elif char in ["'"]:
                    new_char = ""
                else:
                    logging.errors(("Error:", char, ":", attribute_string))
                    sys.exit()
            else:
                new_char = str(char)

            new_attribute_name += new_char
    if new_attribute_name:
        attribute_string = new_attribute_name

    attribute_string = utils.remove_leading_underscores(attribute_string)
    return attribute_string


# end of line
Exemplo n.º 5
0
        help=
        "The absolute path to the file containing all the labels categories.")
    args = parser.parse_args()

    pred_file = args.pred_file_path
    gold_file = args.gold_file_path

    if not args.detailed_results:
        output_log_file = pred_file + ".log"
        logger.info("Logging execution to file " + output_log_file)
        fileLogger = logging.FileHandler(output_log_file)
        fileLogger.setLevel(logging.DEBUG)
        fileLogger.setFormatter(formatter)
        logger.addHandler(fileLogger)
    else:
        logger.addHandler(ch)

    if not os.path.exists(args.classes_file_path):
        logging.errors("File doesnt exists: {}".format(classes_file_path))
        raise ValueError("File doesnt exists: {}".format(classes_file_path))
    CLASSES = read_classes(args.classes_file_path)

    if validate_files(pred_file, gold_file, CLASSES):
        macro_f1, micro_f1 = evaluate(pred_file, gold_file, CLASSES)
        if args.detailed_results:
            logging.info("macro-F1={:.5f}\tmicro-F1={:.5f}".format(
                macro_f1, micro_f1))
        else:
            logging.info("{}\t{}".format(macro_f1, micro_f1))
            print("{}\t{}".format(macro_f1, micro_f1))
Exemplo n.º 6
0
        '''
        rowaccess = "row['%s']"
        if ':' in key:
            keyA, key = key.split(':')
            rowaccess = "json.loads(row['{keyA}']).get('%s','0')".format(
                keyA=keyA)

        input = rowaccess % key if row else '%s' % key
        return input if cast == '' else cast + "(%s)" % input

    def clean(els):
        return [el for el in els if el != '']

    # basic option check
    if opts.add == None or opts.addbool == None:
        logging.errors("Nothing to do buddy")

    reader = csv.DictReader(sys.stdin, delimiter=opts.delimiter)
    header = reader.fieldnames

    # create evaluable rule
    rules = []
    add_rules = clean(opts.add.split(','))
    add_bool_rules = clean(opts.addbool.split(','))
    all_rules = list(add_rules) + list(add_bool_rules)

    logging.info("adding field")
    for i, rule in enumerate(all_rules):
        logging.info("%i -> %s" % (i + 1, rule))

    logging.info("generating add colomn code...")
Exemplo n.º 7
0
def athena_query(config, query):

    # Get AWS Account and Region runtime information
    try:
        aws_account = boto3.client('sts').get_caller_identity().get('Account')
    except Exception as e:
        logging.error("Get Account Info Error: %s" % e)
    logging.debug("AWS Account: %s" % aws_account)
    try:
        aws_region = boto3.session.Session().region_name
    except botocore.exceptions.ClientError as e:
        logging.errors("Get Region Info Error: %s" % e)
    logging.debug("AWS Region: %s" % aws_region)

    output_location = "s3://aws-athena-results-" + aws_account + "-" + aws_region + "/"
    logging.debug("Output Location: %s" % output_location)
    athena = boto3.client('athena')

    try:
        create_response = athena.start_query_execution(
            QueryString=query,
            QueryExecutionContext={'Database': config['athena_db']},
            ResultConfiguration={'OutputLocation': output_location})
    except botocore.exceptions.ClientError as e:
        logging.error("Athena Query Execution Error: %s" % e)
        message = "Athena Query Execution Error - Query Failed: %s, Error: %s" % (
            query, e)
        sns.publish(TopicArn=error_topic, Message=message)
        slack_notify(config, message)

    logging.debug("Response: %s" % create_response)

    try:
        qid = create_response.get("QueryExecutionId")
    except botocore.exceptions.ClientError as e:
        logging.info("Get Athena QID Error: %s" % e)
        message = "Athena Error - Get ID Failed: %s, Error: %s" % (query, e)
        sns.publish(TopicArn=error_topic, Message=message)
        slack_notify(config, message)

    logging.info("Checking Create Query: %s" % qid)

    response = req_check(athena, qid)
    if (response == "SUCCEEDED"):
        logging.info("Query Succeeded")
    else:
        logging.error("Athena Query Failed with message: %s" % response)
        message = "Athena Query check Error - Query Failed: %s, Response: %s" % (
            query, response)
        sns.publish(TopicArn=error_topic, Message=message)
        slack_notify(config, message)

    next = True
    results = []
    iteration = 0
    while next:
        try:
            if next == True:
                response = athena.get_query_results(QueryExecutionId=qid,
                                                    MaxResults=1000)
            elif next != False:
                response = athena.get_query_results(QueryExecutionId=qid,
                                                    NextToken=next,
                                                    MaxResults=1000)
        except botocore.exceptions.ClientError as e:
            logging.error("Athena get Results Error: %s" % e)
            message = "Athena Query getResults Error - Query Failed: %s, Error: %s" % (
                query, e)
            sns.publish(TopicArn=error_topic, Message=message)
            slack_notify(config, message)

        if 'ResultSet' in response and "Rows" in response['ResultSet']:
            logging.debug("LEN: %d" % len(response['ResultSet']['Rows']))
            if iteration > 0:
                response['ResultSet']['Rows'].pop(0)
            else:
                iteration += 1
            results = results + response['ResultSet']['Rows']
        if 'NextToken' in response:
            next = response['NextToken']
        else:
            next = False

    if len(results) > 0:
        logging.debug("Results: %s" % results)
        return results
    else:
        logging.debug("No Rows Found")
        return []