def get_time_series_list(articule): conn = database_connection.DatabaseConnection() filials_set = conn.get_filials_for_articule(articule, start_date, end_date, min_days=40) silpo_fora_trash_filials_set = conn.get_silpo_fora_trash_filials_set() filials_set = filials_set.intersection(silpo_fora_trash_filials_set) print("Number of filials:", len(filials_set)) list_of_time_series = [] filials_list = [] epsilon = 0.1 for filial in filials_set: df = conn.get_all_sales_by_articule_and_filial_with_residues( articule, filial, start_date, end_date) normed_quantities = (df['quantity'].values + epsilon) / REFERENCE_LEVEL is_promo_day = df['is_promo_day'].values residues = df['residue'].values normed_quantities = normed_quantities[(np.logical_not(is_promo_day)) & (residues > 0)] if len(normed_quantities) > 20: list_of_time_series.append(normed_quantities) filials_list.append(filial) return filials_list, list_of_time_series
def on_rx_done(self): logging.debug("IRQ_RX") logging.info("RSSI: " + str(self.get_pkt_rssi_value()) + " dBm; SNR: " + str(self.get_pkt_snr_value()) + " dBm") self.clear_irq_flags(RxDone=1) # check the CrcOnPayload bit in the register and check for CRC errors on the payload if self.get_hop_channel().get( 'crc_on_payload') == 1 and self.get_irq_flags().get( 'crc_error') == 0: logging.debug("Packet integrity ok, continuing") payload = self.read_payload(nocheck=True) logging.info("Payload: {}".format( bytes(payload).decode("utf-8", 'ignore'))) records = list( filter(None, bytes(payload).decode("utf-8", 'ignore').split(";"))) record_count = len(records) - 1 db = database_connection.DatabaseConnection() machine = records[0] saved = False for i in range(1, record_count): row = records[i].split(",") id_external = row[0] motor_name = row[1] start_time = row[2] # logging.debug("Saving {} : {} : {} : {} to database".format(motor_name, start_time, tran_id, machine)) saved = db.save_records(motor_name, start_time, id_external, machine) if not saved: # something happened when saving one of the records, do not send ACK logging.warning("Could not save records, not sending ACK") break if saved: db.close_connection() time.sleep(2) logging.info("Saved {} records".format(record_count)) logging.debug("Sending ACK") self.write_payload([65, 67, 75]) # Send ACK self.set_mode(MODE.TX) time.sleep(2) else: logging.debug("CRC error") logging.debug("Switching back to continuous receive mode") self.reset_ptr_rx() self.set_mode(MODE.RXCONT)
def connect_to_db(self, database_name, country): """ connect to a database, for a given country. return a pandas dataframe. :param database_name: the name of the database :param country: the code of the country (i.e. gr, es, nl, pt) :return: a pandas db that is readable by biogeme """ # connect to the database sql = database_connection.DatabaseConnection(database_name) if country == 'ES': # FIXME remove the workaround, once we have data for ES country = 'GR' # select data from the database, for the country that is currently being estimated sql.run_query(sql.select_data, { 'table_name': 'mode_choice_data', 'columns': [ 'trip_comfort_car', 'trip_comfort_moto', 'trip_comfort_pt', 'trip_cost_car', 'trip_cost_moto', 'trip_cost_pt', 'trip_dur_car', 'trip_dur_moto', 'trip_dur_pt', 'trip_purpose', 'AGE', 'user_gender', 'user_occupation', 'user_trips_car', 'user_trips_pt', 'user_car_avail', 'user_bike_avail', 'user_moto_avail', 'user_choice' ], 'where_cols': [ 'user_country' ], 'where_values': [ country ] }) # store data in a pandas dataframe, readable by biogeme pandas_df_for_specified_country = pd.DataFrame(data=sql.output).transpose() return pandas_df_for_specified_country
def connect_to_db(self, database_name, country): """ connect to a database, for a given country. return a pandas dataframe. :param database_name: the name of the database :param country: the code of the country (i.e. gr, es, nl, pt) :return: a pandas db that is readable by biogeme """ # connect to the database sql = database_connection.DatabaseConnection(database_name) if country == 'ES': country = 'GR' # FIXME remove the workaround, once we have data for ES # select data from the database, for the country that is currently being estimated sql.run_query( sql.select_data, { 'table_name': 'departure_time_data', 'columns': [ 'trip_dur_earlier', 'trip_walk_earlier', 'trip_freq_earlier', 'trip_dur_ontime', 'trip_walk_ontime', 'trip_freq_ontime', 'trip_dur_later', 'trip_walk_later', 'trip_freq_later', 'trip_discount_earlier', 'trip_discount_later', 'trip_discount_ontime', 'user_gender', 'user_imp_arr', 'trip_purpose', 'AGE', 'user_income', 'user_household', 'user_trips_pt', 'user_choice' ], 'where_cols': ['user_country'], 'where_values': [country] }) # store data in a pandas dataframe, readable by biogeme pandas_df_for_specified_country = pd.DataFrame( data=sql.output).transpose() pandas_df_for_specified_country.replace('Null', 0) return pandas_df_for_specified_country
import sys import torch import torch.nn as nn import database_connection start_time = time.time() start_date = "'2019-04-01'" end_date = "'2019-08-31'" articule = 32485 # 361771 519429 97143 32547 32485 117 reference_level = 1.0 # 1000.0 conn = database_connection.DatabaseConnection() filials_set = conn.get_filials_for_articule(articule, start_date, end_date, min_days=40) silpo_fora_trash_filials_set = conn.get_silpo_fora_trash_filials_set() filials_set = filials_set.intersection(silpo_fora_trash_filials_set) print("Number of filials:", len(filials_set)) list_of_time_series = [] filials_list = list(filials_set) for filial in filials_list: df = conn.get_all_sales_by_articule_and_filial_with_residues(articule, filial, start_date, end_date) list_of_time_series.append(df['quantity'].values/reference_level) rnn = nn.RNN(input_size=1, hidden_size=2, num_layers=1, batch_first=False)
def __init__(self): self.db_conn_stack = db.DatabaseConnection("openstackDB") self.db_conn_stack = self.db_conn_stack.getConn() self.db_conn_local = db.DatabaseConnection("openauditDB") self.db_conn_local = self.db_conn_local.getConn()
def __init__(self, snapshot_id): self.db_conn = db.DatabaseConnection("openauditDB") self.db_conn = self.db_conn.getConn() self.snap = snapshot.Snapshot() self.snap.id = snapshot_id
def __init__(self): self.db_conn = db.DatabaseConnection("openauditDB") self.db_conn = self.db_conn.getConn();