public static HtmlString Table(this HtmlHelper helper, int size, NumericRepresentation representation = NumericRepresentation.Decimal)
        {
            var tagBuilder = new TagBuilder("table");

            tagBuilder.Attributes.Add("class", "table table-bordered FormatTable");
            var ta = new TagBuilder("table");

            GenerateHtml(0, size + 1, tagBuilder, representation);
            return(new HtmlString(tagBuilder.ToString()));
        }
Exemple #2
0
        public NumericRepresentationValue Simplify(NumericRepresentation representation, IEnumerable <UnitOfMeasureComponent> components, double value)
        {
            var finalValue = value;
            var unitOfMeasureComponents = new Dictionary <string, UnitOfMeasureComponent>();

            foreach (var component in components)
            {
                finalValue = SimplifyComponent(component, unitOfMeasureComponents, finalValue);
            }

            var baseNumber = CombineComponents(unitOfMeasureComponents.Values.ToList(), finalValue);

            return(new NumericRepresentationValue(representation, baseNumber.UnitOfMeasure, baseNumber));
        }
Exemple #3
0
        private static NumericRepresentationValue GetAccuracy(decimal?accuracyValue)
        {
            if (!accuracyValue.HasValue || accuracyValue < 0m || accuracyValue > 65m)
            {
                return(null);
            }
            double accuracy = Convert.ToDouble(accuracyValue.Value);

            var accuracyUnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("m");
            var numericValue          = new NumericValue(accuracyUnitOfMeasure, accuracy);
            var numericRepresentation = new NumericRepresentation
            {
                DecimalDigits = 1,
                MaxValue      = new NumericValue(accuracyUnitOfMeasure, 65),
                MinValue      = new NumericValue(accuracyUnitOfMeasure, 0),
            };

            return(new NumericRepresentationValue(numericRepresentation, numericValue.UnitOfMeasure, numericValue));
        }
        public void GivenSerializedRasterLayesrWhenConvertToReferenceLayerThenNumericRepresentationsAreConverted()
        {
            var serialzedReferenceLayer = new SerializableReferenceLayer();
            var numericRepresentation1  = new NumericRepresentation
            {
                Description     = "First One",
                Code            = "Code1",
                CodeSource      = RepresentationCodeSourceEnum.ISO11783_DDI,
                LongDescription = "Long Description 1"
            };

            var numericRepresentation2 = new NumericRepresentation
            {
                Description     = "Second One",
                Code            = "Code2",
                CodeSource      = RepresentationCodeSourceEnum.ADAPT,
                LongDescription = "Long Description 2"
            };

            serialzedReferenceLayer.NumericValueValues = new List <SerializableRasterData <NumericValue> >
            {
                new SerializableRasterData <NumericValue> {
                    Representation = numericRepresentation1
                },
                new SerializableRasterData <NumericValue> {
                    Representation = numericRepresentation2
                }
            };
            serialzedReferenceLayer.ReferenceLayer = _referenceLayer;

            var referenceLayer = _converter.ConvertToReferenceLayer(serialzedReferenceLayer) as RasterReferenceLayer;

            for (int rasterDataIndex = 0;
                 rasterDataIndex < serialzedReferenceLayer.NumericValueValues.Count;
                 rasterDataIndex++)
            {
                var serializableData   = serialzedReferenceLayer.NumericValueValues[rasterDataIndex];
                var referenceLayerData = referenceLayer.NumericRasterValues[rasterDataIndex];

                Assert.AreSame(serializableData.Representation, referenceLayerData.Representation);
            }
        }
Exemple #5
0
        private static NumericRepresentationValue GetAccuracy(string accuracyValue)
        {
            double accuracy;

            if (accuracyValue.ParseValue(out accuracy) == false ||
                accuracy < 0 || accuracy > 65)
            {
                return(null);
            }

            var accuracyUnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("m");
            var numericValue          = new NumericValue(accuracyUnitOfMeasure, accuracy);
            var numericRepresentation = new NumericRepresentation
            {
                DecimalDigits = 1,
                MaxValue      = new NumericValue(accuracyUnitOfMeasure, 65),
                MinValue      = new NumericValue(accuracyUnitOfMeasure, 0),
            };

            return(new NumericRepresentationValue(numericRepresentation, numericValue.UnitOfMeasure, numericValue));
        }
Exemple #6
0
 public MultiplyViewModel(int size, NumericRepresentation representation)
 {
     Size           = size;
     Representation = representation;
 }
Exemple #7
0
 public MultiplyViewModel()
 {
     Size           = 10;
     Representation = NumericRepresentation.Decimal;
 }
Exemple #8
0
        public static NumericRepresentationValue Multiply(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue right, NumericRepresentation numericRepresentation)
        {
            var product = numericRepresentationValue.Multiply(right);

            return(new NumericRepresentationValue(numericRepresentation, product.Value));
        }
Exemple #9
0
        public static NumericRepresentationValue Divide(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue denominator, NumericRepresentation numericRepresentation)
        {
            var quotient = numericRepresentationValue.Value.Divide(denominator.Value);

            return(new NumericRepresentationValue(numericRepresentation, quotient));
        }
        private static void GenerateHtml(int current, int size, TagBuilder tagBuilder, NumericRepresentation representation)
        {
            var tr = new TagBuilder("tr");

            if (current == 0)// Create the headers
            {
                for (var i = 0; i < size; i++)
                {
                    var th = new TagBuilder("th");
                    if (i > 0)
                    {
                        th.Attributes.Add("class", "cyanColor");
                    }

                    th.SetInnerText((i == 0 ? "X" : i.ToString()));
                    tr.InnerHtml += th.ToString();
                }
            }
            else
            {
                for (var i = 0; i < size; i++)
                {
                    var td = new TagBuilder("td");

                    if (i == 0)
                    {
                        td.Attributes.Add("class", "cyanColor");
                        td.SetInnerText(current.ToString());
                    }
                    else
                    {
                        var valueToFormat = current * i;
                        var formatedValue = GetRepresentation(valueToFormat, representation);
                        var strPrime      = string.Empty;

                        if (IsPrime(valueToFormat))
                        {
                            td.Attributes.Add("class", "primeColor");
                            strPrime = "Prime Number\n";
                        }

                        td.Attributes.Add("data-toggle", "tooltip");
                        td.Attributes.Add("title", $"{strPrime}{current} x {i} = {valueToFormat} {((representation == NumericRepresentation.Decimal) ? "" : $"({formatedValue} {representation})")}");
                        td.SetInnerText(formatedValue);
                    }

                    tr.InnerHtml += td.ToString();
                }
            }
Exemple #11
0
        public ActionResult RefreshDisplayTable(int size, NumericRepresentation representation)
        {
            var entity = new MultiplyViewModel(size, representation);

            return(View("Index", entity));
        }
        public static ApplicationDataModel.Representations.NumericRepresentation ToModelRepresentation(this NumericRepresentation representation)
        {
            var numericRepresentation = new ApplicationDataModel.Representations.NumericRepresentation
            {
                Code        = representation.DomainId,
                Description = representation.Description,
            };

            numericRepresentation.Id.UniqueIds.Add(new UniqueId
            {
                Id         = representation.DomainId,
                CiTypeEnum = CompoundIdentifierTypeEnum.LongInt,
                Source     = "http://dictionary.isobus.net/isobus/",
                SourceType = IdSourceTypeEnum.URI
            });

            return(numericRepresentation);
        }
 public static ApplicationDataModel.Representations.NumericRepresentation ToModelRepresentation(this NumericRepresentation representation)
 {
     return(new ApplicationDataModel.Representations.NumericRepresentation
     {
         Code = representation.DomainId,
         Description = representation.Description,
     });
 }
        public static void Export(string path)
        {
            ApplicationDataModel adm = new ApplicationDataModel();

            adm.Catalog   = new Catalog();
            adm.Documents = new Documents();

            //--------------------------
            //Setup information
            //--------------------------
            //Add a crop
            Crop corn = new Crop()
            {
                Name = "Corn"
            };

            adm.Catalog.Crops.Add(corn);

            //Add some seed varieties
            CropVarietyProduct seedVariety1 = new CropVarietyProduct()
            {
                CropId = corn.Id.ReferenceId, Description = "Variety 1"
            };
            CropVarietyProduct seedVariety2 = new CropVarietyProduct()
            {
                CropId = corn.Id.ReferenceId, Description = "Variety 2"
            };

            adm.Catalog.Products.Add(seedVariety1);
            adm.Catalog.Products.Add(seedVariety2);

            //Add a liquid product
            CropNutritionProduct fertilizer = new CropNutritionProduct()
            {
                Description = "Starter", Form = ProductFormEnum.Liquid
            };

            fertilizer.ProductType = ProductTypeEnum.Fertilizer;
            adm.Catalog.Products.Add(fertilizer);

            //Add a granular product
            CropProtectionProduct insecticide = new CropProtectionProduct()
            {
                Description = "Insecticide", Form = ProductFormEnum.Solid
            };

            insecticide.ProductType = ProductTypeEnum.Chemical;
            adm.Catalog.Products.Add(insecticide);

            //GFF
            Grower grower = new Grower()
            {
                Name = "Example Grower"
            };

            adm.Catalog.Growers.Add(grower);

            Farm farm = new Farm()
            {
                Description = "Example Farm", GrowerId = grower.Id.ReferenceId
            };

            adm.Catalog.Farms.Add(farm);

            Field field = new Field()
            {
                Description = "Example Field", FarmId = farm.Id.ReferenceId, GrowerId = grower.Id.ReferenceId
            };

            field.Area = GetNumericRepresentationValue(23d, "ha", "vrReportedFieldArea");
            adm.Catalog.Fields.Add(field);

            //Crop zone
            TimeScope season = new TimeScope()
            {
                DateContext = DateContextEnum.CropSeason, TimeStamp1 = new DateTime(2021, 1, 1)
            };
            CropZone cropZone = new CropZone()
            {
                CropId = corn.Id.ReferenceId, FieldId = field.Id.ReferenceId, TimeScopes = new List <TimeScope>()
                {
                    season
                }
            };

            adm.Catalog.CropZones.Add(cropZone);

            //Field boundary
            FieldBoundary boundary = new FieldBoundary()
            {
                SpatialData = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.475010
                                    }
                                }
                            },
                            InteriorRings = new List <LinearRing>()
                            {
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        }
                                    }
                                },
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                FieldId = field.Id.ReferenceId
            };

            adm.Catalog.FieldBoundaries.Add(boundary);
            field.ActiveBoundaryId = boundary.Id.ReferenceId;

            //--------------------------
            //Prescription
            //--------------------------

            //Prescription setup data
            //Setup the representation and units for seed rate & seed depth prescriptions
            NumericRepresentation seedRate = GetNumericRepresentation("vrSeedRateSeedsTarget");
            UnitOfMeasure         seedUOM  = UnitInstance.UnitSystemManager.GetUnitOfMeasure("seeds1ac-1");
            RxProductLookup       seedVariety1RateLookup = new RxProductLookup()
            {
                ProductId = seedVariety1.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM
            };
            RxProductLookup seedVariety2RateLookup = new RxProductLookup()
            {
                ProductId = seedVariety2.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM
            };

            NumericRepresentation seedDepth = GetNumericRepresentation("vrSeedDepthTarget");
            UnitOfMeasure         depthUOM  = UnitInstance.UnitSystemManager.GetUnitOfMeasure("cm");
            RxProductLookup       seedVariety1DepthLookup = new RxProductLookup()
            {
                ProductId = seedVariety1.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM
            };
            RxProductLookup seedVariety2DepthLookup = new RxProductLookup()
            {
                ProductId = seedVariety2.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM
            };

            //Setup liquid rx representation/units
            NumericRepresentation fertilizerRate       = GetNumericRepresentation("vrAppRateVolumeTarget");
            UnitOfMeasure         fertilizerUOM        = UnitInstance.UnitSystemManager.GetUnitOfMeasure("gal1ac-1");
            RxProductLookup       fertilizerRateLookup = new RxProductLookup()
            {
                ProductId = fertilizer.Id.ReferenceId, Representation = fertilizerRate, UnitOfMeasure = fertilizerUOM
            };

            //Setup granular rx representation/units
            NumericRepresentation insecticideRate       = GetNumericRepresentation("vrAppRateMassTarget");
            UnitOfMeasure         insecticideUOM        = UnitInstance.UnitSystemManager.GetUnitOfMeasure("lb1ac-1");
            RxProductLookup       insecticideRateLookup = new RxProductLookup()
            {
                ProductId = insecticide.Id.ReferenceId, Representation = insecticideRate, UnitOfMeasure = insecticideUOM
            };


            //Prescription zones
            //Zone 1 - Variety 1 at 32000 seeds/acre, 4 cm depth target; Starter at 7 gal/ac; Insecticide at 5 lb/ac
            RxShapeLookup zone1 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 32000d,
                        RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 4d,
                        RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 7d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 5d,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.478304
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.477404
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.478304
                                    }
                                }
                            },
                            InteriorRings = new List <LinearRing>()
                            {
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.478091
                                        },
                                        new Point()
                                        {
                                            X = -89.487536, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.477960
                                        },
                                        new Point()
                                        {
                                            X = -89.487719, Y = 40.478091
                                        }
                                    }
                                },
                                new LinearRing()
                                {
                                    Points = new List <Point>()
                                    {
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478172
                                        },
                                        new Point()
                                        {
                                            X = -89.486453, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478082
                                        },
                                        new Point()
                                        {
                                            X = -89.486732, Y = 40.478172
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Zone 2 - Variety 1 at 34000 seeds/acre, depth target 5cm; Starter at 4 gal/ac; Insecticide at 2.5 lb/ac
            RxShapeLookup zone2 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 34000d,
                        RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 5d,
                        RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 4d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 2.5,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.477404
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.477756
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Zone 3 - Variety 2 at 29000 seeds/acre, depth target 6 cm; Starter at 6 gal/ac ; Insecticide at 2.75 lb/ac
            RxShapeLookup zone3 = new RxShapeLookup()
            {
                Rates = new List <RxRate>()
                {
                    new RxRate()
                    {
                        Rate = 29000d,
                        RxProductLookupId = seedVariety2RateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 6d,
                        RxProductLookupId = seedVariety2DepthLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 6d,
                        RxProductLookupId = fertilizerRateLookup.Id.ReferenceId
                    },
                    new RxRate()
                    {
                        Rate = 2.75,
                        RxProductLookupId = insecticideRateLookup.Id.ReferenceId
                    }
                },
                Shape = new MultiPolygon()
                {
                    Polygons = new List <Polygon>()
                    {
                        new Polygon()
                        {
                            ExteriorRing = new LinearRing()
                            {
                                Points = new List <Point>()
                                {
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.476688
                                    },
                                    new Point()
                                    {
                                        X = -89.485439, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.475010
                                    },
                                    new Point()
                                    {
                                        X = -89.488565, Y = 40.476688
                                    }
                                }
                            }
                        }
                    }
                }
            };

            //Assembled Rx
            VectorPrescription vectorPrescription = new VectorPrescription()
            {
                Description      = "Test Prescription",
                RxProductLookups = new List <RxProductLookup>()
                {
                    seedVariety1RateLookup,
                    seedVariety2RateLookup,
                    fertilizerRateLookup,
                    seedVariety1DepthLookup,
                    seedVariety2DepthLookup,
                    insecticideRateLookup
                },
                RxShapeLookups = new List <RxShapeLookup>()
                {
                    zone1, zone2, zone3
                },
                CropZoneId = cropZone.Id.ReferenceId,
                FieldId    = field.Id.ReferenceId
            };

            (adm.Catalog.Prescriptions as List <Prescription>).Add(vectorPrescription);

            //--------------------------
            //Export data to file via the Plugin
            //--------------------------
            PrecisionPlanting.ADAPT._2020.Plugin plugin = new Plugin();
            plugin.Export(adm, path);
        }
 public NumericRepresentationValue(NumericRepresentation representation, UnitOfMeasure userProvidedUnitOfMeasure, NumericValue value)
 {
     Representation = representation;
     UserProvidedUnitOfMeasure = userProvidedUnitOfMeasure;
     Value = value;
 }
 public NumericRepresentationValue(NumericRepresentation representation, NumericValue value)
 {
     Representation = representation;
     Value = value;
 }