Exemplo n.º 1
0
class LocationPost(PostModel):
    latitude = fields.FloatField(required=True,
                                 verbose_name='location_latitude',
                                 mongo_name='latitude')
    longitude = fields.FloatField(required=True,
                                  verbose_name='location_longitude',
                                  mongo_name='longitude')

    @property
    def dict(self):
        return dict(post_id=self.post_id,
                    message_id=self.message_id,
                    creator=self.creator,
                    channel=self.channel,
                    type=self.type,
                    mime_type=self.mime_type,
                    group=self.group_hash,
                    created_date=self.created_date,
                    tags=self.tags,
                    links=dict(links_per_row=self.links.links_per_row,
                               links=[{
                                   'label': i.label,
                                   'url': i.url
                               } for i in self.links.links]),
                    source=dict(label=self.source.label, url=self.source.url),
                    reactions=[
                        dict(emoji=i.emoji, count=i.count)
                        for i in self.reactions.reactions
                    ],
                    location=dict(latitude=self.latitude,
                                  longitude=self.longitude))
Exemplo n.º 2
0
class TaskExecutionPerformance(EmbeddedMongoModel):
    """ Task performance metrics related to execution

    Assignments to timepoints:
        start_time (datetime): time assigned the timepoint 'start'
        pickup_time (datetime): time assigned to the timepoint 'pickup'
        delivery_time (datetime): time assigned to the timepoint 'delivery'

    delay (float): Time (in seconds) between latest admissible time and execution time
                  (if the execution time is later than the latest admissible time)
                   for all timepoints in the dispatchable graph


    earliness (float): Time (in seconds) between the execution time and earliest admissible
                       (if the execution time is earlier than the earliest admissible time)
                       for all timepoints in the dispatchable graph
    """

    start_time = fields.DateTimeField()
    pickup_time = fields.DateTimeField()
    delivery_time = fields.DateTimeField()
    delay = fields.FloatField(default=0.0)
    earliness = fields.FloatField(default=0.0)

    def update(self, start_time, pickup_time, delivery_time):
        self.start_time = start_time
        self.pickup_time = pickup_time
        self.delivery_time = delivery_time
Exemplo n.º 3
0
class BacktestSignalResult(MongoModel):
    """OHLCV + signal + pos"""

    candle_begin_time = fields.DateTimeField(primary_key=True)
    open_price = fields.Decimal128Field(mongo_name='open')
    high_price = fields.Decimal128Field(mongo_name='high')
    low_price = fields.Decimal128Field(mongo_name='low')
    close_price = fields.Decimal128Field(mongo_name='close')
    volume = fields.Decimal128Field()
    signal = fields.FloatField()
    pos = fields.FloatField()

    class Meta:
        connection_alias = DB_BACKTEST_SIGNAL
        codec_options = CodecOptions(tz_aware=True)

    @classmethod
    def bulk_upsert_records(cls, json_list, key_name='_id'):
        """Bulk upsert candle records"""
        coll = cls._mongometa.collection
        bulkOp = coll.initialize_unordered_bulk_op()
        for doc in json_list:
            if isinstance(key_name, list):
                filter_dict = dict(map(lambda k: (k, doc[k]), key_name))
            else:
                filter_dict = {key_name: doc[key_name]}
            doc['_cls'] = cls.__module__ + '.' + cls.__name__
            bulkOp.find(filter_dict).upsert().update({'$set': doc})
        results = bulkOp.execute()
        return results
Exemplo n.º 4
0
class Trails(MongoModel):
    """
    A model defining trails entity undertaken by hikers. It has embedded
    comments which reference the hiker.
    """
    trail_name = fields.CharField(max_length=100, required=True)
    distance = fields.FloatField(max_value=50, required=True)
    elevation = fields.FloatField(required=True)
    route_type = fields.CharField(max_length=20,
                                  choices=('Point to Point', 'Loop',
                                           'Out and Back'),
                                  required=True)
    difficulty = fields.CharField(max_length=20,
                                  choices=('Easy', 'Moderate', 'Difficult'),
                                  required=True)
    description = fields.CharField(max_length=600, required=True)
    centrepoint = fields.PointField(required=False)
    waypoints = fields.LineStringField(required=False)
    image = fields.URLField(required=True)
    embed_route = fields.CharField(max_length=800, required=True)
    location = fields.ReferenceField(Location)
    comments = fields.EmbeddedDocumentListField('Comment', required=False)

    def __str__(self):
        return self.trail_name
Exemplo n.º 5
0
class NeutralPanelCandleRecord(MongoModel):
    """中性策略原始数据"""

    candle_begin_time = fields.DateTimeField()
    symbol = fields.CharField()
    open = fields.FloatField()
    high = fields.FloatField()
    low = fields.FloatField()
    close = fields.FloatField()
    volume = fields.FloatField()
    quote_volume = fields.FloatField()
    trade_num = fields.FloatField()
    taker_buy_base_asset_volume = fields.FloatField()
    taker_buy_quote_asset_volume = fields.FloatField()
    avg_price = fields.FloatField()

    class Meta:
        connection_alias = DB_MARKET
        collection_name = CN_NEUTRAL_PANEL
        codec_options = CodecOptions(tz_aware=True)

    @classmethod
    def bulk_insert_records(cls, json_list):
        """批量插入"""
        def map_func(rec):
            ins = NeutralPanelCandleRecord()
            for key in rec:
                setattr(ins, key, rec[key])
            return ins

        inses = list(map(map_func, list(json_list)))
        NeutralPanelCandleRecord.objects.bulk_create(inses)
Exemplo n.º 6
0
class LoanAccount(BaseAccount):
    bankName = fields.CharField()
    ifscCode = fields.CharField()
    accountNumber = fields.CharField()
    interestRate = fields.FloatField()
    availBalance = fields.FloatField()
    bookBalance = fields.FloatField()
    rateOfInterest = fields.FloatField()
    currency = fields.CharField()
    totalOutstanding = fields.FloatField()

    def payment(self, amount):
        self.balance -= amount

    def charge(self, amount):
        self.balance += amount

    def populate(self):
        print("Adding Banking Account")
        self.name = input("Name: ")
        self.balance = 0.0
        self.description = input("Description: ")
        self.bankName = input("Name of the Bank: ")
        self.ifscCode = input("IFSC code: ")
        self.accountNumber = input("Account Number: ")
        self.rateOfInterest = float(input("Rate of interest: "))
        self.availBalance = 0.0
        self.bookBalance = 0.0
        self.currency = input("Currency: ")
        self.totalOutstanding = 0.0
Exemplo n.º 7
0
class Duration(EmbeddedMongoModel):
    mean = fields.FloatField()
    variance = fields.FloatField()

    def update(self, mean, variance):
        self.mean = mean
        self.variance = variance
Exemplo n.º 8
0
class Accessory(MongoModel):
    name = fields.CharField(primary_key=True, required=True)
    description = fields.CharField(required=True)
    level = fields.IntegerField(required=True)
    rarity = fields.IntegerField(required=True)
    weight = fields.IntegerField(required=True)
    itype = fields.IntegerField(required=True)
    bonus_strength = fields.IntegerField(required=True, default=0)
    bonus_intelligence = fields.IntegerField(required=True, default=0)
    bonus_dexterity = fields.IntegerField(required=True, default=0)
    bonus_willpower = fields.IntegerField(required=True, default=0)
    bonus_health = fields.IntegerField(required=True, default=0)
    bonus_health_regen = fields.IntegerField(required=True, default=0)
    bonus_stamina = fields.IntegerField(required=True, default=0)
    bonus_stamina_regen = fields.IntegerField(required=True, default=0)
    bonus_mana = fields.IntegerField(required=True, default=0)
    bonus_mana_regen = fields.IntegerField(required=True, default=0)
    bonus_init = fields.IntegerField(required=True, default=0)
    bonus_carry = fields.IntegerField(required=True, default=0)
    bonus_dot_res = fields.FloatField(required=True, default=0.0)
    bonus_dot_reduction = fields.IntegerField(required=True, default=0)
    bonus_dot_effect = fields.FloatField(required=True, default=0.0)
    bonus_dot_duration = fields.IntegerField(required=True, default=0)
    bonus_shock_limit = fields.IntegerField(required=True, default=0)
    bonus_confusion_limit = fields.IntegerField(required=True, default=0)
    value = fields.IntegerField(required=True, default=0)
    required_strength = fields.IntegerField(required=True, default=0)
    required_intelligence = fields.IntegerField(required=True, default=0)
    required_dexterity = fields.IntegerField(required=True, default=0)
    required_willpower = fields.IntegerField(required=True, default=0)

    class Meta:
        write_concern = WriteConcern(j=True)
Exemplo n.º 9
0
class InterTimepointConstraint(EmbeddedMongoModel):
    mean = fields.FloatField()
    variance = fields.FloatField()

    @property
    def standard_dev(self):
        return round(self.variance**0.5, 3)

    def __str__(self):
        to_print = ""
        to_print += "N({}, {})".format(self.mean, self.standard_dev)
        return to_print

    @classmethod
    def from_payload(cls, payload):
        document = Document.from_payload(payload)
        return cls.from_document(document)

    def to_dict(self):
        dict_repr = self.to_son().to_dict()
        dict_repr.pop('_cls')
        return dict_repr

    def update(self, mean, variance):
        self.mean = mean
        self.variance = variance
Exemplo n.º 10
0
class TrialErrors(pymodm.EmbeddedMongoModel):
    frame_errors = ReferenceListField(FrameError, required=True, blank=True)
    frames_lost = fields.ListField(fields.IntegerField(), blank=True)
    frames_found = fields.ListField(fields.IntegerField(), blank=True)
    times_lost = fields.ListField(fields.FloatField(), blank=True)
    times_found = fields.ListField(fields.FloatField(), blank=True)
    distances_lost = fields.ListField(fields.FloatField(), blank=True)
    distances_found = fields.ListField(fields.FloatField(), blank=True)
Exemplo n.º 11
0
class User(MongoModel):
    name = fields.CharField(primary_key=True)
    birthdate = fields.CharField()
    button = fields.CharField()
    file_type = fields.CharField()
    file_path = fields.CharField()
    malignant = fields.FloatField()
    benign = fields.FloatField()
Exemplo n.º 12
0
class MutualFund(EmbeddedMongoModel):
    fundName = fields.CharField()
    schemeName = fields.CharField()
    units = fields.FloatField()
    cost = fields.FloatField()
    nav = fields.FloatField()
    value = fields.FloatField()
    folioNumber = fields.FloatField()
Exemplo n.º 13
0
class MDBPermutationMetrics(EmbeddedMongoModel):
    class Meta:
        final = True

    metric_name = fields.CharField(blank=True)
    metric_value = fields.FloatField(blank=True)
    p_value = fields.FloatField(blank=True)
    values_permutations = fields.ListField(blank=True)
Exemplo n.º 14
0
class Forecast(MongoModel):
    lat = fields.FloatField(required=True)
    lng = fields.FloatField(required=True)
    data = fields.DictField(required=True)

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'recommend-ahp'
Exemplo n.º 15
0
class Transaction(EmbeddedMongoModel):
    expense_amount = fields.FloatField()
    payment_mode = fields.CharField()
    merchant = fields.CharField()
    datetime = fields.DateTimeField()
    available_balance = fields.FloatField()
    outstanding_amount = fields.FloatField()
    category = fields.CharField()
    sub_category = fields.CharField()
Exemplo n.º 16
0
class security(MongoModel):
    date = fields.CharField()    
    open = fields.FloatField()
    close = fields.FloatField()
    high = fields.FloatField()
    low = fields.FloatField()    
    volume = fields.FloatField()
    code = fields.CharField()
    name = fields.CharField()    
Exemplo n.º 17
0
class Location(MongoModel):
    longitude = fields.FloatField(required=True)
    latitude = fields.FloatField(required=True)
    user = fields.ReferenceField(User, required=True)
    date = fields.DateTimeField(required=True)

    @property
    def id(self):
        return self._id
Exemplo n.º 18
0
class MDBPermutationMetrics(EmbeddedMongoModel):
    class Meta:
        final = True
        connection_alias = "photon_core"

    metric_name = fields.CharField(blank=True)
    metric_value = fields.FloatField(blank=True)
    p_value = fields.FloatField(blank=True)
    values_permutations = fields.ListField(blank=True)
Exemplo n.º 19
0
class PriceEvent(MongoModel):
    security_id = fields.ReferenceField(Securities)
    event_type = fields.IntegerField()
    change_at = fields.IntegerField()
    price_before = fields.FloatField()
    price_after = fields.FloatField()
    ratio = fields.FloatField()

    class Meta:
        final = True
Exemplo n.º 20
0
 class hsi(MongoModel):
     Date = fields.IntegerField(primary_key=True)
     HIGH = fields.FloatField()
     CLOSE = fields.FloatField()
     LOW = fields.FloatField()
     OPEN = fields.FloatField()
     VOLUME = fields.IntegerField()
     class Meta:
         write_concern = WriteConcern(j=True)
         connection_alias = 'hsi_import'
         final = True
Exemplo n.º 21
0
class Station(MongoModel):
    code = fields.CharField(max_length=50)
    name = fields.CharField(max_length=100)
    lat = fields.FloatField()
    lng = fields.FloatField()

    objects = DefaultManager()

    class Meta:
        collection_name = 'Station'
        final = True
Exemplo n.º 22
0
class AIPRecord(MongoModel):
    """ 定投记录 """
    exchange = fields.CharField()
    coin_pair = fields.CharField()
    date = fields.DateTimeField()
    cost = fields.FloatField()
    amount = fields.FloatField()

    class Meta:
        connection_alias = DB_POSITION
        connection_name = CN_AIP_RECORDS
Exemplo n.º 23
0
class Position(MongoModel):
    """仓位基础"""
    # 交易所
    exchange_name = fields.CharField(min_length=3)
    # 币对
    coin_pair = fields.CharField(min_length=3)
    # 当前基础币总花费
    cost = fields.FloatField()
    # 持有目标币数量
    hold = fields.FloatField()

    class Meta:
        connection_alias = DB_POSITION

    @classmethod
    def position_with(cls, exchange_name, coin_pair_str):
        """获取仓位信息、无则创建

        Parameters
        ----------
        exchange_name : str
        coin_pair_str : str
        """
        try:
            return cls.objects.raw({
                'exchange_name': exchange_name,
                'coin_pair': coin_pair_str
            }).first()
        except Exception:
            return cls(exchange_name=exchange_name,
                       coin_pair=coin_pair_str,
                       cost=0,
                       hold=0)

    def update(self, increase_cost, increase_hold):
        """更新仓位

        Parameters
        ----------
        increase_cost : float
            0.00000123
        increase_hold : float
            0.00000123
        """
        self.cost += increase_cost
        self.hold += increase_hold
        self.save()

    def reset(self):
        """重置仓位(全部卖出了)"""
        self.cost = 0
        self.hold = 0
        self.save()
Exemplo n.º 24
0
class Trade(MongoModel):
    trade_id = fields.IntegerField(min_value=0)
    time = fields.DateTimeField(required=True)
    product_id = fields.CharField(required=True, choices=products_list)
    size = fields.FloatField(required=True)
    price = fields.FloatField(required=True)
    side = fields.CharField(required=True, choices=('buy', 'sell'))
    ticker_data = fields.EmbeddedDocumentField(TickerData, required=False)

    class Meta:
        final = True
        indexes = [IndexModel([('product_id', 1), ('time', -1)])]
Exemplo n.º 25
0
class NotedMedia(MongoModel):
    # because primary_key is True, we will need to query this
    # field using the label _id
    media_id = fields.CharField(primary_key=True)
    media_src = fields.URLField()
    media_title = fields.CharField()
    media_img = fields.URLField()
    # email = fields.EmailField()
    ts_start = fields.ListField(field=fields.FloatField())
    ts_end = fields.ListField(field=fields.FloatField())
    body = fields.ListField(field=fields.CharField())
    ts_insert = fields.ListField(field=fields.DateTimeField())
Exemplo n.º 26
0
class ShareBonus(MongoModel):
    gupiao = fields.ReferenceField(Securities)
    gonggaori = fields.CharField(blank=True)
    chuquanchuxiri = fields.CharField(blank=True)
    dengjiri = fields.CharField(blank=True)
    songgu = fields.FloatField()
    zhuanzeng = fields.FloatField()
    paixi = fields.FloatField()
    jingdu = fields.CharField(blank=True)

    class Meta:
        final = True
Exemplo n.º 27
0
class hk_adjustedfactor(MongoModel):
    ID = fields.CharField(blank=True)
    InnerCode = fields.IntegerField(blank=True)
    ExDiviDate = fields.IntegerField(blank=True)
    UpdateTime = fields.DateTimeField(blank=True)
    AdjustFactor = fields.FloatField(blank=True)
    AdjustConst = fields.FloatField(blank=True)
    InformationMine = fields.CharField(blank=True)
    key = fields.IntegerField(primary_key=True)
    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'initial_update_adjustedinfo'
        final = True
Exemplo n.º 28
0
class ProductoModel(MongoModel):
    codigo_barras = fields.CharField()
    nombre = fields.CharField()
    stock = fields.IntegerField()
    precio_compra = fields.FloatField()
    tipo_de_ganancia = fields.CharField()
    # Porcentaje fijo o por monto neto a mano
    precio_venta = fields.FloatField()
    porcentaje_ganancia = fields.FloatField()
    categoria = fields.CharField()
    proveedor = fields.CharField()
    imagen = fields.CharField()
    atributos = fields.CharField()
Exemplo n.º 29
0
class Entry(MongoModel):
    amount = fields.FloatField()
    debitAccount = fields.ReferenceField(BaseAccount)
    creditAccount = fields.ReferenceField(BaseAccount)
    dateTime = fields.DateTimeField()
    description = fields.CharField()
    debitAccountBalance = fields.FloatField()
    creditAccountBalance = fields.FloatField()

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = CONFIG.CONN_NAME
        collection_name = CONFIG.TRX_COLL_NAME
class Sample(MongoModel):
    account_id = fields.UUIDField()
    created_date = fields.DateTimeField()
    measure = fields.FloatField()
    out_temp = fields.FloatField()
    house_temp = fields.FloatField()
    tank_temp = fields.FloatField()
    burner_state = fields.BooleanField()

    class Meta:
        indexes = [
            IndexModel([('created_date', DESCENDING)]),
            IndexModel([('account_id', HASHED)])
        ]