Ejemplo n.º 1
0
class Block(object):
	def __init__(self, size):
		self.size = size
		self.path = set()
		self.zones = set()
	def build(self):
		self.root = Region((0,0), self.size)
		self.regions = self.root.split_to_size(1000)
		self.graph = RegionGraph(self.regions)
		self.zones = self.graph.assign_zones(3)
		self.build_structures()
		self.starter_zone = random.choice(list(self.zones))
	def build_structures(self):
		for zone in self.zones.copy():
			self.zones.remove(zone)
			self.zones.add(zone.define())
		for zone in self.zones:
			zone.construct()
		structure_graph = RegionGraph(self.root.search_down(), self.root)
		for zone in self.zones:
			zone.determine_interior_edges(self.graph)
			zone.update_structures(structure_graph)
		for zone in self.zones:
			for edge in zone.connections:
				edge.owner.edges.add(edge)	
		for zone in self.zones:
			zone.draw_path()	
		for zone in self.zones:
			for structure in zone.structures:
				structure.draw()
Ejemplo n.º 2
0
def instances_fee():
    try:
        from gcp import fee
        auth = Auth()
        auth.get_service(request)
        data = request.args.to_dict()
        ebs = list(eval(data['ebs']))
        instance_type = data['instance_type']
        os = data['os']

        quantity = int(data['quantity'])
        total_compute = round(
            fee.instance_price[instance_type]['price'][
                Region().get_region_name(auth.region)] * quantity, 2)
        total_ebs = 0
        for each_ebs in ebs:
            total_ebs += round(
                fee.disk_price[each_ebs['type']][Region().get_region_name(
                    auth.region)] * int(each_ebs['size']), 2)
        total = total_compute + total_ebs
        res = {'compute': total_compute, 'ebs': total_ebs, 'total': total}
        return jsonify(res)
    except errors.HttpError as e:
        msg = json.loads(e.content)
        return jsonify(msg=msg['error']['message']), msg['error']['code']
Ejemplo n.º 3
0
	def build(self):
		self.root = Region((0,0), self.size)
		self.regions = self.root.split_to_size(1000)
		self.graph = RegionGraph(self.regions)
		self.zones = self.graph.assign_zones(3)
		self.build_structures()
		self.starter_zone = random.choice(list(self.zones))
Ejemplo n.º 4
0
def plot_graphs_for_year(year_str):
    '''
    This function will create 7 plots for the input year which includes 1 box plot for that year and 6 hostograms for each region
    '''
    #try:
    countries = pd.read_csv('../countries.csv', sep=',')
    income = pd.read_excel('../indicator gapminder gdp_per_capita_ppp.xlsx', index_col=0)
    income = income.transpose()
    list_region_objects = []
    list_of_region_income_data = []
    year = int(year_str)
    directory_name = create_new_directory(year_str)
    print
    print "------------------------------------------------------------------------------------------------------"
    print
    print "Analysis for the year ", year_str, " started ..."
    print
    regions_data = merge_by_year(year, income, countries)
    grouped_region_data = regions_data.groupby('Region')
    region_names = regions_data['Region'].unique()

    #below for loop will create Region type objects for each individual region
    for region_name in region_names:
        region_data = grouped_region_data.get_group(region_name)
        region_object = Region(region_name, region_data)            # Instance creation of Region class
        list_region_objects.append(region_object)

    #creating list of lists having data of each region income for the Box Plot
    for i in range(len(list_region_objects)):
        list_of_region_income_data.append(list_region_objects[i].region_income)


    print "Plotting and saving histograms for each region ...In Progress..."
    for i in range(len(list_region_objects)):
        Region.plot_Hist_Graphs(list_region_objects[i], year_str, directory_name)
    print "Histograms for each region are plotted and saved successfully ...Completed !!!"
    print


    print "Plotting and saving Box Plot ...In Progress..."
    Region.plot_BoxPlots(region_names, list_of_region_income_data, year_str, directory_name)
    print "Box Plt is plotted and saved successfully ...Completed !!!"
    print
Ejemplo n.º 5
0
def create_regions(s, rids, rcolors, refpts, slevels, pids, task):

    if task:
        task.updateStatus('Making ID table')
    id_to_index = dict([(id, i) for i, id in enumerate(rids)])

    if task:
        task.updateStatus('Collecting child region IDs')
    id_to_child_ids = {}
    n = len(rids)
    for i in range(n):
        pid = pids[i]
        if pid > 0:
            if pid in id_to_child_ids:
                id_to_child_ids[pid].append(rids[i])
            else:
                id_to_child_ids[pid] = [rids[i]]

    if task:
        task.updateStatus('Ordering IDs')
    from regions import Region
    ids = depth_order(rids, id_to_child_ids, set())
    rlist = []
    for c, rid in enumerate(ids):
        if rid in id_to_child_ids:
            children = [s.id_to_region[cid] for cid in id_to_child_ids[rid]]
        else:
            children = []
        i = id_to_index[rid]
        r = Region(s, rid, refpts[i], children)
        # TODO: Get wrappy error setting surface piece color to numpy array.
        r.color = tuple(rcolors[i])
        if not slevels is None:
            r.smoothing_level = slevels[i]
        rlist.append(r)
        if task and c % 1000 == 0:
            task.updateStatus('Created %d of %d regions' % (c, n))

    if not slevels is None:
        s.smoothing_level = max(slevels)

    return rlist
 def init_sections_state(self):
     net_manager.init_devices()
     for section in self.vbox.get_children():
         if section.show_or_hide():
             section.section_show()
             section.init_state()
         else:
             section.section_hide()
     slider._append_page(Region(), "region")
     from setting_page_ui import SettingUI
     self.setting_page_ui = SettingUI(None, None)
     slider._append_page(self.setting_page_ui, "setting")
Ejemplo n.º 7
0
def copy_regions(regions, bin_size, seg):

    from regions import Region
    rlist = []
    for r in regions:
        if r.rid in seg.id_to_region:
            rc = seg.id_to_region[r.rid]
        else:
            cc = copy_regions(r.children(), bin_size, seg)
            max_point = tuple([b * i for b, i in zip(bin_size, r.max_point)])
            rc = Region(seg, r.rid, max_point, cc)
        rlist.append(rc)
    return rlist
Ejemplo n.º 8
0
 def make_some_data(self):
     img_path="data_sim/boulder.png"
     region_coordinates={'latmin':0,'latmax':0,'lonmin':0,'lonmax':0}
     Boulder=Region('Boulder',img_path,region_coordinates)
     Boulder.initPointTargets()
     Boulder.generateLayers()
     total_targets=np.zeros((100,100,100))
     for i, (gt_layer,sb_layer,pb_layer) in enumerate(zip(Boulder.ground_truth_layers,Boulder.shake_base_layers,Boulder.pixel_bleed_layers)):
         total_targets=total_targets+gt_layer+sb_layer+pb_layer
     total=total_targets+Boulder.noise_layer+Boulder.structured_noise_layer+Boulder.shotgun_noise_layer
     return total
Ejemplo n.º 9
0
    def initialise_regions(self) -> None:
        """Create all the region data classes"""
        f = open("data/country_names.csv")
        data = f.readlines()

        for line in data[1:]:
            name, continent = DataSet.parse_csv_line(line)
            region = Region(
                name=name,
                continent=continent
            )
            self.regions[name] = region

        f.close()

        # To ensure consistency between different data sets,
        # some names will be changed
        uk = self.regions["United Kingdom of Great Britain & Northern Ireland"]
        del self.regions["United Kingdom of Great Britain & Northern Ireland"]
        self.regions["United Kingdom"] = uk

        us = self.regions["United States of America"]
        del self.regions["United States of America"]
        self.regions["United States"] = us