<commit_before>#!/usr/bin/env python
#
# Copyright 2011 <NAME> & <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


"""
This is a basic database schema for the cs4sq project. Not very sophisticated, but it'll do.
"""
from sqlalchemy import Table, Column, Integer, String, Float, Boolean, DateTime, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import BIGINT
from sqlalchemy.orm import relationship, backref

Base = declarative_base()

class Category( Base ):
    """
    Categories of venues. Does not store the hierarchical structure of foursquare categories.
    """
    __tablename__ = 'categories'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    name = Column( String )

    def __init__( self, name, foursq_id ):
        self.name = name
        self.foursq_id = foursq_id

class CrawlLog( Base ):
    __tablename__ = 'crawllog'

    id = Column( Integer, primary_key=True )
    crawltype = Column( String )
    flag = Column( String )
    date = Column( DateTime )

    def __init__( self, crawltype, flag, date ):
        self.crawltype = crawltype
        self.flag = flag
        self.date = date

    def __repr__( self ):
        return u"<Crawl('%s', '%s', '%s')>" % ( self.crawltype, self.flag, self.date )

class Location( Base ):
    __tablename__ = 'locations'

    id = Column( Integer, primary_key=True )
    latitude = Column( Float )
    longitude = Column( Float )

    def __init__( self, latitude, longitude ):
        self.latitude = latitude
        self.longitude = longitude

    def __repr__( self ):
        return u"<Location('%f', '%f')>" % ( self.latitude, self.longitude )

class Statistic( Base ):
    __tablename__ = 'statistics'

    id = Column( Integer, primary_key=True ) 
    venue_id = Column( Integer, ForeignKey( 'venues.id' ) )
    venue = relationship("Venue", backref=backref('statistics', order_by='Statistic.date'), cascade="all, save-update")
    date = Column( DateTime )
    checkins = Column( Integer )
    users = Column( Integer )

    def __init__( self, venue_id, date, checkins, users ):
        self.date = date
        self.venue_id = venue_id
        self.checkins = checkins
        self.users = users

    def __repr__( self ):
        return u"<Statistics('%s', '%d', '%d')>" % ( self.date, self.checkins, self.users )

class Venue( Base ):
    __tablename__ = 'venues'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    name = Column( String )
    verified = Column( Boolean )
    city_code = Column ( String )
    location_id = Column( Integer, ForeignKey( 'locations.id' ) )
    location = relationship("Location", backref=backref('venues'), cascade="all, save-update")
    category_id = Column( Integer, ForeignKey('categories.id') )
    category = relationship("Category", backref=backref('venues'), cascade="all, save-update")
    mayor_id = Column( Integer, ForeignKey( 'users.id' ) )
    mayor = relationship("User", backref=backref('mayorships'), cascade="all, save-update")

    def __init__( self, foursq_id, name, verified, location_id, city_code ):
        self.foursq_id = foursq_id
        self.name = name
        self.verified = verified
        self.location_id = location_id
        self.city_code = city_code

    def __repr__( self ):
        return u"<Venue('%s', '%s', '%s', '%s', '%s')>" % (self.name, self.foursq_id, self.location, self.statistics, self.checkins)

    def get_latest_statistic():
        return statistics[0]
    
class User( Base ):
    __tablename__ = 'users'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    first_name = Column( String )<commit_msg>minor change to venue __repr__<commit_after>#!/usr/bin/env python
#
# Copyright 2011 <NAME> & <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


"""
This is a basic database schema for the cs4sq project. Not very sophisticated, but it'll do.
"""
from sqlalchemy import Table, Column, Integer, String, Float, Boolean, DateTime, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import BIGINT
from sqlalchemy.orm import relationship, backref

Base = declarative_base()

class Category( Base ):
    """
    Categories of venues. Does not store the hierarchical structure of foursquare categories.
    """
    __tablename__ = 'categories'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    name = Column( String )

    def __init__( self, name, foursq_id ):
        self.name = name
        self.foursq_id = foursq_id

class CrawlLog( Base ):
    __tablename__ = 'crawllog'

    id = Column( Integer, primary_key=True )
    crawltype = Column( String )
    flag = Column( String )
    date = Column( DateTime )

    def __init__( self, crawltype, flag, date ):
        self.crawltype = crawltype
        self.flag = flag
        self.date = date

    def __repr__( self ):
        return u"<Crawl('%s', '%s', '%s')>" % ( self.crawltype, self.flag, self.date )

class Location( Base ):
    __tablename__ = 'locations'

    id = Column( Integer, primary_key=True )
    latitude = Column( Float )
    longitude = Column( Float )

    def __init__( self, latitude, longitude ):
        self.latitude = latitude
        self.longitude = longitude

    def __repr__( self ):
        return u"<Location('%f', '%f')>" % ( self.latitude, self.longitude )

class Statistic( Base ):
    __tablename__ = 'statistics'

    id = Column( Integer, primary_key=True ) 
    venue_id = Column( Integer, ForeignKey( 'venues.id' ) )
    venue = relationship("Venue", backref=backref('statistics', order_by='Statistic.date'), cascade="all, save-update")
    date = Column( DateTime )
    checkins = Column( Integer )
    users = Column( Integer )

    def __init__( self, venue_id, date, checkins, users ):
        self.date = date
        self.venue_id = venue_id
        self.checkins = checkins
        self.users = users

    def __repr__( self ):
        return u"<Statistics('%s', '%d', '%d')>" % ( self.date, self.checkins, self.users )

class Venue( Base ):
    __tablename__ = 'venues'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    name = Column( String )
    verified = Column( Boolean )
    city_code = Column ( String )
    location_id = Column( Integer, ForeignKey( 'locations.id' ) )
    location = relationship("Location", backref=backref('venues'), cascade="all, save-update")
    category_id = Column( Integer, ForeignKey('categories.id') )
    category = relationship("Category", backref=backref('venues'), cascade="all, save-update")
    mayor_id = Column( Integer, ForeignKey( 'users.id' ) )
    mayor = relationship("User", backref=backref('mayorships'), cascade="all, save-update")

    def __init__( self, foursq_id, name, verified, location_id, city_code ):
        self.foursq_id = foursq_id
        self.name = name
        self.verified = verified
        self.location_id = location_id
        self.city_code = city_code

    def __repr__( self ):
        return u"<Venue('%s', '%s', '%s')>" % (self.name, self.foursq_id, self.location)

    def get_latest_statistic():
        return statistics[0]
    
class User( Base ):
    __tablename__ = 'users'

    id = Column( Integer, primary_key=True )
    foursq_id = Column( String )
    first_name = Column( String )
{'fraction_non_alphanumeric': 0.11569069960802945, 'fraction_numerical': 0.002375579047392802, 'mean_word_length': 3.2460917801311147, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660628', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2527, 'n_words': 778}