<commit_before>import sys

from collections import deque, OrderedDict
from time import time
from itertools import chain
from hashlib import sha256

from . import bounds, db, sanitized as conf
from .shared import get_logger
from .utils import dump_pickle, load_pickle, get_current_hour, time_until_time


class BaseSpawns:
    """Manage spawn points and times"""
    def __init__(self):
        ## Spawns with known times
        # {(lat, lon): (spawn_id, spawn_seconds)}
        self.known = OrderedDict()
        # {spawn_id: despawn_seconds}
        self.despawn_times = {}
        self.updated_at = {}
        # {spawn_id: spawnpoints.id}
        self.internal_ids = {}

        ## Spawns with unknown times
        # {(lat, lon)}
        self.unknown = set()

        self.class_version = 3.1 
        self.db_hash = sha256(conf.DB_ENGINE.encode()).digest()
        self.log = get_logger('spawns')

    def __len__(self):
        return len(self.despawn_times)

    def __bool__(self):
        return len(self.despawn_times) > 0

    def update(self):
        bound = bool(bounds)
        last_migration = conf.LAST_MIGRATION

        with db.session_scope() as session:
            query = session.query(db.Spawnpoint)
            if bound or conf.STAY_WITHIN_MAP:
                query = query.filter(db.Spawnpoint.lat >= bounds.south,
                                     db.Spawnpoint.lat <= bounds.north,
                                     db.Spawnpoint.lon >= bounds.west,
                                     db.Spawnpoint.lon <= bounds.east)
            known = {}
            for spawn in query:
                point = spawn.lat, spawn.lon

                # skip if point is not within boundaries (if applicable)
                if bound and point not in bounds:
                    continue

                if not spawn.updated or spawn.updated <= last_migration:
                    self.unknown.add(point)
                    continue

                if spawn.despawn_time:
                    if spawn.duration == 60:
                        spawn_time = spawn.despawn_time
                    else:
                        spawn_time = (spawn.despawn_time + 1800) % 3600

                    self.despawn_times[spawn.spawn_id] = spawn.despawn_time
                    known[point] = spawn.spawn_id, spawn_time

                self.updated_at[spawn.spawn_id] = spawn.updated<commit_msg>[fix]spawns.update()<commit_after>import sys

from collections import deque, OrderedDict
from time import time
from itertools import chain
from hashlib import sha256

from . import bounds, db, sanitized as conf
from .shared import get_logger
from .utils import dump_pickle, load_pickle, get_current_hour, time_until_time


class BaseSpawns:
    """Manage spawn points and times"""
    def __init__(self):
        ## Spawns with known times
        # {(lat, lon): (spawn_id, spawn_seconds)}
        self.known = OrderedDict()
        # {spawn_id: despawn_seconds}
        self.despawn_times = {}
        self.updated_at = {}
        # {spawn_id: spawnpoints.id}
        self.internal_ids = {}

        ## Spawns with unknown times
        # {(lat, lon)}
        self.unknown = set()

        self.class_version = 3.1 
        self.db_hash = sha256(conf.DB_ENGINE.encode()).digest()
        self.log = get_logger('spawns')

    def __len__(self):
        return len(self.despawn_times)

    def __bool__(self):
        return len(self.despawn_times) > 0

    def update(self):
        bound = bool(bounds)
        last_migration = conf.LAST_MIGRATION

        with db.session_scope() as session:
            query = session.query(db.Spawnpoint)
            if bound or conf.STAY_WITHIN_MAP:
                query = query.filter(db.Spawnpoint.lat >= bounds.south,
                                     db.Spawnpoint.lat <= bounds.north,
                                     db.Spawnpoint.lon >= bounds.west,
                                     db.Spawnpoint.lon <= bounds.east)
            known = {}
            for spawn in query:
                point = spawn.lat, spawn.lon

                # skip if point is not within boundaries (if applicable)
                if bound and point not in bounds:
                    continue

                if not spawn.updated or spawn.updated <= last_migration:
                    self.unknown.add(point)
                    continue

                if spawn.despawn_time:
                    if spawn.duration == 60:
                        spawn_time = spawn.despawn_time
                    else:
                        spawn_time = (spawn.despawn_time + 1800) % 3600
                    self.despawn_times[spawn.spawn_id] = spawn.despawn_time
                    known[point] = spawn.spawn_id, spawn_time
                else:
                    self.unknown.add(point)

                self.updated_at[spawn.spawn_id] = spawn.updated
{'fraction_non_alphanumeric': 0.08503679476696648, 'fraction_numerical': 0.00776778413736713, 'mean_word_length': 1.6520325203252033, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021851', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1359, 'n_words': 327}