Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix data for PSQL transfer #1747

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion game/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AttemptAdmin(admin.ModelAdmin):

class LevelDecorAdmin(admin.ModelAdmin):
search_fields = ["level__name"]
list_display = ["id", "level", "x", "y", "decorName"]
list_display = ["id", "level", "x", "y", "decor_name"]


admin.site.register(Level, LevelAdmin)
Expand Down
4 changes: 2 additions & 2 deletions game/end_to_end_tests/test_cow_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setUpClass(cls):
TestCowCrashes.cow_level = Level(
name="Cow crashing",
anonymous=False,
blocklyEnabled=True,
blockly_enabled=True,
character=van,
cows='[{"minCows":"7","maxCows":"7","potentialCoordinates":[{"x":4,"y":4},{"x":2,"y":4},{"x":3,"y":7},{"x":4,"y":6},{"x":2,"y":6},{"x":3,"y":1},{"x":4,"y":2}],"type":"WHITE"}]',
default=False,
Expand All @@ -57,7 +57,7 @@ def setUpClass(cls):
model_solution="[1]",
origin='{"coordinate":[2,5],"direction":"E"}',
path='[{"coordinate":[2,5],"connectedNodes":[1]},{"coordinate":[3,5],"connectedNodes":[0,4,2,5]},{"coordinate":[4,5],"connectedNodes":[1]},{"coordinate":[3,7],"connectedNodes":[4]},{"coordinate":[3,6],"connectedNodes":[8,3,6,1]},{"coordinate":[3,4],"connectedNodes":[10,1,11,16]},{"coordinate":[4,6],"connectedNodes":[4,7]},{"coordinate":[4,7],"connectedNodes":[6]},{"coordinate":[2,6],"connectedNodes":[9,4]},{"coordinate":[2,7],"connectedNodes":[8]},{"coordinate":[2,4],"connectedNodes":[13,5,12]},{"coordinate":[4,4],"connectedNodes":[5,14,15]},{"coordinate":[2,3],"connectedNodes":[10]},{"coordinate":[1,4],"connectedNodes":[10]},{"coordinate":[5,4],"connectedNodes":[11]},{"coordinate":[4,3],"connectedNodes":[11,19]},{"coordinate":[3,3],"connectedNodes":[5,17]},{"coordinate":[3,2],"connectedNodes":[18,16,19,20]},{"coordinate":[2,2],"connectedNodes":[17]},{"coordinate":[4,2],"connectedNodes":[17,15,23,22]},{"coordinate":[3,1],"connectedNodes":[21,17,22]},{"coordinate":[2,1],"connectedNodes":[20]},{"coordinate":[4,1],"connectedNodes":[20,19]},{"coordinate":[5,2],"connectedNodes":[19]}]',
pythonEnabled=False,
python_enabled=False,
theme=grass,
threads=1,
traffic_lights="[]",
Expand Down
4 changes: 2 additions & 2 deletions game/end_to_end_tests/test_python_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_animal_sound_horn(self):
animal_level = Level(
name="Animal commands",
anonymous=False,
blocklyEnabled=False,
blockly_enabled=False,
character=van,
cows='[{"minCows":1,"maxCows":1,"potentialCoordinates":[{"x":3,"y":4}],"type":"WHITE"}]',
default=False,
Expand All @@ -55,7 +55,7 @@ def test_animal_sound_horn(self):
model_solution="",
origin='{"coordinate":[2,4],"direction":"E"}',
path='[{"coordinate":[2,4],"connectedNodes":[1]},{"coordinate":[3,4],"connectedNodes":[0,2]},{"coordinate":[4,4],"connectedNodes":[1]}]',
pythonEnabled=True,
python_enabled=True,
theme=grass,
threads=1,
traffic_lights="[]",
Expand Down
12 changes: 6 additions & 6 deletions game/level_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def get_decor(level):
"""Helper method parsing decor into a dictionary format 'sendable' to javascript."""
decorData = []
for ld in LevelDecor.objects.filter(level=level):
decor = get_decor_element(name=ld.decorName, theme=level.theme)
decor = get_decor_element(name=ld.decor_name, theme=level.theme)
decorData.append(
{
"x": int(ld.x),
"y": int(ld.y),
"z": int(decor.z_index),
"decorName": str(ld.decorName),
"decorName": str(ld.decor_name),
"width": int(decor.width),
"height": int(decor.height),
"url": str(decor.url),
Expand All @@ -81,7 +81,7 @@ def set_decor_inner(level, decor, LevelDecor):
for data in decor:
level_decors.append(
LevelDecor(
level_id=level.id, x=data["x"], y=data["y"], decorName=data["decorName"]
level_id=level.id, x=data["x"], y=data["y"], decor_name=data["decor_name"]
)
)
LevelDecor.objects.bulk_create(level_decors)
Expand Down Expand Up @@ -160,9 +160,9 @@ def save_level(level, data):
level.max_fuel = data["max_fuel"]
level.traffic_lights = data["traffic_lights"]
level.cows = data["cows"]
level.blocklyEnabled = data.get("blocklyEnabled", True)
level.pythonEnabled = data.get("pythonEnabled", False)
level.pythonViewEnabled = data.get("pythonViewEnabled", False)
level.blockly_enabled = data.get("blockly_enabled", True)
level.python_enabled = data.get("python_enabled", False)
level.python_view_enabled = data.get("python_view_enabled", False)
level.theme = get_theme_by_pk(pk=data["theme"])
level.character = get_character_by_pk(pk=data["character"])
level.disable_algorithm_score = data.get("disable_algorithm_score", False)
Expand Down
18 changes: 18 additions & 0 deletions game/migrations/0105_delete_invalid_attempts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.apps.registry import Apps
from django.db import migrations


def delete_invalid_attempts(apps: Apps, *args):
Attempt = apps.get_model("game", "Attempt")

Attempt.objects.filter(start_time__isnull=True).delete()


class Migration(migrations.Migration):
dependencies = [("game", "0104_remove_level_direct_drive")]
operations = [
migrations.RunPython(
delete_invalid_attempts,
reverse_code=migrations.RunPython.noop,
)
]
48 changes: 48 additions & 0 deletions game/migrations/0106_fields_to_snake_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 3.2.25 on 2024-11-01 13:12

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('game', '0105_delete_invalid_attempts'),
]

operations = [
migrations.RenameField(
model_name='episode',
old_name='r_blocklyEnabled',
new_name='r_blockly_enabled',
),
migrations.RenameField(
model_name='episode',
old_name='r_pythonEnabled',
new_name='r_python_enabled',
),
migrations.RenameField(
model_name='episode',
old_name='r_trafficLights',
new_name='r_traffic_lights',
),
migrations.RenameField(
model_name='level',
old_name='blocklyEnabled',
new_name='blockly_enabled',
),
migrations.RenameField(
model_name='level',
old_name='pythonEnabled',
new_name='python_enabled',
),
migrations.RenameField(
model_name='level',
old_name='pythonViewEnabled',
new_name='python_view_enabled',
),
migrations.RenameField(
model_name='leveldecor',
old_name='decorName',
new_name='decor_name',
),
]
14 changes: 7 additions & 7 deletions game/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Episode(models.Model):
r_curviness = models.FloatField(default=0, null=True)
r_num_tiles = models.IntegerField(default=5, null=True)
r_blocks = models.ManyToManyField(Block, related_name="episodes")
r_blocklyEnabled = models.BooleanField(default=True)
r_pythonEnabled = models.BooleanField(default=False)
r_trafficLights = models.BooleanField(default=False)
r_blockly_enabled = models.BooleanField(default=True)
r_python_enabled = models.BooleanField(default=False)
r_traffic_lights = models.BooleanField(default=False)
r_cows = models.BooleanField(default=False)

lesson_plan_link = models.CharField(
Expand Down Expand Up @@ -175,9 +175,9 @@ class Level(models.Model):
disable_route_score = models.BooleanField(default=False)
disable_algorithm_score = models.BooleanField(default=False)
threads = models.IntegerField(blank=False, default=1)
blocklyEnabled = models.BooleanField(default=True)
pythonEnabled = models.BooleanField(default=True)
pythonViewEnabled = models.BooleanField(default=False)
blockly_enabled = models.BooleanField(default=True)
python_enabled = models.BooleanField(default=True)
python_view_enabled = models.BooleanField(default=False)
theme_name = models.CharField(
max_length=10,
choices=theme_choices(),
Expand Down Expand Up @@ -286,7 +286,7 @@ class LevelDecor(models.Model):
x = models.IntegerField()
y = models.IntegerField()
level = models.ForeignKey(Level, on_delete=models.CASCADE)
decorName = models.CharField(max_length=100, default="tree1")
decor_name = models.CharField(max_length=100, default="tree1")


class Workspace(models.Model):
Expand Down
18 changes: 9 additions & 9 deletions game/random_road.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create(episode=None):
loopiness = episode.r_loopiness if episode else DEFAULT_LOOPINESS
curviness = episode.r_curviness if episode else DEFAULT_CURVINESS
blocks = episode.r_blocks.all() if episode else Block.objects.all()
traffic_lights = episode.r_trafficLights if episode else DEFAULT_TRAFFIC_LIGHTS
traffic_lights = episode.r_traffic_lights if episode else DEFAULT_TRAFFIC_LIGHTS
cows = episode.r_cows if episode else DEFAULT_TRAFFIC_LIGHTS
decor = DEFAULT_DECOR

Expand All @@ -68,8 +68,8 @@ def create(episode=None):
level_data["theme"] = 1
level_data["name"] = ("Random level for " + episode.name) if episode else "Default random level"
level_data["character"] = 1
level_data["blocklyEnabled"] = episode.r_blocklyEnabled if episode else True
level_data["pythonEnabled"] = episode.r_pythonEnabled if episode else False
level_data["blockly_enabled"] = episode.r_blockly_enabled if episode else True
level_data["python_enabled"] = episode.r_python_enabled if episode else False
level_data["blocks"] = [{"type": block.type} for block in blocks]

level = Level(default=False, anonymous=True)
Expand Down Expand Up @@ -276,7 +276,7 @@ def generate_traffic_lights(path):
random.shuffle(candidateNodes)
nodesSelected = candidateNodes[:numberOfJunctions]

trafficLights = []
traffic_lights = []
for node in nodesSelected:

controlledNeighbours = []
Expand All @@ -291,7 +291,7 @@ def generate_traffic_lights(path):

direction = get_direction(node, neighbour)

trafficLights.append(
traffic_lights.append(
{
"sourceCoordinate": {"x": neighbour["coordinate"].x, "y": neighbour["coordinate"].y},
"direction": direction,
Expand All @@ -303,7 +303,7 @@ def generate_traffic_lights(path):
)
counter += 1

return trafficLights
return traffic_lights


def generate_cows(path):
Expand Down Expand Up @@ -346,7 +346,7 @@ def find_decor_by_coordinate(x, y, elem, decor):
elem == "pond"
and (coord["x"] // GRID_SIZE == x + 1 and coord["y"] // GRID_SIZE == y or x + 1 < WIDTH)
)
or (dec["decorName"] == "pond" and coord["x"] // GRID_SIZE + 1 == x and coord["y"] // GRID_SIZE == y)
or (dec["decor_name"] == "pond" and coord["x"] // GRID_SIZE + 1 == x and coord["y"] // GRID_SIZE == y)
):
return True

Expand All @@ -368,7 +368,7 @@ def append_decor(decor, x, y, dec, dx=0, dy=0):
x = x * GRID_SIZE + int((GRID_SIZE - decor_object.width) * 0.5 * (1 - dx))
y = y * GRID_SIZE + int((GRID_SIZE - decor_object.height) * 0.5 * (1 - dy))

decor.append({"coordinate": {"x": x, "y": y}, "decorName": dec, "height": decor_object.height})
decor.append({"coordinate": {"x": x, "y": y}, "decor_name": dec, "height": decor_object.height})

def place_near_road(elem, decor, path):
for i in range(1, len(path) - 1):
Expand All @@ -389,7 +389,7 @@ def place_randomly(dec, decor):
def place_bush(elem, decor, nodes):
bush_exists = False
for dec in decor:
if dec["decorName"] == elem:
if dec["decor_name"] == elem:
bush_exists = True
for (dx, dy) in DIRECTIONS:
x = dec["coordinate"]["x"] // GRID_SIZE + dx
Expand Down
12 changes: 6 additions & 6 deletions game/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Meta(object):
"name",
"title",
"default",
"blocklyEnabled",
"pythonEnabled",
"blockly_enabled",
"python_enabled",
)

def get_title(self, obj):
Expand Down Expand Up @@ -67,9 +67,9 @@ class Meta(object):
"levelblock_set",
"map",
"mode",
"blocklyEnabled",
"pythonEnabled",
"pythonViewEnabled",
"blockly_enabled",
"python_enabled",
"python_view_enabled",
)

def get_title(self, obj):
Expand Down Expand Up @@ -101,7 +101,7 @@ def get_leveldecor_set(self, obj):
class LevelModeSerializer(serializers.HyperlinkedModelSerializer):
class Meta(object):
model = Level
fields = ("blocklyEnabled", "pythonEnabled", "pythonViewEnabled")
fields = ("blockly_enabled", "python_enabled", "python_view_enabled")


class LevelMapListSerializer(serializers.HyperlinkedModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ ocargo.Game.prototype._setupSaveTab = function () {
python_contents: ocargo.pythonControl.getCode(),
blockly_enabled: BLOCKLY_ENABLED,
python_enabled: PYTHON_ENABLED,
pythonViewEnabled: PYTHON_VIEW_ENABLED
python_view_enabled: PYTHON_VIEW_ENABLED
}

this.saving.saveWorkspace(
Expand Down
14 changes: 7 additions & 7 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2540,9 +2540,9 @@ ocargo.LevelEditor = function(levelId) {

// Language data
var language = $('#language_select').val();
state.blocklyEnabled = language === 'blockly' || language === 'both' || language === 'blocklyWithPythonView';
state.pythonViewEnabled = language === 'blocklyWithPythonView';
state.pythonEnabled = language === 'python' || language === 'both';
state.blockly_enabled = language === 'blockly' || language === 'both' || language === 'blocklyWithPythonView';
state.python_view_enabled = language === 'blocklyWithPythonView';
state.python_enabled = language === 'python' || language === 'both';

// Description and hint data
if ($('#subtitle').val().length > 0) {
Expand Down Expand Up @@ -2675,11 +2675,11 @@ ocargo.LevelEditor = function(levelId) {

// Load in language data
var languageSelect = $('#language_select');
if (state.blocklyEnabled && state.pythonViewEnabled){
if (state.blockly_enabled && state.python_view_enabled){
languageSelect.val('blocklyWithPythonView');
} else if(state.blocklyEnabled && state.pythonEnabled) {
} else if(state.blockly_enabled && state.python_enabled) {
languageSelect.val('both');
} else if(state.pythonEnabled) {
} else if(state.python_enabled) {
languageSelect.val('python');
} else {
languageSelect.val('blockly');
Expand Down Expand Up @@ -2869,7 +2869,7 @@ ocargo.LevelEditor = function(levelId) {
// you can copy and paste into a Django migration file
var state = extractState();

var boolFields = ["pythonEnabled", "blocklyEnabled", 'fuel_gauge'];
var boolFields = ["python_enabled", "blockly_enabled", 'fuel_gauge'];
var stringFields = ['path', 'traffic_lights', 'cows', 'origin', 'destinations'];
var otherFields = ['max_fuel'];

Expand Down
Loading
Loading