Skip to content

Commit

Permalink
Migrate cobb-douglas hardcoded values to newer "a" variables
Browse files Browse the repository at this point in the history
Issue #3368

Moving forward, it seems all graphs contain a set of fields which all make
use of the following properties:
* Value
* Name (optional)
* Min/Max (optional)
* Alternate value (optional)

We can encapsulate this into an abstraction called a graph "Field".
It's still to be determined what this will actually look like on the
back-end, I am just trying to understand things conceptually.
  • Loading branch information
nikolas committed Jul 29, 2024
1 parent 9aaec38 commit 9e17f07
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 149 deletions.
18 changes: 18 additions & 0 deletions econplayground/main/migrations/0116_graph_a5_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.14 on 2024-07-29 14:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('main', '0115_graph_a1_2_graph_a1_max_2_graph_a1_min_2_graph_a2_2_and_more'),
]

operations = [
migrations.AddField(
model_name='graph',
name='a5_name',
field=models.TextField(blank=True, default=''),
),
]
30 changes: 30 additions & 0 deletions econplayground/main/migrations/0117_auto_20240729_1001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.14 on 2024-07-29 14:01

from django.db import migrations


def migrate_cobb_douglas_fields(apps, schema_editor):
Graph = apps.get_model("main", "Graph")
for graph in Graph.objects.filter(graph_type=3):
# Cobb-Douglas
graph.a1 = graph.cobb_douglas_a
graph.a1_name = graph.cobb_douglas_a_name
graph.a2 = graph.cobb_douglas_l
graph.a2_name = graph.cobb_douglas_l_name
graph.a3 = graph.cobb_douglas_k
graph.a3_name = graph.cobb_douglas_k_name
graph.a4 = graph.cobb_douglas_alpha
graph.a4_name = graph.cobb_douglas_alpha_name
graph.a5_name = graph.cobb_douglas_y_name
graph.save()


class Migration(migrations.Migration):

dependencies = [
('main', '0116_graph_a5_name'),
]

operations = [
migrations.RunPython(migrate_cobb_douglas_fields),
]
56 changes: 35 additions & 21 deletions econplayground/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,56 +296,70 @@ class Meta(OrderedModel.Meta):
# more typical float type, for fixed precision:
# https://docs.python.org/3/library/decimal.html#module-decimal
#
# A1
a1 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a1_max = models.IntegerField(default=10)
a1_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a1_name = models.TextField(default='', blank=True,)
# Alternate value for a1
a1_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a1_max_2 = models.IntegerField(default=10)
a1_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))

# A2
a2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a2_max = models.IntegerField(default=10)
a2_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
# Alternate value for a2
a2_name = models.TextField(default='', blank=True)
a2_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a2_max_2 = models.IntegerField(default=10)
a2_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))

# A3
a3 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a3_max = models.IntegerField(default=10)
a3_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a3_name = models.TextField(default='', blank=True)
# Alternate value for a3
a3_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a3_max_2 = models.IntegerField(default=10)
a3_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))

# A4
a4 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a4_max = models.IntegerField(default=10)
a4_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a4_name = models.TextField(default='', blank=True)
a5 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a5_max = models.IntegerField(default=10)
a5_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))

a1_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a1_max_2 = models.IntegerField(default=10)
a1_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a2_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a2_max_2 = models.IntegerField(default=10)
a2_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a3_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a3_max_2 = models.IntegerField(default=10)
a3_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
# Alternate value for a4
a4_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a4_max_2 = models.IntegerField(default=10)
a4_min_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))

# A5
a5 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a5_max = models.IntegerField(default=10)
a5_min = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a5_name = models.TextField(default='', blank=True)
# Alternate value for a5
a5_2 = models.DecimalField(
max_digits=12, decimal_places=4, default=Decimal('0'))
a5_max_2 = models.IntegerField(default=10)
Expand Down
36 changes: 22 additions & 14 deletions media/js/src/GraphEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,33 +435,41 @@ GraphEditor.propTypes = {
gAlpha: PropTypes.number,

gA1: PropTypes.number,
gA1Name: PropTypes.string,
gA1Max: PropTypes.number,
gA1Min: PropTypes.number,
gA2: PropTypes.number,
gA2Max: PropTypes.number,
gA2Min: PropTypes.number,
gA3: PropTypes.number,
gA3Max: PropTypes.number,
gA3Min: PropTypes.number,
gA4: PropTypes.number,
gA4Max: PropTypes.number,
gA4Min: PropTypes.number,
gA5: PropTypes.number,
gA5Max: PropTypes.number,
gA5Min: PropTypes.number,

gA12: PropTypes.number,
gA1Max2: PropTypes.number,
gA1Min2: PropTypes.number,

gA2: PropTypes.number,
gA2Name: PropTypes.string,
gA2Max: PropTypes.number,
gA2Min: PropTypes.number,
gA22: PropTypes.number,
gA2Max2: PropTypes.number,
gA2Min2: PropTypes.number,

gA3: PropTypes.number,
gA3Name: PropTypes.string,
gA3Max: PropTypes.number,
gA3Min: PropTypes.number,
gA32: PropTypes.number,
gA3Max2: PropTypes.number,
gA3Min2: PropTypes.number,

gA4: PropTypes.number,
gA4Name: PropTypes.string,
gA4Max: PropTypes.number,
gA4Min: PropTypes.number,
gA42: PropTypes.number,
gA4Max2: PropTypes.number,
gA4Min2: PropTypes.number,

gA5: PropTypes.number,
gA5Name: PropTypes.string,
gA5Max: PropTypes.number,
gA5Min: PropTypes.number,
gA52: PropTypes.number,
gA5Max2: PropTypes.number,
gA5Min2: PropTypes.number,
Expand Down Expand Up @@ -494,7 +502,7 @@ GraphEditor.propTypes = {
gXAxisMin: PropTypes.number,
gYAxisMax: PropTypes.number,
gYAxisMin: PropTypes.number,

gXAxisMax2: PropTypes.number,
gXAxisMin2: PropTypes.number,
gYAxisMax2: PropTypes.number,
Expand Down
Loading

0 comments on commit 9e17f07

Please sign in to comment.