def start_sync_file_queries(mode, file, chartname): queries_dict = get_queries(file) keys = list(queries_dict.keys()) print(keys) keys_list = [] #mode "normal" pas de changement on fait les requetes a la suite comme elles sont dans le dict if mode == 0: keys_list = keys #mode double : on fait chaque requete 2 fois a la suite elif mode == 1: for e in keys: keys_list.append(e) keys_list.append(e) #mode aleatoire : on melange les requetes aleatoirement elif mode == 2: keys_list = random.sample(keys, len(keys)) elif mode == 3: keys.reverse() keys_list = keys starts = [] ends = [] #START CONNECTION connection = co.create_connection("postgis_test", "postgres", "admin", "localhost", "5432") f = open("results_seq_{}.txt".format(mode), "w") for key in keys_list: print(key) starts.append(time.perf_counter()) results = qu.execute_read_query(connection, queries_dict[key]) ends.append(time.perf_counter()) values = results[0] runtime_exe = results[1] runtime_fetchall = results[2] ratio = (runtime_fetchall / runtime_exe + runtime_fetchall) * 100 f.write( "{} executed in {} seconds and fetched in {} seconds \n ratio : {} % \n" .format(key, runtime_exe, runtime_fetchall, ratio)) f.close() bd.plot_start_end(starts, ends, chartname)
def latest(cls) -> "Poll": connection = create_connection() poll = database.get_latest_poll(connection) connection.close() return cls(poll[1], poll[2], poll[0])
def all(cls) -> List["Poll"]: connection = create_connection() polls = database.get_polls(connection) connection.close() return [cls(poll[1], poll[2], poll[0]) for poll in polls]
def get(cls, poll_id: int) -> "Poll": connection = create_connection() poll = database.get_poll(connection, poll_id) connection.close() return cls(poll[1], poll[2], poll[0])
def options(self) -> List[Option]: connection = create_connection() options = database.get_poll_options(connection, self.id) connection.close() return [Option(option[1], option[2], option[0]) for option in options]
def save(self): connection = create_connection() new_poll_id = database.create_poll(connection, self.title, self.owner) connection.close() self.id = new_poll_id
def votes(self) -> List[database.Vote]: connection = create_connection() votes = database.get_votes_for_option(connection, self.id) connection.close() return votes
def vote(self, username:str): connection = create_connection() database.add_poll_vote(connection, username, self.id)
def get(cls, option_id: int) -> "Option": connection = create_connection() option = database.get_option(connection, option_id) connection.close() return cls(option[1], option[2], option[0])
def save(self): connection = create_connection() new_option_id = database.add_option(connection, self.text, self.poll_id) connection.close() self.id = new_option_id