def main(args):
    data = utility.read_json(config.RESULTS_DIR[args.browser] + args.browser + '-' + str(args.version) + '.json')
    (hits,misses) = ([],[])
    for result in data:
        if (result['name']=='hit/miss' and result['clock_method'] == args.clock and result['coop'] == args.coop):
            if result['hit/miss']=='hits':
                for value in result['values']:
                    hits.append(value)
            elif result['hit/miss']=='misses':
                for value in result['values']:
                    misses.append(value)
    if hits == [] or misses == []:
        print('No results found for ' + args.browser + ' ' + str(args.version) + ' ' + args.clock + ' and COOP/COEP:' +str(args.coop))
        sys.exit(1)
    results = {'hits':hits,'misses':misses}
    print(results)
    if args.csv:
        if args.max==-1:
            max_value= max(max(hits),max(misses))
        else:
            max_value = args.max
        hist = get_histogram(results, args.min, max_value, args.step)
        output_path = config.CSV_DIR[args.browser] + 'hit_miss-' + args.browser + '-' + str(args.version) + '-' + args.clock + '-coop-' + str(args.coop) + '.csv'
        hit_miss_csv(hist, output_path)
    if args.plot:
        if args.max==-1:
            max_value= max(max(hits),max(misses))
        else:
            max_value = args.max
        plot_hit_miss(results, args.min, max_value, args.step)
Example #2
0
def main():
    opts, args = getopts()

    if opts.data_unit:
        if not opts.signal or not opts.value or not opts.value_type:
            raise IncompleteOptionsError(
                "\nA new data unit must have a signal, a value and a value_type. \n"
                "One or more of these options are missing, make sure to pass all the \n"
                "three when passing a data_unit flag. \n"
                "Please refer to help section of the script to understand each of these options. \n"
            )
        du = DataUnit(opts.signal, opts.value, opts.value_type)
        try:
            du.validate_data_unit()
            print "Valid data unit {%s, %s, %s}" % (opts.signal, opts.value,
                                                    opts.value_type)
        except (InvalidDatatypeError, DatatypeMismatchError, ValueError,
                RuleViolationError) as e:
            raise e
    elif opts.input_file:
        datafile = read_json(opts.input_file)
        for dataunit in datafile:
            print "-------------------------------------------------------"
            print "data_unit -> ", dataunit
            try:
                du = DataUnit.from_dict(dataunit)
                du.validate_data_unit()
                print "Valid data unit"
            except (InvalidDatatypeError, DatatypeMismatchError, ValueError,
                    RuleViolationError) as e:
                # TODO: use python logging module to log the exceptions
                print str(e)
    elif opts.create_rule:
        if not opts.signal or not opts.rule or not opts.value_type:
            raise IncompleteOptionsError(
                "\nA new rule must have a signal, a rule and a value_type. \n"
                "One or more of these options are missing, make sure to pass all the \n"
                "options when passing a create_rule flag. \n"
                "Please refer to help section of the script to understand each of these options. \n"
            )
        r = Rule(opts.signal, opts.rule, opts.value_type)
        try:
            r.create_rule()
        except RuleExistsError as e:
            raise e
    elif opts.edit_rule:
        if not opts.signal or not opts.rule or not opts.value_type:
            raise IncompleteOptionsError(
                "\nA new rule must have a signal, a rule and a value_type. \n"
                "One or more of these options are missing, make sure to pass all the \n"
                "options when passing a create_rule flag. \n"
                "Please refer to help section of the script to understand each of these options. \n"
            )
        r = Rule(opts.signal, opts.rule, opts.value_type)
        try:
            r.edit_rule()
        except RuleMissingError as e:
            raise e
def get_data(browser, coop):
    data = {}
    for file in os.listdir(config.RESULTS_DIR[browser]):
        path = config.RESULTS_DIR[browser] + file
        results = utility.read_json(path)
        for result in results:
            if result['name'] == 'Tick distibution' and result['coop'] == coop:
                print(result)

                data[result['version']] = result['values']
    return data
Example #4
0
    def _get_response(self, n_retry, delay):

        for _ in range(n_retry):
            time.sleep(delay)
            try:
                data = read_json(self.res_path)
                os.remove(self.res_path)  # res 파일 삭제
                return data
            except FileNotFoundError:
                pass
        return None
Example #5
0
    async def run(self, main_func_name):
        reqs = os.listdir(self.req_dir)

        if reqs:
            req_name = reqs[0]
            req_path = os.path.join(self.req_dir, req_name)
            req_content = read_json(req_path)
            os.remove(req_path)  # 읽은 후 바로 삭제

            res = getattr(self.worker, main_func_name)(**req_content)
            res_path = os.path.join(self.res_dir, req_name)
            write_json(res, res_path)  # res 파일 생성
Example #6
0
    def edit_rule(self):
        """
        Method to edit an existing rule.
        If rule for the signal passed does not exist, it raises RuleMissingError.
        Otherwise, edits the rule and dumps it back into the rule book

        """
        rules = read_json('etc/rule_book.json')
        if self.signal not in rules[0].keys():
            raise RuleMissingError(
                "RuleMissingError: Rule for signal %s does not exist."
                "Please create the rule first. " % self.signal)
        if self.value_type not in ('string', 'integer', 'datetime'):
            raise InvalidDatatypeError(
                "currently we only support "
                "string, integer and datetime datatypes ")
        rules[0][self.signal]['rule'] = self.rule
        rules[0][self.signal]['value_type'] = self.value_type.lower()
        with open('etc/rule_book.json', 'w') as f:
            json.dump(rules, f)
Example #7
0
    def create_rule(self):
        """
        Method to create new rules.
        If rule for a signal already exists, it raises RuleExistsError.
        Otherwise dumps the new rule into existing rule book.

        """
        rules = read_json('etc/rule_book.json')
        if self.signal in rules[0].keys():
            raise RuleExistsError(
                "RuleExistsError: Rule for signal %s already exists."
                "Please edit the rule if you wish to "
                "make changes to the existing rule" % self.signal)
        if self.value_type not in ('string', 'integer', 'datetime'):
            raise InvalidDatatypeError(
                "currently we only support "
                "string, integer and datetime datatypes ")
        rules[0][self.signal] = {}
        rules[0][self.signal]['rule'] = self.rule
        rules[0][self.signal]['value_type'] = self.value_type.lower()
        with open('etc/rule_book.json', 'w') as f:
            json.dump(rules, f)
Example #8
0
    def _verify_value_against_rule(self):
        """
        Method to check if the dataunit agrees to the rule defined for the corresponding signal.
        If the rule for the signal does not exists, it raises RuleMissingError.
        If the value_type in dataunit does not match the value_type defined in the rule, it raises RuleViolationError
        If the value in dataunit does not satisfy the rule, it raises RuleViolationError

        """
        rules = read_json('etc/rule_book.json')
        rule = rules[0].get(self.signal, 0)
        if not rule:
            raise RuleMissingError(
                "RuleMissingError: Rule for signal %s does not exist."
                "Please create the rule first. " % self.signal)
        if self.value_type != rule['value_type'].lower():
            raise RuleViolationError(
                'RuleViolationError: value_type for the data unit does not match '
                'the value_type defined in the rule for signal %s' %
                (self.signal))
        s = parse_rule(rule['rule'], self.value, self.value_type)
        if not eval(s):
            raise RuleViolationError(
                'RuleViolationError: value does not match the rule')
Example #9
0
def get_error_repetition(browser, version, clock_method, coop = False, csv = False, plot=False):
    results = utility.read_json(config.RESULTS_DIR[browser] + browser + '-' + str(version) + '.json')
    hits = []
    misses = []
    for result in results:
        if (result['name']=='hit/miss' and result['clock_method'] == clock_method and result['coop'] == coop):
            if result['hit/miss']=='hits':
                for value in result['values']:
                    hits.append(value)
            elif result['hit/miss']=='misses':
                for value in result['values']:
                    misses.append(value)
    if hits == [] or misses == []:
        print('No results found for ' + browser + ' ' + str(version) + ' ' + clock_method + ' and COOP/COEP:' +str(coop))
    error_rep = {}
    for rep in range(1, min(min(len(hits),len(misses)), MAX_REP)):
        (hit_avg, miss_avg) = get_mean_rep(hits,misses,rep)
        error_rep[rep] = get_best_error_rate(hit_avg,miss_avg, clock_method)
    if csv:
        output_path = config.CSV_DIR[browser] + 'error_rep-' + browser + '-' + str(version) + '-' + clock_method + '-coop-' + str(coop) + '.csv'
        json_to_csv(error_rep, output_path)
    if plot:
        plot_error_rep(error_rep)
    return(error_rep)
Example #10
0
def read_simulation_json(f):
    read_json(f)