class Report(db.Model):
    __tablename__ = 'Reports'
    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey(
        'Users.id'))  # ID-ul userului caruia i s-a facut report-ul
    skill_id = db.Column(
        db.Integer,
        db.ForeignKey('Skills.id'))  # Skill-ul pentru care s-a facut report
    project_id = db.Column(db.Integer, db.ForeignKey(
        'Projects.id'))  # Proiectul in cadrul caruia s-a primit feedback
    mark = db.Column('mark', db.Integer)
    date = db.Column('date', db.DateTime)

    def __init__(self, id, user_id, skill_id, project_id, mark, date):
        self.id = id
        self.user_id = user_id
        self.skill_id = skill_id
        self.project_id = project_id
        self.mark = mark
        self.date = date

    def set_user_id(self, value):
        self.user_id = value

    def set_skill_id(self, value):
        self.skill_id = value

    def set_project_id(self, value):
        self.project_id = value

    def set_mark(self, value):
        self.mark = value

    def set_date(self, value):
        self.date = value

    def set_id(self, value):
        self.id = value

    def get_id(self):
        return self.id

    def get_user_id(self):
        return self.user_id

    def get_skill_id(self):
        return self.skill_id

    def get_project_id(self):
        return self.project_id

    def get_mark(self):
        return self.mark

    def get_date(self):
        return self.date
Example #2
0
class ReportSession(db.Model):
    __tablename__ = 'ReportSessions'
    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    project_id = db.Column(db.Integer, db.ForeignKey('Projects.id'))
    user_id = db.Column(
        db.Integer, db.ForeignKey('Users.id'))  # ID-ul celui care da feedback
    start_date = db.Column('start_date', db.DateTime)
    end_date = db.Column('end_date', db.DateTime)
    was_completed = db.Column(
        'was_completed',
        db.Boolean)  # Userul a trimis sau nu feedback pentru sesiunea asta

    def __init__(self, id, project_id, user_id, start_date, end_date,
                 was_completed):
        self.id = id
        self.project_id = project_id
        self.user_id = user_id
        self.start_date = start_date
        self.end_date = end_date
        self.was_completed = was_completed

    def get_id(self):
        return self.id

    def get_project_id(self):
        return self.project_id

    def get_user_id(self):
        return self.user_id

    def get_start_date(self):
        return self.start_date

    def get_end_date(self):
        return self.end_date

    def get_was_completed(self):
        return self.was_completed

    def set_user_id(self, value):
        self.user_id = value

    def set_project_id(self, value):
        self.project_id = value

    def set_start_date(self, value):
        self.start_date = value

    def set_end_date(self, value):
        self.end_date = value

    def set_was_completed(self, value):
        self.was_completed = value

    def set_id(self, value):
        self.id = value
Example #3
0
class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.Text, unique=True)
    created_at = db.Column(db.DateTime, nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))

    def __init__(self, username, email):
        self.name = name
        self.description = description
        self.created_at = datetime.datetime.utcnow()
Example #4
0
class StudentInfo(db.Model):
    __tablename__ = 'StudentInfos'
    id = db.Column("id",
                   db.Integer,
                   db.ForeignKey('Users.id'),
                   primary_key=True)
    name = db.Column("name", db.String)
    pnc = db.Column("pnc", db.String)  # CNP
    student_function = db.Column("student_function",
                                 db.String)  # licenta/master
    faculty = db.Column("faculty", db.String)
    year = db.Column("year", db.Integer)
    group = db.Column("group", db.String)
    specialization = db.Column("specialization", db.String)
    study_line = db.Column("study_line", db.String)

    def __init__(self, student_id, name, pnc, student_function, faculty, year,
                 group, specialization, study_line):
        self.id = student_id
        self.name = name
        self.pnc = pnc
        self.student_function = student_function
        self.faculty = faculty
        self.year = year
        self.group = group
        self.specialization = specialization
        self.study_line = study_line

    def get_id(self):
        return self.id
Example #5
0
class ComplianceRuleResults(db.Model):
    __tablename__ = 'compliance_rule_results'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    ruleId = db.Column('rule_id',
                       db.Integer,
                       db.ForeignKey('rules.id'),
                       nullable=False)
    provider = db.Column(db.String(100))
    region = db.Column(db.String(100))
    result = db.Column(db.String(100))
    message = db.Column(db.Text)
    timestamp = db.Column(db.Date)
    rule = relationship("Rules", backref="rules")

    def __init__(self, ruleId, provider, region, result, message, timestamp):
        self.ruleId = ruleId
        self.provider = provider
        self.region = region
        self.result = result
        self.message = message
        self.timestamp = timestamp

    def __repr__(self):
        return '<Result {} {} {}>'.format(self.ruleId, self.result,
                                          self.message)

    def toString(self):
        return ({
            'name': self.ruleId,
            'region': self.region,
            'message': self.message,
            'provider': self.provider,
            'rule': self.rule.toString(),
            'result': self.result
        })
Example #6
0
class Log(db.Model):
    __tablename__ = 'logs'

    id = db.Column(db.Integer, primary_key=True)
    announcement_id = db.Column(db.Integer,
                                db.ForeignKey('announcements.id'),
                                nullable=False,
                                index=True)
    is_seen = db.Column(db.Boolean, default=False)
    is_submit = db.Column(db.Boolean, default=False)
    created_at = db.Column(db.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    status = db.Column(db.Boolean, default=False)  # Checking status

    def __repr__(self):
        return '<Log {} {} {}>'.format(self.created_at, self.announcement_id,
                                       self.is_seen)

    def log_to_dict(self):
        data = {
            'id': self.id,
            'created_at': self.created_at,
            'announcement': 'announcement',
            'status': self.status,
            'is_seen': self.is_seen,
            'is_submit': self.is_submit,
        }
        return data
Example #7
0
class StudentInternship(db.Model):
    __tablename__ = 'StudentInternships'
    internship_id = db.Column("internship_id", db.Integer,
                              db.ForeignKey('Internships.id'))
    student_id = db.Column("student_id",
                           db.Integer,
                           db.ForeignKey('Users.id'),
                           primary_key=True)
    tutor_id = db.Column("tutor_id", db.Integer, db.ForeignKey('Users.id'))
    supervisor_id = db.Column("supervisor_id", db.Integer,
                              db.ForeignKey('Users.id'))

    def __init__(self, internship_id, student_id, tutor_id, supervisor_id):
        self.id = id
        self.internship_id = internship_id
        self.student_id = student_id
        self.tutor_id = tutor_id
        self.supervisor_id = supervisor_id
Example #8
0
class Tray(db.Model):
    __tablename__ = 'trays'
    id = db.Column(db.Integer, primary_key=True)
    incubator_id = db.Column(db.Integer, db.ForeignKey('incubators.id'), nullable=False)
    incubator = db.relationship('Incubator', backref=db.backref('trays'))
    date_incubated = db.Column(db.DateTime, nullable=True)
    eggs_contained = db.Column(db.Integer, nullable=False, default=0)

    def __repr__(self):
        return '<Role %r>' % self.id
Example #9
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    created_at = db.Column(db.DateTime, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    items = db.relationship('Item', backref='category', lazy='dynamic')

    def __init__(self, username, email):
        self.name = name
        self.created_at = datetime.datetime.utcnow()
Example #10
0
class Post2(Base):
    __tablename__ = 'post2'

    title = db.Column(db.String(64))
    body = db.Column(db.Text)
    user_id = db.Column(db.Integer, db.ForeignKey('user2.id'))

    def __init__(self, user_id, title, body):
        self.user_id = user_id
        self.title = title
        self.body = body
class ServiceInstance(db.Model):

    __tablename__ = "service_instance"
    service_id = db.Column(db.Integer,
                           db.ForeignKey('service_registry.id'),
                           primary_key=True)
    host = db.Column(db.String(255), nullable=False, primary_key=True)
    port = db.Column(db.String(255), nullable=False, primary_key=True)
    health = db.Column(db.Integer)
    created_on = db.Column(db.DateTime, server_default=db.func.now())
    updated_on = db.Column(db.DateTime,
                           server_default=db.func.now(),
                           onupdate=db.func.now())
Example #12
0
class User_Project(db.Model):
    __tablename__ = 'User_Project'
    user_id = db.Column(db.Integer,
                        db.ForeignKey('Users.id'),
                        primary_key=True)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('Projects.id'),
                           primary_key=True)

    def __init__(self, user_id, project_id):
        self.user_id = user_id
        self.project_id = project_id

    def get_user_id(self):
        return self.user_id

    def get_project_id(self):
        return self.project_id

    def set_user_id(self, value):
        self.user_id = value

    def set_project_id(self, value):
        self.project_id = value
class Project_Technology(db.Model):
    __tablename__ = 'Project_Technology'
    project_id = db.Column(db.Integer,
                           db.ForeignKey('Projects.id'),
                           primary_key=True)
    technology_id = db.Column(db.Integer,
                              db.ForeignKey('Technologies.id'),
                              primary_key=True)

    def __init__(self, project_id, technology_id):
        self.project_id = project_id
        self.technology_id = technology_id

    def get_technology_id(self):
        return self.technology_id

    def get_project_id(self):
        return self.project_id

    def set_technology_id(self, value):
        self.technology_id = value

    def set_project_id(self, value):
        self.project_id = value
class DeclaratieTraseu(db.Model):
    __tablename__ = 'DeclaratieTraseu'
    student_id = db.Column("student_id",
                           db.Integer,
                           db.ForeignKey('Users.id'),
                           primary_key=True)
    submitted = db.Column("submitted", db.DateTime)
    content = db.Column("content", db.PickleType)
    checked = db.Column("checked", db.Boolean)

    def __init__(self, student_id, submitted, content, checked):
        self.student_id = student_id
        self.submitted = submitted
        self.content = content
        self.checked = checked
Example #15
0
class TutorInfo(db.Model):
    __tablename__ = 'TutorInfos'
    id = db.Column("id",
                   db.Integer,
                   db.ForeignKey('Users.id'),
                   primary_key=True)
    name = db.Column("name", db.String)
    email = db.Column("email", db.String)
    phone = db.Column("phone", db.String)
    fax = db.Column("fax", db.String)
    function = db.Column("function", db.String)

    def __init__(self, tutor_id, name, email, phone, fax, function):
        self.id = tutor_id
        self.name = name
        self.email = email
        self.phone = phone
        self.fax = fax
        self.function = function
Example #16
0
class SupervisorInfo(db.Model):
    __tablename__ = 'SupervisorInfos'
    id = db.Column("id",
                   db.Integer,
                   db.ForeignKey('Users.id'),
                   primary_key=True)
    #id = db.Column("id", db.Integer, primary_key=True)
    name = db.Column("name", db.String)
    specialization = db.Column("specialization", db.String)
    email = db.Column("email", db.String)
    phone = db.Column("phone", db.String)
    fax = db.Column("fax", db.String)

    def __init__(self, id, name, specialization, email, phone, fax):
        self.id = id
        self.name = name
        self.email = email
        self.specialization = specialization
        self.phone = phone
        self.fax = fax
class Project(db.Model):
    __tablename__ = 'Projects'
    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    name = db.Column('name', db.String)
    description = db.Column('description', db.String)
    start_date = db.Column('start_date', db.Date)
    end_date = db.Column('end_date', db.Date)
    deadline_date = db.Column('deadline_date', db.Date)
    client_id = db.Column(db.Integer, db.ForeignKey("Clients.id"))

    def __init__(self, id, name, description, start_date, end_date,
                 deadline_date, client_id):
        self.id = id
        self.name = name
        self.description = description
        self.start_date = start_date
        self.end_date = end_date
        self.deadline_date = deadline_date
        self.client_id = client_id

    def get_id(self):
        return self.id

    def get_description(self):
        return self.description

    def get_name(self):
        return self.name

    def get_client_id(self):
        return self.client_id

    def get_start_date(self):
        return self.start_date

    def get_end_date(self):
        return self.end_date

    def get_deadline_date(self):
        return self.deadline_date

    def set_client_id(self, value):
        self.client_id = value

    def set_start_date(self, value):
        self.start_date = value

    def set_end_date(self, value):
        self.end_date = value

    def set_deadline_date(self, value):
        self.deadline_date = value

    def set_id(self, value):
        self.id = value

    def set_name(self, value):
        self.name = value

    def set_description(self, value):
        self.description = value
class User(db.Model):
    __tablename__ = 'Users'
    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    name = db.Column('name', db.String)
    email = db.Column('email', db.String)
    password = db.Column('password', db.String)
    role = db.Column('role', db.SmallInteger)
    seniority_level = db.Column('seniority_level', db.SmallInteger)
    department_id = db.Column(db.Integer, db.ForeignKey('Departments.id'))

    def __init__(self, id, name, email, password, role, seniority_level,
                 department_id):
        self.id = id
        self.name = name
        self.email = email
        self.password = password
        self.role = role
        self.seniority_level = seniority_level
        self.department_id = department_id

    def set_id(self, value):
        self.id = value

    def set_name(self, value):
        self.name = value

    def set_email(self, value):
        self.email = value

    def set_password(self, value):
        self.password = value

    def set_role(self, value):
        self.role = value

    def set_seniority_level(self, value):
        self.seniority_level = value

    def set_department_id(self, value):
        self.department_id = value

    def get_id(self):
        return self.id

    def get_name(self):
        return self.name

    def get_email(self):
        return self.email

    def get_password(self):
        return self.password

    def get_role(self):
        return self.role

    def get_seniority_level(self):
        return self.seniority_level

    def get_department_id(self):
        return self.department_id
Example #19
0
class Report(db.Model):
    """The report of a visitor that a drop point needs maintenance.

    When visitors find a drop point needing maintenance, they may report
    the drop point to the bottle collectors. A report is issued for a
    given drop point which has a time and optionally some information
    about the state of the drop point in question.
    """

    state_weights = [
        ["DEFAULT", 5.0],  # 0 should be the default/unknown state
        ["NEW", 1.0],  # 1 should be the state of new drop points
        ["NO_CRATES", 5.0],
        ["SOME_BOTTLES", 1.0],
        ["REASONABLY_FULL", 2.0],
        ["FULL", 3.0],
        ["OVERFLOW", 5.0],
        ["EMPTY", 0.0]  # -1 should be the EMPTY state
    ]

    states = [e[0] for e in state_weights]

    rep_id = db.Column(db.Integer, primary_key=True)

    dp_id = db.Column(db.Integer,
                      db.ForeignKey("drop_point.number"),
                      nullable=False)

    dp = db.relationship("DropPoint")

    time = db.Column(db.DateTime, nullable=False)

    state = db.Column(db.Enum(*states, name="report_states"),
                      default=states[0])

    def __init__(self, dp, time=None, state=None):

        errors = []

        self.dp = dp

        if not isinstance(dp, model.drop_point.DropPoint):
            errors.append({"Report": _("Not given a drop point object.")})
        else:
            if dp.removed:
                errors.append({"Report": _("Drop point has been removed.")})

        if time and not isinstance(time, datetime):
            errors.append({"Report": _("Time not a datetime object.")})

        if isinstance(time, datetime) and time > datetime.today():
            errors.append({"Report": _("Start time in the future.")})

        self.time = time if time else datetime.today()

        if state in Report.states:
            self.state = state
        else:
            errors.append({"Report": _("Invalid or missing reported state.")})

        if errors:
            raise ValueError(*errors)

        db.session.add(self)

    def get_weight(self):
        """Get the weight (i.e. significance) of a report.

        The weight of a report determines how significant it is for the
        calculation of the priority to visit the respective drop point
        soon.

        Most important for the weight of a report is the state of the
        drop point as seen by the reporter. The report of an
        overflowing drop point is certainly more important than one
        of a drop point nearly empty.

        If the reporter is a trusted user, that increases the weight.

        Special users see special weights: The supervisor of the
        bottle collectors is not focused on full drop points (that's
        what they have a collector team for) but rather on solving
        problems like overflows or missing crates reported by trusted
        users.

        The default weight under default conditions is 1 and all
        influences should only multiply that default value with some
        factor.
        """

        # TODO:
        # - weight should depend on the state (OVERFLOW > FULL > rest)
        # - weight should depend on the reporter (trusted > stranger)
        # - weight should depend on the viewer (supervisor: problem-
        #   focused, collector: collection-focused)

        return self.get_state_weight(self.state)

    @classmethod
    def get_state_weight(cls, state):
        for elem in cls.state_weights:
            if elem[0] == state:
                return elem[1]
        return float(cls.state_weights[0][1])

    def __repr__(self):
        return "Report %s of drop point %s (state %s at %s)" % (
            self.rep_id, self.dp_id, self.state, self.time)
Example #20
0
class Location(db.Model):
    """A physical location of a drop point at some point in time.

    Drop points may be relocated at any time for whatever reason. For
    analysis after an event and optimization of the drop point locations
    for the next event at the same venue, drop point locations are tracked
    over time.

    Each location has a start time indicating the placement of the drop
    point at that location. If a drop point is relocated, a new location
    with the respective start time is added. If the start time is null,
    the drop point has been there since the creation of the universe.

    If the human-readable description as well as the coordinates both are
    null, the location of that drop point is unknwon.
    """

    max_description = 140

    loc_id = db.Column(db.Integer, primary_key=True)

    dp_id = db.Column(db.Integer,
                      db.ForeignKey("drop_point.number"),
                      nullable=False)

    dp = db.relationship("DropPoint")

    time = db.Column(db.DateTime)
    description = db.Column(db.String(max_description))
    lat = db.Column(db.Float)
    lng = db.Column(db.Float)
    level = db.Column(db.Integer)

    def __init__(self,
                 dp,
                 time=None,
                 description=None,
                 lat=None,
                 lng=None,
                 level=None):

        errors = []

        if not isinstance(dp, model.drop_point.DropPoint):
            errors.append({"Location": _("Not given a drop point object.")})
            raise ValueError(errors)

        self.dp = dp

        if time and not isinstance(time, datetime):
            errors.append({"Location": _("Start time not a datetime object.")})

        if isinstance(time, datetime) and time > datetime.today():
            errors.append({"Location": _("Start time in the future.")})

        if dp.locations and isinstance(time, datetime) and \
                time < dp.locations[-1].time:
            errors.append({"Location": _("Location older than current.")})

        self.time = time if time else datetime.today()

        try:
            self.lat = float(lat)
        except (TypeError, ValueError):
            errors.append(
                {"lat": _("Latitude is not a floating point number.")})
        else:
            if not -90 < self.lat < 90:
                errors.append(
                    {"lat": _("Latitude is not between 90 degrees N/S.")})

        try:
            self.lng = float(lng)
        except (TypeError, ValueError):
            errors.append(
                {"lng": _("Longitude is not a floating point number.")})
        else:
            if not -180 < self.lng < 180:
                errors.append(
                    {"lng": _("Longitude is not between 180 degrees W/E.")})

        try:
            self.level = int(level)
        except (TypeError, ValueError):
            errors.append({"level": _("Level is not a number.")})

        try:
            self.description = str(description)
        except (TypeError, ValueError):
            errors.append(
                {"description": _("Location description is not a string.")})
        else:
            if len(self.description) > self.max_description:
                errors.append(
                    {"description": _("Location description is too long.")})

        if errors:
            raise ValueError(*errors)

        db.session.add(self)

    def __repr__(self):
        return "Location %s of drop point %s (%s since %s)" % (
            self.loc_id, self.dp_id, self.description, self.time)
Example #21
0
class Visit(db.Model):
    """A maintenance visit of bottle collectors at a drop point.

    After a report of a problem with a certain drop point has been
    generated or a drop point has not been visited for a long time, the
    bottle collectors are advised to visit that drop point. After doing
    so, they log their visit and the action taken.
    """

    actions = (
        "EMPTIED",  # 0 should be the action that empties a drop point
        "ADDED_CRATE",
        "REMOVED_CRATE",
        "RELOCATED",
        "REMOVED",
        "NO_ACTION")

    vis_id = db.Column(db.Integer, primary_key=True)

    dp_id = db.Column(db.Integer,
                      db.ForeignKey("drop_point.number"),
                      nullable=False)

    dp = db.relationship("DropPoint")

    time = db.Column(db.DateTime, nullable=False)

    action = db.Column(db.Enum(*actions, name="visit_actions"),
                       default=actions[0])

    def __init__(self, dp, time=None, action=None):

        errors = []

        self.dp = dp

        if not isinstance(dp, model.drop_point.DropPoint):
            errors.append({"Visit": _("Not given a drop point object.")})
        else:
            if dp.removed:
                errors.append({"Visit": _("Drop point has been removed.")})

        if time and not isinstance(time, datetime):
            errors.append({"Visit": _("Time not a datetime object.")})

        if isinstance(time, datetime) and time > datetime.today():
            errors.append({"Visit": _("Start time in the future.")})

        self.time = time if time else datetime.today()

        if action in Visit.actions:
            self.action = action
        else:
            errors.append(
                {"Visit": _("Invalid or missing maintenance action.")})

        if errors:
            raise ValueError(*errors)

        db.session.add(self)

    def __repr__(self):
        return "Visit %s of drop point %s (action %s at %s)" % (
            self.vis_id, self.dp_id, self.action, self.time)