Ejemplo n.º 1
0
class users(db.Model, UserMixin):
    id = db.Column(db.Integer, db.Sequence('seq_users'), primary_key=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255))
    name = db.Column(db.String(255), nullable=False)
    organisation = db.Column(db.String(255))
    active = db.Column(db.Boolean(), default=True)
    roles = db.relationship('roles',
                            secondary=users_roles,
                            backref=db.backref('users', lazy='dynamic'))  #
    preferences = db.Column(db.String(40000))
    country = db.Column(db.String(50))
    usercreationdate = db.Column(TIMESTAMP, default=func.now())
    usercreationreason = db.Column(db.String(1000))

    def __str__(self):
        return "{0} ({1})".format(self.name, self.email)

    def GetPref(self, prjid, name, defval):
        try:
            prjid = str(prjid)
            tmp = json.loads(self.preferences)
            if prjid not in tmp:
                return defval
            if isinstance(defval, int):
                return int(tmp[prjid].get(name, defval))
            if isinstance(defval, (float)):
                return float(tmp[prjid].get(name, defval))
            return tmp[prjid].get(name, defval)
        except:
            return defval

    def SetPref(self, prjid, name, newval):
        try:
            prjid = str(prjid)
            tmp = json.loads(self.preferences)
            if prjid not in tmp:
                tmp[prjid] = {}
            if tmp[prjid].get(name, -99999) == newval:
                return 0  # déjà la bonne valeur donc il n'y a rien à faire
        except:
            tmp = {}
        if prjid not in tmp:
            tmp[prjid] = {}
        tmp[prjid][name] = newval
        tmp[prjid]['ts'] = time.time()
        if len(
                tmp
        ) > 75:  # si des settings pour plus de 50 projets on ne garde que les 25 plus recents
            newpref = {
                k: v
                for k, v in tmp.items() if isinstance(v, dict) and 'ts' in v
            }
            ChronoSorted = [[k, v['ts']] for k, v in newpref.items()]
            sorted(ChronoSorted, key=lambda r: r[1], reverse=True)
            tmp = {}
            for id, ts in ChronoSorted[0:50]:
                tmp[id] = newpref[id]
        self.preferences = json.dumps(tmp)
        return 1
Ejemplo n.º 2
0
class part_projects(db.Model):
    __tablename__ = 'part_projects'
    # pprojid  = db.Column(INTEGER,db.Sequence('seq_part_projects'), primary_key=True)
    # SQL Alchemy ne genere pas la sequence comme dans les autres tables précédentes, probablement un evolution
    # mais genere à la place un champ de type serial qui crée une sequence associée
    pprojid = db.Column(INTEGER,
                        db.Sequence('part_projects_pprojid_seq'),
                        primary_key=True)
    ptitle = db.Column(VARCHAR(250), nullable=False)
    rawfolder = db.Column(VARCHAR(250), nullable=False)
    ownerid = db.Column(db.Integer, db.ForeignKey('users.id'))
    owneridrel = db.relationship("users")
    projid = db.Column(INTEGER, db.ForeignKey('projects.projid'))
    project = db.relationship("Projects")
    instrumtype = db.Column(VARCHAR(50))
    op_name = db.Column(VARCHAR(100))
    op_email = db.Column(VARCHAR(100))
    cs_name = db.Column(VARCHAR(100))
    cs_email = db.Column(VARCHAR(100))
    do_name = db.Column(VARCHAR(100))
    do_email = db.Column(VARCHAR(100))
    prj_info = db.Column(VARCHAR(1000))
    prj_acronym = db.Column(VARCHAR(100))
    cruise = db.Column(VARCHAR(100))
    ship = db.Column(VARCHAR(100))
    default_instrumsn = db.Column(VARCHAR(50))
    default_depthoffset = db.Column(DOUBLE_PRECISION)
    public_visibility_deferral_month = db.Column(INTEGER)
    public_partexport_deferral_month = db.Column(INTEGER)
    public_zooexport_deferral_month = db.Column(INTEGER)
    oldestsampledate = db.Column(TIMESTAMP)

    def __str__(self):
        return "{0} ({1})".format(self.ptitle, self.pprojid)
Ejemplo n.º 3
0
class EcotaxaInst(db.Model):
    __tablename__ = 'ecotaxainst'
    id = db.Column(INTEGER, db.Sequence('seq_ecotaxainst'), primary_key=True)
    name = db.Column(VARCHAR(100), nullable=False)
    url = db.Column(VARCHAR(100))
    laststatupdate_datetime = db.Column(TIMESTAMP(precision=0))
    ecotaxa_version = db.Column(VARCHAR(10))
    sharedsecret = db.Column(VARCHAR(100), nullable=False)
Ejemplo n.º 4
0
class Process(db.Model):
    __tablename__ = 'process'
    processid = db.Column(BIGINT, db.Sequence('seq_process'), primary_key=True)
    projid = db.Column(INTEGER, db.ForeignKey('projects.projid'))
    project = db.relationship("Projects")
    orig_id = db.Column(VARCHAR(255))

    def __str__(self):
        return "{0} ({1})".format(self.orig_id, self.processid)
Ejemplo n.º 5
0
class Samples(db.Model):
    __tablename__ = 'samples'
    sampleid = db.Column(BIGINT, db.Sequence('seq_samples'), primary_key=True)
    projid = db.Column(INTEGER, db.ForeignKey('projects.projid'))
    project = db.relationship("Projects")
    orig_id = db.Column(VARCHAR(255))
    latitude = db.Column(DOUBLE_PRECISION)
    longitude = db.Column(DOUBLE_PRECISION)
    dataportal_descriptor = db.Column(VARCHAR(8000))

    def __str__(self):
        return "{0} ({1})".format(self.orig_id, self.processid)
Ejemplo n.º 6
0
class Objects(db.Model):
    __tablename__ = 'obj_head'
    objid = db.Column(BIGINT, db.Sequence('seq_objects'), primary_key=True)
    projid = db.Column(INTEGER,
                       db.ForeignKey('projects.projid'),
                       nullable=False)
    project = db.relationship("Projects")
    latitude = db.Column(DOUBLE_PRECISION)
    longitude = db.Column(DOUBLE_PRECISION)
    objdate = db.Column(DATE)
    objtime = db.Column(TIME)
    depth_min = db.Column(FLOAT)
    depth_max = db.Column(FLOAT)
    images = db.relationship("Images")
    classif_id = db.Column(INTEGER)
    classif = db.relationship(
        "Taxonomy",
        primaryjoin="Taxonomy.id==Objects.classif_id",
        foreign_keys="Taxonomy.id",
        uselist=False,
    )
    classif_qual = db.Column(CHAR(1))
    classif_who = db.Column(db.Integer, db.ForeignKey('users.id'))
    classiffier = db.relationship(
        "users",
        primaryjoin="users.id==Objects.classif_who",
        foreign_keys="users.id",
        uselist=False,
    )
    classif_when = db.Column(TIMESTAMP)
    classif_auto_id = db.Column(INTEGER)
    classif_auto_score = db.Column(DOUBLE_PRECISION)
    classif_auto_when = db.Column(TIMESTAMP)
    classif_auto = db.relationship(
        "Taxonomy",
        primaryjoin="Taxonomy.id==foreign(Objects.classif_auto_id)",
        uselist=False,
    )
    classif_crossvalidation_id = db.Column(INTEGER)
    img0id = db.Column(BIGINT)
    img0 = db.relationship("Images", foreign_keys="Images.objid")
    imgcount = db.Column(INTEGER)
    complement_info = db.Column(VARCHAR)
    similarity = db.Column(DOUBLE_PRECISION)
    sunpos = db.Column(CHAR(1))  # position du soleil
    random_value = db.Column(INTEGER)
    sampleid = db.Column(INTEGER, db.ForeignKey('samples.sampleid'))
    sample = db.relationship("Samples")
    acquisid = db.Column(INTEGER, db.ForeignKey('acquisitions.acquisid'))
    acquis = db.relationship("Acquisitions")
    processid = db.Column(INTEGER, db.ForeignKey('process.processid'))
    processrel = db.relationship("Process")
Ejemplo n.º 7
0
class users(db.Model, UserMixin):
    id = db.Column(db.Integer, db.Sequence('seq_users'), primary_key=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255))
    name = db.Column(db.String(255), nullable=False)
    organisation = db.Column(db.String(255))
    active = db.Column(db.Boolean(), default=True)
    roles = db.relationship('roles',
                            secondary=users_roles,
                            backref=db.backref('users', lazy='dynamic'))  #

    def __str__(self):
        return "{0} ({1})".format(self.name, self.email)
Ejemplo n.º 8
0
class Images(db.Model):
    __tablename__ = 'images'
    imgid = db.Column(BIGINT, db.Sequence('seq_images'),
                      primary_key=True)  # manuel ,db.Sequence('seq_images')
    objid = db.Column(BIGINT, db.ForeignKey('obj_head.objid'))
    imgrank = db.Column(INTEGER)
    file_name = db.Column(VARCHAR(255))
    orig_file_name = db.Column(VARCHAR(255))
    width = db.Column(INTEGER)
    height = db.Column(INTEGER)
    thumb_file_name = db.Column(VARCHAR(255))
    thumb_width = db.Column(INTEGER)
    thumb_height = db.Column(INTEGER)
Ejemplo n.º 9
0
class Task(db.Model):
    __tablename__ = 'temp_tasks'
    id = db.Column(db.Integer(),
                   db.Sequence('seq_temp_tasks'),
                   primary_key=True)
    owner_id = db.Column(db.Integer(), db.ForeignKey('users.id'))
    owner_rel = db.relationship("users")
    taskclass = db.Column(db.String(80))
    taskstate = db.Column(db.String(80))
    taskstep = db.Column(db.Integer())
    progresspct = db.Column(db.Integer())
    progressmsg = db.Column(db.String())
    inputparam = db.Column(db.String())
    creationdate = db.Column(db.DateTime())
    lastupdate = db.Column(db.DateTime())

    def __str__(self):
        return self.name
Ejemplo n.º 10
0
class ProjectsPriv(db.Model):
    __tablename__ = 'projectspriv'
    id = db.Column(db.Integer,
                   db.Sequence('seq_projectspriv'),
                   primary_key=True)
    projid = db.Column(INTEGER,
                       db.ForeignKey('projects.projid', ondelete="CASCADE"),
                       nullable=False)
    member = db.Column(db.Integer, db.ForeignKey('users.id'))
    privilege = db.Column(VARCHAR(255), nullable=False)
    memberrel = db.relationship("users")
    refproject = db.relationship('Projects',
                                 backref=db.backref(
                                     'projmembers',
                                     cascade="all, delete-orphan",
                                     single_parent=True))  # ,cascade='delete'

    def __str__(self):
        return "{0} ({1})".format(self.member, self.privilege)
Ejemplo n.º 11
0
class Taxonomy(db.Model):
    __tablename__ = 'taxonomy'
    id = db.Column(INTEGER, db.Sequence('seq_taxonomy'), primary_key=True)
    parent_id = db.Column(INTEGER)
    name = db.Column(VARCHAR(100), nullable=False)
    taxotype = db.Column(CHAR(1), nullable=False,
                         server_default='P')  # P = Phylo , M = Morpho
    display_name = db.Column(VARCHAR(200))
    id_source = db.Column(VARCHAR(20))
    source_url = db.Column(VARCHAR(200))
    source_desc = db.Column(VARCHAR(1000))
    creator_email = db.Column(VARCHAR(255))
    creation_datetime = db.Column(TIMESTAMP(precision=0))
    lastupdate_datetime = db.Column(TIMESTAMP(precision=0))
    id_instance = db.Column(INTEGER)
    taxostatus = db.Column(CHAR(1), nullable=False, server_default='A')
    rename_to = db.Column(INTEGER)
    nbrobj = db.Column(INTEGER)
    nbrobjcum = db.Column(INTEGER)

    def __str__(self):
        return "{0} ({1})".format(self.name, self.id)
Ejemplo n.º 12
0
class part_samples(db.Model):
    __tablename__ = 'part_samples'
    # psampleid  = db.Column(INTEGER,db.Sequence('seq_part_samples'), primary_key=True)
    # SQL Alchemy ne genere pas la sequence comme dans les autres tables précédentes, probablement un evolution
    # mais genere à la place un champ de type serial qui crée une sequence associée
    psampleid = db.Column(INTEGER,
                          db.Sequence('part_samples_psampleid_seq'),
                          primary_key=True)
    pprojid = db.Column(INTEGER, db.ForeignKey('part_projects.pprojid'))
    project = db.relationship("part_projects")
    profileid = db.Column(VARCHAR(250), nullable=False)
    filename = db.Column(VARCHAR(250), nullable=False)
    sampleid = db.Column(INTEGER, db.ForeignKey('samples.sampleid'))
    sample = db.relationship("Samples")
    latitude = db.Column(DOUBLE_PRECISION)
    longitude = db.Column(DOUBLE_PRECISION)
    organizedbydeepth = db.Column(db.Boolean())
    histobrutavailable = db.Column(db.Boolean())
    qualitytaxo = db.Column(VARCHAR(20))
    qualitypart = db.Column(VARCHAR(20))
    daterecalculhistotaxo = db.Column(TIMESTAMP)
    winddir = db.Column(INTEGER)
    winspeed = db.Column(INTEGER)
    seastate = db.Column(INTEGER)
    nebuloussness = db.Column(INTEGER)
    comment = db.Column(VARCHAR(1000))
    stationid = db.Column(VARCHAR(100))
    firstimage = db.Column(INTEGER)
    lastimg = db.Column(BIGINT)
    lastimgused = db.Column(BIGINT)
    bottomdepth = db.Column(INTEGER)
    yoyo = db.Column(db.Boolean())
    sampledate = db.Column(TIMESTAMP)
    op_sample_name = db.Column(VARCHAR(100))
    op_sample_email = db.Column(VARCHAR(100))
    ctd_desc = db.Column(VARCHAR(1000))
    ctd_origfilename = db.Column(VARCHAR(250))
    ctd_import_name = db.Column(VARCHAR(100))
    ctd_import_email = db.Column(VARCHAR(100))
    ctd_import_datetime = db.Column(TIMESTAMP)
    ctd_status = db.Column(VARCHAR(50))
    instrumsn = db.Column(VARCHAR(50))
    acq_aa = db.Column(DOUBLE_PRECISION)
    acq_exp = db.Column(DOUBLE_PRECISION)
    acq_volimage = db.Column(DOUBLE_PRECISION)
    acq_depthoffset = db.Column(DOUBLE_PRECISION)
    acq_pixel = db.Column(DOUBLE_PRECISION)
    acq_shutterspeed = db.Column(INTEGER)
    acq_smzoo = db.Column(INTEGER)
    acq_exposure = db.Column(INTEGER)
    acq_gain = db.Column(INTEGER)
    acq_filedescription = db.Column(VARCHAR(200))
    acq_eraseborder = db.Column(INTEGER)
    acq_tasktype = db.Column(INTEGER)
    acq_threshold = db.Column(INTEGER)
    acq_choice = db.Column(INTEGER)
    acq_disktype = db.Column(INTEGER)
    acq_smbase = db.Column(INTEGER)
    acq_ratio = db.Column(INTEGER)
    acq_descent_filter = db.Column(db.Boolean())
    acq_presure_gain = db.Column(DOUBLE_PRECISION)
    acq_xsize = db.Column(INTEGER)
    acq_ysize = db.Column(INTEGER)
    acq_barcode = db.Column(VARCHAR(50))
    proc_datetime = db.Column(TIMESTAMP)
    proc_gamma = db.Column(DOUBLE_PRECISION)
    proc_soft = db.Column(VARCHAR(250))
    lisst_zscat_filename = db.Column(VARCHAR(200))
    lisst_kernel = db.Column(VARCHAR(200))
    lisst_year = db.Column(INTEGER)
    txt_data01 = db.Column(VARCHAR(200))
    txt_data02 = db.Column(VARCHAR(200))
    txt_data03 = db.Column(VARCHAR(200))
    txt_data04 = db.Column(VARCHAR(200))
    txt_data05 = db.Column(VARCHAR(200))
    txt_data06 = db.Column(VARCHAR(200))
    txt_data07 = db.Column(VARCHAR(200))
    txt_data08 = db.Column(VARCHAR(200))
    txt_data09 = db.Column(VARCHAR(200))
    txt_data10 = db.Column(VARCHAR(200))
    proc_process_ratio = db.Column(INTEGER)
    imp_descent_filtered_row = db.Column(INTEGER)
    imp_removed_empty_slice = db.Column(INTEGER)

    def __str__(self):
        return "{0} ({1})".format(self.profileid, self.psampleid)
Ejemplo n.º 13
0
class Projects(db.Model):
    __tablename__ = 'projects'
    projid = db.Column(INTEGER, db.Sequence('seq_projects'), primary_key=True)
    title = db.Column(VARCHAR(255), nullable=False)
    visible = db.Column(db.Boolean(), default=True)
    status = db.Column(
        VARCHAR(40),
        default="Annotate")  # Annotate, ExploreOnly, Annotate No Prediction
    mappingobj = db.Column(VARCHAR)
    mappingsample = db.Column(VARCHAR)
    mappingacq = db.Column(VARCHAR)
    mappingprocess = db.Column(VARCHAR)
    objcount = db.Column(DOUBLE_PRECISION)
    pctvalidated = db.Column(DOUBLE_PRECISION)
    pctclassified = db.Column(DOUBLE_PRECISION)
    classifsettings = db.Column(
        VARCHAR)  # Settings for Automatic classification.
    initclassiflist = db.Column(VARCHAR)  # Initial list of categories
    classiffieldlist = db.Column(
        VARCHAR
    )  # Fields available on sort & displayed field of Manual classif screen
    popoverfieldlist = db.Column(
        VARCHAR)  # Fields available on popover of Manual classif screen
    comments = db.Column(VARCHAR)
    projtype = db.Column(VARCHAR(50))
    fileloaded = db.Column(VARCHAR)
    rf_models_used = db.Column(VARCHAR)
    cnn_network_id = db.Column(VARCHAR(50))

    def __str__(self):
        return "{0} ({1})".format(self.title, self.projid)

    def CheckRight(
        self,
        Level,
        userid=None
    ):  # Level -1=Read public, 0 = Read, 1 = Annotate, 2 = Admin . userid=None = current user
        # pp=self.projmembers.filter(member=userid).first()
        if userid is None:
            u = current_user
            userid = getattr(u, 'id', None)
            if userid is None:  # correspond à anonymous
                if Level <= -1 and self.visible:  # V1.2 tout projet visible est visible par tous
                    return True
                return False
        else:
            u = users.query.filter_by(id=userid).first()
        if len([x for x in u.roles if x == 'Application Administrator']) > 0:
            return True  # Admin à tous les droits
        pp = [x for x in self.projmembers if x.member == userid]
        if len(pp) == 0:  # pas de privileges pour cet utilisateur
            if Level <= -1 and self.visible:  # V1.2 tout projet visible est visible par tous
                return True
            return False
        pp = pp[0]  #on recupere la premiere ligne seulement.
        if pp.privilege == 'Manage':
            return True
        if pp.privilege == 'Annotate' and Level <= 1:
            return True
        if Level <= 0:
            return True
        return False

    def GetFirstManager(self):
        # retourne le utilisateur créé avec un privilege Manage
        lst = sorted([(r.id, r.memberrel.email, r.memberrel.name)
                      for r in self.projmembers if r.privilege == 'Manage'],
                     key=lambda r: r[0])
        if lst:
            return lst[0]
        return None

    def GetFirstManagerMailto(self):
        r = self.GetFirstManager()
        if r:
            return "<a href='mailto:{1}'>{2} ({1})</a>".format(*r)
        return ""