예제 #1
0
 def get_locations() -> Set[Location]:
     """
     get a list of all the defined locations
     :return: Set[Location]
     """
     locations = {
         # Exeter flood defence cycle path - trews wier at 3.89 (and slowly falling) path is part covered
         # .../flood-monitoring/data/readings/45128-level-stage-i-15_min-m/2021-01-28T17-45-00Z
         Location(
             name="Millers Crossing and the Quay",
             monitoring_station="45128",
             wet=3.86,
             warn=3.84,
             messages={
                 FloodStates.DRY:
                 "Flood defence path between Millers Crossing and the Quay is clear",
                 FloodStates.WARN:
                 "Possibility of flooding soon on the flood defence path between "
                 "Millers Crossing and the Quay",
                 FloodStates.CARE:
                 "Flood defence path between Millers Crossing and the Quay may be passable",
                 FloodStates.WET:
                 "Flood defence path between Millers Crossing and the Quay is wet. "
                 "Plan an alternative route",
                 FloodStates.CLEAR_SOON:
                 "Flood defence path between Millers Crossing and the Quay "
                 "may be dry in 1 hour",
                 FloodStates.CLEAR_VERY_SOON:
                 "Flood defence path between Millers Crossing and the Quay "
                 "may be dry in 1/2 hour"
             }),
         Location(
             name="St David's and Millers Crossing",
             monitoring_station="45128",
             wet=4.03,
             warn=4.00,
             messages={
                 FloodStates.DRY:
                 "Flood defence path between St David's and Millers Crossing is clear",
                 FloodStates.WARN:
                 "Possibility of flooding soon on the flood defence path between "
                 "St David's and Millers Crossing",
                 FloodStates.CARE:
                 "Flood defence path between St David's and Millers Crossing may be passable",
                 FloodStates.WET:
                 "Flood defence path between St David's and Millers Crossing is wet. "
                 "Plan an alternative route",
                 FloodStates.CLEAR_SOON:
                 "Flood defence path between St David's and Millers Crossing "
                 "may be dry in 1 hour",
                 FloodStates.CLEAR_VERY_SOON:
                 "Flood defence path between St David's and Millers Crossing "
                 "may be dry in 1/2 hour"
             })
     }
     return locations
예제 #2
0
    def decode(self, reader):
        """
        BOGUS extra data not handled
        :param reader:
        :return:
        """
        self.type = reader.read_byte()

        if self.type == -31:
            self.item_type = reader.read_ushort()

        self.source = Location(reader)

        if self.type == -11:    # Move item
            self.src_level = reader.read_byte()
            self.sub = reader.read_ubyte()
            if self.sub == 0xe5:
                self.dst_level = reader.read_byte()
                self.dst_blk = Location(reader)
            elif self.sub == 0xeb:
                self.dst_blk = Location(reader)
            else:
                self.payload = reader.read_ubyte(4)

        elif self.type == -31:  # Move item by type
            self.src_blk = Location(reader)
            self.dst_blk = Location(reader)

        elif self.type == -13:  # Move monster
            self.destination = Location(reader)

        elif self.type == -24:  # Move party
            self.destination = Location(reader)

        i = 1
예제 #3
0
def find_location(location):
	if location is None:
		return None

	response = get_station_and_gmt(location)
	if response is None:
		return None

	station = response['station']
	timezone = response['gmt']
	name = response['name']
	location_entity = Location.all().filter('station =', station).get()

	if location_entity is None:
		location_entity = Location(name=name, station=station, timezone=timezone)
		location_entity.put()

	return location_entity
예제 #4
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.location = Location(reader)
예제 #5
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.id = reader.read_ubyte()
        self.location = Location(reader)
예제 #6
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.type = reader.read_byte()
        if self.type != -1:
            self.location = Location(reader)
예제 #7
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.whom = reader.read_byte()
        self.location = Location(reader)
        self.sub_position = reader.read_ubyte()
예제 #8
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.type = reader.read_byte()

        if self.type == -9:    # All sides
            self.location = Location(reader)
            self.to = reader.read_ubyte()

        elif self.type == -23:     # one side
            self.location = Location(reader)
            self.side = reader.read_ubyte()
            self.to = reader.read_ubyte()

        elif self.type == -19:     # change party direction
            self.direction = reader.read_ubyte()
예제 #9
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.type = reader.read_byte()
        self.item_id = reader.read_ushort()
        self.location = Location(reader)
        self.direction = reader.read_ubyte()
        self.sub_position = reader.read_ubyte()
예제 #10
0
	def post(self):
		place = Location.get(self.request.get('location_key'))
		forecast = get_next_rainy_day(place.station, place.timezone)
		if not forecast and place.next_rain_datetime:
			place.forecast = "It will not rain in the next week!"
			place.next_rain_datetime = None
			place.changed_prediction = True
		if forecast and forecast[0] != place.next_rain_datetime:
			logging.debug("Updating forecast of %s to %s"%(place.station, str(forecast)))
			place.forecast = forecast[1]
			place.next_rain_datetime = forecast[0]
			place.changed_prediction = True
		db.put(place)
		logging.debug('Updated %s forecast' % (place.name, ))
예제 #11
0
    def decode(self, reader):

        if not reader:
            return

        self.unit = reader.read_ubyte()
        self.timer = reader.read_ubyte()
        self.location = Location(reader)
        self.pos = reader.read_ubyte()
        self.dir = reader.read_byte()
        self.type = reader.read_ubyte()
        self.frame = reader.read_ubyte()
        self.phase = reader.read_ubyte()
        self.pause = reader.read_ubyte()
        self.pocket = reader.read_ushort()
        self.weapon = reader.read_ushort()
예제 #12
0
 def test_load(self):
     location = Location(
         name="test",
         monitoring_station="45128",
         wet=1,
         warn=0.5,
         messages={state: f"message {state.name}"
                   for state in FloodStates})
     x_data, y_data = get_data(location)
     self.assertEqual(24, len(x_data))
     self.assertEqual(24, len(y_data))
     x_data, y_data = get_data(location, 5)
     self.assertEqual(5, len(x_data))
     self.assertEqual(5, len(y_data))
     # check the last point in the sequence is within 5 minutes of where it should be
     self.assertAlmostEqual(min(x_data) + 4 * 60 * 15,
                            max(x_data),
                            delta=300)
예제 #13
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.cmd = reader.read_byte()
        self.index = reader.read_byte()

        if self.cmd == -27:
            self.sub = reader.read_byte()
            self.location = Location(reader)
            self.direction = reader.read_byte()

        else:
            self.level = reader.read_byte()
            self.monster = reader.read_byte(13)
예제 #14
0
	def get(self):
		all_places = list(Location.all())
		rainy_places = self._get_locations(all_places)
		twitter = login_twitter_bot()

		logging.debug("The rainy places are: "+str([location.name for location in rainy_places]))
		for place in all_places:
			if place in rainy_places:
				users = list(User.all(keys_only=True).filter('location =', place).filter('active =', True))
				message = self._format_message(place)

				user_len = len(users)
				for i in range(0, user_len / RainNotification.DM_PER_REQUEST + 1):
					slice = users[i*RainNotification.DM_PER_REQUEST:(i + 1)*RainNotification.DM_PER_REQUEST]

					if len(slice) > 0:
						QueueHandler.queue_notify(message, slice, i*10)
			else:
				place.last_broadcast_rain = False

		db.put(all_places)
예제 #15
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.item_id = reader.read_ushort()
        self.location = Location(reader)
        self.subpos = reader.read_ubyte()
        self.flags = reader.read_ubyte()

        i = 1
        if self.flags & 1 == 1:
            self.item_value = reader.read_byte()
        if self.flags & 2 == 2:
            self.item_flag = reader.read_byte()
        if self.flags & 4 == 4:
            self.item_icon = reader.read_byte()
예제 #16
0
    def decode(self, reader):
        """

        :param reader:
        :return:
        """
        if not reader:
            return

        self.type = reader.read_byte()
        self.location = Location(reader)

        if self.type == -9:   # All side
            self.to = reader.read_ubyte()
            self.model = reader.read_ubyte()

        elif self.type == -23:     # One side
            self.side = reader.read_ubyte()
            self.to = reader.read_ubyte()
            self.model = reader.read_ubyte()

        elif self.type == -22:     # Door
            pass
예제 #17
0
	def get(self):
		places = list(Location.all(keys_only=True))
		for i in xrange(len(places)):
			QueueHandler.queue_fetch(places[i], 5*i)
예제 #18
0
def get_location_from_update(update):
    return Location(update.message.location.latitude,
                    update.message.location.longitude)