Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""bool: Whether or not the event is closed."""
now = datetime.datetime.utcnow()
return now > self.closing_timestamp
@property
def n_jobs(self):
"""int: The number of cv fold which can be used as number of jobs."""
return sum(1 for cv_fold in self.cv_folds if cv_fold.type == 'live')
@property
def n_participants(self):
"""int: The number of participants to the event."""
return len(self.event_teams)
class EventScoreType(Model):
"""EventScoreType table.
This is a many-to-one relationship between Event and ScoreType. Stores the
ScoresTypes for each event.
For each Event / ScoreType combo, also a new record in ScoreType is
created, which is not that useful (TODO consider removing ScoreType table)
Parameters
----------
event : :class:`ramp_database.model.Event`
The event instance.
score_type_object : :class:`rampwf.score_types`
A scoring instance.
Attributes
----------
_, y_test = self.get_test_data()
return self.Predictions(y_true=y_test)
def ground_truths_valid(self, test_is):
"""Predictions: the true labels for the validation."""
_, y_train = self.get_train_data()
return self.Predictions(y_true=y_train[test_is])
@property
def workflow_object(self):
""":class:`rampwf.worflows`: The workflow instance used for the
problem."""
return self.module.workflow
class HistoricalContributivity(Model):
"""HistoricalContributivity table.
Attributes
----------
id : int
The ID of the table row.
timestamp : datetime
The date and time of the submission.
submission_id : int
The ID of the submission.
submission : :class:`rampwf.model.Submission`
The submission instance.
contributivity : float
The contributivity of the current submission.
historical_contributivity : float
The historical contributivity.
'looking at leaderboard',
'looking at my_submissions',
'looking at private leaderboard',
'looking at submission',
'looking at user',
'save',
'signing up at event',
'submit',
'upload',
name='user_interaction_type'
)
# TODO: the ip should not be read from the environment variable but from the
# config file instead.
class UserInteraction(Model):
"""UserInteraction table.
This class is used to record the interaction of a user with the frontend.
Parameters
----------
interactions : None or str, default is None
The type of interaction.
user : None or :class:`ramp_database.model.User`, default is None
The user instance.
problem : None or :class:`ramp_database.model.Problem`, default is None
The problem instance.
event : None or :class:`ramp_database.model.Event`, default is None
The event instance.
ip : None or str, default is None
The ip address from the server.
The description of the keyword.
problems : list of :class:`ramp_database.model.ProblemKeyword`
A back-reference to the problems associated with the keyword.
"""
__tablename__ = 'keywords'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(), nullable=False, unique=True)
# 'data_domain' or 'data_science_theme'
type = Column(String(), nullable=False)
# 'industrial', 'research', etc.
category = Column(String())
description = Column(String())
class ProblemKeyword(Model):
"""ProblemKeyword table.
This a many-to-many relationship between a Problem and a Keyword.
Attributes
----------
id : int
The ID of the table row.
description : str
Optional description of the keyword for a particular problem.
problem_id : int
The ID of the problem.
problem : :class:`ramp_database.model.Problem`
The problem instance.
keyword_id : int
The ID of the keyword.
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship
from .base import Model
from .problem import Problem
from .score import ScoreType
__all__ = [
'Event',
'EventTeam',
'EventAdmin',
'EventScoreType',
]
class Event(Model):
"""Event table.
This table contains all information of a RAMP event.
Parameters
----------
problem_name : str
The name of the problem.
name : str
The name of the event.
event_title : str
The title to give for the event (used in the frontend, can contain
spaces).
ramp_sandbox_name : str
Name of the submission which will be considered the sandbox. It will
correspond to the key ``sandbox_name`` of the dictionary created with
self.state = 'training_error'
i = states.index('training_error')
self.error_msg = all_cv_folds[i].error_msg
elif any(state == 'validating_error' for state in states):
self.state = 'validating_error'
i = states.index('validating_error')
self.error_msg = all_cv_folds[i].error_msg
elif any(state == 'testing_error' for state in states):
self.state = 'testing_error'
i = states.index('testing_error')
self.error_msg = all_cv_folds[i].error_msg
if 'error' not in self.state:
self.error_msg = ''
class SubmissionScore(Model):
"""SubmissionScore table.
Attributes
----------
id : int
The ID of the row table.
submission_id : int
The ID of the associated submission.
submission : :class:`ramp_database.model.Submission`
The submission instance associated.
event_score_type_id : int
The ID of the event/score type associated.
event_score_type : :class:`ramp_database.model.EventScoreType`
The event/score type instance associated.
valid_score_cv_bag : float
The validation bagged scores.
__tablename__ = 'event_admins'
id = Column(Integer, primary_key=True)
event_id = Column(Integer, ForeignKey('events.id'), nullable=False)
event = relationship('Event',
backref=backref('event_admins',
cascade='all, delete-orphan'))
admin_id = Column(Integer, ForeignKey('users.id'), nullable=False)
admin = relationship('User',
backref=backref('admined_events',
cascade='all, delete-orphan'))
class EventTeam(Model):
"""EventTeam table.
This is a many-to-many relationship between Event and Team.
Parameters
----------
event : :class:`ramp_database.model.Event`
The event instance.
team : :class:`ramp_database.model.Team`
The team instance.
Attributes
----------
id : int
The ID of a row in the table.
event_id : int
from sqlalchemy import Float
from sqlalchemy import Column
from sqlalchemy import String
from sqlalchemy import Integer
from sqlalchemy import Boolean
from .base import Model
__all__ = ['ScoreType']
# XXX: Should probably be addressed at some point?
# Deprecated: score types are now defined in problem.py.
# EventScoreType.score_type should be deleted then DB migrated.
class ScoreType(Model):
"""ScoreType table.
Parameters
----------
name : str
The name of the score.
is_lower_the_better : bool
Whether a lower score is better.
minimum : float
The minimum possible score.
maximum : float
The maximum possible score.
Attributes
----------
id : int
from sqlalchemy import String
from sqlalchemy import Integer
from sqlalchemy import ForeignKey
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship
from .base import Model
__all__ = [
'Workflow',
'WorkflowElement',
'WorkflowElementType',
]
class WorkflowElementType(Model):
"""WorkflowElementType table.
Attributes
----------
id : int
The ID of the table row.
name : str
The name of the workflow element type.
type_id : int
The ID of the submission file type.
type : :class:`ramp_database.model.SubmissionFileType`
The submission file type instance.
workflows : list of :class:`ramp_database.model.WorkflowElement`
A back-reference to the workflows linked with the workflow element.
"""
__tablename__ = 'workflow_element_types'
"""bool: Whether or not the submission file is an editable type."""
return self.type.is_editable
@property
def max_size(self):
"""int: The maximum size of supported by the submission file type."""
return self.type.max_size
# training and test code now belongs to the workflow, not the workflow
# element. This latter would requre to carefully define workflow element
# interfaces. Eg, a dilemma: classifier + calibrator needs to handled at the
# workflow level (since calibrator needs held out data). Eventually we should
# have both workflow-level and workflow-element-level code to avoid code
# repetiotion.
class Workflow(Model):
"""Workflow table.
Parameters
----------
name : str
The name of the workflow.
Attributes
----------
id : int
The ID of the table row.
name : str
The name of the workflow.
problems : list of :class:`ramp_database.model.Problem`
A back-reference to the problems using this workflow.
elements : list of :class:`ramp_database.model.WorkflowElement`