Skip to content

Commit

Permalink
Merge branch 'main' into review-treatment-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
pflopez authored Oct 22, 2024
2 parents a8a6884 + 948f977 commit 7638731
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 33 deletions.
18 changes: 14 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ whitenoise = "^6.7.0"
djangorestframework-types = "^0.8.0"
toml = "^0.10.2"
rio-cogeo = "^5.3.6"
django-json-widget = "^2.0.1"

[tool.poetry.group.dev.dependencies]
colorama = "^0.4.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
.overview {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;

mat-icon {
Expand All @@ -123,6 +124,7 @@
display: flex;
align-items: center;
gap: 4px;
white-space: nowrap;
color: $color-dark-gray;

&::after {
Expand Down Expand Up @@ -159,6 +161,7 @@
color: $color-standard-blue;
padding-left: 4px;
font-weight: 500;

&:active,
&:visited {
color: $color-standard-blue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
line-height: 22px;
}

.mat-icon-button {
.help.mat-icon-button {
line-height: 36px;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<mgl-map
*ngIf="mapExtent$ | async; let bounds"
(mapLoad)="mapLoaded($event)"
[style]="(baseLayerUrl$ | async) || ''"
[fitBounds]="bounds"
[fitBoundsOptions]="{ padding: 20 }"
[dragPan]="(standSelectionEnabled$ | async) === false"
[minZoom]="7"
[maxZoom]="17"
[boxZoom]="false"
[interactive]="true"
[pitchWithRotate]="false"
(sourceData)="onSourceData($event)"
(mapMouseDown)="onMapMouseDown($event)"
(mapMouseMove)="onMapMouseMove($event)"
(mapMouseUp)="onMapMouseUp()"
(mapMouseOut)="onMapMouseOut()"
(mapMouseUp)="onMapMouseUp()"
(sourceData)="onSourceData($event)"
[boxZoom]="false"
[doubleClickZoom]="(standSelectionEnabled$ | async) === false"
[dragPan]="(standSelectionEnabled$ | async) === false"
[dragRotate]="false"
[fitBoundsOptions]="{ padding: 20 }"
[fitBounds]="bounds"
[interactive]="true"
[maxZoom]="17"
[minZoom]="7"
[pitchWithRotate]="false"
[style]="(baseLayerUrl$ | async) || ''"
[transformRequest]="transformRequest">
<app-map-controls
*ngIf="showMapControls$ | async"
Expand Down
1 change: 1 addition & 0 deletions src/interface/src/styleguide/button/button.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


:host {
font-family: inherit;
box-sizing: border-box;
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
:host {
display: block;


&.small {
max-width: 140px;
}

&.medium {
max-width: 240px;
}

&.large {
max-width: 380px;
}
Expand All @@ -35,6 +38,7 @@
}

.dropdown-button {
font-family: inherit;
display: flex;
flex-direction: row;
justify-content: space-between;
Expand Down
33 changes: 32 additions & 1 deletion src/planscape/datasets/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Dict
from django.contrib import admin
from datasets.forms import DatasetAdminForm, CategoryAdminForm
from datasets.forms import DataLayerAdminForm, DatasetAdminForm, CategoryAdminForm
from datasets.models import Category, DataLayer, Dataset
from treebeard.admin import TreeAdmin
from treebeard.forms import movenodeform_factory
Expand All @@ -8,23 +9,53 @@
class CategoryAdmin(TreeAdmin):
form = CategoryAdminForm
search_fields = ["name"]
list_display = ("id", "name", "order", "dataset")

def get_changeform_initial_data(self, request) -> Dict[str, Any]:
return {"created_by": request.user}


class DatasetAdmin(admin.ModelAdmin):
list_filter = ["visibility"]
search_fields = ["organization__name__icontains", "name"]
autocomplete_fields = ["organization"]
form = DatasetAdminForm
list_display = ("id", "name", "visibility", "organization")
list_display_links = (
"id",
"name",
)

def get_changeform_initial_data(self, request) -> Dict[str, Any]:
return {"created_by": request.user}


class DataLayerAdmin(admin.ModelAdmin):
form = DataLayerAdminForm
search_fields = [
"organization__name__icontains",
"dataset__name__icontains",
"created_by__username__icontains",
"name",
]
autocomplete_fields = ["organization", "created_by", "dataset", "category"]
list_display = (
"id",
"name",
"status",
"type",
"geometry_type",
"dataset",
"category",
"organization",
)
list_display_links = (
"id",
"name",
"status",
"type",
"geometry_type",
)


admin.site.register(Dataset, DatasetAdmin)
Expand Down
43 changes: 41 additions & 2 deletions src/planscape/datasets/forms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from django import forms

from datasets.models import Category, Dataset
from datasets.models import Category, DataLayer, Dataset
from treebeard.forms import movenodeform_factory
from django_json_widget.widgets import JSONEditorWidget


class DatasetAdminForm(forms.ModelForm):
description = forms.CharField(widget=forms.Textarea, required=False)
version = forms.CharField(required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["created_by"].disabled = True

class Meta:
model = Dataset
fields = (
Expand All @@ -23,12 +28,46 @@ class Meta:
class CategoryAdminForm(movenodeform_factory(Category)):
order = forms.IntegerField(required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["created_by"].disabled = True

class Meta:
model = Category
fields = (
"organization",
"created_by",
"dataset",
"created_by",
"name",
"order",
)


class DataLayerAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["created_by"].disabled = True
self.fields["original_name"].disabled = True
self.fields["mimetype"].disabled = True
self.fields["url"].disabled = True
self.fields["geometry"].disabled = True

class Meta:
model = DataLayer
widgets = {
"info": JSONEditorWidget,
"metadata": JSONEditorWidget,
}
fields = (
"organization",
"created_by",
"dataset",
"category",
"name",
"info",
"metadata",
"original_name",
"mimetype",
"url",
"geometry",
)
1 change: 1 addition & 0 deletions src/planscape/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ def __str__(self) -> str:
return f"{self.name} [{self.type}]"

class Meta(TypedModelMeta):
ordering = ("organization", "dataset", "id")
verbose_name = "Datalayer"
verbose_name_plural = "Datalayers"
12 changes: 8 additions & 4 deletions src/planscape/gis/rasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

def get_profile(
input_profile: Dict[str, Any],
crs: str,
transform,
width: int,
height: int,
Expand All @@ -23,6 +24,7 @@ def get_profile(
) -> Dict[str, Any]:
return {
**input_profile,
"crs": crs,
"transform": transform,
"blockxsize": blockxsize,
"blockysize": blockysize,
Expand All @@ -48,7 +50,9 @@ def to_planscape(input_file: str) -> List[str]:
cog_output = get_random_output_file(input_file=warped_output)

warped_raster = warp(
input_file=input_file, output_file=warped_output, crs=f"EPSG:3857"
input_file=input_file,
output_file=warped_output,
crs="EPSG:3857",
)

cog_raster = cog(input_file=warped_raster, output_file=cog_output)
Expand Down Expand Up @@ -94,9 +98,9 @@ def warp(
output_file: str,
crs: str,
num_threads: str = "ALL_CPUS",
resampling_method=Resampling.nearest,
resampling_method: Resampling = Resampling.nearest,
) -> str:
log.info("warrrrrping")
log.info(f"Warping raster {input_file}")
with rasterio.Env(GDAL_NUM_THREADS=num_threads):
with rasterio.open(input_file) as source:
left, bottom, right, top = source.bounds
Expand All @@ -110,9 +114,9 @@ def warp(
right=right,
top=top,
)

output_profile = get_profile(
input_profile=source.meta,
crs=crs,
transform=transform,
width=width, # type: ignore
height=height, # type: ignore
Expand Down
20 changes: 20 additions & 0 deletions src/planscape/impacts/migrations/0007_treatmentresult_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("impacts", "0006_alter_treatmentresult_variable"),
]

operations = [
migrations.AddField(
model_name="treatmentresult",
name="type",
field=models.CharField(
choices=[("DIRECT", "Direct"), ("INDIRECT", "Indirect")],
default="DIRECT",
help_text="Type of Treatment Result (choice).",
null=True,
),
),
]
11 changes: 11 additions & 0 deletions src/planscape/impacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ def get_impact_raster_path(
return f"s3://{settings.S3_BUCKET}/rasters/impacts/{treatment_name}_{year}_{variable}_3857_COG.tif"


class TreatmentResultType(models.TextChoices):
DIRECT = "DIRECT", "Direct"
INDIRECT = "INDIRECT", "Indirect"


class TreatmentResult(CreatedAtMixin, DeletedAtMixin, models.Model):
treatment_plan = models.ForeignKey(
TreatmentPlan,
Expand Down Expand Up @@ -385,6 +390,12 @@ class TreatmentResult(CreatedAtMixin, DeletedAtMixin, models.Model):
help_text="Delta between this years value and base year value. From 0-1, null for base years.",
null=True,
)
type = models.CharField(
choices=TreatmentResultType.choices,
default=TreatmentResultType.DIRECT,
help_text="Type of Treatment Result (choice).",
null=True,
)

class Meta(TypedModelMeta):
constraints = [
Expand Down
Loading

0 comments on commit 7638731

Please sign in to comment.