def test_overlapping(self): for city_1, city_2, overlap in self.city_sets: r = round(city_f.overlap(city_1, city_2)) r2 = round(city_f.overlap(city_2, city_1))# Make sure it works both ways round try: self.assertEqual(overlap, r) self.assertEqual(r, r2) except Exception as e: r = city_f.overlap(city_1, city_2, debug=True) raise
def overlapping_cities(cursor, verbose): city_dict = city_q.get_live_cities(cursor) checked = [] overlap_dict = {} for id1, c1 in city_dict.items(): c1.overlap = 0 # Cache some stuff if verbose: it = cli_f.progressbar(city_dict.items(), "cities_check.overlapping_cities: ", 40, with_eta = True) else: it = city_dict.items() for id1, c1 in it: checked.append(id1) for id2, c2 in city_dict.items(): if id2 in checked: continue amount = city_f.overlap(c1, c2) c1.overlap += city_f.overlap_percentage(c1, amount) c2.overlap += city_f.overlap_percentage(c2, amount) # Reset all cities query = """UPDATE cities SET overlap = 0""" try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) updates = 0 for id1, c1 in city_dict.items(): if c1.overlap >= 1: updates += 1 query = "UPDATE cities SET overlap = %d WHERE id = %d;" % (c1.overlap, id1) # print("%s - %s" % (query, c1.name)) # continue try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))