Insights Detail
Insights
Directories:
src/containers/Insights
src/components/Insights
Front End
Components
InsightsInfoComponent
Props Used:
title: string
value: string
valueLabel: string
percent: number (0-100)
Used In:
People Fed
Soil Organic Matter
Labour Happiness
Biodiversity
BalanceBarComponent
Props used:
value: number
unit: string
Used In:
Water Balance
Nitrogen Balance
FrequencySelectorComponent
Props used:
None
Used In:
Nitrogen Balance
InfoBoxComponent
Props used:
title: string
body: string
showSave: boolean
showDelete: boolean
Used In:
All of the Insights Containers
LabourHappinessTask
Props used:
title: string
mood: number
Used In:
Labour Happiness
NitrogenBalanceInfo
Props used:
title: string
PriceCropContainer
Props used:
cropData: Crop Object
PriceDistanceComponent
Props Used:
None
Saga Calls
Saga Call | Description |
---|---|
getCropsSoldNutrition | Get Crops Sold for Farm |
getSoilOMData | Get Soil OM for Farm |
getLabourHappinessData | Get Labour Happiness for Farm |
getBiodiversityData | Get Biodiversity Data for Farm |
getPricesData | Get All Prices Data for Farm (Excluding Distance) |
getPricesWithDistanceData | Get Prices including distances for Farm |
getWaterBalanceData | Get Water Balance Data for Farm |
getNitrogenBalanceData | Get Nitrogen Balance Data for Farm |
createWaterBalanceSchedule | Create Water Balance Schedule for Farm |
getNitrogenBalanceFrequency | Get Nitrogen Balance Schedule for Farm |
postNitrogenBalanceFrequency | Create Nitrogen Balance Schedule for Farm |
deleteNitrogenBalanceFrequency | Delete Nitrogen Balance Schedule for Farm |
Back End
API Endpoints:
Method | Endpoint | Information |
---|---|---|
GET | /people_fed/:farm_id | Grabs People Fed Info based on a FarmID |
GET | /labour_happiness/:farm_id | Grabs Labour Happiness based on a FarmID |
GET | /biodiversity/:farm_id | Grabs Biodiversity based on a FarmID |
GET | /prices/distance/:farm_id | Grabs a persons prices based on FarmID |
GET | /waterbalance/:farm_id | Grabs a persons water balance based on FarmID |
GET | /waterbalance/schedule/:farm_id | Grabs a persons water balance schedule based on FarmID |
GET | /nitrogenbalance/:farm_id | Grabs a persons nitrogen balance data based on FarmID |
GET | /nitrogenbalance/schedule/:farm_id | Grabs a persons nitrogen balance scheduled based on FarmID |
POST | /waterbalance | Adds a water balance calculation |
POST | /waterbalance/schedule | Adds a water balance schedule |
POST | /nitrogenbalance/schedule | Adds a nitrogen balance schedule |
DEL | /nitrogenbalance/schedule/:id | Deletes a nitrogen balance schedule based on the nitrogen schedule ID |
Submodules:
People Fed
In People Fed, we calculate how many meals the farmer has fed based off their cropSale and harvest logs using crop nutritional data
This equation is derived from ./src/controllers/insightHelpers.js
A persons expected intake for nutrition:
- Calories: 2500 kcal
- Protein: 52g
- Fat: 750g
- Vitamin C: 90mg
- Vitamin A: 900mg
For every crop that the farmer has sold:
percentLeft = 1 - crop.percentRefuse
Calculate the nutritional value by taking each crop nutritional value:
crop.Calories = (crop.energy * 10) * crop.quantity_kg * percentLeft
crop.Protein = (crop.protein * 10) * crop.quantity_kg * percentLeft
crop.Fat = (crop.lipid * 10) * crop.quantity_kg * percentLeft
crop.VitaminC = (crop.vitc * 10) * crop.quantity_kg * percentLeft
crop.VitaminA = (crop.vita_rae * 10) * crop.quantity_kg * percentLeft
Take each of these values:
crop.MEAL = crop.NUTRITION / (expectedIntake.NUTRITION / MEALS_PER_DAY)
Assume Nutrition is one of: Calories, Protein, Fat, VitC, VitA
Assume Meals Per Day is 3
Prices
In Prices, we compare the farms sales with the rest of the sales in the network based on their proximity setting in the app.
The algorithm organizes the sales into its crop and month/year and displays it as a graph on the front end
This equation is derived from ./src/controllers/insightHelpers.js
For each crop the algorithm grabs:
quantity sold, quantity value, date sold
The algorithm first checks if the crop is a cropSale in my farm.
It then keeps two running sums, one for the farmers crops, and another for the network crops
After, it totals the quantity sold, quantity value based off the date sold.
Finally, it takes totalQuantity / totalValue as well as networkQuantity / networkValue
Water Balance
In Water Balance, we use soil data logs, weather data, and crop nutritional data to make an estimate on the crops plant available water.
This equation is derived from ./src/jobs/waterBalance/waterBalance.js
There are <b>two</b> types of cron jobs that are run everyday
Hourly Weather Calculations
Daily Water Balance Calculation
Hourly Calculation
The algorithm is run hourly pulling weather data from OpenWeatherMap API
The algorithm saves these values into the database based on each field registered
Daily Calculation
The algorithm runs a daily calculation based off equations from cited sources below
This algorithm calculates the water balance for each crop
This algorithm then puts a number in our backend DB in the Water Balance Table
References:
Plant Available Water
Soil Water Content
Wilting Point
Field Capacity
Precipitation
Evapotranspiration
Elevation Data
Wind Speed
Extra T Solar Radiation
Solar Radiation
Slope
Psychometric Constant
Saturated Vapour Pressure
Actual Vapour Pressure
RNL
RNS
Additional in-depth documentation (by @Brandon Tai (Unlicensed) )
The water balance insight serves to help farmers observe the water content in the soil of their locations. A centerpiece of this algorithm is the texture of the soil, which is reported to LiteFarm through soil data logs. When creating a soil data log, the farmer will be prompted to select one of a fixed list of textures. Possible values to select include “Sand”, “Loamy Sand”, “Silt”, and “Clay Loam”. The water balance algorithm involves a handful of lengthy and specific calculations that will plug in the values of the sand content, the clay content, and the silt content of the soil. The chosen texture of a log will determine these three values. The values that are used are shown in the following table:
Texture | Sand % | Clay % |
---|---|---|
Sand | 88 | 5 |
Loamy Sand | 80 | 5 |
Sandy Loam | 65 | 10 |
Loam | 40 | 20 |
Silt Loam | 20 | 15 |
Silt | 10 | 5 |
Sandy Clay Loam | 60 | 25 |
Clay Loam | 30 | 35 |
Silty Clay Loam | 10 | 35 |
Sandy Clay | 10 | 45 |
Silty Clay | 50 | 40 |
Clay | 25 | 50 |
The silt percentage can be determined by calculating the amount that is neither sand nor clay. For example, sandy loam is 65% sand and 10% clay, so silt percentage is 100% - 65% - 10% = 25%.
Unfortunately, the texture of soil is not so clear cut and are not necessarily confined to these values alone. This can be demonstrated with the soil triangle, which can be found here.
To sum up the problem, there is a lack of granularity within the water balance algorithm due to the fact that textures are fixed to specific sand, clay, and silt values. To present an example that demonstrates this, consider a farmer who has measured the sand, clay, and silt content of their soil and determined the percentages to be 5, 90, and 5 respectively. According to the triangle figure, this is classified to be “clay”. However, when this soil data is reported to be “clay” in the LiteFarm log, the calculation will always use 25% sand and 50% clay, which differs pretty significantly to the values that the farmer measured.
This presents room for improvement for the water balance calculation: allow soil data logs to take input for more information, namely the specific clay and sand percentages of the soil. This will allow more accurate calculations and more granularity of information. There is a caveat, which is that more granular information will not work with the equations that exist in the code currently, and the insight algorithm will likely need to be redone from scratch, with the help of a specialist.
To sum the situation up, the current water balance calculation works properly with fixed texture values, and will provide an adequate approximation for the water balance, and aiming for a more accurate value may require an overhaul of the equations that currently exist.
Nitrogen Balance
In Nitrogen Balance, it is very similar to Water Balance as there one daily job.
References:
Daily Calculation
Nitrogen In
Nitrogen Out
Additional in-depth documentation (by @Brandon Tai (Unlicensed) )
The nitrogen balance insight acts as an indicator to a farmer on the balance of nitrogen in the soil of a location on their farm, as the name entails. The algorithm for this insight is run daily for each farm and will save a nitrogen value for each location of a farm that resulted in a non-trivial value. The calculation can be summed up as simply being the difference between how much nitrogen is going into the soil (typically through the application of fertilizers) and how much nitrogen is being taken out (usually through harvests). As such, this can be broken down as the calculations of the nitrogen in value and the nitrogen out value.
Nitrogen In
There are three factors that play into the addition of nitrogen content into the soil:
Fertilizer (e.g. manure)
Cover crops
Legumes
Fertilizers is accounted for through fertilizer logs. The algorithm will take fertilizer logs that exist for a location and use the nitrogen percentage (denoted by n_percentage
in the fertilizer
table), ammonium content measured in ppm (denoted by nh4_n_ppm
in the fertilizer
table), and the mineralization rate (denoted by mineralization_rate
in the fertilizer
table). Usually, nitrate content is taken into account, but since most fertilizers have negligible amounts of nitrate, this value is set to zero in the code’s calculations.
After consulting with a specialist, an improvement that can be made to the fertilizer’s part of the nitrogen in calculation is calculating the dry weight of a given fertilizer when calculating currentTotalNitrogen
. Currently, the code calculates this value as quantity_kg * n_percentage / 100
instead of accounting for the moisture percentage of the fertilizer:
Cover crops are defined as “plants that are planted to cover the soil rather than for the purpose of being harvested” (taken from Wikipedia). Once cover crops are finished growing, they will be crunched into the ground for the benefit of the soil. One such benefit is adding nitrogen content, and this value can be derived by calculating how much cover crop is being planted in a location (usually calculated upon location crop creation) and multiplying that value by some factor of the amount of nitrogen credits that the cover crop provides. Currently, LiteFarm does not support the tracking of cover crops and does not have nitrogen credit values assigned to the various crops in the database. A more accurate calculation can be achieved once a system has been designed for cover crop tracking in the future.
Legumes are subgroup of crops that possess a unique property of taking nitrogen from the air and into the soil in the duration between their seeding and their harvest. That is the say, when a legume is planted and harvested, some amount of nitrogen content will be restored to the soil. This is one method through which extra nitrogen content, known as nitrogen credits, can be gained (the other method being cover crops). Currently, any crop that has a non-zero nutrient credit value (denoted by nutrient_credits
in the crop
table) will factor into the nitrogen in calculation if it is at some point planted and harvested in a location.
Here is a list of crops that have non-zero nutrient credit values, from the seeded data only:
To sum up the nitrogen in calculation, there are three primary factors that contribute to the final value, most of which is being calculated properly. Fertilizer should take only take into account its dry weight when calculating the nitrogen quantity, but otherwise the calculations accounting for fertilizers have been verified to be accurate. Cover crops can be accounted for once a way to track them has been designed and implemented in LiteFarm. Lastly, legumes are being properly accounted for.
Nitrogen Out
Calculating nitrogen out involves less distinct factors as compared to calculating nitrogen in. In summary, when a crop is planted, grown, and harvested, it will remove some amount of nitrogen from the soil. Calculations are performed on harvest logs. As shown in the abridged version above, the size of a harvest, the refuse, and the protein content of a crop are plugged into an equation to return the nitrogen out value. The algorithm has been verified with the exception of the refuse factor. Due to time running out for the interview with the specialist, we are unable to ascertain the significance of refuse in general, let alone within the algorithm.
Finally, a thank you to the specialist we interviews, Sean Smukler, for taking the time to discuss the nitrogen balance algorithm and provide insight on how it can be improved.
Labour Happiness
Soil Organic Matter
The algorithm calls SoilGridsAPI to grab organic matter data for the soil. This API accepts a latitude and longitude input and returns an integer for soil OM (e.g. 9).