1.2.11.10 Golf Courses

This commit is contained in:
2024-06-18 18:08:11 +01:00
parent 1c77a2b2e9
commit 8f73e616ca
56 changed files with 802 additions and 316 deletions
@@ -303,11 +303,11 @@ namespace Saxonite.Net.Core.Web.Base.Procs
{
if (usgaCountry != null)
{
markersData = usgaDataLookup.LookupUsgaMarkersForCourse(usgaCourse.CourseId);
markersData = usgaDataLookup.LookupUsgaMarkersForCourse(usgaCourse.UsgaCourseId);
List<String> annotations = new List<string>();
if (usgaCourse.Priority) annotations.Add("Priority");
if (fallback) annotations.Add("Fallback");
SaLogger.Info($"{SysUtil.Fn} USGA Markers " + (refresh ? "refreshed" : "populated") + $" for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName} - {usgaCourse.Caption} [Id: {usgaCourse.CourseId}" + (annotations.Any() ? $"{annotations.Concat("",", ")}" : "") + $"]: {markersData.Count}.", true);
SaLogger.Info($"{SysUtil.Fn} USGA Markers " + (refresh ? "refreshed" : "populated") + $" for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName} - {usgaCourse.Caption} [Id: {usgaCourse.UsgaCourseId}" + (annotations.Any() ? $"{annotations.Concat("",", ")}" : "") + $"]: {markersData.Count}.", true);
}
else SaLogger.Error($"{SysUtil.Fn} Missing Country for Province {usgaProvince.ProvinceName}. Country Id: {usgaProvince.CountryId}.");
}
@@ -78,12 +78,12 @@ namespace Saxonite.Net.Core.Web.Base.Procs
public class CourseData
{
public string CourseId { get; set; }
public string UsgaCourseId { get; set; }
public string LegacyCrpCourseId { get; set; }
public string Caption { get; set; }
public string CourseName { get; set; }
public string FullName { get; set; }
public string FacilityId { get; set; }
public string UsgaFacilityId { get; set; }
public string FacilityName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
@@ -126,7 +126,7 @@ namespace Saxonite.Net.Core.Web.Base.Procs
//if (!SysId.IsValid(MarkerId)) return false;
if (Holes < 1) return false;
if (StringUtil.IsBlank(Tee)) return false;
if (StringUtil.IsBlank(Gender)) return false;
//if (StringUtil.IsBlank(Gender)) return false;
if (SlopeRating == 0) return false;
if (!ignorePar && Par == 0) return false;
if (CourseRating == 0) return false;
@@ -395,7 +395,10 @@ namespace Saxonite.Net.Core.Web.Base.Procs
ReferenceGolfMgr.BulkUpdateUsgaProvinces(provincesData, DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Provinces updates OK.
// Provinces stored OK = update Country.
usgaCountry.ProvincesUpdateAt = DateTime.Now;
usgaCountry.Priority = false;
ReferenceGolfMgr.UpdateUsgaCountry(usgaCountry, DbUpdateInfo);
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA provinces: {ReferenceGolfMgr.ErrorStateMessage}.");
}
@@ -487,13 +490,13 @@ namespace Saxonite.Net.Core.Web.Base.Procs
String propertyName = courseProperty.Name;
String propertyStringValue = StringUtil.TrimWhitespace(courseProperty.Value.ToString());
if (propertyName.EqualsCI("courseId"))
courseData.CourseId = propertyStringValue;
courseData.UsgaCourseId = propertyStringValue;
else if (propertyName.EqualsCI("legacyCRPCourseId"))
courseData.LegacyCrpCourseId = propertyStringValue;
else if (propertyName.EqualsCI("courseName"))
courseData.CourseName = propertyStringValue;
else if (propertyName.EqualsCI("facilityId"))
courseData.FacilityId = propertyStringValue;
courseData.UsgaFacilityId = propertyStringValue;
else if (propertyName.EqualsCI("facilityName"))
courseData.FacilityName = propertyStringValue;
else if (propertyName.EqualsCI("fullName"))
@@ -526,7 +529,7 @@ namespace Saxonite.Net.Core.Web.Base.Procs
else UnrecognisedCourseProperties.Add(propertyName);
}
}
if (!StringUtil.IsBlank(courseData.CourseId) && !StringUtil.IsBlank(courseData.CourseName))
if (!StringUtil.IsBlank(courseData.UsgaCourseId) && !StringUtil.IsBlank(courseData.CourseName))
{
// Populate caption and add to list.
SetCourseCaption(courseData);
@@ -569,17 +572,17 @@ namespace Saxonite.Net.Core.Web.Base.Procs
Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData> facilitiesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.FacilityId)) continue;
if (StringUtil.IsBlank(usgaCourse.UsgaFacilityId)) continue;
SaxReferenceGolfMgr.UsgaFacilityData facilityData = new SaxReferenceGolfMgr.UsgaFacilityData();
facilityData.ProvinceCode = provinceCode;
facilityData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
facilityData.UsgaFacilityId = StringUtil.ToSysId(usgaCourse.UsgaFacilityId);
facilityData.FacilityName = usgaCourse.FacilityName;
if (!SysId.IsValid(facilityData.FacilityId))
if (!SysId.IsValid(facilityData.UsgaFacilityId))
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Facility Id for {usgaCourse.CourseName}: {usgaCourse.FacilityId}.");
SaLogger.Warn($"{SysUtil.Fn} Invalid Facility Id for {usgaCourse.CourseName}: {usgaCourse.UsgaFacilityId}.");
continue;
}
facilitiesData[facilityData.FacilityId] = facilityData;
facilitiesData[facilityData.UsgaFacilityId] = facilityData;
}
ReferenceGolfMgr.BulkUpdateUsgaFacilities(facilitiesData.Values.ToList(), DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
@@ -589,10 +592,10 @@ namespace Saxonite.Net.Core.Web.Base.Procs
Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData> coursesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.CourseId)) continue;
if (StringUtil.IsBlank(usgaCourse.UsgaCourseId)) continue;
SaxReferenceGolfMgr.UsgaCourseData courseData = new SaxReferenceGolfMgr.UsgaCourseData();
courseData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
courseData.CourseId = StringUtil.ToSysId(usgaCourse.CourseId);
courseData.UsgaFacilityId = StringUtil.ToSysId(usgaCourse.UsgaFacilityId);
courseData.UsgaCourseId = StringUtil.ToSysId(usgaCourse.UsgaCourseId);
courseData.LegacyCrpCourseId = StringUtil.ToSysId(usgaCourse.LegacyCrpCourseId);
courseData.Caption = usgaCourse.Caption;
courseData.CourseName = usgaCourse.CourseName;
@@ -602,17 +605,20 @@ namespace Saxonite.Net.Core.Web.Base.Procs
courseData.City = usgaCourse.City;
courseData.Email = usgaCourse.Email;
courseData.Telephone = usgaCourse.Telephone;
if (!SysId.IsValid(courseData.CourseId))
if (!SysId.IsValid(courseData.UsgaCourseId))
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Course Id for {usgaCourse.CourseName}: {usgaCourse.CourseId}.");
SaLogger.Warn($"{SysUtil.Fn} Invalid Course Id for {usgaCourse.CourseName}: {usgaCourse.UsgaCourseId}.");
continue;
}
coursesData[courseData.CourseId] = courseData;
coursesData[courseData.UsgaCourseId] = courseData;
}
ReferenceGolfMgr.BulkUpdateUsgaCourses(coursesData.Values.ToList(), DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Courses updates OK.
// Courses stored OK - update Province.
usgaProvince.CoursesUpdateAt = DateTime.Now;
usgaProvince.Priority = false;
ReferenceGolfMgr.UpdateUsgaProvince(usgaProvince, DbUpdateInfo);
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA courses: {ReferenceGolfMgr.ErrorStateMessage}.");
}
@@ -646,15 +652,13 @@ namespace Saxonite.Net.Core.Web.Base.Procs
/// <summary>
/// Cleanse Facility name by removing generic phrases, eg. golf club, hotel etc.
/// </summary>
private String CleanseFacilityName(String facilityName)
public static String CleanseFacilityName(String facilityName)
{
facilityName = Regex.Replace(facilityName, "Hotel\\s*(and|&)\\s*(Golf|Country)\\s*Club", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Hotel,*\\s*Golf\\s*(and|&)\\s*Spa", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf\\s*(and|&)\\s*(Country|Sailing)\\s*Club", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf\\s*Club\\s*(and|&)\\s*Hotel", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf\\s*Club\\s*Ltd", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf\\s*(Club|Course|Links|Centre|Academy|Resort|Klub)", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Hotel(,\\s*Golf)?\\s*(and|&)\\s*(Golf|Country|Sailing|Spa)(\\s*Club)?", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf(\\s*Club)?\\s*(and|&)\\s*(Hotel|Country|Sailing|Spa)\\s*Club", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Golf\\s*(Club|Course|Links|Centre|Academy|Resort|Klub)(\\s*(Ltd|Limited))?", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "Club\\s*de\\s*Golf", "", RegexOptions.IgnoreCase);
facilityName = Regex.Replace(facilityName, "\\s*(Golf|Country\\s*Club|Club|Ltd)\\s*$", "", RegexOptions.IgnoreCase);
return StringUtil.TrimWhitespace(facilityName);
}
@@ -675,6 +679,8 @@ namespace Saxonite.Net.Core.Web.Base.Procs
if (Regex.Replace(courseName, "[\\s-',\\.]", "").EqualsCI(Regex.Replace(facilityName, "[\\s-',\\.]", ""))) return true;
// Course name can end on Golf or Course and still match facility.
if (Regex.Replace(courseName, "\\s*(Golf|Course)$", "").EqualsCI(facilityName)) return true;
// Course name can start with facility name or vice-versa.
if (courseName.StartsWithCI(facilityName) || facilityName.StartsWithCI(courseName)) return true;
return false;
}
@@ -721,7 +727,7 @@ namespace Saxonite.Net.Core.Web.Base.Procs
{
// Retrieve and validate course.
SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params();
prmCourse.CourseIdsIncluded.Add(usgaCourseId);
prmCourse.UsgaCourseIdsIncluded.Add(usgaCourseId);
SaxGolfUsgaCourse usgaCourse = ReferenceGolfMgr.GetUsgaCourse(prmCourse);
disposableItems.Add(usgaCourse);
if (usgaCourse == null)
@@ -907,8 +913,8 @@ namespace Saxonite.Net.Core.Web.Base.Procs
//if (!SysId.IsValid(usgaMarker.MarkerId)) continue;
if (StringUtil.IsBlank(usgaMarker.Caption)) continue;
SaxReferenceGolfMgr.UsgaMarkerData markerData = new SaxReferenceGolfMgr.UsgaMarkerData();
markerData.CourseId = usgaMarker.CourseId;
markerData.MarkerId = usgaMarker.MarkerId;
markerData.UsgaCourseId = usgaMarker.CourseId;
markerData.UsgaMarkerId = usgaMarker.MarkerId;
markerData.Caption = usgaMarker.Caption;
markerData.Holes = usgaMarker.Holes;
markerData.HolesCaption = usgaMarker.HolesCaption;
@@ -924,17 +930,14 @@ namespace Saxonite.Net.Core.Web.Base.Procs
ReferenceGolfMgr.BulkUpdateUsgaMarkers(markersUpdateData, DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Markers updates OK.
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA markers: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store Marker data and clear Course 'priority' flag.
if (markersData.Markers.Any())
{
usgaCourse.MarkersData = JsonConvert.SerializeObject(markersData);
// Markers stored OK - update Course.
if (markersData.Markers.Any())
usgaCourse.MarkersData = JsonConvert.SerializeObject(markersData);
usgaCourse.MarkersUpdateAt = DateTime.Now;
usgaCourse.Priority = false;
ReferenceGolfMgr.UpdateUsgaCourse(usgaCourse, DbUpdateInfo);
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA markers: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{