Exemplo n.º 1
0
def train(account_id):
    message = "Started training for: %s" % account_id
    logging.info(message)
    train_async.delay(account_id)
    account = AccountHelper.get_account_object(account_id)
    account['is_training'] = True
    return JsonHelper.build_action_response(account, message)
Exemplo n.º 2
0
def generate(account_id):
    message = "Started generating bids for: %s" % account_id
    logging.info(message)
    train_async.delay(account_id)
    account = AccountHelper.get_account_object(account_id)
    account['is_generating_bids'] = True
    return JsonHelper.build_action_response(account, message)
Exemplo n.º 3
0
def default():
    areas = {"belfast": "belfast"}

    area_uris = utils.get_area_uris(areas)
    utils.print_uris(area_uris)
    JsonHelper("area_uris").dump(area_uris)
    utils.write_csv(area_uris)
Exemplo n.º 4
0
class LinkShortener:
    def __init__(self):
        self.url_dict = {}
        self.json_helper = JsonHelper("short_links.json")
        self.link_length = 10
        self.port = os.getenv("PORT", 5000)
        self.load_from_file()

    def load_from_file(self):
        self.url_dict = self.json_helper.get_json()
        if not self.url_dict:
            self.url_dict = {}

    def save_to_file(self):
        self.json_helper.save(self.url_dict)

    def get_generated_code(self):
        identifier = str(uuid.uuid4()).replace("-", "")
        return identifier[0 : self.link_length]

    def add_http_before_url(self, url):
        if str(url).startswith("http://") or str(url).startswith("https://"):
            return url
        else:
            new_url = "http://" + url
            return new_url

    def get_code(self, url):
        url = self.add_http_before_url(url)
        if not self.url_dict or not self.url_dict.get(url):
            self.url_dict[url] = self.get_generated_code()
            self.save_to_file()
            print(self.url_dict)
        return self.url_dict.get(url)

    def get_code_url(self, url, to_shorten_url):
        return (
            self.add_http_before_url(str(url).strip("/"))
            + "/link/"
            + self.get_code(to_shorten_url)
        )

    def get_url(self, code):
        for key, value in self.url_dict.items():
            if value == code:
                return key
Exemplo n.º 5
0
def continue_scrape():
    start_area = sys.argv[1]
    start_index = sys.argv[2]
    json_file = sys.argv[3]
    csv_file = sys.argv[4]

    area_uris = JsonHelper(json_file).read()
    utils.continue_csv(area_uris, start_area, start_index, csv_file)
Exemplo n.º 6
0
class Saver:
    def __init__(self, ckpt_path: str, parameters_path: str):
        self.ckpt_path = ckpt_path
        self.parameters_path = parameters_path
        self.parameters_helper = JsonHelper(self.parameters_path)

    def save_models(self, episode: int, *models: DQModel):
        for model in models:
            try:
                model.reset_metrics()
                model.save_weights(
                    self.ckpt_path.format(type=model.get_name()) +
                    f"/cp-{episode:04d}",
                    save_format='tf')
                print(
                    f'--- MODELLO {model.get_name()} salvato con successo ---')
            except Exception as err:
                print(
                    f"--- Non è stato possibile salvare il MODELLO {model.get_name()} ---\n",
                    err)

    def load_models(self, *models: DQModel):
        for model in models:
            last_ckpt = tf.train.latest_checkpoint(
                self.ckpt_path.format(type=model.get_name()))
            try:
                model.load_weights(last_ckpt)
                print(
                    f"--- MODELLO {model.get_name()} (ckeckpoint: {last_ckpt}) caricato con successo ---"
                )
            except Exception as err:
                print(
                    f"--- Non è stato possibile caricare il MODELLO {model.get_name()} ---\n",
                    err)

    def save_parameters(self, total_steps: int, episode: int, eps: float,
                        session: str):
        self.parameters_helper.save_parameters(total_steps=total_steps,
                                               episode=episode,
                                               eps=eps,
                                               session=session)

    def load_parameters(self):
        return self.parameters_helper.load_parameters()
Exemplo n.º 7
0
def write_distances(csv_file, json_file):
    original_csv_file = CsvHelper(csv_file)
    new_csv_file = CsvHelper(f"new_props_{time.time()}")
    distance_matrix = JsonHelper(json_file).read()

    try:
        for index, row in enumerate(original_csv_file.read()):
            key = str(index + 1)

            if key in distance_matrix:
                result = DistanceMatrix.to_h(distance_matrix[key])

                price = int(row["Price"].replace("£",
                                                 "").replace("$", "").replace(
                                                     "€", "").replace(",", ""))
                row["Price"] = price
                address_index = 10

                row_keys = list(row.keys())
                row_values = list(row.values())

                postal_info = Postal(row["Address"]).info()
                postal_length = len(postal_info)

                postal_keys = list(postal_info.keys())
                for index, key in enumerate(postal_keys):
                    offset_index = address_index + index + 1
                    row_keys.insert(offset_index, key)

                postal_values = list(postal_info.values())
                for index, value in enumerate(postal_values):
                    offset_index = address_index + index + 1
                    row_values.insert(offset_index, value)

                keys = list(result.keys())
                for index, key in enumerate(keys):
                    offset_index = address_index + postal_length + index + 1
                    row_keys.insert(offset_index, key)

                values = list(result.values())
                for index, value in enumerate(values):
                    offset_index = address_index + postal_length + index + 1
                    row_values.insert(offset_index, value)

                new_row = dict(zip(row_keys, row_values))
                new_csv_file.write(new_row)
    finally:
        original_csv_file.file.close()
        new_csv_file.file.close()
Exemplo n.º 8
0
 def get_account_json(cls, account_id):
     return JsonHelper.to_json(cls.get_account_object(account_id))
Exemplo n.º 9
0
def accounts():
    return JsonHelper.to_json([])
Exemplo n.º 10
0
def hello():
    return JsonHelper.build_action_response(None, "Hello World from Flask")
Exemplo n.º 11
0
                        cg = CommandGenerator()
                        command = cg.orb(filename=filename,
                                         path_to_orb=PATH_TO_ORB_SLAM,
                                         path_to_data=PATH_TO_TMP_DIR,
                                         path_to_config=PATH_TO_CONFIG,
                                         dataset=dataset,
                                         resolution=resolution)
                        print("Running ORB slam on {}!".format(filename))
                        t1 = time.perf_counter()
                        process = subprocess.Popen(command, shell=True)
                        process.wait()
                        t2 = time.perf_counter()

                        # write the elapsed time to json file
                        elapsed = t2 - t1
                        jh = JsonHelper()
                        jh.add_json(
                            os.path.join(res_orb_data_dir, "results.txt"),
                            "processing_time", elapsed)

                        # try to copy the output in the right place
                        try:
                            shutil.move(
                                "KeyFrameTrajectory.txt",
                                os.path.join(res_orb_data_dir,
                                             "estimated_data.txt"))
                            shutil.move(
                                "pq.ply",
                                os.path.join(res_orb_data_dir,
                                             "PointCloud.txt"))
                            point_cloud_gt_path = os.path.join(
Exemplo n.º 12
0
 def __init__(self):
     self.url_dict = {}
     self.json_helper = JsonHelper("short_links.json")
     self.link_length = 10
     self.port = os.getenv("PORT", 5000)
     self.load_from_file()
Exemplo n.º 13
0
from json_helper import JsonHelper
from companies_comparison import CompaniesComparison

MIN_CRITERIA_NUM = 4

with open('companiesComparisonWidgetInput.json', 'r') as content_file:
    content = content_file.read()

company_to_labels = JsonHelper.convert_companies_json_to_dictionary(content)

all_companies_with_all_labels_dict,max_companies_dict,all_with_max_dict = \
    CompaniesComparison.find_groups_with_size(company_to_labels, MIN_CRITERIA_NUM)

print "All combinations of all companies with all combinations of shared creterias of size %s:" % MIN_CRITERIA_NUM
print JsonHelper.convert_companies_to_labels_list_to_json(
    all_companies_with_all_labels_dict) + '\n'

print 'All the Maximum number of companies that have a shared creteria of %s:' % MIN_CRITERIA_NUM
print JsonHelper.convert_companies_to_labels_list_to_json(
    max_companies_dict) + '\n'

print 'All the Companies combinations with their max shared cretierias that have a minimum shared creteria of %s:' % MIN_CRITERIA_NUM
print JsonHelper.convert_companies_to_labels_list_to_json(
    all_with_max_dict) + '\n'
Exemplo n.º 14
0
 def __init__(self, ckpt_path: str, parameters_path: str):
     self.ckpt_path = ckpt_path
     self.parameters_path = parameters_path
     self.parameters_helper = JsonHelper(self.parameters_path)