def index_country(self, root_model): boats_data = Etl_data.open_json("recommandation_boats", root_model) index_country = Etl_data.open_json("indexed_countryt", root_model) unique_country = list(boats_data.country.unique()) for i in range(0, len(unique_country)): one_index = index_country[index_country["label"] == unique_country[i]] for index, one_contry in one_index.iterrows(): boats_data.loc[boats_data['country'] == unique_country[i], ['country']] = one_contry["index"] return index_country, boats_data
def destination_boat_statetique(root_model, id_location, api_all_boats): df_boats = Etl_data.open_json("data_boat_destination_statestique", root_model) df_boats = df_boats[df_boats["id"] == id_location] boat = list(df_boats.id_gen.unique()) df_score = [] for i in range(0, len(boat)): score = 0 one_boat = pd.DataFrame(df_boats[df_boats["id_gen"] == boat[i]]) score = len(one_boat) df_score.append({"id_gen": boat[i], "score": score}) df_score = pd.DataFrame(df_score) all_boats = Etl_data.web_service_response(api_all_boats) all_boats = all_boats.rename(columns={'generic': 'id_gen'}) all_boats = all_boats.drop_duplicates(subset="id_gen", keep="first") df_boats = pd.merge(df_score, all_boats, on='id_gen', how='inner') df_final = [] for index, boat in df_boats.iterrows(): df_final.append({ "id_gen": boat["id_gen"], "name_boat": boat["boat_brand"] + " " + boat["boat_model"] + " " + boat["shipyard_name"], "score": boat["score"] }) return df_final
def courbe_destination(self, root_model, location=21): destination = Etl_data.open_json("data_Ml_destination", root_model) destination = destination[destination["id"] == location] destination = self.rank(destination) destination = pd.DataFrame(destination) df_destination_choix = self.reg_time(destination) return df_destination_choix.to_dict('records')
def found_all_year(root_model): df_destination = Etl_data.open_json("data_Ml_destination", root_model) df_final = [] one_year = list(df_destination.year.unique()) for i in range(0, len(one_year)): df_final.append({'year': one_year[i]}) return sorted(df_final, key=lambda k: k["year"], reverse=False)
def all_boats_destination(root_model, api_all_boat, api_all_destination): boats_destination = Etl_data.open_json( "data_boat_destination_statestique", root_model) all_boat = Statestique_bosts.all_boats(api_all_boat) all_boat = pd.DataFrame(all_boat) df_boats = boats_destination.drop_duplicates(subset="id_gen", keep="first") df_boats = pd.merge(df_boats, all_boat, on='id_gen', how='inner') df_boats = df_boats.to_dict('records') df_boats = sorted(df_boats, key=lambda k: k["name"], reverse=False) all_destination = Etl_data.web_service_response(api_all_destination) df_destenation = boats_destination.drop_duplicates(subset="id", keep="first") all_destination = all_destination[all_destination["ref_language"] == "1"] all_destination = all_destination.rename(columns={'location_id': 'id'}) df_destenation = pd.merge(df_destenation, all_destination, on='id', how='inner') df_destenation = df_destenation.to_dict('records') df_destenation = sorted(df_destenation, key=lambda k: k["location_name"], reverse=False) return df_destenation, df_boats
def country_boat_statistique(root_model, code_country): df_boats = Etl_data.open_json("recommandation_boats", root_model) df_boats = df_boats[df_boats["country"] == code_country] boat = list(df_boats.name.unique()) df_score = [] for i in range(0, len(boat)): one_boat = pd.DataFrame(df_boats[df_boats["name"] == boat[i]]) for index, bateaux in one_boat.iterrows(): df_score.append({"counts": bateaux["counts"], 'name': boat[i]}) df_final = pd.DataFrame(df_score) return df_final.to_dict('records')
def number_request_allyear_statistique(root_model): df_destination = Etl_data.open_json("data_Ml_destination", root_model) one_year = list(df_destination.year.unique()) df_final = [] for i in range(0, len(one_year)): one_boat = pd.DataFrame( df_destination[df_destination["year"] == one_year[i]]) score = 0 for index, one_data_frame in one_boat.iterrows(): score = score + one_data_frame['counts'] df_final.append({'year': one_year[i], 'counts': score}) return sorted(df_final, key=lambda k: k["year"], reverse=True)
def country_alldestnation_statistique(root_model, code_country): df_destination = Etl_data.open_json("recommendation_destination", root_model) indexed_country = Etl_data.open_json("indexed_country", root_model) index_c = indexed_country[indexed_country["label"] == code_country.upper()] for index, country in index_c.iterrows(): df_destination = df_destination[df_destination["country"] == country['index']] destination = list(df_destination.destination.unique()) df_score = [] for i in range(0, len(destination)): one_boat = pd.DataFrame(df_destination[ df_destination["destination"] == destination[i]]) for index, des in one_boat.iterrows(): df_score.append({ "counts": des["counts"], 'name': destination[i] }) df_final = pd.DataFrame(df_score) return df_final.to_dict('records')
def satestique_boat_generique(self, id_generic, root_model): boats = Etl_data.open_json("data_boat_destination_statestique", root_model) df_boats = boats[boats["id_gen"] == id_generic] if len(df_boats) < 1: return {"dates": "", "score": 0} df_boats = self.rank_boat(df_boats) df_boats = pd.DataFrame(df_boats) df_boats["dates"] = pd.DatetimeIndex(data=df_boats.dates) df_boats = df_boats.sort_values(by='dates') df_boats["dates"] = df_boats["dates"].dt.strftime('%Y/%m') return df_boats.to_dict('records')
def top_boats(api_all_boats, root_model): boats = Etl_data.open_json("data_boat_destination_statestique", root_model) all_boat = Statestique_bosts.all_boats(api_all_boats) boat = list(boats.id_gen.unique()) df_score = [] for i in range(0, len(boat)): one_boat = pd.DataFrame(boats[boats["id_gen"] == boat[i]]) score = len(one_boat) df_score.append({"id_gen": boat[i], "score": score}) df_score = pd.DataFrame( sorted(df_score, key=lambda k: k["score"], reverse=True)) all_boat = pd.DataFrame(all_boat) df_boats = pd.merge(df_score, all_boat, on='id_gen', how='inner') return df_boats.to_dict('records')
def found_tuple(self, root_model, api_all_destination): all_destination = Etl_data.web_service_response(api_all_destination) destination = Etl_data.open_json("data_Ml_destination", root_model) all_destination = all_destination[all_destination["ref_language"] == "1"] unique = list(destination.id.unique()) id_destination_f = [] for i in range(0, len(unique)): id_destination = all_destination[all_destination["location_id"] == unique[i]] for index, des in id_destination.iterrows(): id_destination_f.append({ "id": des["location_id"], "destination": des["location_name"] }) return sorted(id_destination_f, key=lambda k: k["destination"], reverse=False)
def country_destinaion_statistique(root_model, code_country, id_destination): df_destination = Etl_data.open_json("data_Ml_destination", root_model) df_destination = df_destination[df_destination["country"] == code_country] df_destination = df_destination[df_destination["id"] == id_destination] list_destination = [] for index, destination in df_destination.iterrows(): list_destination.append({ "dates": destination["month"] + "/" + destination["year"], "counts": destination["counts"] }) statis = Statestique_all_destination() list_destination = pd.DataFrame(list_destination) if len(list_destination) > 0: list_destination = statis.reg_time(list_destination) return list_destination.to_dict('records')
def top_destination_request(root_model, api_all_destination): df_destination = Etl_data.open_json("data_Ml_destination", root_model) all_destination = Etl_data.web_service_response(api_all_destination) all_destination = all_destination[all_destination["ref_language"] == "1"] destination = list(df_destination.id.unique()) df_score = [] for i in range(0, len(destination)): one_destination = pd.DataFrame( df_destination[df_destination["id"] == destination[i]]) score = 0 for index, des in one_destination.iterrows(): score = score + des["counts"] df_score.append({"location_id": destination[i], "score": score}) df_score = pd.DataFrame( sorted(df_score, key=lambda k: k["score"], reverse=True)) df_destination = pd.merge(df_score, all_destination, on='location_id', how='inner') return df_destination.to_dict('records')
def boat_type_destination(self, root_model, id_location, api_all_boats): df_boats = Etl_data.open_json("data_boat_destination_statestique", root_model) df_boats = df_boats[df_boats["id"] == id_location] req_generic = Etl_data.web_service_response(api_all_boats) req_generic = req_generic.rename(columns={'boat_id': 'id_gen'}) df_boats = pd.merge(df_boats, req_generic, on='id_gen', how='inner') df_boats_type = [] motoryacht = 0 monohull = 0 catamaran = 0 for index, boat in df_boats.iterrows(): if boat["hull"].upper() == "MONOHULL": if boat["propulsion"].upper() == "SAILING": monohull = monohull + 1 else: motoryacht = motoryacht + 1 else: catamaran = catamaran + 1 df_boats_type.append({'label': 'Catamaran', 'value': catamaran}) df_boats_type.append({'label': 'Monohull', 'value': monohull}) df_boats_type.append({'label': 'Motoryacht', 'value': motoryacht}) return df_boats_type
def __init__(self, root_model, name_model): self.df_boats_destination = Etl_data.open_json( "data_final_boats_destination", root_model) self.training_model(self.df_boats_destination, root_model, name_model)
def __init__(self, root_model, name_model): self.path = root_model self.name_model = name_model self.boat_data = Etl_data.open_json('data_Ml_boat', self.path) self.training_data_boat()
def score_ml_destination(self, root_model): score = Etl_data.open_json("score_ml_destination", root_model) for index, sc in score.iterrows(): return sc["scoretrai"], sc["scoretes"], sc["errortr"], sc[ "errorte"]