[virtualcommons-svn] commit/vcweb: 2 new changesets
Status: Beta
Brought to you by:
alllee
|
From: <com...@bi...> - 2013-07-23 22:22:26
|
2 new commits in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/aece9dcf96c5/ Changeset: aece9dcf96c5 User: alllee Date: 2013-07-24 00:21:56 Summary: - clamping self storage to zero if negative - setting participant ready and harvest decisions to 0 when resource is depleted Affected #: 2 files diff -r 68ff86fb364365d7ce5894c53a27c18bf9f0a3da -r aece9dcf96c5b20256ccaf1c08eace4329ab30cc vcweb/bound/models.py --- a/vcweb/bound/models.py +++ b/vcweb/bound/models.py @@ -123,7 +123,7 @@ def get_average_storage(group, round_data): return get_total_storage(group, round_data) / float(group.size) -def get_resource_level_dv(group, round_data=None, round_configuration=None, cluster=None): +def get_resource_level_dv(group, round_data=None, round_configuration=None, cluster=None, shared_resource_enabled=None): ''' Returns either the GroupClusterDataValue (shared resource condition) or the GroupRoundDataValue (standard resource per group condition) for the given group @@ -132,7 +132,9 @@ round_data = group.current_round_data if round_configuration is None: round_configuration = round_data.round_configuration - if is_shared_resource_enabled(round_configuration): + if shared_resource_enabled is None: + shared_resource_enabled = is_shared_resource_enabled(round_configuration) + if shared_resource_enabled: return get_shared_resource_level_dv(group, round_data, cluster) else: return get_unshared_resource_level_dv(group, round_data) @@ -267,26 +269,20 @@ group_parameters=(get_regrowth_parameter(), get_group_harvest_parameter(), get_resource_level_parameter(),), participant_parameters=(get_storage_parameter(), get_player_status_parameter(),) ) - if round_configuration.is_playable_round: - # check for dead participants and set their ready and harvest decision flags - deceased_participants = ParticipantRoundDataValue.objects.select_related('participant_group_relationship').filter(parameter=get_player_status_parameter(), - round_data=round_data, boolean_value=False) - for prdv in deceased_participants: - pgr = prdv.participant_group_relationship - set_harvest_decision(pgr, 0, round_data, submitted=True) - pgr.set_participant_ready(round_data) + shared_resource_enabled = is_shared_resource_enabled(round_configuration) ''' during a practice or regular round, set up resource levels, participant harvest decision parameters, and group formation ''' if should_reset_resource_level(round_configuration, experiment): initial_resource_level = get_max_resource_level(round_configuration) - logger.debug("Resetting resource level for %s to %d", round_configuration, initial_resource_level) + logger.debug("Resetting resource level for all groups in %s to %d", round_configuration, initial_resource_level) for group in experiment.groups: ''' set resource level to initial default ''' - existing_resource_level = get_resource_level_dv(group, round_data, round_configuration) + existing_resource_level = get_resource_level_dv(group, round_data, round_configuration, + shared_resource_enabled=shared_resource_enabled) group.log( - "Setting resource level (%s) to initial value [%s]" % (existing_resource_level, initial_resource_level)) + "Resetting resource level (%s) to initial value [%s]" % (existing_resource_level, initial_resource_level)) existing_resource_level.update_int(initial_resource_level) # FIXME: verify that this is expected behavior - if the resource level is reset, reset all participant storages to 0 ParticipantRoundDataValue.objects.for_group(group, parameter=get_storage_parameter(), @@ -294,9 +290,34 @@ # reset all player statuses to alive ParticipantRoundDataValue.objects.for_group(group, parameter=get_player_status_parameter(), round_data=round_data).update(boolean_value=True) + elif round_configuration.is_playable_round: + # first check for a depleted resource + for group in experiment.groups: + existing_resource_level = get_resource_level_dv(group, round_data, round_configuration, + shared_resource_enabled=shared_resource_enabled) + if existing_resource_level.int_value <= 0: + group.log("setting all participant ready flags because of depleted resource %s", + existing_resource_level) + _zero_harvest_decisions(group.participant_group_relationship_set.all(), round_data) + # check for dead participants and set their ready and harvest decision flags + deceased_participants = ParticipantRoundDataValue.objects.select_related('participant_group_relationship').filter(parameter=get_player_status_parameter(), + round_data=round_data, boolean_value=False).values_list('participant_group_relationship', flatten=True) + _zero_harvest_decisions(deceased_participants, round_data) + ''' + for prdv in deceased_participants: + pgr = prdv.participant_group_relationship + set_harvest_decision(pgr, 0, round_data, submitted=True) + pgr.set_participant_ready(round_data) + ''' +def _zero_harvest_decisions(participant_group_relationships, round_data): + # FIXME: possible performance issue, replace with direct update query + for pgr in participant_group_relationships: + set_harvest_decision(pgr, 0, round_data, submitted=True) + pgr.set_participant_ready(round_data) + def adjust_harvest_decisions(current_resource_level, group, round_data, total_harvest, group_size=0): if group_size == 0: group_size = group.size @@ -336,7 +357,7 @@ def update_resource_level(experiment, group, round_data, regrowth_rate, max_resource_level=None): if max_resource_level is None: max_resource_level = get_max_resource_level(round_data.round_configuration) - current_resource_level_dv = get_resource_level_dv(group, round_data) + current_resource_level_dv = get_resource_level_dv(group, round_data, shared_resource_enabled=False) current_resource_level = current_resource_level_dv.int_value group_harvest_dv = get_group_harvest_dv(group, round_data) regrowth_dv = get_regrowth_dv(group, round_data) diff -r 68ff86fb364365d7ce5894c53a27c18bf9f0a3da -r aece9dcf96c5b20256ccaf1c08eace4329ab30cc vcweb/bound/templates/bound/participate.html --- a/vcweb/bound/templates/bound/participate.html +++ b/vcweb/bound/templates/bound/participate.html @@ -57,7 +57,7 @@ <tr><th>Trees left in the forest</th><th>Trees harvested</th><th>Trees in storage</th><th>Earnings</th></tr></thead><tbody> - <tr><td data-bind='text: resourceLevel'></td><td data-bind='text: totalHarvest'></td><td data-bind='text: Math.max(0, storage())'></td><td class='text-success' data-bind='text: totalEarnings'></td></tr> + <tr><td data-bind='text: resourceLevel'></td><td data-bind='text: totalHarvest'></td><td data-bind='text: clampedStorage'></td><td class='text-success' data-bind='text: totalEarnings'></td></tr></tbody></table><div class='alert alert-info'> @@ -365,7 +365,7 @@ <div class='alert bound-status-dashboard span1'><h4 id='dashboard-storage'>Total Earnings <i class='icon-info-sign' data-bind='attr: {"data-content": "You need at least " + costOfLiving() + " trees to survive each round."}'></i></h4><p> - <strong data-bind='css: { "text-error": storage() < costOfLiving(), "text-success": storage() > costOfLiving()}'><span data-bind='text: storage'></span><i class='icon-leaf'></i></strong> + <strong data-bind='css: { "text-error": storage() < costOfLiving(), "text-success": storage() > costOfLiving()}'><span data-bind='text: clampedStorage'></span><i class='icon-leaf'></i></strong></p></div><div class='alert bound-status-dashboard span1'> @@ -404,7 +404,7 @@ <tr><td>Earnings</td><!-- ko foreach: playerData --> - <td data-bind='text: Math.max(0, storage()), css: { "current-player": id() === $root.participantGroupId() }'></td> + <td data-bind='text: clampedStorage, css: { "current-player": id() === $root.participantGroupId() }'></td><!-- /ko --></tr><tr> @@ -542,6 +542,9 @@ var self = this; var model = ko.mapping.fromJS(experimentModelJson); model.tour = ko.observable(); + model.clampedStorage = ko.computed(function() { + return Math.max(0, model.storage()); + }); model.harvestDecisionOptions = ko.computed(function() { return ko.utils.range(0, model.maxHarvestDecision()); }); @@ -559,7 +562,7 @@ return formatCurrency(model.sessionTwoStorage() * model.exchangeRate()) }); model.totalEarnings = ko.computed(function() { - return formatCurrency(Math.max(0, model.storage() * model.exchangeRate())); + return formatCurrency(model.clampedStorage() * model.exchangeRate())); }); model.templateId = ko.computed(function() { switch ( model.templateName() ) { https://bitbucket.org/virtualcommons/vcweb/commits/17f4caf07855/ Changeset: 17f4caf07855 User: alllee Date: 2013-07-24 00:22:07 Summary: fixing forestry tests Affected #: 2 files diff -r aece9dcf96c5b20256ccaf1c08eace4329ab30cc -r 17f4caf0785518a6e6312f740c5ff7ecb0c44cbd vcweb/forestry/fixtures/forestry_experiment_metadata.json --- a/vcweb/forestry/fixtures/forestry_experiment_metadata.json +++ b/vcweb/forestry/fixtures/forestry_experiment_metadata.json @@ -84,10 +84,11 @@ "date_created": "2010-09-07 15:13:03", "duration": 0, "experiment_configuration": 1, - "instructions": "The following quiz is designed to ensure you understand the dynamics of this experiment.", + "instructions": "First practice round.", "last_modified": "2010-09-07 15:13:03", "round_type": "PRACTICE", - "sequence_number": 2 + "sequence_number": 2, + "initialize_data_values": true }, "model": "core.roundconfiguration", "pk": 2 @@ -140,7 +141,8 @@ "last_modified": "2010-09-07 15:13:03", "round_type": "REGULAR", "display_number": 1, - "sequence_number": 6 + "sequence_number": 6, + "initialize_data_values": true }, "model": "core.roundconfiguration", "pk": 6 diff -r aece9dcf96c5b20256ccaf1c08eace4329ab30cc -r 17f4caf0785518a6e6312f740c5ff7ecb0c44cbd vcweb/forestry/models.py --- a/vcweb/forestry/models.py +++ b/vcweb/forestry/models.py @@ -122,16 +122,11 @@ round_configuration = experiment.current_round logger.debug("setting up forestry round %s", round_configuration) if round_configuration.is_playable_round: - # participant parameter - harvest_decision_parameter = get_harvest_decision_parameter() - # group parameters - regrowth_parameter = get_regrowth_parameter() - group_harvest_parameter = get_group_harvest_parameter() - resource_level_parameter = get_resource_level_parameter() + # FIXME: push this step into the realm of experiment configuration # initialize group and participant data values experiment.initialize_data_values( - group_parameters=(regrowth_parameter, group_harvest_parameter, resource_level_parameter), - participant_parameters=[harvest_decision_parameter] + group_parameters=(get_regrowth_parameter(), get_group_harvest_parameter(), get_resource_level_parameter()), + participant_parameters=[get_harvest_decision_parameter()] ) ''' during a practice or regular round, set up resource levels and participant @@ -153,32 +148,36 @@ calculates new resource levels for practice or regular rounds based on the group harvest and resultant regrowth. also responsible for transferring those parameters to the next round as needed. ''' - current_round_configuration = experiment.current_round + round_data = experiment.current_round_data + current_round_configuration = round_data.round_configuration logger.debug("current round: %s", current_round_configuration) max_resource_level = MAX_RESOURCE_LEVEL - for group in experiment.group_set.all(): + for group in experiment.groups: # FIXME: simplify logic logger.debug("group %s has resource level", group) if has_resource_level(group): - current_resource_level_dv = get_resource_level_dv(group) + current_resource_level_dv = get_resource_level_dv(group, round_data) current_resource_level = current_resource_level_dv.int_value + group_harvest_dv = get_group_harvest_dv(group, round_data) + regrowth_dv = get_regrowth_dv(group, round_data) if current_round_configuration.is_playable_round: # FIXME: update this to use django queryset aggregation ala boundaries experiment total_harvest = sum( [ hd.value for hd in get_harvest_decisions(group).all() ]) logger.debug("total harvest for playable round: %d", total_harvest) if current_resource_level > 0 and total_harvest > 0: group.log("Harvest: removing %s from current resource level %s" % (total_harvest, current_resource_level)) - set_group_harvest(group, total_harvest) + group_harvest_dv.update_int(total_harvest) current_resource_level = max(current_resource_level - total_harvest, 0) # implements regrowth function inline # FIXME: parameterize regrowth rate. regrowth = current_resource_level / 10 group.log("Regrowth: adding %s to current resource level %s" % (regrowth, current_resource_level)) - set_regrowth(group, regrowth) - current_resource_level_dv.int_value = min(current_resource_level + regrowth, max_resource_level) - current_resource_level_dv.save() + regrowth_dv.update_int(regrowth) + current_resource_level_dv.update_int(min(current_resource_level + regrowth, max_resource_level)) ''' transfer resource levels across chat and quiz rounds if they exist ''' if experiment.has_next_round: ''' set group round data resource_level for each group + regrowth ''' group.log("Transferring resource level %s to next round" % current_resource_level_dv.int_value) - group.copy_to_next_round(current_resource_level_dv) +# FIXME: technically group harvest and regrowth data values should be re-initialized each round. Maybe push initialize +# data values flag into round parameter values + group.copy_to_next_round(current_resource_level_dv, group_harvest_dv, regrowth_dv) Repository URL: https://bitbucket.org/virtualcommons/vcweb/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |