示例#1
0
class Hacker(BaseDocument):  # Stored in the "user" collection

    meta = {"indexes": ["email"]}

    private_fields = ["id", "email_token_hash"]

    first_name = db.StringField()
    last_name = db.StringField()
    birthday = db.DateTimeField()
    country = db.StringField()
    phone_number = db.StringField()
    isaccepted = db.BooleanField(default=False)
    can_share_info = db.BooleanField(default=False)
    rsvp_status = db.BooleanField(default=False)
    beginner = db.BooleanField(default=False)
    ethnicity = db.StringField()
    pronouns = db.StringField()
    edu_info = db.EmbeddedDocumentField(Education_Info)
    resume = db.ReferenceField(Resume)
    socials = db.EmbeddedDocumentField(Socials)
    why_attend = db.StringField()
    what_learn = db.ListField()
    in_person = db.BooleanField(default=False)
    dietary_restrictions = db.StringField()

    email = db.EmailField(unique=True, required=True)
    date = db.DateTimeField(default=datetime.utcnow)

    mlh = db.EmbeddedDocumentField(MLH_Authorizations)

    def encode_email_token(self) -> str:
        """Encode the email token"""
        email_token = encode_jwt(sub=self.email)

        conf = app.config["BCRYPT_LOG_ROUNDS"]
        email_token_hash = bcrypt.generate_password_hash(email_token, conf)

        self.modify(set__email_token_hash=email_token_hash)
        self.save()

        return email_token

    @staticmethod
    def decode_email_token(email_token: str) -> str:
        """Decodes the email token"""
        return decode_jwt(email_token)["sub"]

    @classmethod
    def pre_delete(cls, sender, document, **kwargs):
        if document.resume:
            document.resume.delete()
示例#2
0
class Model(UserMixin, db.Document):
    meta = {'collection': 'models'}
    keep = db.BooleanField(default=True)
    mod_type = db.StringField(max_length=3, choices=TYPES)
    ticker = db.StringField(max_length=6)
    period = db.StringField(max_length=6)
    interval = db.StringField(max_length=6)
    money = db.FloatField()
    buy = db.FloatField()
    sell = db.FloatField()
    av_length = db.IntField()
    trade_cost = db.FloatField()
示例#3
0
class Resume(BaseDocument):
    file = db.FileField(required=True)
    attached = db.BooleanField(default=False)
    created = db.DateTimeField(default=datetime.utcnow)
    meta = {
        "indexes": [{
            "fields": ["created"],
            "expireAfterSeconds": 86400,  # Expires after 24 hours
            "partialFilterExpression": {
                "attached": False
            }
        }]
    }
示例#4
0
class User(db.Document):
    uid = db.UUIDField(required=True, primary_key=True)
    player_ids = db.ListField(db.UUIDField(required=True))
    read = db.MapField(field=db.BooleanField(default=False, required=True))
    notifications = db.ListField(db.ReferenceField(GenericNotification, reverse_delete_rule=mongoengine.PULL))

    def read_notifications(self):
        for notification in self.notifications:
            self.read[str(notification.id)] = True
        self.update(read=self.read)

    def serialize_notifications(self):
        notifications = self.notifications[-PER_PAGE:]
        utils.populate_name_cache(notifications)
        serialized_notifications = []
        for notification in notifications:
            serialized_notification = notification.serialize()
            read = str(notification.nid) in self.read
            serialized_notification['read'] = read
            serialized_notifications.append(serialized_notification)
        return serialized_notifications[::-1]
示例#5
0
class MLH_Authorizations(db.EmbeddedDocument):
    mlh_code_of_conduct = db.BooleanField(required=True)
    mlh_privacy_and_contest_terms = db.BooleanField(required=True)
    mlh_send_messages = db.BooleanField(default=False)
示例#6
0
文件: vote.py 项目: fltrbbl/fltrbbl
class Vote(db.Document):
    like = db.BooleanField()

    article = db.ReferenceField(Article)
    user = db.ReferenceField(User)
示例#7
0
class Article(db.Document):
    feed = db.ReferenceField(Feed, required=True)
    source_id = db.StringField(required=True)
    url = db.StringField()

    title = db.StringField()
    top_image = db.StringField()
    movies = db.ListField()
    keywords = db.ListField()
    tags = db.ListField()
    authors = db.ListField()
    publish_date = db.DateTimeField()
    summary = db.StringField()
    html = db.StringField()
    meta_data = db.DictField()

    language = db.StringField()

    text = db.StringField()
    active = db.BooleanField(default=True)

    vector = db.ListField(db.FloatField())
    vector_2d = db.ListField(db.FloatField())

    def as_dict(self):
        return dict(feed=self.feed.url,
                    source_id=self.source_id,
                    url=self.url,
                    title=self.title,
                    top_image=self.top_image,
                    movies=self.movies,
                    keywords=self.keywords,
                    tags=self.tags,
                    authors=self.authors,
                    publish_date='%s' % self.publish_date,
                    summary=self.summary,
                    html=self.html,
                    meta_data=self.meta_data,
                    language=self.language,
                    text=self.text,
                    vector=self.vector,
                    vector_2d=self.vector_2d)

    @staticmethod
    def update_vectors(model, vectors_2d=[]):
        # https://stackoverflow.com/questions/30943076/mongoengine-bulk-update-without-objects-update
        bulk_operations = []

        keys = model.docvecs.doctags.keys()
        vectors = model.docvecs.vectors_docs

        for key, vector, vector_2d in zip(keys, vectors, vectors_2d):
            bulk_operations.append(
                UpdateOne({'_id': key}, {
                    '$set':
                    dict(vector=vector.tolist(), vector_2d=vector_2d)
                }))

        if bulk_operations:
            collection = Article._get_collection() \
                .bulk_write(bulk_operations, ordered=False)
class Calculation(UserMixin, db.Document):
    meta = {'collection': 'entries'}
    keep = db.BooleanField(default=True)
    date_stamp = db.StringField(max_length=40)
    type_info = db.StringField()
    buy = db.FloatField()
    sell = db.FloatField()
    av_length = db.IntField()
    ticker = db.StringField()
    period = db.StringField()
    interval = db.StringField()
    money = db.FloatField()
    trade_cost = db.FloatField()
    owner = db.LazyReferenceField('User')
    final_money = db.FloatField()
    final_owned = db.FloatField()
    final_liquid = db.FloatField()
    td = db.ListField()
    tt = db.ListField()
    ty = db.ListField()
    tp = db.ListField()
    tv = db.ListField()
    graph_x = db.ListField()
    graph_y = db.ListField()
    chart_x = db.ListField()
    chart_y = db.ListField()
    model = db.LazyReferenceField('Model')
    user_model = db.LazyReferenceField('UserModel')


    def static_range(self):
        stock = yf.Ticker(self.ticker)
        df = stock.history(period=self.period, interval=self.interval)
        owned = 0
        count = 0
        trade_money = self.money
        trade_cost = self.trade_cost
        buy = self.buy
        sell = self.sell
        td = []     #trade date
        tt = []     #trade time
        ty = []     #trade type
        tp = []     #trade price
        tv = []     #trade volume
        store_chart_x = []
        store_chart_y = []
        for index, row in df.iterrows():
            count += 1
            available_money = trade_money - trade_cost
            available_volume = row['Volume']/40
            low = round(row['Low'], 4)
            high = round(row['High'], 4)
            date = index.to_pydatetime().strftime("%d-%m-%Y")
            time = index.to_pydatetime().strftime("%H:%M")
            etime = index.to_pydatetime() + timedelta(minutes=2)
            endtime = etime.strftime("%H:%M")
            if low != high:
                if float(row['Open']) > float(row['Close']):
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10]+'-'+date[3:5]+'-'+date[0:2] + 'T' + time + ':00')
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T' + endtime + ':00')
                elif float(row['Close']) > float(row['Open']):
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T' + time + ':00')
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T' + endtime + ':00')
            elif low == high:
                store_chart_y.append(low)
                store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T' + time + ':00')
            lvalue = (low * available_volume)
            hvalue = (high * available_volume)
            if available_money > 0 and low <= buy and lvalue > trade_cost:
                if lvalue>available_money>0:
                    owned += (available_money/low)
                    trade_money = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
                elif available_money>lvalue>0:
                    owned += (lvalue/low)
                    trade_money -= trade_cost
                    trade_money -= lvalue
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
            if owned > 0 and high >= sell and hvalue > trade_cost:
                if available_volume > owned:
                    trade_money += (owned*high)
                    trade_money -= trade_cost
                    owned = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
                elif owned > available_volume:
                    trade_money += (available_volume*high)
                    trade_money -= trade_cost
                    owned -= available_volume
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
        if owned > 0:
            liquid_money = (trade_money - trade_cost) + df.Low.ix[count-1]*owned
        else:
            liquid_money = trade_money
        self.chart_x = store_chart_x
        self.chart_y = store_chart_y
        self.final_money = round(trade_money, 2)
        self.final_owned = round(owned)
        self.final_liquid = round(liquid_money, 2)
        self.td = td
        self.tt = tt
        self.ty = ty
        self.tp = tp
        self.tv = tv
        self.save()
        return self.id

    def moving_average(self):
        stock = yf.Ticker(self.ticker)
        df = stock.history(period=self.period, interval='1d')
        owned = 0
        count = 0
        trade_money = self.money
        trade_cost = self.trade_cost
        bd = self.buy
        sd = self.sell
        ma_length = self.av_length
        ma_conv = ma_length - 1
        ma_sum = 0
        td = []  # trade date
        tt = []  # trade time
        ty = []  # trade type
        tp = []  # trade price
        tv = []  # trade volume
        store_ma = []
        store_ma_x = []
        store_chart_x = []
        store_chart_y = []
        for i in range(0, df.shape[0] - ma_conv):
            for j in range(0, ma_length):
                ma_sum += df.iloc[i + j, 3]
            df.loc[df.index[i + ma_conv], 'SMA_' + str(ma_length)] = np.round((ma_sum / ma_length), 4)
            ma_sum = 0
        for index, row in df.iloc[ma_length:].iterrows():
            count += 1
            available_money = trade_money - trade_cost
            available_volume = row['Volume'] / 40
            low = round(row['Low'], 4)
            high = round(row['High'], 4)
            date = index.to_pydatetime().strftime("%d-%m-%Y")
            time = index.to_pydatetime().strftime("%H:%M")
            if low != high:
                if float(row['Open']) > float(row['Close']):
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10]+'-'+date[3:5]+'-'+date[0:2]+'T09:30:00')
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T16:00:00')
                elif float(row['Close']) > float(row['Open']):
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T09:30:00')
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T16:00:00')
            elif low == high:
                store_chart_y.append(low)
                store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T12:45:00')
            lvalue = (low * available_volume)
            hvalue = (high * available_volume)
            buy = row['SMA_' + str(ma_length)] - bd
            sell = row['SMA_' + str(ma_length)] + sd
            store_ma.append(float(row['SMA_' + str(ma_length)]))
            store_ma_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T' + time + ':00')
            if available_money > 0 and low <= buy and lvalue > trade_cost:
                if lvalue > available_money > 0:
                    owned += (available_money / low)
                    trade_money = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
                elif available_money > lvalue > 0:
                    owned += (lvalue / low)
                    trade_money -= trade_cost
                    trade_money -= lvalue
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
            if owned > 0 and high >= sell and hvalue > trade_cost:
                if available_volume > owned:
                    trade_money += (owned * high)
                    trade_money -= trade_cost
                    owned = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
                elif owned > available_volume:
                    trade_money += (available_volume * high)
                    trade_money -= trade_cost
                    owned -= available_volume
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
        if owned > 0:
            liquid_money = (trade_money - trade_cost) + df.Low.ix[count - 1] * owned
        else:
            liquid_money = trade_money
        self.chart_x = store_chart_x
        self.chart_y = store_chart_y
        self.graph_y = store_ma
        self.graph_x = store_ma_x
        self.final_money = round(trade_money, 2)
        self.final_owned = round(owned)
        self.final_liquid = round(liquid_money, 2)
        self.td = td
        self.tt = tt
        self.ty = ty
        self.tp = tp
        self.tv = tv
        self.save()
        return self.id

    def weighted_moving_average(self):
        stock = yf.Ticker(self.ticker)
        df = stock.history(period=self.period, interval='1d')
        owned = 0
        count = 0
        trade_money = self.money
        trade_cost = self.trade_cost
        bd = self.buy
        sd = self.sell
        wma_length = self.av_length
        wma_conv = wma_length - 1
        wma_sum = 0
        weight = 0
        weight_sum = 0
        for k in range(1, wma_length + 1):
            weight_sum += k
        td = []  # trade date
        tt = []  # trade time
        ty = []  # trade type
        tp = []  # trade price
        tv = []  # trade volume
        store_wma = []
        store_wma_x = []
        store_chart_y = []
        store_chart_x = []
        for i in range(0, df.shape[0] - wma_conv):
            for j in range(0, wma_length):
                weight += 1
                wma_sum += (df.iloc[i + j, 3]*weight)
            weight = 0
            df.loc[df.index[i + wma_conv], 'WMA_' + str(wma_length)] = np.round((wma_sum / weight_sum), 4)
            wma_sum = 0
        for index, row in df.iloc[wma_length:].iterrows():
            count += 1
            available_money = trade_money - trade_cost
            available_volume = row['Volume'] / 40
            low = round(row['Low'], 4)
            high = round(row['High'], 4)
            date = index.to_pydatetime().strftime("%d-%m-%Y")
            time = index.to_pydatetime().strftime("%H:%M")
            if low != high:
                if float(row['Open']) > float(row['Close']):
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10]+'-'+date[3:5]+'-'+date[0:2]+'T09:30:00')
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T16:00:00')
                elif float(row['Close']) > float(row['Open']):
                    store_chart_y.append(float(low))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T09:30:00')
                    store_chart_y.append(float(high))
                    store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T16:00:00')
            elif low == high:
                store_chart_y.append(low)
                store_chart_x.append(date[6:10] + '-' + date[3:5] + '-' + date[0:2] + 'T12:45:00')
            lvalue = (low * available_volume)
            hvalue = (high * available_volume)
            buy = row['WMA_' + str(wma_length)] - bd
            sell = row['WMA_' + str(wma_length)] + sd
            store_wma.append(float(row['WMA_' + str(wma_length)]))
            store_wma_x.append(date[6:10]+'-'+date[3:5]+'-'+date[0:2]+'T'+time+':00')
            if available_money > 0 and low <= buy and lvalue > trade_cost:
                if lvalue > available_money > 0:
                    owned += (available_money / low)
                    trade_money = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
                elif available_money > lvalue > 0:
                    owned += (lvalue / low)
                    trade_money -= trade_cost
                    trade_money -= lvalue
                    td.append(date)
                    tt.append(time)
                    ty.append('b')
                    tp.append(low)
                    tv.append(available_volume)
            if owned > 0 and high >= sell and hvalue > trade_cost:
                if available_volume > owned:
                    trade_money += (owned * high)
                    trade_money -= trade_cost
                    owned = 0
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
                elif owned > available_volume:
                    trade_money += (available_volume * high)
                    trade_money -= trade_cost
                    owned -= available_volume
                    td.append(date)
                    tt.append(time)
                    ty.append('s')
                    tp.append(high)
                    tv.append(available_volume)
        if owned > 0:
            liquid_money = (trade_money - trade_cost) + df.Low.ix[count - 1] * owned
        else:
            liquid_money = trade_money
        self.chart_x = store_chart_x
        self.chart_y = store_chart_y
        self.graph_x = store_wma_x
        self.graph_y = store_wma
        self.final_money = round(trade_money, 2)
        self.final_owned = round(owned)
        self.final_liquid = round(liquid_money, 2)
        self.td = td
        self.tt = tt
        self.ty = ty
        self.tp = tp
        self.tv = tv
        self.save()
        return self.id
示例#9
0
class PureTone(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    Right_250 = db.BooleanField()
    Right_500 = db.BooleanField()
    Right_1000 = db.BooleanField()
    Right_2000 = db.BooleanField()
    Right_4000 = db.BooleanField()
    Right_8000 = db.BooleanField()
    Left_250 = db.BooleanField()
    Left_500 = db.BooleanField()
    Left_1000 = db.BooleanField()
    Left_2000 = db.BooleanField()
    Left_4000 = db.BooleanField()
    Left_8000 = db.BooleanField()

    def __repr__(self):
        return '[PureTone] id: {}, status: {}'.format(self.start_time,
                                                      self.Left_125)

    def create(self, property, result):
        self.__setattr__(property, result)
        return self