예제 #1
0
class User(db.Document):
    fb_id = db.StringField(max_length=255, required=True)
    name = db.StringField(max_length=255, required=True)
    description = db.StringField(required=True)
    twitter = db.URLField(verify_exists=True)
    fb_link = db.URLField(verify_exists=True)
    template_choice = db.IntField(min_value=0)
예제 #2
0
class EventModel(db.Document):
    title = db.StringField()
    description = db.StringField()
    createTime = db.DateTimeField(default=datetime.datetime.now)
    startTime = db.StringField()
    endTime = db.StringField()
    userID = db.StringField()
    location = db.StringField()
    # latitude = db.FloatField()
    # longitude = db.FloatField()
    eventDate = db.StringField()
    LatLng = db.PointField()
    ZIP = db.StringField()
    status = db.StringField(default='new')
예제 #3
0
class Users(db.Document):
    username = db.StringField(required=True)
    password = db.StringField(required=True)
    first_name = db.StringField(max_length=50)
    last_name = db.StringField(max_length=50)

    @classmethod
    def check_user_passwd(cls, username, password):
        is_valid = None

        try:
            Users.objects.get(username=username, password=password)
        except Users.DoesNotExist:
            is_valid = False
        else:
            is_valid = True

        return is_valid
예제 #4
0
class ProfileModel(db.Document):
    name = db.StringField()
    gender = db.StringField()
    age = db.StringField()
    description = db.StringField()
    userID = db.StringField()
    image = db.StringField()
    phone = db.StringField()
예제 #5
0
class Post(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    updated_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    title = db.StringField(max_length=255, required=True)
    slug = db.StringField(max_length=255, required=True)
    body = db.StringField(required=True)
    tags = db.ListField(db.StringField(max_length=60), default=[u'未分类'])
    comments = db.ListField(db.EmbeddedDocumentField('Comment'))

    def get_absolute_url(self):
        return url_for('post', kwargs={"slug": self.slug})

    def __unicode__(self):
        return self.title

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at', 'slug'],
        'ordering': ['-updated_at']
    }
예제 #6
0
class MongoTestModel(db.Document):
    k1 = db.StringField(required=True)
    k2 = db.StringField()
예제 #7
0
class EventMatchModel(db.Document):
    eventId = db.StringField()
    eventOwnerId = db.StringField()
    reqUserId = db.StringField()
    status = db.StringField(default='pending')
예제 #8
0
class Comment(db.EmbeddedDocument):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    body = db.StringField(verbose_name="Comment", required=True)
    author = db.StringField(verbose_name="Name", max_length=255, required=True)
예제 #9
0
파일: models.py 프로젝트: VeeSot/yals
class Entity(db.DynamicDocument):
    """"""
    # Symbolic representation for entity.For example - 1110111
    sequence = db.StringField(max_length=7, required=True)
    # Channel for signal.Range from 0 to 9.
    __channel = db.IntField(max_length=1, required=True, default=-1)
    # Set of frequency for possibly channels.For example - [0,0,1,2,0,0,5,0,0,1]
    __frequencies = db.ListField(db.IntField(),
                                 default=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

    def get_channel(self) -> int:
        """Returns channel number"""
        return self.__channel

    def get_frequencies(self) -> List[int]:
        """Returns list of freq"""
        return self.__frequencies

    def _set_channel(self, new_chanel: int):
        self.__channel = new_chanel

    def set_frequencies(self, new_frequencies: List[int]):
        self.__frequencies = new_frequencies

    def reset_frequencies(self):
        self.set_frequencies([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

    def reset_channels(self):
        self._set_channel(-1)

    def update_channel(self):
        """Update channel use max value from freq"""
        max_value = max(self.__frequencies)
        channel_number = self.__frequencies.index(max_value)
        self._set_channel(channel_number)
        self.save()

    @classmethod
    def update_all(cls):
        all_entities = Entity.objects.all()
        for entity in all_entities:
            entity.update_channel()

    @classmethod
    def drop_all(cls):
        all_entities = Entity.objects.all()
        for entity in all_entities:
            entity.delete()

    @classmethod
    def add(cls, data_set: str):
        sequence = Entity.data_set_to_sequence(data_set)
        channel = int(
            re.findall(re_channel, data_set)
            [0])  # Узнаем номер канала,что учитывать частотность по нему.
        # Возможно такая последовательность уже есть у нас в БД, поэтому стоит проверить
        entities = Entity.objects.filter(sequence=sequence)
        if entities:
            # Обновим эту запись
            entity = entities[0]
        else:
            # Нужна новая запись
            entity = Entity.objects.create(sequence=sequence)

        frequencies = entity.get_frequencies()
        frequencies[channel] += 1  # Увеличим счетчик "попаданий" на канал
        entity.set_frequencies(frequencies)
        entity.save()

    @classmethod
    def data_set_to_sequence(cls, data_set: str) -> str:
        # Сразу складываем в строчку  приводя  к унифицированой последовательности вида 1110111
        sequence = ''.join(re.findall(re_sequence, data_set))
        return sequence

    @classmethod
    def get_channel_by_key(cls, key: str) -> int:
        """Return metadata about record which has sequence equal key
        :param key:sequence of symbol.For example 1110111
        """
        entities = Entity.objects.filter(sequence=key)
        if entities:
            entity = entities[0]
            return entity.get_channel()
        else:
            return None