protected internal Shard(ShardSet set, IConfigSectionNode conf) { m_Set = set.NonNull(nameof(set)); ConfigAttribute.Apply(this, conf.NonEmpty(nameof(conf))); m_Name = conf.ValOf(Configuration.CONFIG_NAME_ATTR).NonBlank("$name"); m_NameHash = ShardKey.ForString(m_Name); m_Weight = conf.Of(CONFIG_WEIGHT_ATTR).ValueAsDouble(1.0d); m_ConnectString = conf.Of(CONFIG_CONNECT_ATTR, CONFIG_CONNECT_STRING_ATTR).Value.NonBlank($"${CONFIG_CONNECT_ATTR}"); m_DatabaseName = conf.Of(CONFIG_DB_ATTR).Value.NonBlank($"${CONFIG_DB_ATTR}"); }
/// <summary> /// Here we implement pattern matching score logic. The higher = the better the match. /// The 'pattern' parameter delivers the config vector from [StrategyPattern(....)] candidates /// </summary> public double GetPatternMatchScore(IConfigSectionNode pattern) { //for flexibility: attribute is optional var center = pattern.ValOf("center"); if (center.IsNullOrWhiteSpace()) { return(0); } //calc the distance between to LAT/LNG in KM var distance = Location.HaversineEarthDistanceKm(new LatLng(center)); //the smaller the distance - the higher the score var ratio = LatLng.EARTH_CIRCUMFERENCE_KM / (distance == 0 ? 0.001 : distance); return(ratio);//is the score for this case }
/// <summary> /// By sister city names /// </summary> public double GetPatternMatchScore(IConfigSectionNode pattern) => Location.Name.EqualsIgnoreCase(pattern.ValOf("sister")) ? 10000 : 0;