Add treatments information to cell debug page
This commit is contained in:
parent
782b13c6a0
commit
7b13b4b1ad
2 changed files with 70 additions and 48 deletions
63
html.go
63
html.go
|
|
@ -58,10 +58,10 @@ var (
|
|||
var components = [...]string{"header", "map"}
|
||||
|
||||
type BreedingSource struct {
|
||||
Address string
|
||||
ID string
|
||||
Type string
|
||||
LastInspected string
|
||||
LastTreated string
|
||||
LastInspected *time.Time
|
||||
LastTreated *time.Time
|
||||
}
|
||||
|
||||
type BuiltTemplate struct {
|
||||
|
|
@ -83,6 +83,7 @@ type ContentCell struct {
|
|||
BreedingSources []BreedingSource
|
||||
CellBoundary h3.CellBoundary
|
||||
MapData ComponentMap
|
||||
Treatments []Treatment
|
||||
User User
|
||||
}
|
||||
type ContentPhoneCall struct {
|
||||
|
|
@ -125,6 +126,12 @@ type ServiceRequestSummary struct {
|
|||
Location string
|
||||
Status string
|
||||
}
|
||||
type Treatment struct {
|
||||
Date time.Time
|
||||
LocationID string
|
||||
Notes string
|
||||
Product string
|
||||
}
|
||||
type User struct {
|
||||
DisplayName string
|
||||
Initials string
|
||||
|
|
@ -220,7 +227,12 @@ func htmlCell(ctx context.Context, w http.ResponseWriter, user *models.User, c i
|
|||
resolution := h3.Cell(c).Resolution()
|
||||
sources, err := breedingSourcesByCell(ctx, org, h3.Cell(c))
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get boundaries", err, http.StatusInternalServerError)
|
||||
respondError(w, "Failed to get sources", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
treatments, err := treatmentsByCell(ctx, org, h3.Cell(c))
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get treatments", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data := ContentCell{
|
||||
|
|
@ -235,7 +247,8 @@ func htmlCell(ctx context.Context, w http.ResponseWriter, user *models.User, c i
|
|||
MapboxToken: MapboxToken,
|
||||
Zoom: resolution + 5,
|
||||
},
|
||||
User: userContent,
|
||||
Treatments: treatments,
|
||||
User: userContent,
|
||||
}
|
||||
renderOrError(w, cell, &data)
|
||||
}
|
||||
|
|
@ -478,6 +491,7 @@ func makeFuncMap() template.FuncMap {
|
|||
"latLngDisplay": latLngDisplay,
|
||||
"timeElapsed": timeElapsed,
|
||||
"timeSince": timeSince,
|
||||
"uuidShort": uuidShort,
|
||||
}
|
||||
return funcMap
|
||||
}
|
||||
|
|
@ -587,6 +601,31 @@ func renderOrError(w http.ResponseWriter, template BuiltTemplate, context interf
|
|||
buf.WriteTo(w)
|
||||
}
|
||||
|
||||
func treatmentsByCell(ctx context.Context, org *models.Organization, c h3.Cell) ([]Treatment, error) {
|
||||
var results []Treatment
|
||||
boundary, err := c.Boundary()
|
||||
if err != nil {
|
||||
return results, fmt.Errorf("Failed to get cell boundary: %w", err)
|
||||
}
|
||||
geom_query := gisStatement(boundary)
|
||||
rows, err := org.FSTreatments(
|
||||
sm.Where(
|
||||
psql.F("ST_Within", "geom", geom_query),
|
||||
),
|
||||
).All(ctx, PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return results, fmt.Errorf("Failed to query rows: %w", err)
|
||||
}
|
||||
for _, r := range rows {
|
||||
results = append(results, Treatment{
|
||||
Date: *fsTimestampToTime(r.Enddatetime),
|
||||
LocationID: r.Pointlocid.GetOr("none"),
|
||||
Notes: r.Comments.GetOr("none"),
|
||||
Product: r.Product.GetOr("none"),
|
||||
})
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
func breedingSourcesByCell(ctx context.Context, org *models.Organization, c h3.Cell) ([]BreedingSource, error) {
|
||||
var results []BreedingSource
|
||||
|
||||
|
|
@ -605,11 +644,19 @@ func breedingSourcesByCell(ctx context.Context, org *models.Organization, c h3.C
|
|||
}
|
||||
for _, r := range rows {
|
||||
results = append(results, BreedingSource{
|
||||
Address: "nowhere",
|
||||
ID: r.Globalid,
|
||||
LastInspected: fsTimestampToTime(r.Lastinspectdate),
|
||||
LastTreated: fsTimestampToTime(r.Lasttreatdate),
|
||||
Type: r.Habitat.GetOr("none"),
|
||||
LastInspected: "never",
|
||||
LastTreated: "never",
|
||||
})
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func uuidShort(uuid string) string {
|
||||
if len(uuid) < 7 {
|
||||
return uuid // Return as is if too short
|
||||
}
|
||||
|
||||
return uuid[:3] + "..." + uuid[len(uuid)-4:]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<th>ID</th>
|
||||
<th>Source Type</th>
|
||||
<th>Last Inspected</th>
|
||||
<th>Last Treated</th>
|
||||
|
|
@ -83,16 +83,16 @@
|
|||
<tbody>
|
||||
{{ range .BreedingSources }}
|
||||
<tr>
|
||||
<td>{{.Address}}</td>
|
||||
<td>{{.ID|uuidShort}}</td>
|
||||
<td>{{.Type}}</td>
|
||||
<td>{{.LastInspected}}</td>
|
||||
<td>{{.LastTreated}}</td>
|
||||
<td>{{.LastInspected|timeSince}}</td>
|
||||
<td>{{.LastTreated|timeSince}}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<nav aria-label="Breeding sources pagination">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item disabled">
|
||||
|
|
@ -106,6 +106,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -169,53 +170,26 @@
|
|||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Approximate Address</th>
|
||||
<th>Location</th>
|
||||
<th>Treatment Date</th>
|
||||
<th>Insecticide Used</th>
|
||||
<th>Technician Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Treatments }}
|
||||
<tr>
|
||||
<td>123 Main St</td>
|
||||
<td>04/16/2023</td>
|
||||
<td>Bacillus thuringiensis israelensis (Bti)</td>
|
||||
<td>Applied larvicide to standing water.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>125 Main St</td>
|
||||
<td>04/16/2023</td>
|
||||
<td>Methoprene</td>
|
||||
<td>Treated catch basin with long-lasting formula.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>130 Main St</td>
|
||||
<td>04/15/2023</td>
|
||||
<td>Bacillus sphaericus</td>
|
||||
<td>Applied to drainage ditch, full coverage achieved.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>135 Main St</td>
|
||||
<td>04/14/2023</td>
|
||||
<td>Bacillus thuringiensis israelensis (Bti)</td>
|
||||
<td>Applied to small pond area.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>140 Main St</td>
|
||||
<td>04/14/2023</td>
|
||||
<td>Methoprene</td>
|
||||
<td>Applied to standing water in yard.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>145 Main St</td>
|
||||
<td>04/13/2023</td>
|
||||
<td>Bacillus sphaericus</td>
|
||||
<td>Treated problem area behind property.</td>
|
||||
<td>{{.LocationID|uuidShort}}</td>
|
||||
<td>{{.Date|timeSince}}</td>
|
||||
<td>{{.Product}}</td>
|
||||
<td>{{.Notes}}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<nav aria-label="Treatments pagination">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item disabled">
|
||||
|
|
@ -229,6 +203,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue