Пример #1
0
 def play(self):
     self.box.delete(0, END)
     if self.option_seed.get() == "1":
         self.seed = int(self.valueseed.get())
     if self.option.get() == "":
         msg = "{:^180}".format("Invalid option!!")
         self.box.insert(END, msg)
     elif self.option.get() == "1":
         self.box.insert(END, "Random River")
         self.box.insert(END, "Initial river:")
         self.rio = River(int(self.len.get()), self.seed)
         self.box.insert(END, self.rio)
         self.riverOutPut()
     elif self.option.get() == "2":
         arg = self.lb.get(0)
         seed = self.seed
         if arg.endswith(".txt"):
             self.rio = River(arg, seed)
             self.box.insert(END, "File input")
             self.box.insert(END, "Initial river:")
             self.box.insert(END, self.rio)
             self.riverOutPut()
         else:
             msg = messagebox.showinfo("Invalid file format", "Please enter a valid txt file")
             return msg
Пример #2
0
    def __init__(self, group, screen):

        self.screen = screen
        self.clock = pygame.time.Clock()
        self.group = group
        self.river = River(self.group)

        self.running = True
        self.time_run = 0
Пример #3
0
class TestMethods(TestCase):
    r = River(3)
    r.setSeed(1)

    def testCreateRiver(self):
        self.r.createRiver(3)
        self.assertEqual(str(self.r.river), '[BF7, BM7, BF7]')
        self.assertNotEqual(str(self.r.river), '[BF7, BM6, BF7]')

    def testSetSeed(self):
        self.r.setSeed(0)
        self.assertEqual(self.r.seed, 0)
        self.r.setSeed(4)
        self.assertEqual(self.r.seed, 4)

    def testGetLength(self):
        self.assertEqual(self.r.getLength, 3)

    def testUpdateCell(self):
        pass

    def testUpdateRiver(self):
        self.r.updateRiver()
        self.assertEqual(str(self.r.river[0]), 'BF8')
        self.assertEqual(str(self.r.river[1]), 'BM8')
        self.assertEqual(str(self.r.river[2]), 'BF0')
Пример #4
0
 def create_assets(self):
     bears = [Bear('bear') for i in range(self.bears)]
     fish = [Fish('fish') for j in range(self.fish)]
     animals = bears + fish
     ecosystem = River(animals, self.river)
     cycles = self.cycles
     return animals, ecosystem, cycles
Пример #5
0
def river_continent(river_continent):
  #1. get data

  river_list = River.objects(continent=river_continent) #filter data

  # #2. render
  return render_template("river_continent.html",rc = river_list)
Пример #6
0
class Game:
    def __init__(self, group, screen):

        self.screen = screen
        self.clock = pygame.time.Clock()
        self.group = group
        self.river = River(self.group)

        self.running = True
        self.time_run = 0

    def run(self):
        while self.running:
            self.event()
            self.update()
            self.draw()

            pygame.display.update()

    def update(self):
        dt = self.clock.tick(FPS)
        self.time_run += dt
        self.river.update(dt)

        end = True
        for player in self.group:
            player.update(self.river)
            if player.boat.movement:
                end = False
        if end or self.time_run > TIME_MAX * 1000:
            for player in self.group:
                player.calculate_fitness()
            self.running = False

    def event(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.running = False
                sys.exit()

    def draw(self):
        self.screen.fill(COLOR_RIVER)
        self.river.draw(self.screen)
        for player in self.group:
            player.draw(self.screen)
Пример #7
0
    def run(self):

        input_num = None
        trial_num = 1

        while (input_num != 3):
            print("keys: 1 (random river) 2 (file input) 3 (exit)")

            input_num = None

            trial_label = "Trial {0}: ".format(trial_num)
            input_num = input(trial_label)

            if input_num == "3":
                print("Adieu!")
                return False

            if input_num == "2":
                river_file_path = input("Input the path to your file: ")

                river = River(river_file_path)

                print("River from file")
                cycles_number = input("Enter the number of cycles: ")

                print("Initial river:")
                print(river)

                for i in range(0, int(cycles_number)):
                    print("After cycle {0}".format(i + 1))
                    river.update_river()
                    print(river)

                trial_num += 1

            if input_num == "1":
                print("Random river")

                river_length = input("Enter river length: ")
                cycles_number = input("Enter the number of cycles: ")

                river = River(int(river_length))
                print("Initial river:")
                print(river)

                for i in range(0, int(cycles_number)):
                    print("After cycle {0}".format(i + 1))
                    river.update_river()
                    print(river)

                trial_num += 1
Пример #8
0
 def create_assets(self):
     """Creates animals and river"""
     bears = [
         Bear('bear', rnd.choice([True, False]), rnd.random())
         for i in range(self.bears)
     ]
     fish = [
         Fish('fish', rnd.choice([True, False]), rnd.random())
         for j in range(self.fish)
     ]
     animals = bears + fish
     ecosystem = River(animals, self.river)
     cycles = self.cycles
     return animals, ecosystem, cycles
    int(
        input(
            'Till what distance do you wish to find the isolated land patches : '
        )) / scale)
thresh = int(
    input(
        'Please specify a threshold value (enter 0 to find the threshold automatically) : '
    ))
len_dang_arcs = math.floor(100 / scale)

# Load the image into a cv2.imread() variable, in grey scale mode -----------------------
img = cv2.imread(name1, 0)
# ---------------------------------------------------------------------------------------

# Calculate the average width -----------------------------------------------------------
river = River(img, thresh, math.floor(interval_distance / scale),
              0)  # process the river image
skeleton = Skeleton(river, math.floor(len_dang_arcs / scale),
                    0)  # find the skeleton, junctions and reaches
scan = Scan(river, skeleton,
            l_r_error)  # create a new Scan type object and run Compute() on it
scan.Compute()

l2_stream = scan.getAllStreamFromReach(
    scan.l_reaches)  # create a list of all the lists of stream points
scan.averageCalculation(
    math.floor(interval_distance / scale), l2_stream
)  # calculate the average width of the river (section by section also)
final_average_width = scan.average_width_river  # store the average width into the variable - final_average_width

print(final_average_width * scale, " <- Average width of the river")
# ---------------------------------------------------------------------------------------
Пример #10
0
import mlab
from river import River

mlab.connect()

#ex 2
# record = River.objects(continent__istartswith="Africa")
# print(len(record))
# for r in record:
#     print(r.name)

# ex3
record = River.objects(continent__istartswith="S. America", length__lte=1000)
print(len(record))
for r in record:
    print(r.name)
Пример #11
0
import mlab
from river import River

mlab.connect()

records = River.objects(continent="S. America", length__gt=1000)
for r in records:
    print(r.name)
Пример #12
0
import mlab1
from river import River

mlab1.connect()

# exer2

list_africa = River.objects(continent = "Africa")
print(list_africa.name)



# exer3

list_american = River.objects(continent = "S.America", length_lte = 1000)
print(list_american.name)
Пример #13
0
def river_length():

  river_list = River.objects(continent = 'S. America', length__lt = 1000)

  return render_template("river_length.html",rl = river_list)
Пример #14
0
from river import River
import mlab

#1 connect
mlab.connect()

#2. read all
rivers_list = River.objects(continent="Africa")
for p in rivers_list:
    print(p.name)
    print(p.continent)
    print(p.length)
    print("*" * 20)
Пример #15
0
import mlab
from river import River

mlab.connect()

# ex2
africa_river = River.objects(continent__icontains="Africa")
print(len(africa_river))
for r in africa_river:
    print(r.name)
print("--------")
# ex3
river_length = River.objects(continent__icontains="S.America", length__lt=1000)
print(len(river_length))
for l in river_length:
    print(r.name)
import mlab
from river import River

mlab.connect()

#ex2
africa_river_list = River.objects(continent__icontains="Africa")
for a in africa_river_list:
    print(a.name, end=', ')

print()
#ex3
america_river_list = River.objects(continent__icontains="America", length__lt=1000)
for a in america_river_list:
    print(a.name, end=', ')

Пример #17
0
from river import River
import mlab_ex1

mlab_ex1.connect()

rivers_list = River.objects()
for p in rivers_list:
    if p.continent == "Africa":
        print(p.name)
        print(p.continent)
        print(p.length)
        print("*" * 20)
Пример #18
0
import mlab
from river import River

mlab.connect()

#search
#ex2
records = River.objects(continent='Africa')
for river in records:
    print(river.name, river.continent, river.length, sep='\n')
    print("*******************")

print("-------------------")
#ex3
records = River.objects(continent="S. America", length__lt=1000)
for river in records:
    print(river.name, river.continent, river.length, sep='\n')
    print("*******************")
Пример #19
0
import mlab
from river import River

mlab.connect()

records = River.objects(continent="Africa")
for r in records:
    print(r.name)
Пример #20
0
Bc = 600  # channel width
Bf = Bc * 3  # floodplain width
S0 = 1e-4  # channel slope
Cfc = 0.005  # channel friction coefficient
Cff = 0.01  # floodplain friction coefficient
Qbf = 600

g = 9.81

xmin = -Bf
xmax = Bf

Q = Qinit = Qbf / 6
Qmin = Qbf / 10

river = River(Bc=Bc, Bf=Bf, S0=S0, Cfc=Cfc, Cff=Cff, Qbf=Qbf)

# Hninit = channel_geom.get_flowdepth(Qinit, Bc, Cfc, Cff, S0, g, Qbf)
# Hnmax = channel_geom.get_flowdepth(Qbf, B, Cfc, Cff, S0, g, Qbf)

# x = channel_geom.make_xcoords(B)
# y = channel_geom.make_ycoords(x, Hninit, Hnmax)
# bed_patch = channel_geom.channel_bed(x, xmin, xmax)

# ymin = np.floor(-Hnmax)


# DEFINE FUNCTIONS
def update(val):
    Q = slide_Q.val
    Hn = channel_geom.get_flowdepth(Q, B, Cfc, Cff, S0, g, Qbf)
from river import River
import mlab_ex1

mlab_ex1.connect()

rivers_list = River.objects(length__lt=1000)
for p in rivers_list:
    if p.continent == "S. America":
        print(p.name)
        print(p.continent)
        print(p.length)
        print("*"*20) 
Пример #22
0
import mlab
from faker import Faker
from river import River
from random import randint

mlab.connect()

# http://docs.mongoengine.org/guide/querying.html

# Ex 2
records = River.objects(continent__icontains="Africa")
for r in records:
    print(r.name)

# Ex 3
records = River.objects(continent__icontains="S. America", length__lt=1000)
for r in records:
    print(r.name)
Пример #23
0
def river(continent_river):
    #1. get poll
    name = River.objects(continent=continent_river)
    #2.render
    return render_template("river.html", river=name)
Пример #24
0
 def run_number_of_times(self, numbers):
     for i in range(numbers):
         river = River(2, self._limit)
         river.eat()
         self._results.append(river.total_bear_kgs)
Пример #25
0
def longest_rivers_query():

	print ("Obtaining data ...\n")
	list_rivers = []
	rank = 1
	i = 1
	sparql = SPARQLWrapper("https://query.wikidata.org/sparql")

	sparql.setReturnFormat(JSON)

	sparql.setQuery("""SELECT DISTINCT ?river ?riverLabel (MAX(?length) AS ?length) (SAMPLE(?image) AS ?image)
	   		(SAMPLE(?coord) AS ?coord) ?continentLabel (SAMPLE(?origin) AS ?origin) ?mouthLabel
	   		(MAX(?discharge) AS ?discharge)
			WHERE
			{
			?river wdt:P31/wdt:P279* wd:Q4022 .
			?river wdt:P2043 ?length .
			?river wdt:P18 ?image .
			?river wdt:P625 ?coord .
			?river wdt:P30 ?continent .
			?river wdt:P885 ?origin .
			?river wdt:P403 ?mouth .
			?river wdt:P2225 ?discharge .

			SERVICE wikibase:label {
			   bd:serviceParam wikibase:language "en" .
			}
			}
			GROUP BY ?river ?riverLabel ?continentLabel ?mouthLabel
			ORDER BY DESC(?length)
                        LIMIT """+str(NUM_RIVERS))

	queryResults = sparql.query().convert()

	for result in queryResults["results"]["bindings"]:

	    river = result["riverLabel"]["value"]

	    length = result["length"]["value"]

	    image = result["image"]["value"]

	    coord = result["coord"]["value"]
	    longitude = coord.split("(")[1].split(" ")[0]
	    latitude = coord.split("(")[1].split(" ")[1]
	    latitude = latitude[:len(latitude) - 1]

	    continent = result["continentLabel"]["value"]

	    origin_id = result["origin"]["value"]

	    sparql_origin = SPARQLWrapper("https://query.wikidata.org/sparql")
	    sparql_origin.setReturnFormat(JSON)
	    sparql_origin.setQuery("""SELECT DISTINCT (SAMPLE(?label) AS ?label)
			       	      WHERE { <"""+origin_id+"""> rdfs:label ?label
      				              SERVICE wikibase:label {
    					 	bd:serviceParam wikibase:language "en" .
  				       	      }
        				    FILTER (langMatches( lang(?label), "EN" ) )
      				      }""")
	    queryResults = sparql_origin.query().convert()
	    for result2 in queryResults["results"]["bindings"]:
	    	origin = result2["label"]["value"]

	    mouth = result["mouthLabel"]["value"]

	    discharge = result["discharge"]["value"]

	    list_rivers.append(River(rank, river, image, length, continent, origin, mouth, discharge))
	    list_rivers[rank-1].coordinates(latitude,longitude)

	    rank = rank + 1

	print ("----- RIVER INFORMATION -----")
	print ("RANK: ",list_rivers[i].rank)
	print ("RIVER: ",list_rivers[i].river)
	print ("LATITUDE: ",list_rivers[i].latitude)
	print ("LONGITUDE: ",list_rivers[i].longitude)
	print ("IMAGE: ",list_rivers[i].image)
	print ("LENGTH: ",list_rivers[i].length)
	print ("CONTINENT: ",list_rivers[i].continent)
	print ("ORIGIN: ",list_rivers[i].origin)
	print ("MOUTH: ",list_rivers[i].mouth)
	print ("DISCHARGE: ",list_rivers[i].discharge)

	return list_rivers