[virtualcommons-svn] /hgrepo/v/vi/virtualcommons/virtualcommons: updated data model. ...
Status: Beta
Brought to you by:
alllee
From: <vir...@li...> - 2010-07-12 06:24:54
|
Subject: hg.virtualcommons 10 details: http://virtualcommons.hg.sourceforge.net:8000/hgroot/virtualcommons/virtualcommons/hgrepo/v/vi/virtualcommons/virtualcommons/rev/b241d176bef2 changeset: 10:b241d176bef2 user: alllee date: Sun Jul 11 23:24:47 2010 -0700 description: updated data model. starting to form query methods / API for data values and other parameters via DataAccess module. diffstat: vcweb/core/DataAccess.py | 18 ++++++++++++ vcweb/core/models.py | 67 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 14 deletions(-) diffs (149 lines): diff -r 33b54e8163ff -r b241d176bef2 vcweb/core/DataAccess.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vcweb/core/DataAccess.py Sun Jul 11 23:24:47 2010 -0700 @@ -0,0 +1,18 @@ +''' +Created on Jul 11, 2010 + +Data access interface (if necessary) for interacting with GroupRoundDataValue and ParticipantDataValue +@author: alllee +''' + +class DataAccess(object): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + \ No newline at end of file diff -r 33b54e8163ff -r b241d176bef2 vcweb/core/models.py --- a/vcweb/core/models.py Fri Jul 09 16:15:08 2010 -0700 +++ b/vcweb/core/models.py Sun Jul 11 23:24:47 2010 -0700 @@ -18,11 +18,16 @@ class Meta: ordering = ['name', 'date_created'] +class Institution(models.Model): + name = models.CharField(max_length=255) + description = models.TextField(null=True) + url = models.URLField(null=True) + class Experimenter(models.Model): email = models.EmailField() - last_name = models.TextField() - first_name = models.TextField() - institution = models.TextField() + last_name = models.CharField(max_length=64) + first_name = models.CharField(max_length=64) + institution = models.ForeignKey(Institution) password = models.CharField(max_length=255) approved = models.BooleanField() last_login_date = models.DateTimeField() @@ -47,7 +52,11 @@ # an actual instance of a game; represents a concrete # parameterization of this game. class GameInstance(models.Model): - GAME_STATUS_CHOICES = ('INACTIVE', 'ACTIVE', 'COMPLETED') + GAME_STATUS_CHOICES = ( + ('INACTIVE', 'Not active'), + ('ACTIVE', 'Active'), + ('COMPLETED', 'Completed'), + ) authentication_code = models.CharField(max_length=255) current_round_number = models.PositiveIntegerField() experimenter = models.ForeignKey(Experimenter) @@ -58,6 +67,15 @@ start_time = models.TimeField(null=True) end_time = models.TimeField(null=True) + def ___eq___(self, other): + return self.id == other.id + + def ___cmp___(self, other): + return self.id.___cmp___(other.id) + + def ___hash___(self): + return self.id.___hash___() + class RoundConfiguration(models.Model): game_configuration = models.ForeignKey(GameConfiguration) sequence_number = models.PositiveIntegerField(blank=False) @@ -89,6 +107,17 @@ class DataParameter(Parameter): + + def ___eq___(self, other): + return self.name == other.name + + def ___cmp___(self, other): + return self.name.__cmp__(other.name) + + def ___hash___(self): + return self.name.__hash__() + + def __unicode__(self): return 'Data Parameter - [name: ' + self.name + '] [type: ' + self.type + ']' @@ -99,7 +128,7 @@ class RoundParameter(models.Model): round_configuration = models.ForeignKey(RoundConfiguration) parameter = models.ForeignKey(ConfigurationParameter) - parameter_value = models.TextField() + parameter_value = models.CharField(max_length=255) # class Meta: # db_table = 'vcweb_round_parameter' @@ -128,15 +157,25 @@ # class Meta: # db_table = 'vcweb_group_round_data' -class GroupRoundDataParameter(models.Model): - group_round_data = models.ForeignKey(GroupRoundData) +class DataValue(models.Model): parameter = models.ForeignKey(DataParameter) - parameter_value = models.TextField() - time_recorded = models.TimeField() + parameter_value = models.CharField(max_length=255) + time_recorded = models.TimeField(auto_now_add = True) + game_instance = models.ForeignKey(GameInstance) + + @staticmethod + def find(incoming_parameter, incoming_game_instance): + DataValue.objects.filter(parameter=incoming_parameter, game_instance=incoming_game_instance) + class Meta: + abstract = True + +class GroupRoundDataValue(DataValue): + group_round_data = models.ForeignKey(GroupRoundData) + class Meta: ordering = [ 'parameter' ] - + class Participant(models.Model): name = models.CharField(max_length=255) @@ -152,11 +191,11 @@ participant = models.ForeignKey(Participant) round_configuration = models.ForeignKey(RoundConfiguration) -class ParticipantDataParameter(models.Model): +class ParticipantDataValue(DataValue): participant_data = models.ForeignKey(ParticipantData) - parameter = models.ForeignKey(DataParameter) - parameter_value = models.TextField() - time_recorded = models.TimeField() + + class Meta: + ordering = [ 'parameter' ] |