예제 #1
0
	def match_wgn(self, prog):
		if Weather_wgn_cli.select().count() > 0:
			self.emit_progress(prog, "Matching wgn to weather stations...")
			with project_base.db.atomic():
				for row in Weather_sta_cli.select():
					id = closest_lat_lon(project_base.db, "weather_wgn_cli", row.lat, row.lon)
					row.wgn = id
					row.save()
예제 #2
0
	def match_to_weather_stations(self, start_prog, total_prog):
		if Weather_wgn_cli.select().count() > 0:
			with project_base.db.atomic():
				query = Weather_sta_cli.select()
				records = query.count()
				i = 1
				for row in query:
					if self.__abort: return

					prog = round(i * total_prog / records) + start_prog
					i += 1

					if row.lat is not None and row.lon is not None:
						id = closest_lat_lon(project_base.db, "weather_wgn_cli", row.lat, row.lon)

						self.emit_progress(prog, "Updating weather station with generator {i}/{total}...".format(i=i, total=records))
						row.wgn_id = id
						row.save()
    def create_weather_stations(
        self, start_prog, total_prog
    ):  # total_prog is the total progress percentage available for this method
        if self.__abort: return

        stations = []
        cursor = project_base.db.execute_sql(
            "select lat, lon from weather_file group by lat, lon")
        data = cursor.fetchall()
        records = len(data)
        i = 1
        for row in data:
            if self.__abort: return

            lat = row[0]
            lon = row[1]
            name = weather_sta_name(lat, lon)

            prog = round(i * total_prog / records) + start_prog
            # self.emit_progress(prog, "Creating weather station {name}...".format(name=name))

            try:
                existing = Weather_sta_cli.get(Weather_sta_cli.name == name)
            except Weather_sta_cli.DoesNotExist:
                station = {
                    "name": name,
                    "wnd_dir": None,
                    "atmo_dep": None,
                    "lat": lat,
                    "lon": lon,
                }
                """
					"hmd": closest_lat_lon(project_base.db, "weather_file", lat, lon, "hmd"),
					"pcp": closest_lat_lon(project_base.db, "weather_file", lat, lon, "pcp"),
					"slr": closest_lat_lon(project_base.db, "weather_file", lat, lon, "slr"),
					"tmp": closest_lat_lon(project_base.db, "weather_file", lat, lon, "tmp"),
					"wnd": closest_lat_lon(project_base.db, "weather_file", lat, lon, "wnd")
					"""

                stations.append(station)
            i += 1

        db_lib.bulk_insert(project_base.db, Weather_sta_cli, stations)
        self.match_files_to_stations(45, 45)
    def create_weather_stations(
        self, start_prog, total_prog
    ):  # total_prog is the total progress percentage available for this method
        if self.__abort: return

        stations = []
        query = Weather_wgn_cli.select()
        records = query.count()
        i = 1
        for row in query:
            if self.__abort: return

            lat = row.lat
            lon = row.lon
            #name = "w{lat}{lon}".format(lat=abs(round(lat*1000)), lon=abs(round(lon*1000)))
            name = weather_sta_name(lat, lon)

            prog = round(i * total_prog / records) + start_prog
            # self.emit_progress(prog, "Creating weather station {name}...".format(name=name))

            try:
                existing = Weather_sta_cli.get(Weather_sta_cli.name == name)
            except Weather_sta_cli.DoesNotExist:
                station = {
                    "name": name,
                    "hmd": None,
                    "pcp": None,
                    "slr": None,
                    "tmp": None,
                    "wnd": None,
                    "wnd_dir": None,
                    "atmo_dep": None,
                    "lat": lat,
                    "lon": lon,
                    "wgn": row.id
                }

                stations.append(station)
            i += 1

        db_lib.bulk_insert(project_base.db, Weather_sta_cli, stations)
 def delete_existing(self):
     Weather_file.delete().execute()
     Weather_sta_cli.delete().execute()