Exemple #1
0
class CovidModel(Model):
    __keyspace__ = KEYSPACE
    __table_name__ = 'covid19data'

    # Index(['Province/State', 'Country/Region', 'Last Update', 'Confirmed', 'Deaths', 'Recovered'], dtype='object')
    id = columns.Text(primary_key=True)
    province_or_state = columns.Text()
    country_or_region = columns.Text()
    last_update = columns.DateTime()
    confirmed = columns.Integer()
    deaths = columns.Integer()
    recovered = columns.Integer()
Exemple #2
0
class UserTransactions(DjangoCassandraModel):
    transaction_id = columns.UUID(primary_key=True)
    user_id = columns.UUID()
    created_date = columns.DateTime()
    trade_type = columns.Text()
    purchase_type = columns.Text()
    currency = columns.Text()
    staring_price = columns.Float()
    closing_price = columns.Float()
    amount = columns.Float()
    start_time = columns.DateTime()
    end_time = columns.DateTime()
    changes_allowed_time = columns.DateTime()
    outcome = columns.Text()
    status = columns.Text()
    time_close = columns.DateTime()
    level_pips = columns.Integer()
    levels_price = columns.Text()
    level_owners = columns.Text()
    join_date = columns.DateTime()
    level_start_price = columns.Float()
    level_end_price = columns.Float()
    level_selected = columns.Integer()
    created_by = columns.UUID()
    parent_id = columns.UUID()
    child = columns.Boolean()
    available_levels = columns.List(columns.Integer())
class CompletedSession(Base):

    player_id = columns.Text(primary_key=True, partition_key=True)
    session_id = columns.Text(primary_key=True)
    ts = columns.DateTime(primary_key=True, clustering_order="DESC")

    def get_data(self):

        return {
            'player_id': self.player_id,
            'session_id': self.session_id,
            'ts': str(self.ts)
        }
Exemple #4
0
class AccountModel(Model):
    __table_name__ = "account"
    tp = columns.Text(required=True)
    name = columns.Text(required=True, primary_key=True)
    cash = columns.Float(required=True)
    initial_cash = columns.Float(required=True)
    positions = columns.Map(key_type=columns.Text,
                            value_type=columns.Float,
                            default={})
    history_net_value = columns.Map(key_type=columns.DateTime(),
                                    value_type=columns.Float(),
                                    default={})
    orders = columns.List(value_type=UserDefinedType(UserOrderModel))
Exemple #5
0
class Post(Model):
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    title = columns.Text()
    subtitle = columns.Text()
    content = columns.Text()
    date_posted = columns.DateTime()

    def __repr__(self):
        return {
            'title': self.title,
            'subtitle': self.subtitle,
            'date_posted': self.date_posted
        }
Exemple #6
0
class ChatByUserId(Model):
    user_id = columns.Text(primary_key=True)
    chat_id = columns.Text()
    chat_name = columns.Text()
    time = columns.DateTime(default=date_now)  # rename to creation_date

    def to_object(self):
        return {
            'user_id': self.user_id,
            'chat_id': self.chat_id,
            'chat_name': self.chat_name,
            'time': self.time.isoformat()
        }
Exemple #7
0
class Earthquake(Model):
    eventId = columns.Text(primary_key=True, required=True)
    place = columns.Text(required=True, index=True)
    time = columns.Text(required=True, index=True)
    fecha = columns.DateTime(required=True, index=True)
    magnitude = columns.Decimal(required=True)
    depth = columns.Decimal(required=True)
    longitude = columns.Decimal(required=True, index=True)
    latitude = columns.Decimal(required=True, index=True)
    geojson = columns.Text(required=True)
    quadrant = columns.Text(index=True)
    quadrantX = columns.Decimal(index=True)
    quadrantY = columns.Decimal(index=True)
class AccountModel(Model):
    __table_name__ = "account2"
    tp = columns.Text(required=True)
    name = columns.Text(required=True, primary_key=True)
    cash = columns.Float(required=True)
    initial_cash = columns.Float(required=True)
    positions = columns.Map(key_type=columns.Text,
                            value_type=columns.Float,
                            default={})
    account_id = columns.Text()
    history_net_value = columns.Map(key_type=columns.DateTime(),
                                    value_type=columns.Float(),
                                    default={})
Exemple #9
0
class visa_detail(Model):

    id = columns.UUID(required=True, partition_key=True)

    course_id = columns.UUID(required=False, )

    information = columns.Text(required=False, )

    last_date_submission = columns.Text(required=False, )

    document_description = columns.Text(required=False, )

    visa_url = columns.Text(required=False, )

    schooli_invitation_letter = columns.Text(required=False, )

    refund_policy = columns.Text(required=False, )

    auto_reply_message = columns.Text(required=False, )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
Exemple #10
0
class UserIdentity(BaseModel):
    """User's identities model."""

    user_id = columns.UUID(primary_key=True)
    identity_id = columns.UUID(primary_key=True)
    credentials = columns.Map(columns.Text, columns.Text)
    display_name = columns.Text()
    identifier = columns.Text()
    infos = columns.Map(columns.Text, columns.Text)
    last_check = columns.DateTime()
    protocol = columns.Text()
    status = columns.Text()
    type = columns.Text()
    def test_mintimeuuid_function(self):
        """
        Tests that queries with helper functions are generated properly
        """
        now = datetime.now()
        where = WhereClause('time', EqualsOperator(),
                            functions.MinTimeUUID(now))
        where.set_context_id(5)

        self.assertEqual(str(where), '"time" = MinTimeUUID(%(5)s)')
        ctx = {}
        where.update_context(ctx)
        self.assertEqual(ctx, {'5': columns.DateTime().to_database(now)})
Exemple #12
0
class HarvesterResponse(models.Model, BaseHarvesterResponse):
    __table_name__ = 'responses'

    method = columns.Text(primary_key=True)
    url = columns.Text(primary_key=True, required=True)

    # Raw request data
    ok = columns.Boolean()
    content = columns.Bytes()
    encoding = columns.Text()
    headers_str = columns.Text()
    status_code = columns.Integer()
    time_made = columns.DateTime(default=datetime.now)
Exemple #13
0
class EventErrComm(DjangoCassandraModel):
    # uid_ev = columns.TimeUUID(primary_key=True, default=uuid.uuid1)
    year = columns.Integer(primary_key=True, partition_key=True)
    post_time = columns.DateTime(primary_key=True, clustering_order="DESC")
    eve_name = columns.Text()
    mis_clock = columns.BigInt()
    seq_number = columns.Integer()

    class Meta:
        get_pk_field = 'post_time'

    def __str__(self):
        return "Error Event {} with clock {} and sequence {}.".format(
            self.eve_name, self.mis_clock, self.seq_number)
Exemple #14
0
class RaceResult(Model):
    raceResultId = columns.UUID(primary_key=True, default=uuid.uuid4)
    raceId = columns.UUID(index=True, default=uuid.uuid4)
    raceParticipantId = columns.UUID(index=True, default=uuid.uuid4)
    petCategoryId = columns.UUID(index=True, default=uuid.uuid4)
    petName = columns.Text(index=True)
    petType = columns.Text(required=False)
    petColor = columns.Text()
    petCategoryName = columns.Text(required=False)
    finishPosition = columns.Integer()
    finishTime = columns.Decimal()
    startTime = columns.DateTime()

    __keyspace__ = 'gpmr'
Exemple #15
0
class FlightModel(Model):
    __table_name__ = "flightlog"
    __keyspace__   = "airport"

    id                  = columns.Integer(primary_key=True)
    year                = columns.Integer()
    day_of_month        = columns.Integer()
    fl_date             = columns.DateTime()
    airline_id          = columns.Integer()
    carrier             = columns.Text()
    fl_num              = columns.Integer()
    origin_airport_id   = columns.Integer()
    origin              = columns.Text()
    origin_city_name    = columns.Text()
    origin_state_abr    = columns.Text()
    dest                = columns.Text()
    dest_city_name      = columns.Text()
    dest_state_abr      = columns.Text()
    dep_time            = columns.DateTime()
    arr_time            = columns.DateTime()
    actual_elapsed_time = columns.Integer()
    air_time            = columns.Integer()
    distance            = columns.Integer()
Exemple #16
0
class Tweet(Model):
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    event_name = columns.Text(index=True)
    t_id = columns.Text(primary_key=True, clustering_order="DESC")
    event_kw = columns.Text()
    t_created_at = columns.DateTime()
    t_text = columns.Text()
    t_retweet_count = columns.Integer()
    t_favorite_count = columns.Integer()
    t_geo = columns.Text()
    t_coordinates = columns.Text()
    t_favorited = columns.Boolean()
    t_retweeted = columns.Boolean()
    t_is_a_retweet = columns.Boolean()
    t_lang = columns.Text()
    u_id = columns.Text()
    u_name = columns.Text()
    u_screen_name = columns.Text()
    u_location = columns.Text()
    u_url = columns.Text()
    u_lang = columns.Text()
    u_description = columns.Text()
    u_time_zone = columns.Text()
    u_geo_enabled = columns.Boolean()
    media_url = columns.Text()
    um_screen_name = columns.Text()
    um_name = columns.Text()
    um_id = columns.Text()
    u_followers_count = columns.Integer()
    u_friends_count = columns.Integer()
    u_listed_count = columns.Integer()
    u_favourites_count = columns.Integer()
    u_utc_offset = columns.Integer()
    u_statuses_count = columns.Integer()
    u_created_at = columns.DateTime()
    hashtags = columns.List(value_type=columns.Text)
    urls = columns.List(value_type=columns.Text)
class Shipment(Model):
    shipping_code = columns.UUID(primary_key=True, default=uuid4)
    created_at = columns.DateTime(primary_key=True,
                                  required=True,
                                  clustering_order="ASC",
                                  default=datetime.utcnow)

    inventory_code = columns.Text(primary_key=True,
                                  clustering_order="ASC",
                                  required=True)
    status = columns.Text(default=constants.K_STATUS_CREATED, required=True)

    # location
    start_name = columns.Text(required=True)
    start_lat = columns.Double(required=True)
    start_lng = columns.Double(required=True)

    destination_name = columns.Text(required=True)
    destination_lat = columns.Double(required=True)
    destination_lng = columns.Double(required=True)

    def set_as_otw(self):
        self.status = constants.K_STATUS_OTW

    def set_as_finished(self):
        self.status = constants.K_STATUS_FINISHED

    @property
    def is_finished(self):
        return self.status == constants.K_STATUS_FINISHED

    @property
    def is_new(self):
        return self.status == constants.K_STATUS_CREATED

    def to_dict(self):
        return {
            'shipping_code': str(self.shipping_code),
            'created_at': str(self.created_at),
            'inventory_code': self.inventory_code,
            'status': self.status,
            'is_finished': self.is_finished,
            'start_name': self.start_name,
            'start_lat': self.start_lat,
            'start_lng': self.start_lng,
            'destination_name': self.destination_name,
            'destination_lat': self.destination_lat,
            'destination_lng': self.destination_lng,
        }
Exemple #18
0
class SeismicEvent(DjangoCassandraModel):
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    mag = columns.Double()
    place = columns.Text()
    time = columns.DateTime()
    updated = columns.DateTime()
    tz = columns.SmallInt()
    status = columns.Text()
    tsunami = columns.TinyInt()
    sig = columns.SmallInt()
    net = columns.Text()
    code = columns.Text()
    ids = columns.Text()
    sources = columns.Text()
    types = columns.Text()
    nst = columns.SmallInt()
    dmin = columns.Double()
    rms = columns.Double()
    gap = columns.SmallInt()
    magType = columns.Text()
    type = columns.Text()
    latitude = columns.Double()
    longitude = columns.Double()
    depth = columns.Double()
Exemple #19
0
class HashLookup(BaseModel):
    """
    Table to lookup in which hash(es) an uri is embedded

    URIs in the form of "scheme:path"
     - for example : "email:[email protected]", "twitter:caliopen_org"

    It is updated each time a message gets in or out (including draft edition)
    """

    user_id = columns.UUID(primary_key=True)
    uri = columns.Text(primary_key=True)
    hash = columns.Text(primary_key=True)
    hash_components = columns.List(columns.Text())
    date_insert = columns.DateTime()
Exemple #20
0
class MeasurementRaw(Model):
    __keyspace__ = 'measurements'
    site = columns.Text(required=True, primary_key=True)
    meas_name = columns.Text(required=True, primary_key=True)
    ts = columns.DateTime(primary_key=True) # timestamp in schema
    sensor = columns.Text(required=True, primary_key=True)
    station = columns.Text(required=True, primary_key=True)
    company = columns.Text(required=True, primary_key=True)
    lat_lon = UserDefinedType(Geopoint)
    meas_description = columns.Text()
    meas_status = columns.Boolean()
    meas_unit = columns.Text()
    meas_val_b = columns.Boolean()
    meas_val_f = columns.Float()
    meas_val_s = columns.Text()
Exemple #21
0
class Product(AioModel):

    __table_name__ = 'product'

    manager_id = columns.UUID(partition_key=True)
    product_id = columns.UUID(primary_key=True)
    name = columns.Text(index=True)
    price = columns.Float()
    description = columns.Text()

    created_at = columns.DateTime(default=datetime.utcnow())
    updated_at = columns.DateTime(default=datetime.utcnow())

    @classmethod
    async def new(cls, manager_id, name, price, description):
        return await Product.async_create(manager_id=manager_id,
                                          product_id=str(uuid.uuid4()),
                                          name=name,
                                          price=price,
                                          description=description)

    async def update_product(self, **new_product):
        new_product['updated_at'] = datetime.utcnow()
        return await self.async_update(**new_product)
class AllDatatypes(UserType):
    a = columns.Ascii()
    b = columns.BigInt()
    c = columns.Blob()
    d = columns.Boolean()
    e = columns.DateTime()
    f = columns.Decimal()
    g = columns.Double()
    h = columns.Float()
    i = columns.Inet()
    j = columns.Integer()
    k = columns.Text()
    l = columns.TimeUUID()
    m = columns.UUID()
    n = columns.VarInt()
class SampleModel(Model):
    __keyspace__ = 'test_keyspace'
    __table_name__ = 'sample_table'

    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    name = columns.Text(required=True)
    surname = columns.Text(required=True)
    title = columns.Text(required=True)
    skills = columns.Map(
        key_type=columns.Text,
        value_type=columns.Text,
        required=False,
    )
    created_at = columns.DateTime(default=datetime.utcnow)
    city_name = columns.Text(required=False)
Exemple #24
0
class Task(models.Model):
    title = columns.Text()
    complete = columns.Boolean(default=False)
    created = columns.DateTime()  # set auto now add = True
    description = columns.Text()
    author = columns.UUID(
        primary_key=True
    )  # here we are using author id instead of django author
    completed_picture = columns.Bytes(required=False)

    class Meta:
        ordering = ('created', )

    def __str__(self) -> str:
        return self.title
Exemple #25
0
class Song(DjangoCassandraModel):
    __table_name__ = 'songs_by_user'

    class Meta:
        get_pk_field = 'uid'

    uid = columns.UUID(primary_key=True)
    created = columns.DateTime(primary_key=True, clustering_order="DESC")
    uri = columns.Text(primary_key=True)

    title = columns.Text()
    artists = columns.List(columns.Text())
    duration = columns.Double()
    album = columns.Text()
    isrc = columns.Text()
Exemple #26
0
class RaceData(Model):
    raceDataId = columns.UUID(primary_key=True, default=uuid.uuid4)
    petId = columns.UUID(index=True, default=uuid.uuid4)
    raceId = columns.UUID(index=True, default=uuid.uuid4)
    petName = columns.Text(index=True)
    petCategoryName = columns.Text(required=False)
    petCategoryId = columns.UUID(index=True, default=uuid.uuid4)
    interval = columns.Integer()
    runnerPosition = columns.Integer()
    runnerDistance = columns.Decimal()
    startTime = columns.DateTime()
    finished = columns.Boolean()
    runnerPreviousDistance = columns.Decimal()

    __keyspace__ = 'gpmr'
Exemple #27
0
class Metrics(Model):
    """Cassandra model that's represents metric from SWAN.

    Variables:
    ------------------
    ns: Namespace of metric.

    ver: Collector plugin version.

    disk: Host name.

    time: Time when metric was collected.

    boolval: Boolean value of metric.

    doubleval: Double value of metric.

    strval: String value of metric.

    tags: Tags in <key,value>.

    valtype: Value type of metric."""

    ns = columns.Text(partition_key=True)
    ver = columns.Integer(partition_key=True)
    host = columns.Text(partition_key=True)
    time = columns.DateTime(partition_key=True)
    boolval = columns.Boolean()
    doubleval = columns.Double()
    strval = columns.Text()
    tags = columns.Map(columns.Text(), columns.Text())
    valtype = columns.Text()

    @staticmethod
    def get_by_experiment_id(experiment_id):
        """Return metrics from experiment.

        Keyword arguments:
        ------------------
        experiment_id : string
            Experiment id.

        Returns:
        --------
        host_aggregates: list of Metric objects."""

        return Metrics.objects().filter(
            tags__contains=experiment_id).allow_filtering().limit(None)
 class AllDatatypesModel(Model):
     id = columns.Integer(primary_key=True)
     a = columns.Ascii()
     b = columns.BigInt()
     c = columns.Blob()
     d = columns.Boolean()
     e = columns.DateTime()
     f = columns.Decimal()
     g = columns.Double()
     h = columns.Float()
     i = columns.Inet()
     j = columns.Integer()
     k = columns.Text()
     l = columns.TimeUUID()
     m = columns.UUID()
     n = columns.VarInt()
class result(Model):
    __keyspace__ = os.getenv("CASSANDRA_KEY_SPACE")
    __table_name__ = "result"

    id = columns.UUID(primary_key=True, default=uuid4)
    data = columns.List(value_type=columns.Float)
    is_fraud = columns.Boolean(default=False)
    time = columns.DateTime(default=datetime.utcnow)

    @classmethod
    def find_all(cls):
        return cls.objects.all()

    @classmethod
    def count_all(cls):
        return cls.objects.count()
Exemple #30
0
class MessageModel(Model):
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    chat_id = columns.UUID(required=True)
    user_id = columns.Integer(required=True)
    message = columns.Text(required=True)
    status = columns.Set(columns.Integer())
    create_at = columns.DateTime()

    def to_dict(self):
        return {
            'id': str(self.id),
            'chat_id': self.chat_id,
            'user_id': self.user_id,
            'message': self.message,
            'create_at': self.create_at,
        }