Beispiel #1
0
class SpeechNoise(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    right_silence = db.ListField()
    left_silence = db.ListField()
    right_noise = db.ListField()
    left_noise = db.ListField()

    def create(self, property, result):
        self.__setattr__(property, result)
        return self
Beispiel #2
0
class D2VModel(db.Document):
    serialized_model = db.FileField()
    last_run = db.DateTimeField()

    vectors = db.DictField()

    # [
    #   [a1, a2],
    #   [b1, b2]
    # ]
    vectors_2d = db.ListField(db.ListField(db.FloatField()))

    @property
    def model(self):
        """
        load serialized model

        :return:
        """
        if not self.serialized_model:
            return None

        bytes_io = io.BytesIO(self.serialized_model)
        model = pickle.load(bytes_io)
        return model

    @model.setter
    def model(self, model):
        # instead of a file
        bytes_io = io.BytesIO()

        # save model to bytesio
        model.save(bytes_io)

        # getvalue has the actual bytes
        self.serialized_model = bytes_io.getvalue()

        # close buffer
        bytes_io.close()

        # update timestamp and save
        self.touch()

    @staticmethod
    def get():
        d2v_model = D2VModel.objects.first()
        if not d2v_model:
            d2v_model = D2VModel()
            d2v_model.touch()
            d2v_model.save()
        return d2v_model

    def touch(self):
        self.last_run = datetime.datetime.now()
Beispiel #3
0
class Patient(db.Document):
    ssnid = db.StringField(max_length=9, unique=True)
    patientId = db.IntField()
    name = db.StringField(required=True)
    age = db.IntField(max_length=3)
    address = db.StringField()
    dateOfJoining = db.StringField()
    roomType = db.StringField()
    city = db.StringField()
    state = db.StringField()
    pharmacy = db.ListField(db.StringField())
    diagnostics = db.ListField(db.StringField())
    status = db.StringField(default="active")
Beispiel #4
0
class Feed(db.Document):
    title = db.StringField()
    url = db.StringField(required=True)

    articles = db.ListField(db.ReferenceField("Article"))

    users = db.ListField(db.ReferenceField("User"))

    def as_dict(self):
        return dict(title=self.title, url=self.url)

    def __repr__(self):
        return '<Feed %r (%s)>' % (self.title, self.url)
Beispiel #5
0
class Post(UserMixin, db.Document):
    meta = {'collection': 'posts'}
    title = db.StringField(max_length=30)
    date = db.DateTimeField()
    content = db.StringField(max_length=1000)
    author = db.StringField(max_length=30)
    tags = db.ListField()
    owner = db.LazyReferenceField('User')
class ClubEvent(BaseDocument):
    name = db.StringField(required=True)
    image = db.ImageField(size=(500, 500), thumbnail_size=(20, 20))
    tags = db.ListField(db.StringField())
    presenter = db.EmbeddedDocumentField(Presenter)
    start = db.DateTimeField(requried=True)
    end = db.DateTimeField(requried=True)
    description = db.StringField()
    location = db.StringField()

    meta = {"ordering": ["start"]}
class Subscriber(BaseDocument):
    cellphone = db.StringField()
    email = db.EmailField()
    vaccine_site = db.ListField(db.ReferenceField(Maps))

    def to_mongo(self, *args, **kwargs):
        data = super().to_mongo(*args, **kwargs)

        data["vaccine_site"] = [s.name for s in self.vaccine_site]

        return data
Beispiel #8
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]
Beispiel #9
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()
Beispiel #10
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)
Beispiel #11
0
class LabInvoice(db.Document):
    date = db.DateTimeField(default=datetime.datetime.utcnow())
    items = db.ListField(db.ObjectIdField())
    total = db.FloatField()
Beispiel #12
0
class PharmacyInvoice(db.Document):
    date = db.DateTimeField(default=datetime.datetime.utcnow())
    items = db.ListField(db.DictField())
    total = db.FloatField()
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
Beispiel #14
0
class Ternary(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    d1 = db.ListField()
    d2 = db.ListField()
    d3 = db.ListField()
    d4 = db.ListField()
    d5 = db.ListField()
    d6 = db.ListField()
    d7 = db.ListField()
    d8 = db.ListField()
    d9 = db.ListField()
    d10 = db.ListField()
    d11 = db.ListField()
    d12 = db.ListField()
    d13 = db.ListField()
    d14 = db.ListField()
    d15 = db.ListField()
    d16 = db.ListField()
    d17 = db.ListField()
    d18 = db.ListField()
    d19 = db.ListField()
    d20 = db.ListField()
    d21 = db.ListField()
    d22 = db.ListField()
    d23 = db.ListField()
    d24 = db.ListField()
    d25 = db.ListField()

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