set up the table for supported grains

This commit is contained in:
csawatzky 2025-12-31 15:29:57 -06:00
parent 586c971795
commit cd283a0ea1
2 changed files with 100 additions and 46 deletions

View file

@ -14,11 +14,12 @@ import WheatImg from "assets/grain/wheat.jpg";
import { Option } from "common/SearchSelect"; import { Option } from "common/SearchSelect";
import { cloneDeep } from "lodash"; import { cloneDeep } from "lodash";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { Equation } from "./GrainMoisture";
export interface GrainExtension { export interface GrainExtension {
name: string; name: string;
group: string; group: string;
equation: pond.MoistureEquation; equation: Equation;
a: number; a: number;
b: number; b: number;
c: number; c: number;
@ -36,7 +37,7 @@ const defaultSetTemp = 30.0;
const defaultGrain: GrainExtension = { const defaultGrain: GrainExtension = {
name: "None", name: "None",
group: "", group: "",
equation: pond.MoistureEquation.MOISTURE_EQUATION_NONE, equation: Equation.none,
a: 0, a: 0,
b: 0, b: 0,
c: 0, c: 0,
@ -55,7 +56,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Custom Type", name: "Custom Type",
group: "", group: "",
equation: pond.MoistureEquation.MOISTURE_EQUATION_NONE, equation: Equation.none,
a: 0, a: 0,
b: 0, b: 0,
c: 0, c: 0,
@ -71,7 +72,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Barley", name: "Barley",
group: "Barley", group: "Barley",
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST, equation: Equation.chungPfost,
a: 475.12, a: 475.12,
b: 0.14843, b: 0.14843,
c: 71.996, c: 71.996,
@ -88,7 +89,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Buckwheat", name: "Buckwheat",
group: "Buckwheat", group: "Buckwheat",
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST, equation: Equation.chungPfost,
a: 103540000, a: 103540000,
b: 0.1646, b: 0.1646,
c: 15853000, c: 15853000,
@ -105,7 +106,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Canola", name: "Canola",
group: "Canola", group: "Canola",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 3.489, a: 3.489,
b: -0.010553, b: -0.010553,
c: 1.86, c: 1.86,
@ -123,7 +124,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Rapeseed", name: "Rapeseed",
group: "Canola", group: "Canola",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 3.0026, a: 3.0026,
b: -0.0048967, b: -0.0048967,
c: 1.7607, c: 1.7607,
@ -140,7 +141,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Corn (Henderson)", name: "Corn (Henderson)",
group: "Corn", group: "Corn",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000066612, a: 0.000066612,
b: 1.9677, b: 1.9677,
c: 42.143, c: 42.143,
@ -157,7 +158,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Corn (Chung-Pfost)", name: "Corn (Chung-Pfost)",
group: "Corn", group: "Corn",
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST, equation: Equation.chungPfost,
a: 374.34, a: 374.34,
b: 0.18662, b: 0.18662,
c: 31.696, c: 31.696,
@ -174,7 +175,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Corn (Oswin)", name: "Corn (Oswin)",
group: "Corn", group: "Corn",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 15.303, a: 15.303,
b: -0.10164, b: -0.10164,
c: 3.0358, c: 3.0358,
@ -191,7 +192,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Maize White", name: "Maize White",
group: "Corn", group: "Corn",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000066612, a: 0.000066612,
b: 1.9677, b: 1.9677,
c: 70.143, c: 70.143,
@ -208,7 +209,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Maize Yellow", name: "Maize Yellow",
group: "Corn", group: "Corn",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000066612, a: 0.000066612,
b: 1.9677, b: 1.9677,
c: 65.143, c: 65.143,
@ -225,7 +226,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Oats (Henderson)", name: "Oats (Henderson)",
group: "Oats", group: "Oats",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000085511, a: 0.000085511,
b: 2.0087, b: 2.0087,
c: 37.811, c: 37.811,
@ -242,7 +243,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Oats (Chung-Pfost)", name: "Oats (Chung-Pfost)",
group: "Oats", group: "Oats",
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST, equation: Equation.chungPfost,
a: 442.85, a: 442.85,
b: 0.21228, b: 0.21228,
c: 35.803, c: 35.803,
@ -259,7 +260,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Oats (Oswin)", name: "Oats (Oswin)",
group: "Oats", group: "Oats",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 12.412, a: 12.412,
b: -0.060707, b: -0.060707,
c: 2.9397, c: 2.9397,
@ -276,7 +277,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Peanuts", name: "Peanuts",
group: "Peanuts", group: "Peanuts",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 8.6588, a: 8.6588,
b: -0.057904, b: -0.057904,
c: 2.6204, c: 2.6204,
@ -293,7 +294,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Long Grain Rice", name: "Long Grain Rice",
group: "Rice", group: "Rice",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000041276, a: 0.000041276,
b: 2.1191, b: 2.1191,
c: 49.828, c: 49.828,
@ -310,7 +311,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Medium Grain Rice", name: "Medium Grain Rice",
group: "Rice", group: "Rice",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000035502, a: 0.000035502,
b: 2.31, b: 2.31,
c: 27.396, c: 27.396,
@ -327,7 +328,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Short Grain Rice", name: "Short Grain Rice",
group: "Rice", group: "Rice",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.000048524, a: 0.000048524,
b: 2.0794, b: 2.0794,
c: 45.646, c: 45.646,
@ -344,7 +345,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Sorghum", name: "Sorghum",
group: "Sorghum", group: "Sorghum",
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST, equation: Equation.chungPfost,
a: 797.33, a: 797.33,
b: 0.18159, b: 0.18159,
c: 52.238, c: 52.238,
@ -361,8 +362,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Soybeans", name: "Soybeans",
group: "Soybeans", group: "Soybeans",
//equation: Equation.chungPfost, equation: Equation.chungPfost,
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST,
a: 228.2, a: 228.2,
b: 0.2072, b: 0.2072,
c: 30, c: 30,
@ -379,7 +379,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Sunflower", name: "Sunflower",
group: "Sunflower", group: "Sunflower",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.00031, a: 0.00031,
b: 1.7459, b: 1.7459,
c: 66.603, c: 66.603,
@ -396,7 +396,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Durum Wheat", name: "Durum Wheat",
group: "Wheat", group: "Wheat",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 13.101, a: 13.101,
b: -0.052626, b: -0.052626,
c: 2.9987, c: 2.9987,
@ -413,8 +413,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Hard Red Wheat", name: "Hard Red Wheat",
group: "Wheat", group: "Wheat",
//equation: Equation.chungPfost, equation: Equation.chungPfost,
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST,
a: 610.34, a: 610.34,
b: 0.15526, b: 0.15526,
c: 93.213, c: 93.213,
@ -431,8 +430,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Wheat SAWOS", name: "Wheat SAWOS",
group: "Wheat", group: "Wheat",
//equation: Equation.chungPfost, equation: Equation.chungPfost,
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST,
a: 610.34, a: 610.34,
b: 0.15526, b: 0.15526,
c: 93.213, c: 93.213,
@ -449,7 +447,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Un-retted Flax", name: "Un-retted Flax",
group: "Flax", group: "Flax",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 5.11, a: 5.11,
b: Math.pow(-8.46 * 10, -3), b: Math.pow(-8.46 * 10, -3),
c: 2.26, c: 2.26,
@ -466,7 +464,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Dew-retted Flax", name: "Dew-retted Flax",
group: "Flax", group: "Flax",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 6.5, a: 6.5,
b: Math.pow(-1.68 * 10, -2), b: Math.pow(-1.68 * 10, -2),
c: 3.2, c: 3.2,
@ -483,7 +481,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Yellow Peas", name: "Yellow Peas",
group: "Peas", group: "Peas",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 14.81, a: 14.81,
b: -0.109, b: -0.109,
c: 3.019, c: 3.019,
@ -500,7 +498,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Blaze Lentils", name: "Blaze Lentils",
group: "Lentils", group: "Lentils",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 5.39, a: 5.39,
b: -0.015, b: -0.015,
c: 2.273, c: 2.273,
@ -517,7 +515,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Redberry Lentils", name: "Redberry Lentils",
group: "Lentils", group: "Lentils",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 4.749, a: 4.749,
b: -0.0116, b: -0.0116,
c: 2.066, c: 2.066,
@ -534,7 +532,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Robin Lentils", name: "Robin Lentils",
group: "Lentils", group: "Lentils",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 5.176, a: 5.176,
b: -0.0065, b: -0.0065,
c: 2.337, c: 2.337,
@ -551,7 +549,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Dry Beans Red", name: "Dry Beans Red",
group: "Dry Beans", group: "Dry Beans",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 4.2669, a: 4.2669,
b: -0.013382, b: -0.013382,
c: 1.6933, c: 1.6933,
@ -566,7 +564,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Dry Beans Black", name: "Dry Beans Black",
group: "Dry Beans", group: "Dry Beans",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 5.2003, a: 5.2003,
b: -0.022685, b: -0.022685,
c: 1.9656, c: 1.9656,
@ -581,7 +579,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Rye (Henderson)", name: "Rye (Henderson)",
group: "Rye", group: "Rye",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HENDERSON, equation: Equation.henderson,
a: 0.00006343, a: 0.00006343,
b: 2.2060, b: 2.2060,
c: 13.1810, c: 13.1810,
@ -596,8 +594,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Rye (Chung-Pfost)", name: "Rye (Chung-Pfost)",
group: "Rye", group: "Rye",
//equation: Equation.chungPfost, equation: Equation.chungPfost,
equation: pond.MoistureEquation.MOISTURE_EQUATION_CHUNG_PFOST,
a: 461.0230, a: 461.0230,
b: 0.1840, b: 0.1840,
c: 36.7410, c: 36.7410,
@ -612,7 +609,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Rye (Halsey)", name: "Rye (Halsey)",
group: "Rye", group: "Rye",
equation: pond.MoistureEquation.MOISTURE_EQUATION_HALSEY, equation: Equation.halsey,
a: 4.2970, a: 4.2970,
b: 0.380, b: 0.380,
c: 2.2710, c: 2.2710,
@ -627,7 +624,7 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
{ {
name: "Rye (Oswin)", name: "Rye (Oswin)",
group: "Rye", group: "Rye",
equation: pond.MoistureEquation.MOISTURE_EQUATION_OSWIN, equation: Equation.oswin,
a: 11.8870, a: 11.8870,
b: 0.0210, b: 0.0210,
c: 3.2620, c: 3.2620,
@ -644,6 +641,16 @@ export function GetGrainExtensionMap(): Map<pond.Grain, GrainExtension> {
return cloneDeep(GrainExtensions); return cloneDeep(GrainExtensions);
} }
export function GetValidGrainExtensions(): GrainExtension[] {
let validGrains: GrainExtension[] = []
GrainExtensions.forEach((ext, key) => {
if(key !== pond.Grain.GRAIN_NONE && key !== pond.Grain.GRAIN_INVALID && key !== pond.Grain.GRAIN_CUSTOM){
validGrains.push(ext)
}
})
return validGrains
}
export default function GrainDescriber(type: pond.Grain): GrainExtension { export default function GrainDescriber(type: pond.Grain): GrainExtension {
let describer = GrainExtensions.get(type); let describer = GrainExtensions.get(type);
//console.log(describer) //console.log(describer)

View file

@ -7,7 +7,7 @@ import ButtonGroup from "common/ButtonGroup";
import { useMobile, useSnackbar, useUserAPI } from "hooks"; import { useMobile, useSnackbar, useUserAPI } from "hooks";
import { useGrainAPI } from "providers/pond/grainAPI"; import { useGrainAPI } from "providers/pond/grainAPI";
import ResponsiveTable from "common/ResponsiveTable"; import ResponsiveTable from "common/ResponsiveTable";
import { GrainExtension } from "grain"; import { GetGrainExtensionMap, GetValidGrainExtensions, GrainExtension } from "grain";
import ResponsiveDialog from "common/ResponsiveDialog"; import ResponsiveDialog from "common/ResponsiveDialog";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
import { Scope } from "models"; import { Scope } from "models";
@ -42,16 +42,33 @@ export default function Grains() {
},[tableSize, tablePage]) },[tableSize, tablePage])
useEffect(() => { useEffect(() => {
//load the custom grains
if(displayCustom){ if(displayCustom){
loadCustomGrain() loadCustomGrain()
}else{
let displayedGrains: GrainExtension[] = []
let offset = tablePage * tableSize
let limit = tableSize
let grainList = GetValidGrainExtensions()
let sortedGrain = grainList.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
sortedGrain.forEach((ext, i) => {
if(i >= offset && displayedGrains.length < limit){
displayedGrains.push(ext)
} }
//if the user is viewing as a team get their permissions to the team, if they are not then we will get their permission to the grain typ individually when a type is selected })
setSupportedGrainTableData(displayedGrains)
setTableTotal(sortedGrain.length)
}
},[loadCustomGrain, tableSize, tablePage, displayCustom, as])
useEffect(()=>{
//if the user is viewing as a team get their permissions to the team, if they are not then we will get their permission to the grain type individually when a type is selected
if(as){ if(as){
userAPI.getUser(user.id(), { key: as, kind: "team" } as Scope).then(resp => { userAPI.getUser(user.id(), { key: as, kind: "team" } as Scope).then(resp => {
setPermissions(resp.permissions); setPermissions(resp.permissions);
}); });
} }
},[loadCustomGrain, tableSize, tablePage, displayCustom, as]) },[as, userAPI])
const equationName = (enumVal: number) => { const equationName = (enumVal: number) => {
switch(enumVal){ switch(enumVal){
@ -134,8 +151,38 @@ export default function Grains() {
rows={supportedGrainTableData} rows={supportedGrainTableData}
page={tablePage} page={tablePage}
pageSize={tableSize} pageSize={tableSize}
handleRowsPerPageChange={() => {}} columns={[
setPage={() => {}} {
title: "Name",
render: row => <Box>
<Typography>
{row.name}
</Typography>
</Box>
},
{
title: "Group",
render: row => <Box>
<Typography>
{row.group}
</Typography>
</Box>
},
{
title: "Equation",
render: row => <Box>
<Typography>
{equationName(row.equation ?? 0)}
</Typography>
</Box>
}
]}
handleRowsPerPageChange={(e) => {
setTableSize(e.target.value)
}}
setPage={(page) => {
setTablePage(page)
}}
total={tableTotal} total={tableTotal}
/> />
) )