Skip to content

Commit

Permalink
feat: change format of color fields in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Mar 7, 2024
1 parent a6eddfc commit 1029190
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 171 deletions.
115 changes: 8 additions & 107 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,10 @@ type DepthDependentSoilDataNode {
texture: SoilIdDepthDependentSoilDataTextureChoices
clayPercent: Int
rockFragmentVolume: SoilIdDepthDependentSoilDataRockFragmentVolumeChoices
colorHueSubstep: SoilIdDepthDependentSoilDataColorHueSubstepChoices
colorHue: SoilIdDepthDependentSoilDataColorHueChoices
colorValue: SoilIdDepthDependentSoilDataColorValueChoices
colorChroma: SoilIdDepthDependentSoilDataColorChromaChoices
colorHue: Float
colorValue: Float
colorChroma: Float
colorPhotoUsed: Boolean
colorPhotoSoilCondition: SoilIdDepthDependentSoilDataColorPhotoSoilConditionChoices
colorPhotoLightingCondition: SoilIdDepthDependentSoilDataColorPhotoLightingConditionChoices
conductivity: Decimal
Expand Down Expand Up @@ -1207,105 +1207,6 @@ enum SoilIdDepthDependentSoilDataRockFragmentVolumeChoices {
VOLUME_60
}

"""An enumeration."""
enum SoilIdDepthDependentSoilDataColorHueSubstepChoices {
"""2.5"""
SUBSTEP_2_5

"""5"""
SUBSTEP_5

"""7.5"""
SUBSTEP_7_5

"""10"""
SUBSTEP_10
}

"""An enumeration."""
enum SoilIdDepthDependentSoilDataColorHueChoices {
"""R"""
R

"""YR"""
YR

"""Y"""
Y

"""GY"""
GY

"""G"""
G

"""B"""
B

"""BG"""
BG
}

"""An enumeration."""
enum SoilIdDepthDependentSoilDataColorValueChoices {
"""2.5"""
VALUE_2_5

"""3"""
VALUE_3

"""4"""
VALUE_4

"""5"""
VALUE_5

"""6"""
VALUE_6

"""7"""
VALUE_7

"""8"""
VALUE_8

"""8.5"""
VALUE_8_5

"""9"""
VALUE_9

"""9.5"""
VALUE_9_5
}

"""An enumeration."""
enum SoilIdDepthDependentSoilDataColorChromaChoices {
"""1"""
CHROMA_1

"""2"""
CHROMA_2

"""3"""
CHROMA_3

"""4"""
CHROMA_4

"""5"""
CHROMA_5

"""6"""
CHROMA_6

"""7"""
CHROMA_7

"""8"""
CHROMA_8
}

"""An enumeration."""
enum SoilIdDepthDependentSoilDataColorPhotoSoilConditionChoices {
"""Moist"""
Expand Down Expand Up @@ -2289,10 +2190,10 @@ input DepthDependentSoilDataUpdateMutationInput {
texture: SoilIdDepthDependentSoilDataTextureChoices
clayPercent: Int
rockFragmentVolume: SoilIdDepthDependentSoilDataRockFragmentVolumeChoices
colorHueSubstep: SoilIdDepthDependentSoilDataColorHueSubstepChoices
colorHue: SoilIdDepthDependentSoilDataColorHueChoices
colorValue: SoilIdDepthDependentSoilDataColorValueChoices
colorChroma: SoilIdDepthDependentSoilDataColorChromaChoices
colorHue: Float
colorValue: Float
colorChroma: Float
colorPhotoUsed: Boolean
colorPhotoSoilCondition: SoilIdDepthDependentSoilDataColorPhotoSoilConditionChoices
colorPhotoLightingCondition: SoilIdDepthDependentSoilDataColorPhotoLightingConditionChoices
conductivity: Decimal
Expand Down
24 changes: 4 additions & 20 deletions terraso_backend/apps/soil_id/graphql/soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,6 @@ def texture_enum(cls):
def rock_fragment_volume_enum(cls):
return cls._meta.fields["rock_fragment_volume"].type()

@classmethod
def color_hue_substep_enum(cls):
return cls._meta.fields["color_hue_substep"].type()

@classmethod
def color_hue_enum(cls):
return cls._meta.fields["color_hue"].type()

@classmethod
def color_value_enum(cls):
return cls._meta.fields["color_value"].type()

@classmethod
def color_chroma_enum(cls):
return cls._meta.fields["color_chroma"].type()

@classmethod
def color_photo_soil_condition_enum(cls):
return cls._meta.fields["color_photo_soil_condition"].type()
Expand Down Expand Up @@ -397,10 +381,10 @@ class Input:
texture = DepthDependentSoilDataNode.texture_enum()
clay_percent = graphene.Int()
rock_fragment_volume = DepthDependentSoilDataNode.rock_fragment_volume_enum()
color_hue_substep = DepthDependentSoilDataNode.color_hue_substep_enum()
color_hue = DepthDependentSoilDataNode.color_hue_enum()
color_value = DepthDependentSoilDataNode.color_value_enum()
color_chroma = DepthDependentSoilDataNode.color_chroma_enum()
color_hue = graphene.Float()
color_value = graphene.Float()
color_chroma = graphene.Float()
color_photo_used = graphene.Boolean()
color_photo_soil_condition = DepthDependentSoilDataNode.color_photo_soil_condition_enum()
color_photo_lighting_condition = (
DepthDependentSoilDataNode.color_photo_lighting_condition_enum()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright © 2024 Technology Matters
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

# Generated by Django 5.0.2 on 2024-03-07 22:36

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("soil_id", "0011_alter_soildata_depth_interval_preset_and_more"),
]

operations = [
migrations.RemoveField(
model_name="depthdependentsoildata",
name="color_hue_substep",
),
migrations.RemoveField(
model_name="depthdependentsoildata",
name="color_hue",
),
migrations.RemoveField(
model_name="depthdependentsoildata",
name="color_value",
),
migrations.RemoveField(
model_name="depthdependentsoildata",
name="color_chroma",
),
migrations.AddField(
model_name="depthdependentsoildata",
name="color_photo_used",
field=models.BooleanField(blank=True, null=True),
),
migrations.AddField(
model_name="depthdependentsoildata",
name="color_chroma",
field=models.FloatField(
blank=True,
null=True,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(50),
],
),
),
migrations.AddField(
model_name="depthdependentsoildata",
name="color_hue",
field=models.FloatField(
blank=True,
null=True,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(100),
],
),
),
migrations.AddField(
model_name="depthdependentsoildata",
name="color_value",
field=models.FloatField(
blank=True,
null=True,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(10),
],
),
),
]
57 changes: 13 additions & 44 deletions terraso_backend/apps/soil_id/models/depth_dependent_soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,19 @@ class RockFragmentVolume(models.TextChoices):
blank=True, null=True, choices=RockFragmentVolume.choices
)

class ColorHueSubstep(models.TextChoices):
SUBSTEP_2_5 = "SUBSTEP_2_5", "2.5"
SUBSTEP_5 = "SUBSTEP_5", "5"
SUBSTEP_7_5 = "SUBSTEP_7_5", "7.5"
SUBSTEP_10 = "SUBSTEP_10", "10"

color_hue_substep = models.CharField(blank=True, null=True, choices=ColorHueSubstep.choices)

class ColorHue(models.TextChoices):
R = "R", "R"
YR = "YR", "YR"
Y = "Y", "Y"
GY = "GY", "GY"
G = "G", "G"
B = "B", "B"
BG = "BG", "BG"

color_hue = models.CharField(blank=True, null=True, choices=ColorHue.choices)

class ColorValue(models.TextChoices):
VALUE_2_5 = "VALUE_2_5", "2.5"
VALUE_3 = "VALUE_3", "3"
VALUE_4 = "VALUE_4", "4"
VALUE_5 = "VALUE_5", "5"
VALUE_6 = "VALUE_6", "6"
VALUE_7 = "VALUE_7", "7"
VALUE_8 = "VALUE_8", "8"
VALUE_8_5 = "VALUE_8_5", "8.5"
VALUE_9 = "VALUE_9", "9"
VALUE_9_5 = "VALUE_9_5", "9.5"

color_value = models.CharField(blank=True, null=True, choices=ColorValue.choices)

class ColorChroma(models.TextChoices):
CHROMA_1 = "CHROMA_1", "1"
CHROMA_2 = "CHROMA_2", "2"
CHROMA_3 = "CHROMA_3", "3"
CHROMA_4 = "CHROMA_4", "4"
CHROMA_5 = "CHROMA_5", "5"
CHROMA_6 = "CHROMA_6", "6"
CHROMA_7 = "CHROMA_7", "7"
CHROMA_8 = "CHROMA_8", "8"

color_chroma = models.CharField(blank=True, null=True, choices=ColorChroma.choices)
color_hue = models.FloatField(
blank=True, null=True, validators=[MinValueValidator(0), MaxValueValidator(100)]
)

color_value = models.FloatField(
blank=True, null=True, validators=[MinValueValidator(0), MaxValueValidator(10)]
)

color_chroma = models.FloatField(
blank=True, null=True, validators=[MinValueValidator(0), MaxValueValidator(50)]
)

color_photo_used = models.BooleanField(blank=True, null=True)

class ColorPhotoSoilCondition(models.TextChoices):
MOIST = "MOIST"
Expand Down

0 comments on commit 1029190

Please sign in to comment.