def __init__(self, parent, controller, username): super().__init__(parent) self.controller = controller self.parent = parent self.username = username self.db = Database() self.predictor = Predictor() self.create_widgets()
class Predictor: def __init__(self, url=None): self.db = Database() self.engine_client_class = predictionio.EngineClient(url="http://192.168.1.127:8000") self.engine_client_rec = predictionio.EngineClient(url="http://192.168.1.127:8001") self.event_client = predictionio.EventClient(access_key="6S_JIW0eesru9ea5NsTwO0dIBea-Q8Wp2tBX7Kh8EojF4KRme8JTnqpr5J0M1hTk", url="http://192.168.1.127:7070", threads=5, qsize=500) def predict_company(self, name): features = self.db.read_company("*", "name", name) X = self.transform_features(features[0]) result = self.engine_client_class.send_query(X) result_dict = {'operating': 0, 'closed': 1, 'acquired': 2} result_dict_inverted = {} for key in result_dict.keys(): result_dict_inverted[result_dict[key]] = key return result_dict_inverted[result['status']] def transform_features(self, features): feature_names = ["name", "market", "total_investment", "funding_rounds", "founded_at", "first_funding_at", "last_funding_at"] elements = {} i = 0 for f in feature_names: elements[f] = features[i] i += 1 X = pd.DataFrame(elements, columns=["name", "market", "total_investment", "funding_rounds", "founded_at", "first_funding_at", "last_funding_at"], index = [0]) X['age_first_funding'] = (X['first_funding_at'] - X['founded_at']) / pd.Timedelta(days=365) X['age_last_funding'] = (X['last_funding_at'] - X['founded_at']) / pd.Timedelta(days=365) X['market'] = X['market'].apply(lambda s: s.strip()) dict_market = {'Other': 0, 'Software': 1, 'Curated Web': 2, 'Analytics': 3, 'E-Commerce': 4, 'Games': 5, 'Semiconductors': 6, 'Clean Technology': 7, 'Finance': 8, 'Mobile': 9, 'Biotechnology': 10, 'Search': 11, 'Advertising': 12, 'Security': 13, 'Health Care': 14, 'Enterprise Software': 15, 'Social Media': 16, 'Messaging': 17, 'Web Hosting': 18, 'Hardware + Software': 19, 'Education': 20} X['market'] = X['market'].map(dict_market) X = X[["market", "total_investment", "funding_rounds", "age_first_funding", "age_last_funding"]] features_dict = {} for i in range(len(X)): count = 0 for val in X.iloc[i]: features_dict[X.iloc[i].index[count]] = val count += 1 return features_dict def predict_consigliati(self, username): X = {"user": username, "num":30} result = self.engine_client_rec.send_query(X) if(len(result['itemScores']) == 0): return [{'item': "Nessun elemento consigliato"}] return result['itemScores'] def insert_consigliato(self, username, name): self.event_client.create_event(event="interested", entity_type="user", entity_id=username, target_entity_type="company", target_entity_id=name) def insert_nonconsigliato(self, username, name): self.event_client.create_event(event="notinterested", entity_type="user", entity_id=username, target_entity_type="company", target_entity_id=name)
def __init__(self, url=None): self.db = Database() self.engine_client_class = predictionio.EngineClient(url="http://192.168.1.127:8000") self.engine_client_rec = predictionio.EngineClient(url="http://192.168.1.127:8001") self.event_client = predictionio.EventClient(access_key="6S_JIW0eesru9ea5NsTwO0dIBea-Q8Wp2tBX7Kh8EojF4KRme8JTnqpr5J0M1hTk", url="http://192.168.1.127:7070", threads=5, qsize=500)
def __init__(self, parent, controller): super().__init__(parent) self.controller = controller self.db = Database() self.create_widgets()
class Registrazione(Frame): def __init__(self, parent, controller): super().__init__(parent) self.controller = controller self.db = Database() self.create_widgets() def create_widgets(self): self.register_label = Label(self, text="Registrazione", font=("bold", 25), pady=20) self.register_label.place(relx=0.5, rely=0.1, anchor=CENTER) self.nome_label = Label(self, text="Nome:", font=(18)) self.nome_label.place(relx=0.3, rely=0.2, anchor=CENTER) self.nome_text = StringVar() self.nome_textbox = Entry(self, width=20, textvariable=self.nome_text) self.nome_textbox.place(relx=0.5, rely=0.2, anchor=CENTER) self.cognome_label = Label(self, text="Cognome:", font=(18)) self.cognome_label.place(relx=0.3, rely=0.3, anchor=CENTER) self.cognome_text = StringVar() self.cognome_textbox = Entry(self, width=20, textvariable=self.cognome_text) self.cognome_textbox.place(relx=0.5, rely=0.3, anchor=CENTER) self.username_label = Label(self, text="Username:"******"Password:"******"*") self.password_textbox.place(relx=0.5, rely=0.5, anchor=CENTER) self.conferma_password_label = Label(self, text="Conferma password:"******"*") self.conferma_password_textbox.place(relx=0.5, rely=0.6, anchor=CENTER) self.registrazione_button = Button(self, text="Registrati", font=(18), width=10, command=lambda: self.registrato()) self.registrazione_button.place(relx=0.5, rely=0.7, anchor=CENTER) self.indietro_button = Button( self, text="Indietro", font=(18), width=10, command=lambda: self.controller.show_frame(LoginPage.Login)) self.indietro_button.place(relx=0.5, rely=0.8, anchor=CENTER) def registrato(self): if (len(self.nome_text.get()) < 3): error = Label(self, text="Errore: nome troppo corto.", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return if (len(self.cognome_text.get()) < 2): error = Label(self, text="Errore: cognome troppo corto.", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return if (len(self.username_text.get()) < 3): error = Label(self, text="Errore: username troppo corto.", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return if (len(self.password_text.get()) < 5): error = Label(self, text="Errore: password troppo corta.", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return if (self.conferma_password_text.get() != self.password_text.get()): error = Label(self, text="Errore: le password non coincidono", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return users = self.db.read_user("username", "username", self.username_text.get()) if (len(users) != 0): error = Label(self, text="Esiste già un utente con qesto username.", font=(18), fg="red") error.place(relx=0.5, rely=0.65, anchor=CENTER) return self.db.insert_user(self.username_text.get(), self.nome_text.get(), self.cognome_text.get(), self.password_text.get()) self.controller.show_frame(HomePage.Home, self.username_text.get())
class CreateCompany(Frame): def __init__(self, parent, controller, username): super().__init__(parent) self.controller = controller self.username = username self.db = Database() self.create_widgets() def create_widgets(self): self.register_label = Label(self, text="Aggiungi un'azienda", font=("bold", 25), pady=20) self.register_label.place(relx=0.5, rely=0.1, anchor=CENTER) self.nome_label = Label(self, text="Nome:", font=(18)) self.nome_label.place(relx=0.3, rely=0.2, anchor=CENTER) self.nome_text = StringVar() self.nome_textbox = Entry(self, width=20, textvariable=self.nome_text) self.nome_textbox.place(relx=0.5, rely=0.2, anchor=CENTER) markets = [ 'Other', 'Software', 'Curated Web', 'Analytics', 'E-Commerce', 'Games', 'Semiconductors', 'Clean Technology', 'Finance', 'Mobile', 'Biotechnology', 'Search', 'Advertising', 'Security', 'Health Care', 'Enterprise Software', 'Social Media', 'Messaging', 'Web Hosting', 'Hardware + Software', 'Education' ] self.market_label = Label(self, text="Settore:", font=(18)) self.market_label.place(relx=0.3, rely=0.3, anchor=CENTER) self.market_text = StringVar() self.market_combobox = ttk.Combobox(self, values=markets) self.market_combobox.place(relx=0.5, rely=0.3, anchor=CENTER) self.total_investment_label = Label(self, text="Totale fondi ricevuti:", font=(18)) self.total_investment_label.place(relx=0.3, rely=0.4, anchor=CENTER) self.total_investment_text = StringVar() self.total_investment_textbox = Entry( self, width=20, textvariable=self.total_investment_text) self.total_investment_textbox.place(relx=0.5, rely=0.4, anchor=CENTER) self.funding_rounds_label = Label(self, text="Numero investimenti ricevuti:", font=(18)) self.funding_rounds_label.place(relx=0.3, rely=0.5, anchor=CENTER) self.funding_rounds_text = StringVar() self.funding_rounds_textbox = Entry( self, width=20, textvariable=self.funding_rounds_text) self.funding_rounds_textbox.place(relx=0.5, rely=0.5, anchor=CENTER) self.founded_at_label = Label(self, text="Fondata nel:", font=(18)) self.founded_at_label.place(relx=0.3, rely=0.6, anchor=CENTER) self.founded_at_cal = tkcalendar.DateEntry(self, bg="darkblue", fg="white") self.founded_at_cal.place(relx=0.5, rely=0.6, anchor=CENTER) self.first_funding_at_label = Label(self, text="Data primo investimento:", font=(18)) self.first_funding_at_label.place(relx=0.3, rely=0.7, anchor=CENTER) self.first_funding_at_cal = tkcalendar.DateEntry(self, bg="darkblue", fg="white") self.first_funding_at_cal.place(relx=0.5, rely=0.7, anchor=CENTER) self.last_funding_at_label = Label(self, text="Data ultimo investimento:", font=(18)) self.last_funding_at_label.place(relx=0.3, rely=0.8, anchor=CENTER) self.last_funding_at_cal = tkcalendar.DateEntry(self, bg="darkblue", fg="white") self.last_funding_at_cal.place(relx=0.5, rely=0.8, anchor=CENTER) self.inserimento_button = Button(self, text="Inserisci azienda", font=(18), width=20, command=lambda: self.inserisci()) self.inserimento_button.place(relx=0.5, rely=0.9, anchor=CENTER) self.indietro_button = Button(self, text="Indietro", font=(18), width=10, command=lambda: self.controller. show_frame(HomePage.Home, self.username)) self.indietro_button.place(relx=0.5, rely=0.95, anchor=CENTER) def inserisci(self): if (len(self.nome_text.get()) < 3): error = Label(self, text="Errore: nome troppo corto.", font=(18), fg="red") error.place(relx=0.5, rely=0.85, anchor=CENTER) return if (len(self.market_combobox.get()) == 0): error = Label(self, text="Errore: selezionare un settore.", font=(18), fg="red") error.place(relx=0.5, rely=0.85, anchor=CENTER) return try: float(self.total_investment_text.get()) except: error = Label( self, text= "Errore: il totale dei fondi ricevuti deve essere numerico.", font=(18), fg="red") error.place(relx=0.5, rely=0.85, anchor=CENTER) return try: int(self.funding_rounds_text.get()) except: error = Label( self, text= "Errore: il numero di investimenti ricevuti deve essere un numero intero.", font=(18), fg="red") error.place(relx=0.5, rely=0.85, anchor=CENTER) return companies = self.db.read_company("name", "name", self.nome_text.get()) if (len(companies) != 0): error = Label(self, text="Esiste già un'azienda con qesto username.", font=(18), fg="red") error.place(relx=0.5, rely=0.85, anchor=CENTER) return self.db.insert_company(self.nome_text.get(), self.market_combobox.get(), float(self.total_investment_text.get()), int(self.funding_rounds_text.get()), self.founded_at_cal.get_date(), self.first_funding_at_cal.get_date(), self.last_funding_at_cal.get_date()) self.controller.show_frame(HomePage.Home, self.username)
class Home(Frame): def __init__(self, parent, controller, username): super().__init__(parent) self.controller = controller self.parent = parent self.username = username self.db = Database() self.predictor = Predictor() self.create_widgets() def create_widgets(self): self.login_label = Label( self, text="Benvenuto %s %s." % (self.db.read_user("nome", "username", self.username)[0][0], self.db.read_user("cognome", "username", self.username)[0][0]), font=("bold", 19)) self.login_label.place(relx=0.01, rely=0.01, anchor=NW) self.profilo_button = Button( self, text="Profilo", font=(18), width=10, command=lambda: self.controller.show_frame(ProfiloPage.Profilo, self.username)) self.profilo_button.place(relx=0.85, rely=0.01, anchor=NE) self.logout_button = Button( self, text="Logout", font=(18), width=10, command=lambda: self.controller.show_frame(LoginPage.Login)) self.logout_button.place(relx=0.99, rely=0.01, anchor=NE) self.separator = ttk.Separator(self, orient="horizontal") self.separator.place(relx=0, rely=0.055, relwidth=2, relheight=0.02, anchor=N) self.interessi_frame = LabelFrame(self, text="I tuoi interessi", font=("bold", 18), height=20) self.interessi_frame.place(relx=0.2, rely=0.5, relheight=0.85, relwidth=0.3, anchor=CENTER) self.interessi_list = Listbox(self.interessi_frame) self.interessi_list.place(relx=0.47, rely=0.5, relheight=0.95, relwidth=0.85, anchor=CENTER) self.interessi_scrollbar = Scrollbar(self.interessi_frame) self.interessi_scrollbar.pack(side=RIGHT, fill=Y) self.interessi_list.configure( yscrollcommand=self.interessi_scrollbar.set) self.interessi_scrollbar.configure(command=self.interessi_list.yview) self.populate_interessi_list() self.interessi_list.bind("<Double-1>", self.select_item_interessi) self.consigliati_frame = LabelFrame(self, text="Esplora", font=("bold", 18), height=20) self.consigliati_frame.place(relx=0.5, rely=0.5, relheight=0.85, relwidth=0.3, anchor=CENTER) self.consigliati_list = Listbox(self.consigliati_frame) self.consigliati_list.place(relx=0.47, rely=0.5, relheight=0.95, relwidth=0.85, anchor=CENTER) self.consigliati_scrollbar = Scrollbar(self.consigliati_frame) self.consigliati_scrollbar.pack(side=RIGHT, fill=Y) self.consigliati_list.configure( yscrollcommand=self.consigliati_scrollbar.set) self.consigliati_scrollbar.configure( command=self.consigliati_list.yview) self.populate_consigliati_list() self.consigliati_list.bind("<Double-1>", self.select_item_consigliati) self.cerca_frame = LabelFrame(self, text="Cerca", font=("bold", 18), height=20) self.cerca_frame.place(relx=0.8, rely=0.5, relheight=0.85, relwidth=0.3, anchor=CENTER) self.cerca_list = Listbox(self.cerca_frame) self.cerca_list.place(relx=0.47, rely=0.52, relheight=0.9, relwidth=0.85, anchor=CENTER) self.cerca_text = StringVar() self.cerca_textbox = Entry(self.cerca_frame, textvariable=self.cerca_text) self.cerca_textbox.place(relx=0.36, rely=0.03, anchor=CENTER) self.cerca_button = Button(self.cerca_frame, text="Cerca", command=self.populate_cerca_list) self.cerca_button.place(relx=0.78, rely=0.028, anchor=CENTER) self.cerca_scrollbar = Scrollbar(self.cerca_frame) self.cerca_scrollbar.pack(side=RIGHT, fill=Y) self.cerca_list.configure(yscrollcommand=self.cerca_scrollbar.set) self.cerca_scrollbar.configure(command=self.cerca_list.yview) self.cerca_list.bind("<Double-1>", self.select_item_cerca) def populate_interessi_list(self): interessi = self.db.read_interested("name", "username", self.username) if (len(interessi) == 0): self.interessi_list.insert( END, "Non sei interessato a nessuna azienda") return for row in interessi: self.interessi_list.insert(END, row[0]) def populate_cerca_list(self): self.cerca_list.delete(0, self.cerca_list.size()) risultati = self.db.read_company("*", "name", self.cerca_text.get()) if (len(risultati) == 0): self.cerca_list.insert(END, "Nessun risultato. Aggiungi l'azienda") return for row in risultati: self.cerca_list.insert(END, row[0]) def populate_consigliati_list(self): result = self.predictor.predict_consigliati(self.username) for row in result: self.consigliati_list.insert(END, row['item']) def select_item_interessi(self, event): index = self.interessi_list.curselection()[0] name = self.interessi_list.get(index) if (name != "Non sei interessato a nessuna azienda"): self.controller.show_frame(CompanyPage.Company, self.username, name) def select_item_consigliati(self, event): index = self.consigliati_list.curselection()[0] name = self.consigliati_list.get(index) if (name != "Nessun elemento consigliato"): self.controller.show_frame(CompanyPage.Company, self.username, name) def select_item_cerca(self, event): index = self.cerca_list.curselection()[0] name = self.cerca_list.get(index) if (name != "Nessun risultato. Aggiungi l'azienda"): self.controller.show_frame(CompanyPage.Company, self.username, name) else: self.controller.show_frame(CreateCompanyPage.CreateCompany, self.username)
class Company(Frame): def __init__(self, parent, controller, username, name): super().__init__(parent) self.controller = controller self.parent = parent self.username = username self.name = name self.db = Database() self.predictor = Predictor() self.create_widgets() def create_widgets(self): self.nome_label = Label(self, text="Azienda: " + self.name, font=("bold", 25)) self.nome_label.place(relx=0.5, rely=0.1, anchor=CENTER) self.market_label = Label( self, text="Settore: " + self.db.read_company("market", "name", self.name)[0][0], font=("bold", 25)) self.market_label.place(relx=0.5, rely=0.2, anchor=CENTER) self.total_investment_label = Label( self, text="Totale fondi ricevuti: " + str( self.db.read_company("total_investment", "name", self.name)[0][0]) + " $", font=("bold", 25)) self.total_investment_label.place(relx=0.5, rely=0.3, anchor=CENTER) self.funding_rounds_label = Label( self, text="Numero investimenti ricevuti: " + str( self.db.read_company("funding_rounds", "name", self.name)[0][0]), font=("bold", 25)) self.funding_rounds_label.place(relx=0.5, rely=0.4, anchor=CENTER) self.founded_at_label = Label( self, text="Fondata il: " + str(self.db.read_company("founded_at", "name", self.name)[0][0]), font=("bold", 25)) self.founded_at_label.place(relx=0.5, rely=0.5, anchor=CENTER) self.first_funding_at_label = Label( self, text="Data primo investimento: " + str( self.db.read_company("first_funding_at", "name", self.name)[0][0]), font=("bold", 25)) self.first_funding_at_label.place(relx=0.5, rely=0.6, anchor=CENTER) self.last_funding_at_label = Label( self, text="Data ultimo investimento: " + str( self.db.read_company("last_funding_at", "name", self.name)[0][0]), font=("bold", 25)) self.last_funding_at_label.place(relx=0.5, rely=0.7, anchor=CENTER) if (len( self.db.read_interested_mul("username", "username", self.username, "name", self.name)) == 0): self.interessato_button = Button(self, text="Sono interessato", font=(18), width=20, command=self.interessato) self.interessato_button.place(relx=0.4, rely=0.8, anchor=CENTER) else: self.interessato_button = Button(self, text="Non sono più interessato", font=(18), width=20, command=self.non_interessato) self.interessato_button.place(relx=0.4, rely=0.8, anchor=CENTER) self.predict_button = Button(self, text="Come andrà in futuro?", font=(18), width=20, command=self.predict) self.predict_button.place(relx=0.6, rely=0.8, anchor=CENTER) self.indietro_button = Button(self, text="Indietro", font=(18), width=10, command=lambda: self.controller. show_frame(HomePage.Home, self.username)) self.indietro_button.place(relx=0.5, rely=0.9, anchor=CENTER) def interessato(self): self.db.insert_interested(self.username, self.name) self.predictor.insert_consigliato(self.username, self.name) self.interessato_button.destroy() self.interessato_button = Button(self, text="Non sono più interessato", font=(18), width=20, command=self.non_interessato) self.interessato_button.place(relx=0.4, rely=0.8, anchor=CENTER) def non_interessato(self): self.db.delete_interested(self.username, self.name) self.predictor.insert_nonconsigliato(self.username, self.name) self.interessato_button.destroy() self.interessato_button = Button(self, text="Sono interessato", font=(18), width=20, command=self.interessato) self.interessato_button.place(relx=0.4, rely=0.8, anchor=CENTER) def predict(self): self.nome_label.destroy() self.market_label.destroy() self.total_investment_label.destroy() self.funding_rounds_label.destroy() self.founded_at_label.destroy() self.first_funding_at_label.destroy() self.last_funding_at_label.destroy() self.nome_label = Label(self, text="Azienda: " + self.name, font=("bold", 25)) self.nome_label.place(relx=0.25, rely=0.1, anchor=CENTER) self.market_label = Label( self, text="Settore: " + self.db.read_company("market", "name", self.name)[0][0], font=("bold", 25)) self.market_label.place(relx=0.25, rely=0.2, anchor=CENTER) self.total_investment_label = Label( self, text="Totale fondi ricevuti: " + str( self.db.read_company("total_investment", "name", self.name)[0][0]) + " $", font=("bold", 25)) self.total_investment_label.place(relx=0.25, rely=0.3, anchor=CENTER) self.funding_rounds_label = Label( self, text="Numero investimenti ricevuti: " + str( self.db.read_company("funding_rounds", "name", self.name)[0][0]), font=("bold", 25)) self.funding_rounds_label.place(relx=0.25, rely=0.4, anchor=CENTER) self.founded_at_label = Label( self, text="Fondata il: " + str(self.db.read_company("founded_at", "name", self.name)[0][0]), font=("bold", 25)) self.founded_at_label.place(relx=0.25, rely=0.5, anchor=CENTER) self.first_funding_at_label = Label( self, text="Data primo investimento: " + str( self.db.read_company("first_funding_at", "name", self.name)[0][0]), font=("bold", 25)) self.first_funding_at_label.place(relx=0.25, rely=0.6, anchor=CENTER) self.last_funding_at_label = Label( self, text="Data ultimo investimento: " + str( self.db.read_company("last_funding_at", "name", self.name)[0][0]), font=("bold", 25)) self.last_funding_at_label.place(relx=0.25, rely=0.7, anchor=CENTER) self.separator = ttk.Separator(self, orient="vertical") self.separator.place(relx=0.5, rely=0, relwidth=0.02, relheight=0.75, anchor=N) status = self.predictor.predict_company(self.name) if (status == "operating"): text = "L'azienda continuerà a operare\nnel suo campo senza subire variazioni" elif (status == "closed"): text = "L'azienda fallirà: non conviene investire" else: text = "L'azienda verrà acquisita: conviene investire" self.status_label = Label(self, text=text, font=("bold", 25)) self.status_label.place(relx=0.75, rely=0.5, anchor=CENTER)