def perform_test(self, name, setting_file, golden_file):
        print("%s test" % name, end="")
        sys.stdout.flush()
        from util.config import Config
        config = Config(get_file(setting_file))

        notify_data = collections.OrderedDict()
        for notify_name in config.notifications:
            parsed_data = collections.OrderedDict()
            notification = config.notifications[notify_name]
            for entry in notification.get_key_and_path():
                [key, path] = entry
                from util.content import get_content
                content = get_content(path)
                data_list = notification.parser.parse(content)
                assert data_list and type(data_list) is list
                source_key = tuple(sorted(key.items()))  # convert to sorted-tuple, for dict is not hashable
                parsed_data[source_key] = data_list
            analyzed_data = notification.post_analysis.analyze(parsed_data, notify_data)
            notify_data[notify_name] = analyzed_data
            os.remove("immature_" + notify_name + ".txt")
            os.remove("mature_" + notify_name + ".txt")
        with open(get_file(golden_file), encoding='utf8') as f:
            golden = f.read()
        from pp.pretty_print import get_beautiful_data
        self.assertEqual(get_beautiful_data(notify_data), golden)
예제 #2
0
def display():
    if checkIfLogged():
        global parameters
        imgs = get_content(parameters, "img")
        print len(imgs)
        imgs = json.loads(imgs)
        return render_template("display.html", medium="art", images=imgs)
    else:
        return redirect(url_for("home"))
예제 #3
0
def update_display():
    data = request.args.get("replace_pics")
    data = json.loads(data)
    print "\n\n\n\n\n\n\n\n"
    print data
    print "\n\n\n\n\n\n\n\n"
    for i in data:
        print i
    c = [[int(ml_db.get_word_num("img", x)) for x in api.clarifai(i)]
         for i in data]
    d = []
    for x in c:
        d.append(x[:3])  #takes only the first three parameters
    # update training set
    # optimize parameters
    # return 3 random and 2 predicted images
    #print "\n========================x: \n", x
    print "\n\n\n\n\n\n\n\n"
    print "d: ", d
    print "\n\n\n\n\n\n\n\n end of d"
    global tsetX
    global tsetY
    global parameters
    for i in d:
        ml.append_train_set(i, tsetX, tsetY)
    print tsetX, tsetY
    parameters = ml.optimize_parameters(parameters, tsetX, tsetY)
    print "parameters:", parameters[0] + 1
    #print parameters
    print "\n\n\n\n\n\n\n\n"
    print "parameters: ", parameters
    print "\n\n\n\n\n\n\n\n"
    #predict(parameters, x) # x is a list of data retrieved from ml_db
    img = get_content(parameters, "img")
    print "\n\n\n\n\n\n\n\n"
    print img
    print "\n\n\n\n\n\n\n\n"
    # response = json.loads(img)
    #response=(calls getty)
    #img = json.dumps(img)
    return img
예제 #4
0
    def run(self):
        logging.info("[WbNt] web-notifier is running!")

        notify_data = collections.OrderedDict()  # key: notify_name, value: dict (see below)
        for notify_name in self.__config.notifications:
            logging.info("[WbNt] dealing with notification \"%s\"" % notify_name)
            parsed_data = collections.OrderedDict()  # key: source key, value: list of parsed data
            notification = self.__config.notifications[notify_name]
            for entry in notification.get_key_and_path():
                assert isinstance(entry, list) and 2 == len(entry)
                [key, path] = entry
                key_str = "" if 0 == len(key) else \
                    str([key_value_pair[1] for key_value_pair in list(key.items())])
                logging.debug("[WbNt] " + path)
                content = get_content(path, self.args.web_login, self.args.web_password)
                WebNotifier.backup_content(key, content, notify_name)
                data_list = notification.parser.parse(content)
                if data_list:
                    assert type(data_list) is list
                    source_key = tuple(sorted(key.items()))  # convert to sorted-tuple, for dict is not hashable
                    parsed_data[source_key] = data_list
                    logging.info("[WbNt] %s %sfind %i entry(s)" %
                                 (key_str, " => " if len(key_str) > 0 else "", len(data_list)))
                else:
                    if "" != key_str:
                        logging.info("[WbNt] %s" % key_str)
            info_entry = notification.parser.informative
            analyzed_data = notification.post_analysis.analyze(parsed_data, notify_data, info_entry)
            notify_data[notify_name] = analyzed_data

        pp_data = get_beautiful_data(notify_data, self.args.full_data)
        logging.info(pp_data)
        self.__config.audiences.notify(pp_data)

        import json
        output_file = self.args.output
        with open(output_file, 'w') as write_fd:
            json.dump(get_beautiful_pre_json(notify_data), write_fd)

        logging.info("[WbNt] notification done")