def changeX(self): #case 1:none if self.describe == '': table_id = 0 table = self.instance.tables[table_id] for i in range(self.instance.tables[0].column_num): f = self.instance.tables[0].features[i] if i == self.x_id or self.instance.types[ i] != self.instance.types[self.x_id] or f.ratio < 1.0: continue if self.fit(table, i, self.y_id, self.chart): v = View(table, i, self.y_id, -1, 1, [table.T[i]], [table.T[self.y_id]], self.chart) v.output('changeX', '') #case 2:group by x, then group by other categorical/temporal elif len(self.describe1) >= 5 and self.describe1[ 0:5] == 'GROUP' and self.describe2 == '': for i in range(self.instance.column_num): if i == self.x_id or self.instance.types[ i] != self.instance.types[ self.x_id] or self.instance.tables[0].features[ i].ratio == 1: continue if self.instance.types[ i] == Type.categorical and self.instance.tables[ 0].features[i].distinct > 20: continue table_id = -1 for j in range(self.instance.table_num): if self.instance.tables[ j].describe == 'GROUP BY ' + self.instance.names[i]: table_id = j break if table_id == -1: new_table = self.instance.tables[0].dealWithGroup( i, 0, self.instance.tables[0].tuple_num, True, True) new_table.getFeatures() self.instance.addTable(new_table) table_id = self.instance.table_num - 1 table = self.instance.tables[table_id] #get new x,y id new_x_id = table.column_num - 1 new_y_id = -1 for j in range(table.column_num): if table.names[j] == self.y_name: new_y_id = j break if new_y_id == -1: new_y_id = 0 if self.fit(table, i, new_y_id, self.chart): v = View(table, new_x_id, new_y_id, -1, 1, [table.T[new_x_id]], [table.T[new_y_id]], self.chart) v.output('changeX', '') #case 3:group by z, group by x then group by z,group by other categorical/temporal elif len(self.describe1 ) >= 5 and self.describe1[0:5] == 'GROUP' and len( self.describe2) >= 5 and self.describe2[0:5] == 'GROUP': for i in range(self.instance.column_num): if i == self.x_id or i == self.z_id or self.instance.types[ i] != self.instance.types[self.x_id]: continue if self.instance.types[ i] == Type.categorical and self.instance.tables[ 0].features[i].distinct > 20: continue if self.instance.tables[0].features[ self.z_id].distinct > self.instance.tables[0].features[ i].distinct: continue s = set() for j in range(self.instance.tuple_num): s.add((self.instance.tables[0].D[j][self.z_id], self.instance.tables[0].D[j][i])) len_s = len(s) if len_s <= self.instance.tables[0].features[i].distinct: continue table_id = -1 for j in range(self.instance.table_num): if self.instance.tables[ j].describe1 == self.describe1 and self.instance.tables[ j].describe2 == 'GROUP BY ' + self.instance.names[ i]: table_id = j break if table_id == -1: if len_s == self.instance.tuple_num: new_table = self.instance.tables[0].getClassifyTable( self.z_id, i, self.instance.tables[0].dealWithGroup, False) else: new_table = self.instance.tables[0].getClassifyTable( self.z_id, i, self.instance.tables[0].dealWithGroup, True) new_table.getFeatures() self.instance.addTable(new_table) table_id = self.instance.table_num - 1 table = self.instance.tables[table_id] #get new x,y id new_x_id = table.column_num - 1 new_y_id = -1 for j in range(table.column_num): if table.names[j] == self.y_name: new_y_id = j break delta = table.tuple_num / table.classify_num series_data = [ table.T[new_y_id][series * delta:(series + 1) * delta] for series in range(table.classify_num) ] if self.fit(table, i, new_y_id, self.chart): v = View(table, new_x_id, new_y_id, self.z_id, table.classify_num, [table.T[new_x_id][0:delta]], series_data, self.chart) v.output('changeX', '')
from controller import Controller from model import FuzzyDescriptions from view import View if __name__ == '__main__': temperature = FuzzyDescriptions() humidity = FuzzyDescriptions() time = FuzzyDescriptions() rules = [] ctrl = Controller() view = View(ctrl) view.readProblemData([temperature, humidity, time], rules) ctrl.setData(temperature, humidity, time, rules) inputFile = open('input.in', 'r') outputFile = open('output.out', 'w') x = int(inputFile.readline()) for _ in range(x): values = inputFile.readline().split() res = str(view.compute({'humidity': int(values[0]), 'temperature': int(values[1])})) print("Humidity: " + values[0] + "\nTemperature: " + values[1] + "\nOperating time: " + res + "\n") outputFile.write(res + '\n') inputFile.close() outputFile.close()
def __init__(self, sys_argv): super(App, self).__init__(sys_argv) self.model = Model() self.ctrl = Control(self.model) self.view = View(self.model, self.ctrl) self.view.show()
def __init__(self): self.model = Model() self.view = View(self)
from model import Model from view import View my_model = Model() my_view = View() running = True while running == True: user_input = my_view.menu() if user_input == "1": choosing = True while choosing == True: new_card_num = my_view.takeInput("Enter a card number: ") if new_card_num.isdigit() and len(new_card_num) > 0: my_model.setCardNumber(new_card_num) choosing = False else: my_view.printOut("Invalid card number. Try again") elif user_input == "2": new_card_type = "INVALID" for key in my_model.starting_numbers.keys():
def reset(self): self._model = Model(self.rows, self.cols) self._view = View(self.rows, self.cols)
from model import State, Bot from view import View from controller import controller controller(State(), Bot(), View())
def render_GET(self, request): flattenString(None, View()).addCallback(self.renderDone) print self.html return self.html
from command import CommandHelp from file_handler import FileHandler from validator import Validator from view import View from db import DatabaseHandler import pickle import sys # hasitha try: database_name = sys.argv[1] except IndexError: database_name = "db" try: database = pickle.load(open(database_name + ".p", "rb")) except FileNotFoundError: database = DatabaseHandler(Validator(), database_name) database.load() pickle.dump(database, open(database_name + ".p", "wb")) cli = CommandHelp(FileHandler(Validator()), database, View()) cli.cmdloop()
def __init__(self): self.__model = Model() self.__view = View()
# Select the case-study to run case = 'case2' # Set the mission specification global_spec, local_spec, prio, init_x, init_y, sensing_range = case_studies[ case] # Create the environment env = Environment(case) # Create the quadrotor quad = Quadrotor(env, init_x, init_y, sensing_range) # Create the view view = View(env, quad) with lomap.Timer('Offline Computation'): planner = Planner(env, quad, global_spec, local_spec, prio) # Animation anim = animation.FuncAnimation(view.fig, animate, frames=list(range(0, 200)), interval=250, repeat=False) if video_name: anim.save(video_name) exit(0) plt.show()
def main(): database = DB() repository = Repository(database) controller = Controller(repository) view = View(controller) view.mainMenu()
def create_view(self,p_type = None, fname = None, t_num = 0, region = []): self.Views.append( View(plot_type = p_type,filename = fname, model = self.model, trace_num = t_num, region = region) ) self.mdiArea.addSubWindow(self.Views[len(self.Views)-1]) self.Views[len(self.Views)-1].show()
def __init__(self, env_name, **kwargs): """Initializes the environment. Args: env_name: The name of the environment to display. This should have a corresponding PNG image and YAML file with the same name in the maps folder. Keyword Args: render: Whether the environment should be rendered. Defaults to True. vision: Whether to return raw pixel values as observations. Defaults to False. obstacle: Whether to use the special Obstacle NPC. Defaults to False. decimals: Number of decimals in the observations. Defaults to None (no rounding). reward_function: The reward funtion to use. Defaults to internal reward. feature_function: A function to transform observations to a feature vector. tick: Whether to tick the clock at the desired frequency when stepping the env. Defaults to False. flip: Whether to flip the display so that the user can control the car more easily. Defaults to False. scroll: Whether to follow the view of the agent or generate the whole environment. Defaults to True. """ self.max_angle = global_var.MAX_ANGLE self.max_acc = global_var.MAX_ACC self.max_speed = global_var.MAX_SPEED set_env(env_name) # KEYWORD ARGS self.render = kwargs["render"] if "render" in kwargs else True self.vision = kwargs["vision"] if "vision" in kwargs else False self.obstacle = kwargs["obstacle"] if "obstacle" in kwargs else False self.decimals = kwargs["decimals"] if "decimals" in kwargs else None self.reward = kwargs["reward_function"] if "reward_function" in kwargs else self._default_reward self.feature_fn = kwargs["feature_function"] if "feature_function" in kwargs else self._default_feature_fn self.tick = kwargs["tick"] if "tick" in kwargs else False self.flip = kwargs["flip"] if "flip" in kwargs else False self.scroll = kwargs["scroll"] if "scroll" in kwargs else True # ZONES self.lanes = [] self.intersections = [] self.lane_markers = [] with open(os.path.join(global_var.PATH, "maps", env_name + ".yaml")) as f: description = yaml.load(f) # Width and height of the actual environment. self.width = description["width"] self.height = description["height"] self._create_zones(description) # Choose whether to use the pos from the config or the default pos from the map. if agent.USE_POS: self.agent = Agent() else: pos = description["agent_start"] self.agent = Agent(pos["x"], pos["y"], pos["theta"]) self._keep_agent_in_map() self.npc_manager = NPCManager(description["starts"], (self.width, self.height), self.obstacle) # Number of elements in the action and the observation vectors. self.observation_n = len(self._get_observation()) self.action_n = 2 self.clock = None self.display_surface = None # The PNG image of the map. if self.scroll: self.view = View(env_name, description["width"], description["height"], screen.WIDTH, screen.HEIGHT, self.flip) else: self.view = View(env_name, description["width"], description["height"]) self.setup()
fetchers.yahoo.Yahoo( "https://query1.finance.yahoo.com/v7/finance/download/AIR.F?period1=1594709909&period2=1606245909&interval=1d&events=history&includeAdjustedClose=true" ) # parse and apply arguments args = parser.parse_args() logging.basicConfig(level=logging.getLevelName(args.log_level)) logger.debug(f"CLI arguments:\n{args}") # load simulation configuration config = yaml.load(open(args.config), Loader=yaml.FullLoader) logger.info(f"configuration:\n{yaml.dump(config)}") # prepare and run simulation view = View() market_data = MarketData(config["file"], view) strategy = Strategy() indicator_constructors = indicator.load_modules(config["indicators"]) indicators = [ictor() for ictor in indicator_constructors] wallet = Wallet(args.init_money) simulation = Simulation(strategy=strategy, indicators=indicators, instrument_data=market_data, wallet=wallet, view=view) simulation.run() simulation.print_results()
def generateViews(self): T=map(list,zip(*self.D)) if self.transformed: for column_id in range(self.column_num): f = Features(self.names[column_id],self.types[column_id],self.origins[column_id]) #calculate min,max for numerical if f.type==Type.numerical: if self.classify_num==1 or not self.describe2:#not categorized or categorized scatter f.min,f.max=min(T[column_id]),max(T[column_id]) f.minmin=f.min if f.min==f.max: self.types[column_id]=f.type=Type.none self.features.append(f) continue else: delta=self.tuple_num/self.classify_num f.min=[min(T[column_id][class_id*delta:(class_id+1)*delta]) for class_id in range(self.classify_num)] f.minmin=min(f.min) f.max=[max(T[column_id][class_id*delta:(class_id+1)*delta]) for class_id in range(self.classify_num)] if sum([f.max[class_id]-f.min[class_id] for class_id in range(self.classify_num)])==0: self.types[column_id]=f.type=Type.none self.features.append(f) continue if min(f.min)==max(f.min) and min(f.max)==max(f.max): if sum([0 if T[column_id][class_id*delta:(class_id+1)*delta]==T[column_id][(class_id+1)*delta:(class_id+2)*delta] else 1 for class_id in range(self.classify_num-1)])==0: self.types[column_id]=f.type=Type.none self.features.append(f) continue #calculate distinct,ratio for categorical,temporal if f.type==Type.categorical or f.type==Type.temporal: f.distinct=self.tuple_num f.ratio=1.0 self.features.append(f) else: for column_id in range(self.column_num): f = Features(self.names[column_id],self.types[column_id],self.origins[column_id]) #calculate min,max for numerical,temporal if f.type==Type.numerical or f.type==Type.temporal: f.min,f.max=min(T[column_id]),max(T[column_id]) f.minmin=f.min if f.min==f.max: self.types[column_id]=f.type=Type.none self.features.append(f) continue d={} #calculate distinct,ratio for categorical,temporal if f.type == Type.categorical or f.type == Type.temporal: for i in range(self.tuple_num): if self.D[i][column_id] in d: d[self.D[i][column_id]]+=1 else: d[self.D[i][column_id]]=1 f.distinct = len(d) if f.distinct==1: self.types[column_id]=f.type=Type.none self.features.append(f) continue f.ratio = 1.0 * f.distinct / self.tuple_num f.distinct_values=[(k,d[k]) for k in sorted(d)] if f.type==Type.temporal: self.getIntervalBins(f) self.features.append(f) #generate 2D views if self.describe2=='' and self.classify_id==-1: for i in range(self.column_num): for j in range(self.column_num): if i==j: continue fi=self.features[i] fj=self.features[j] if fi.type==Type.categorical and fj.type==Type.numerical and fi.ratio==1.0: charts=[] if fj.minmin>0 and fi.distinct<=5 and not (len(fj.name)>=6 and fj.name[0:4]=='AVG(' and fj.name[-1]==')'): charts.append(Chart.pie) if fi.distinct<=20: charts.append(Chart.bar) elif fi.type==Type.temporal and fj.type==Type.numerical and fi.ratio==1.0: charts=[] if fi.distinct<7: charts.append(Chart.bar) else: charts.append(Chart.line) elif (not self.transformed) and fi.type==Type.numerical and fj.type==Type.numerical and i<j: charts=[Chart.scatter] else: charts=[] for chart in charts: v=View(self,i,j,-1,1,[T[i]],[T[j]],chart) self.views.append(v) self.view_num+=1 #generate 3D views elif self.describe2: for i in range(self.column_num): for j in range(self.column_num): fi=self.features[i] fj=self.features[j] if fi.type==Type.categorical and fj.type==Type.numerical and fj.minmin>0: charts=[Chart.bar] elif fi.type==Type.temporal and fj.type==Type.numerical: if self.tuple_num/self.classify_num<7: charts=[Chart.bar] else: charts=[Chart.line] else: charts=[] for chart in charts: delta=self.tuple_num/self.classify_num series_data = [T[j][series * delta:(series + 1) * delta] for series in range(self.classify_num)] v = View(self, i, j, self.classify_id, self.classify_num, [T[i][0:delta]], series_data, chart) self.views.append(v) self.view_num += 1 else: for i in range(self.column_num): for j in range(self.column_num): if i>=j or self.types[i]!=Type.numerical or self.types[j]!=Type.numerical: continue X=[] Y=[] id=0 for k in range(self.classify_num): x=T[i][id:id+self.classes[k][1]] y=T[j][id:id+self.classes[k][1]] id+=self.classes[k][1] X.append(x) Y.append(y) v=View(self,i,j,self.classify_id,self.classify_num,X,Y,Chart.scatter) self.views.append(v) self.view_num+=1 self.instance.view_num+=self.view_num
def setUp(self): self.view = View() self.db = ContactBook(':memory:') self.db.add_contact('Test', 'Tester', 111222333, '*****@*****.**') self.contact_list = self.db.view_contacts()
def __init__(self): self.view = View() self.serialize = Serialize()
def __init__(self, rows, cols): self.rows, self.cols = rows, cols self._model = Model(rows, cols) self._view = View(rows, cols, open_browser=True)
asset_globalids = ['120000001', '120000002', '120000013', '120000014', '120000015'] assets = {} for asset_id in asset_globalids: assets[asset_id] = Asset(asset_id) #assets[asset_id] = WaveletAsset(asset_id, 2) allocate = AvgAllocate('ALC.000001', assets, trade_date, 14) #print allocate.allocate().tail() allocate = MzAllocate('ALC.000002', assets, trade_date, 14) #print allocate.allocate().tail() allocate = MzBootAllocate('ALC.000002', assets, trade_date, 14) #print allocate.allocate().tail() view_df = View.load_view('BL.000001') asset_globalids = ['120000001', '120000002', 'ERI000001', '120000014', 'ERI000002'] assets = {} for asset_id in asset_globalids: assets[asset_id] = Asset(asset_id) views = {} for asset_id in asset_globalids: views[asset_id] = View(None, asset_id, view_sr = view_df[asset_id], confidence = 0.5) if asset_id in view_df.columns else View(None, asset_id, confidence = 0.5) allocate = MzBootBlAllocate('ALC.000002', assets, views, trade_date, 26)
#Programa princial #importacao de classes from view import View from control import Control from model import Model #Instanciar o Model m = Model() #Instanciar a View v = View() #Instanciar a Control c = Control(v, m) #Guardando a control na model m.set_control(c) #Guardando a control na view v.set_control(c) #Exibir o menu c.exibir_menu()
def get_search_input(self): category = self.get_category() query = self.get_query(category) entries = self.search_params(category, query) View(entries)
def main(): controller = Controller(Model(), View()) controller.run()
def __init__(self): self.db = Database() self.view = View(self, self.db)
def main(self): v = View() files = ['assets/data/map_data.json', 'assets/data/cmi_hub.json'] g = Graph() self.build_graph_from_files(g, files) utils = GraphUtils() v.print_menu() while (True): v.print_prompt_user() code = raw_input() if (code == '0' or code == 'exit'): exit(0) elif (code == '1'): #@todo fix this v.city_info(g) elif (code == '2'): longest_flight = utils.longest_flight(g) v.print_flight(longest_flight) elif (code == '3'): shortest_flight = utils.shortest_flight(g) v.print_flight(shortest_flight) elif (code == '4'): map_string = utils.get_map_string(g) v.display_map(map_string) elif (code == '5'): average_flight_distance = utils.average_distance(g) v.print_average_flight_distance(average_flight_distance) elif (code == '6'): largest_population = utils.biggest_city(g) v.print_population(largest_population) elif (code == '7'): smallest_population = utils.smallest_city(g) v.print_population(smallest_population) elif (code == '8'): average_population = utils.average_city(g) v.print_population_number(average_population) elif (code == '9'): continents_dict = utils.get_continents_and_cities(g) v.print_continents_and_cities(continents_dict) elif (code == '10'): hubs = utils.get_hub_cities(g) v.print_hub_cities(hubs) elif (code == '11'): cities = utils.get_cities(g) v.print_cities(cities) elif (code == '12'): # add a city data = v.add_city_menu() g.add_node(data) elif (code == '13'): data = v.add_route_menu() g.add_route(data['src'], data['dst'], data['distance']) # add a route pass elif (code == '14'): # remove a city code = v.remove_city_menu() g.remove_node(code) elif (code == '15'): # remove a route data = v.remove_route_menu() g.remove_route(data['src'], data['dst']) elif (code == '16'): # edit a city data = v.edit_city_menu() g.edit_node(data) elif (code == '17'): # save to disk utils.save_to_disk(g) v.print_success() # @todo prints errors success elif (code == '18'): cities = v.route_menu() route_return = utils.route_info(g, cities) v.print_route_info(route_return) elif (code == '19'): cities = v.route_menu() route = utils.shortestPath(g, cities[0], cities[1]) v.print_route(route) route_return = utils.route_info(g, route) v.print_route_info(route_return) elif (code == '20'): v.print_menu() else: v.print_error()
from view import View from models import initialize_database if __name__ == '__main__': initialize_database() View().start()
'price': 0.5, 'quantity': 20 }, { 'name': 'milk', 'price': 1.0, 'quantity': 10 }, { 'name': 'wine', 'price': 10.0, 'quantity': 5 }, ] c = Controller(ModelSQLite(my_items), View()) c.show_items() c.show_items(bullet_points=True) c.show_item('chocolate') c.show_item('bread') c.insert_item('bread', price=1.0, quantity=5) c.insert_item('chocolate', price=2.0, quantity=10) c.show_item('chocolate') c.update_item('milk', price=1.2, quantity=20) c.update_item('ice cream', price=3.5, quantity=20) c.delete_item('fish') c.delete_item('bread')
def setUp(self): self.model = Model() self.view = View(self.model)
self.fc2 = torch.nn.Linear(120, 84) self.act4 = torch.nn.Tanh() self.fc3 = torch.nn.Linear(84, 10) def forward(self, x): x = self.conv1(x) x = self.act1(x) x = self.pool1(x) x = self.conv2(x) x = self.act2(x) x = self.pool2(x) x = x.view(x.size(0), x.size(1) * x.size(2) * x.size(3)) x = self.fc1(x) x = self.act3(x) x = self.fc2(x) x = self.act4(x) x = self.fc3(x) return x model = Model() view = View(model) view.start()
def changeY(self): table_id = -1 for i in range(self.instance.table_num): if self.instance.tables[i].describe == self.describe: table_id = i break if table_id == -1: if self.describe1[0:5] == 'GROUP' and self.describe2 == '': new_table = self.instance.tables[0].dealWithGroup( self.x_id, 0, self.instance.tables[0].tuple_num, True, True) elif self.describe1[0:3] == 'BIN' and self.describe2 == '': if self.describe1[-4:] == 'TIME': new_table = self.instance.tables[0].dealWithIntervalBin( self.x_id, 0, self.instance.tables[0].tuple_num, True, True) elif self.describe1[-4:] == 'HOUR': new_table = self.instance.tables[0].dealWithHourBin( self.x_id, 0, self.instance.tables[0].tuple_num, True, True) else: new_table = self.instance.tables[0].dealWithWeekBin( self.x_id, 0, self.instance.tables[0].tuple_num, True, True) elif self.describe1[0:5] == 'GROUP' and self.describe2[ 0:5] == 'GROUP': self.instance.tables[0].D.sort( key=lambda tuple: tuple[self.z_id]) if self.y_name != self.instance.names[self.y_id]: new_table = self.instance.tables[0].getClassifyTable( self.z_id, self.x_id, self.instance.tables[0].dealWithGroup, True) else: new_table = self.instance.tables[0].getClassifyTable( self.z_id, self.x_id, self.instance.tables[0].dealWithGroup, False) else: if self.describe2[-4:] == 'TIME': new_table = self.instance.tables[0].getClassifyTable( self.z_id, self.x_id, self.instance.tables[0].dealWithIntervalBin, True) elif self.describe2[-4:] == 'HOUR': new_table = self.instance.tables[0].getClassifyTable( self.z_id, self.x_id, self.instance.tables[0].dealWithHourBin, True) else: new_table = self.instance.tables[0].getClassifyTable( self.z_id, self.x_id, self.instance.tables[0].dealWithWeekBin, True) new_table.getFeatures() self.instance.addTable(new_table) table_id = self.instance.table_num - 1 self.origin_table_id = table_id table = self.instance.tables[table_id] #get new x id new_x_id = new_y_id = -1 for i in range(table.column_num): if table.names[i] == self.x_name: new_x_id = i if new_y_id == -1: break if table.names[i] == self.y_name: new_y_id = i if new_x_id == -1: break self.X = table.T[new_x_id] self.Y = table.T[new_y_id] if self.z_id == -1: for i in range(table.column_num): if table.types[ i] == Type.numerical and table.names[i] != self.y_name: if self.fit(table, self.x_id, i, self.chart): v = View(table, new_x_id, i, -1, 1, [table.T[new_x_id]], [table.T[i]], self.chart) v.output('changeY', '') else: for i in range(table.column_num): if table.types[ i] == Type.numerical and table.names[i] != self.y_name: delta = table.tuple_num / table.classify_num series_data = [ table.T[i][series * delta:(series + 1) * delta] for series in range(table.classify_num) ] if self.fit(table, self.x_id, i, self.chart): v = View(table, new_x_id, i, self.z_id, table.classify_num, [table.T[new_x_id][0:delta]], series_data, self.chart) v.output('changeY', '')