def count_avg_sq(): districts = DistrictModel.query.all() flats = RealtyModel.query.all() for d in districts: sum = 0.0 count = 0 for f in flats: if f.type == 1: if d.id == f.dist: sum += f.price / f.area count += 1 if count > 0: d.avg_sq = sum / count RealtyModel.update_dist()
def parse_ao(): # with open('ao.json', 'r') as myfile: # data=myfile.read() # # obj = json.loads(data) # # for i in obj['features']: # new_ao = AoModel( # id=i['properties']['OKATO'], # name=i['properties']['NAME'], # type=i['geometry']['type'] # ) # # new_ao.save_to_db() # districts = DistrictModel.query.all() ao = AoModel.query.all() for a in ao: sumsq = 0.0 sumcoeff = 0 countsq = 0 countcoeff = 0 for d in districts: if a.id == d.okato_ao: if d.avg_sq: sumsq += d.avg_sq countsq += 1 if d.avg_coeff: sumcoeff += d.avg_coeff countcoeff += 1 if countsq != 0: a.avg_sq = sumsq / countsq if countcoeff != 0: a.avg_coeff = int(sumcoeff / countcoeff) RealtyModel.update_dist()
def count_avg_coeff(): districts = DistrictModel.query.all() flats = RealtyModel.query.all() flats_with_coeffs = TempModel.query.all() for fwc in flats_with_coeffs: for f in flats: if fwc.id == f.id: fwc.dist = f.dist RealtyModel.update_dist() for d in districts: coeff = 0 count = 0 for fwc in flats_with_coeffs: if d.id == fwc.dist: coeff += fwc.coeff count += 1 if count > 0: d.avg_coeff = int(coeff / count) RealtyModel.update_dist()
def check_point_is_in_polygon(): districts = DistrictModel.query.all() flats = RealtyModel.query.filter(RealtyModel.dist == None) res = 0 for d in districts: for f in flats: if d.type == "Polygon": if ray_tracing(f.longitude, f.latitude, np.array(d.coordinates)): print('here') res += 1 f.dist = d.id continue elif d.type == "MultiPolygon": for p in d.coordinates: if ray_tracing(f.longitude, f.latitude, np.array(p)): print('here') res += 1 f.dist = d.id continue RealtyModel.update_dist() print(RealtyModel.query.filter(RealtyModel.dist == None).count())