/// <summary> convert workstep to json object /// </summary> /// <param name="step">workstep </param> /// <returns></returns> private static JObject CropRoationWorkstepToJSON(CropRoationWorkstep step) { JObject jObject = new JObject( new JProperty("date", step.Isodate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)), new JProperty("type", step.WorkstepType)); if (step.WorkstepType == "Sowing") { if (step.Crop == "BAR") { if (step.IsWinterCrop && step.Crop == "BAR") { jObject.Add(new JProperty("crop", new JArray("ref", "crops", "WG"))); } else { jObject.Add(new JProperty("crop", new JArray("ref", "crops", "SG"))); } } jObject.Add(new JProperty("PlantDensity", new JArray(step.PlantsPerSquareMeter, "plants m-2"))); } if (step.WorkstepType == "Tillage") { jObject.Add(new JProperty("depth", new JArray(0.30, "m"))); } if (step.WorkstepType == "MineralFertilization") { jObject.Add(new JProperty("amount", new JArray(step.FertilizerAmount, "kg N"))); jObject.Add(new JProperty("partition", new JArray("ref", "fert-params", "AN"))); } return(jObject); }
/// <summary> create workstep for given /// </summary> /// <param name="date">(required) date for workstep execution </param> /// <param name="cropID">(required) crop id</param> /// <param name="fertilizerAmount">required for workstep 'fertilizer', else ignored</param> /// <param name="type">type of workstep</param> /// <param name="isWinterCrop">identify if crop is a winter crop</param> /// <param name="plantsPerSqm">required for workstep 'planting' plant per square meter</param> /// <returns>workstep</returns> private static CropRoationWorkstep ExtractCropRoationWorkstep(string date, string cropID, double fertilizerAmount, string type, bool isWinterCrop, double plantsPerSqm) { CropRoationWorkstep cropRoationWorkstep = new CropRoationWorkstep(); cropRoationWorkstep.Isodate = DateTime.ParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); cropRoationWorkstep.Crop = cropID; switch (type) { case "planting": cropRoationWorkstep.WorkstepType = "Sowing"; cropRoationWorkstep.IsWinterCrop = isWinterCrop; cropRoationWorkstep.PlantsPerSquareMeter = plantsPerSqm; break; case "fertilizer": // use MineralFertilization since there is no distinction between organic an mineral cropRoationWorkstep.WorkstepType = "MineralFertilization"; cropRoationWorkstep.FertilizerAmount = fertilizerAmount; break; case "tillage": cropRoationWorkstep.WorkstepType = "Tillage"; break; default: cropRoationWorkstep.WorkstepType = "unknown type"; break; } return(cropRoationWorkstep); }